From 1b56fff6cb045eb201252800f00db98cbc6b269a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 29 Sep 2020 16:50:57 -0500 Subject: [PATCH] Chats: fix #451 duplicated message --- app/soapbox/actions/streaming.js | 4 +++- app/soapbox/reducers/chat_message_lists.js | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/soapbox/actions/streaming.js b/app/soapbox/actions/streaming.js index b3ca60fb3..3b66a0472 100644 --- a/app/soapbox/actions/streaming.js +++ b/app/soapbox/actions/streaming.js @@ -57,11 +57,13 @@ export function connectTimelineStream(timelineId, path, pollingRefresh = null, a case 'pleroma:chat_update': dispatch((dispatch, getState) => { const chat = JSON.parse(data.payload); - const messageOwned = !(chat.last_message && chat.last_message.account_id !== getState().get('me')); + const me = getState().get('me'); + const messageOwned = !(chat.last_message && chat.last_message.account_id !== me); dispatch({ type: STREAMING_CHAT_UPDATE, chat, + me, // Only play sounds for recipient messages meta: !messageOwned && getSettings(getState()).getIn(['chats', 'sound']) && { sound: 'chat' }, }); diff --git a/app/soapbox/reducers/chat_message_lists.js b/app/soapbox/reducers/chat_message_lists.js index 8848a8389..3a7ec8610 100644 --- a/app/soapbox/reducers/chat_message_lists.js +++ b/app/soapbox/reducers/chat_message_lists.js @@ -39,9 +39,7 @@ const importLastMessages = (state, chats) => })); const replaceMessage = (state, chatId, oldId, newId) => { - const ids = state.get(chatId, ImmutableOrderedSet()); - const newIds = ids.delete(oldId).add(newId).sort(idComparator); - return state.set(chatId, newIds); + return state.update(chatId, chat => chat.delete(oldId).add(newId).sort(idComparator)); }; export default function chatMessageLists(state = initialState, action) {