Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!isInboxEnabled) {
// the recipient's inbox is disabled
return left(
RecipientError("Recipient inbox is disabled.")
);
}
// whether the user has blocked inbox storage for messages from this sender
const isMessageStorageBlockedForService = blockedInboxOrChannels.has(
BlockedInboxOrChannelEnum.INBOX
);
if (isMessageStorageBlockedForService) {
// the recipient's inbox is disabled
return left(
RecipientError("Sender is blocked by recipient.")
);
}
// Save the content of the message to the blob storage.
// In case of a retry this operation will overwrite the message content with itself
// (this is fine as we don't know if the operation succeeded at first)
const errorOrAttachment = await lMessageModel.attachStoredContent(
lBlobService,
newMessageWithoutContent.id,
newMessageWithoutContent.fiscalCode,
createdMessageEvent.content
);
if (isLeft(errorOrAttachment)) {
return left(
TransientError("Cannot store message content")
);
"handleMessage|Blocked Channels(%s): %s",
newMessageWithoutContent.fiscalCode,
JSON.stringify(blockedInboxOrChannels)
);
//
// Inbox storage
//
// a profile exists and the global inbox flag is enabled
const isInboxEnabled = profile.isInboxEnabled === true;
if (!isInboxEnabled) {
// the recipient's inbox is disabled
return left(
RecipientError("Recipient inbox is disabled.")
);
}
// whether the user has blocked inbox storage for messages from this sender
const isMessageStorageBlockedForService = blockedInboxOrChannels.has(
BlockedInboxOrChannelEnum.INBOX
);
if (isMessageStorageBlockedForService) {
// the recipient's inbox is disabled
return left(
RecipientError("Sender is blocked by recipient.")
);
}
// Save the content of the message to the blob storage.
if (isLeft(errorOrMaybeProfile)) {
// The query has failed.
// It's *critical* to trigger a retry here
// otherwise no message content will be saved
return left(
TransientError("Cannot get user's profile")
);
}
const maybeProfile = errorOrMaybeProfile.value;
if (isNone(maybeProfile)) {
// the recipient doesn't have any profile yet
return left(
RecipientError("Recipient profile does not exist.")
);
}
const profile = maybeProfile.value;
// channels ther user has blocked for this sender service
const blockedInboxOrChannels = fromNullable(profile.blockedInboxOrChannels)
.chain((bc: IProfileBlockedInboxOrChannels) =>
fromNullable(bc[newMessageWithoutContent.senderServiceId])
)
.getOrElse(new Set());
winston.debug(
"handleMessage|Blocked Channels(%s): %s",
newMessageWithoutContent.fiscalCode,
JSON.stringify(blockedInboxOrChannels)