diff options
| author | Shpuld Shpludson <shp@cock.li> | 2020-11-02 05:36:42 +0000 |
|---|---|---|
| committer | Shpuld Shpludson <shp@cock.li> | 2020-11-02 05:36:42 +0000 |
| commit | 5254fdba75fc8d645c2235902a39b79c45f9aa6f (patch) | |
| tree | ac329a5fc0448d804d5aa8d77e137b00e64a4491 /src/modules/api.js | |
| parent | 590f8e17544969b1fc2456b3724e85b16cf81bdd (diff) | |
| parent | 78e5a639228ba846e38ae722590aec1310275c79 (diff) | |
Merge branch 'optimistic-chat-posting' into 'develop'
Optimistic / nonblocking message posting for chats
See merge request pleroma/pleroma-fe!1228
Diffstat (limited to 'src/modules/api.js')
| -rw-r--r-- | src/modules/api.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/modules/api.js b/src/modules/api.js index 0a354c3f..08485a30 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -75,12 +75,18 @@ const api = { } else if (message.event === 'delete') { dispatch('deleteStatusById', message.id) } else if (message.event === 'pleroma:chat_update') { - dispatch('addChatMessages', { - chatId: message.chatUpdate.id, - messages: [message.chatUpdate.lastMessage] - }) - dispatch('updateChat', { chat: message.chatUpdate }) - maybeShowChatNotification(store, message.chatUpdate) + // The setTimeout wrapper is a temporary band-aid to avoid duplicates for the user's own messages when doing optimistic sending. + // The cause of the duplicates is the WS event arriving earlier than the HTTP response. + // This setTimeout wrapper can be removed once the commit `8e41baff` is in the stable Pleroma release. + // (`8e41baff` adds the idempotency key to the chat message entity, which PleromaFE uses when it's available, and it makes this artificial delay unnecessary). + setTimeout(() => { + dispatch('addChatMessages', { + chatId: message.chatUpdate.id, + messages: [message.chatUpdate.lastMessage] + }) + dispatch('updateChat', { chat: message.chatUpdate }) + maybeShowChatNotification(store, message.chatUpdate) + }, 100) } } ) |
