Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 17d90b07cb fix(messaging): set direction on message record during import and send
https://sonarly.com/issue/30362?type=bug

All messages in the `/objects/messages` view show Direction as "Incoming" because the `direction` field on the `message` record is never set during import or send — it always falls back to the default value `'INCOMING'`.

Fix: Added `direction` to the message record insert in both code paths where messages are persisted:

1. **`messaging-message.service.ts`** (import path): Added `direction: message.direction` to the `messageToCreate` object. The `message.direction` value is already correctly computed by all providers (Gmail, Microsoft, IMAP) via `computeMessageDirection()` — it was just never included in the message insert.

2. **`sent-message-persistence.service.ts`** (send path): Added `direction: MessageDirection.OUTGOING` to the message insert. `MessageDirection` was already imported in this file for use on the MCMA record.

These changes ensure the `direction` field on the `message` table is populated with the correct value instead of falling back to the default `'INCOMING'`. Existing messages will retain their incorrect default — a data migration could backfill them from the MCMA records, but that is out of scope for this fix.
2026-04-23 17:29:33 +00:00
2 changed files with 2 additions and 0 deletions
@@ -166,6 +166,7 @@ export class MessagingMessageService {
headerMessageId: message.headerMessageId,
subject: message.subject,
receivedAt: message.receivedAt,
direction: message.direction,
text: message.text,
messageThreadId,
};
@@ -74,6 +74,7 @@ export class SentMessagePersistenceService {
headerMessageId: input.sendResult.headerMessageId,
subject: input.subject,
text: input.body,
direction: MessageDirection.OUTGOING,
receivedAt: new Date(),
messageThreadId,
});