Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

handle message deduplication #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/common/src/chat/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ export const ChatInternal: FC<ChatProps> = (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;
});

Expand Down Expand Up @@ -298,7 +299,8 @@ export const ChatInternal: FC<ChatProps> = (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;
});

Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/hooks/use-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down