From e798e9a4177f025dda2b40d109fa40c2ebfd814e Mon Sep 17 00:00:00 2001 From: eugenijm Date: Thu, 29 Oct 2020 13:33:06 +0300 Subject: Optimistic message sending for chat --- src/services/chat_utils/chat_utils.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/services/chat_utils/chat_utils.js') diff --git a/src/services/chat_utils/chat_utils.js b/src/services/chat_utils/chat_utils.js index 86fe1af9..de6e0625 100644 --- a/src/services/chat_utils/chat_utils.js +++ b/src/services/chat_utils/chat_utils.js @@ -18,3 +18,24 @@ export const maybeShowChatNotification = (store, chat) => { showDesktopNotification(store.rootState, opts) } + +export const buildFakeMessage = ({ content, chatId, attachments, userId, idempotencyKey }) => { + const fakeMessage = { + content, + chat_id: chatId, + created_at: new Date(), + id: `${new Date().getTime()}`, + attachments: attachments, + account_id: userId, + idempotency_key: idempotencyKey, + emojis: [], + pending: true, + isNormalized: true + } + + if (attachments[0]) { + fakeMessage.attachment = attachments[0] + } + + return fakeMessage +} -- cgit v1.2.3-70-g09d2