diff --git a/packages/common/src/chat/chat.tsx b/packages/common/src/chat/chat.tsx index 10c5ff09a..a5180eadd 100644 --- a/packages/common/src/chat/chat.tsx +++ b/packages/common/src/chat/chat.tsx @@ -195,7 +195,8 @@ export const ChatInternal: FC = (props: ChatProps) => { setMessages((messages) => { const messagesClone = cloneDeep(messages) || {}; messagesClone[message.channel] = messagesClone[message.channel] || []; - messagesClone[message.channel].push(message); + const hasMessage = messagesClone[message.channel].findIndex(m => m.timetoken === message.timetoken) > -1; + if (!hasMessage) messagesClone[message.channel].push(message); return messagesClone; }); @@ -298,7 +299,8 @@ export const ChatInternal: FC = (props: ChatProps) => { const newMessage = { ...payload, message: { file, message }, messageType: 4 }; const messagesClone = cloneDeep(messages) || {}; messagesClone[newMessage.channel] = messagesClone[newMessage.channel] || []; - messagesClone[newMessage.channel].push(newMessage); + const hasMessage = messagesClone[message.channel].findIndex(m => m.timetoken === message.timetoken) > -1; + if (!hasMessage) messagesClone[message.channel].push(message); return messagesClone; }); diff --git a/packages/common/src/hooks/use-messages.ts b/packages/common/src/hooks/use-messages.ts index 4a48b6bd5..fa57dcb33 100644 --- a/packages/common/src/hooks/use-messages.ts +++ b/packages/common/src/hooks/use-messages.ts @@ -49,7 +49,8 @@ export const useMessages = (options: FetchMessagesParameters): HookReturnValue = setMessages((messages) => { const messagesClone = cloneDeep(messages); if (!messagesClone[message.channel]) messagesClone[message.channel] = []; - messagesClone[message.channel].push(message); + const hasMessage = messagesClone[message.channel].findIndex(m => m.timetoken === message.timetoken) > -1; + if (!hasMessage) messagesClone[message.channel].push(message); return messagesClone; }); } catch (e) {