chore: migrate sendMessage + getReadReceipts callers to REST

Merged
GG
3mo ago
+109-28

Summary

The two DDP methods that were reverted from #40659 because their client plumbing depends on DDP-specific semantics. This PR contains the deeper refactor each needed.

sendMessage

  • sdk.call('sendMessage', message, previewUrls) → sdk.rest.post('/v1/chat.sendMessage', { message, previewUrls }).
  • Primary send flow (apps/meteor/client/lib/chats/flows/sendMessage.ts) feeds the server-rendered { message } back into Messages.state via mapMessageFromApi, replacing the optimistic temp record in the same tick the REST call resolves. Reproduces the Minimongo replication the DDP method triggered.
  • The seven fire-and-forget callsites are straight URL swaps:
    • apps/meteor/client/hooks/notification/useNotification.ts (desktop notification reply)
    • apps/meteor/client/apps/gameCenter/GameCenterInvitePlayersModal.tsx
    • 5 asciiart slashcommands

getReadReceipts

  • useMethod('getReadReceipts') → useEndpoint('GET', '/v1/chat.getMessageReadReceipts') in ReadReceiptsModal.
  • Dialog now takes a rid prop and subscribes to notify-room/<rid>/messagesRead; on event, invalidates the ['read-receipts', messageId] react-query so the dialog refetches when new receipts land.
  • mapReadReceiptFromApi helper revives the Date fields the REST endpoint serializes as strings.

Server-side race fix

ReadReceipt.markMessagesAsRead, markMessageAsReadBySender and storeThreadMessagesReadReceipts no longer fire-and-forget the inner storeReadReceipts(...) call — they await it. Closes the read-after-write race that the omnichannel-livechat-read-receipts e2e exposed.

Test plan

  • Quote a message with attachment in a channel; confirm the blockquote appears in the sent message and the composer's quote preview unmounts.
  • Same flow inside a thread.
  • Edit a message after sending.
  • Run the asciiart slash commands.
  • Reply from a desktop notification.
  • Livechat: visitor sends a message; agent opens the chat; agent inspects "Read receipts" — expects two entries (visitor + agent).
  • CI: `omnichannel-livechat-read-receipts.spec.ts:53` passes.
  • CI: `quote-attachment.spec.ts:29` passes.

Task: ARCH-2165

Task: [ARCH-2266]

Summary by CodeRabbit

  • Improvements

    • Improved message sending reliability across chats, notifications, game invites, and slash commands.
    • Quoted-message composers now dismiss promptly after sending, including when delivery encounters an error.
    • Session credentials are cleared when certain requests indicate an expired session.
  • Read Receipts

    • Read-receipt details now refresh automatically when messages are read.
    • Improved consistency when marking messages and threads as read.
  • Bug Fixes

    • Improved attachment validation to prevent incorrect message formatting.