From 04ae8fbc2a646caa579eab5c6092a716ba3f69ad Mon Sep 17 00:00:00 2001 From: Aaron Ogle Date: Mon, 5 Jan 2026 16:16:11 -0600 Subject: [PATCH 1/2] [Fix] Remove the delay of waiting on websocket to consider a message sent --- apps/meteor/app/lib/client/methods/sendMessage.ts | 10 ++++++++-- .../app/ui-utils/client/lib/LegacyRoomManager.ts | 12 +++++++++++- apps/meteor/client/stores/Messages.ts | 9 ++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/apps/meteor/app/lib/client/methods/sendMessage.ts b/apps/meteor/app/lib/client/methods/sendMessage.ts index 0969ea8d9cf36..89ba1f49a3483 100644 --- a/apps/meteor/app/lib/client/methods/sendMessage.ts +++ b/apps/meteor/app/lib/client/methods/sendMessage.ts @@ -42,9 +42,15 @@ Meteor.methods({ return; } - await onClientMessageReceived(message as IMessage).then((message) => { + await onClientMessageReceived(message as IMessage).then(async (message) => { Messages.state.store(message); - return clientCallbacks.run('afterSaveMessage', message, { room, user }); + await clientCallbacks.run('afterSaveMessage', message, { room, user }); + + // Now that the message is stored, we can go ahead and mark as sent + Messages.state.update( + (record) => record._id === message._id && record.temp === true, + (record) => ({ ...record, temp: false }), + ); }); }, }); diff --git a/apps/meteor/app/ui-utils/client/lib/LegacyRoomManager.ts b/apps/meteor/app/ui-utils/client/lib/LegacyRoomManager.ts index d6a8abf9c35da..0c1513e42fbe1 100644 --- a/apps/meteor/app/ui-utils/client/lib/LegacyRoomManager.ts +++ b/apps/meteor/app/ui-utils/client/lib/LegacyRoomManager.ts @@ -177,7 +177,17 @@ const openRoom = (typeName: string, record: OpenedRoom) => { if (msg.t !== 'command') { const subscription = Subscriptions.state.find(({ rid }) => rid === record.rid); const isNew = !Messages.state.find((record) => record._id === msg._id && record.temp !== true); - ({ _id: msg._id, temp: { $ne: true } }); + + // Measure and log message receive delay for messages + if (msg.ts) { + const receiveDelay = Date.now() - new Date(msg.ts).getTime(); + + // Log warning if delay is significant (>2 seconds) + if (receiveDelay > 2000) { + console.warn(`[Message Delivery] High delay detected: ${receiveDelay}ms. Possible network or backend issue.`); + } + } + await upsertMessage({ msg, subscription }); if (isNew) { await clientCallbacks.run('streamNewMessage', msg); diff --git a/apps/meteor/client/stores/Messages.ts b/apps/meteor/client/stores/Messages.ts index ff9fcdeee9f38..09706de1d95b2 100644 --- a/apps/meteor/client/stores/Messages.ts +++ b/apps/meteor/client/stores/Messages.ts @@ -6,5 +6,12 @@ import { createGlobalStore } from '../lib/cachedStores/createGlobalStore'; /** @deprecated prefer fetching data from the REST API, listening to changes via streamer events, and storing the state in a Tanstack Query */ export const Messages = createGlobalStore( - createDocumentMapStore(), + createDocumentMapStore< + IMessage & { + ignored?: boolean; + autoTranslateFetching?: boolean; + autoTranslateShowInverse?: boolean; + temp?: boolean; + } + >(), ); From cd2d095f9594d783b933d0a9fe37a2cf9149c8bf Mon Sep 17 00:00:00 2001 From: Tasso Date: Wed, 7 Jan 2026 00:24:47 -0300 Subject: [PATCH 2/2] fix: call `afterSaveMessage` callback without awaiting for it --- apps/meteor/app/lib/client/methods/sendMessage.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/meteor/app/lib/client/methods/sendMessage.ts b/apps/meteor/app/lib/client/methods/sendMessage.ts index 89ba1f49a3483..ee67688a0b6ae 100644 --- a/apps/meteor/app/lib/client/methods/sendMessage.ts +++ b/apps/meteor/app/lib/client/methods/sendMessage.ts @@ -42,14 +42,14 @@ Meteor.methods({ return; } - await onClientMessageReceived(message as IMessage).then(async (message) => { + await onClientMessageReceived(message as IMessage).then((message) => { Messages.state.store(message); - await clientCallbacks.run('afterSaveMessage', message, { room, user }); + void clientCallbacks.run('afterSaveMessage', message, { room, user }); // Now that the message is stored, we can go ahead and mark as sent Messages.state.update( (record) => record._id === message._id && record.temp === true, - (record) => ({ ...record, temp: false }), + ({ temp: _, ...record }) => record, ); }); },