fix: Remove duplicate message in slow networks (#1332)

This commit is contained in:
Pranav Raj S
2020-10-11 20:24:26 +05:30
committed by GitHub
parent 59bee66e63
commit 58c0792920
4 changed files with 108 additions and 17 deletions

View File

@@ -78,19 +78,12 @@ export const mutations = {
chat.muted = false;
},
[types.default.SEND_MESSAGE](_state, currentMessage) {
const [chat] = getSelectedChatConversation(_state);
const allMessagesExceptCurrent = (chat.messages || []).filter(
message => message.id !== currentMessage.id
);
allMessagesExceptCurrent.push(currentMessage);
chat.messages = allMessagesExceptCurrent;
},
[types.default.ADD_MESSAGE](_state, message) {
const [chat] = _state.allConversations.filter(
c => c.id === message.conversation_id
);
[types.default.ADD_MESSAGE]({ allConversations, selectedChatId }, message) {
const { conversation_id: conversationId } = message;
const [chat] = getSelectedChatConversation({
allConversations,
selectedChatId: conversationId,
});
if (!chat) return;
const previousMessageIndex = chat.messages.findIndex(
m => m.id === message.id
@@ -98,7 +91,7 @@ export const mutations = {
if (previousMessageIndex === -1) {
chat.messages.push(message);
chat.timestamp = message.created_at;
if (_state.selectedChatId === message.conversation_id) {
if (selectedChatId === conversationId) {
window.bus.$emit('scrollToMessage');
}
} else {