Files
twenty/packages/twenty-server/src/modules/messaging/message-outbound-manager/utils/resolve-outbound-thread-external-id.util.ts
T
neo773 6545ca274c fix(messaging): refactor SentMessagePersistenceService (#20077)
refactored `SentMessagePersistenceService` to be thin wrapper over
`saveMessagesAndEnqueueContactCreation`
this fixes a bug where the old logic did not call match participants
causing messages to not show up
2026-04-27 11:56:41 +00:00

26 lines
807 B
TypeScript

import { isNonEmptyString } from '@sniptt/guards';
import { type SendMessageResult } from 'src/modules/messaging/message-outbound-manager/types/send-message-result.type';
export const resolveOutboundThreadExternalId = ({
sendResult,
inReplyTo,
}: {
sendResult: SendMessageResult;
inReplyTo?: string;
}): string => {
if (isNonEmptyString(sendResult.threadExternalId)) {
return sendResult.threadExternalId;
}
// IMAP/SMTP have no server-side thread id. Reuse the parent's Message-ID so
// the reply attaches to the same thread the parent stored under.
if (isNonEmptyString(inReplyTo)) {
return inReplyTo;
}
// New IMAP/SMTP send: own Message-ID is unique per RFC822, so unrelated
// sends never collide on a shared empty thread key.
return sendResult.headerMessageId;
};