Дедубликаия сообщений в диалогах
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -14,3 +14,4 @@ CREDS
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
app/servers.ts
|
||||
packs
|
||||
|
||||
@@ -61,5 +61,6 @@ export const ALLOWED_DOMAINS_ZONES = [
|
||||
'chat',
|
||||
'gg',
|
||||
'fm',
|
||||
'tv'
|
||||
'tv',
|
||||
'im'
|
||||
];
|
||||
@@ -917,10 +917,28 @@ export function DialogProvider(props: DialogProviderProps) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Дедубликация сообщений по message_id, так как может возникать ситуация, что одно и то же сообщение
|
||||
* может загрузиться несколько раз при накладках сети, отставании часов, при синхронизации
|
||||
* @param messages массив сообщений
|
||||
* @returns массив уникальных сообщений
|
||||
*/
|
||||
const deduplicate = (messages: Message[]) => {
|
||||
const map = new Map<string, Message>();
|
||||
for(let i = 0; i < messages.length; i++){
|
||||
const message = messages[i];
|
||||
if(map.has(message.message_id)){
|
||||
continue;
|
||||
}
|
||||
map.set(message.message_id, message);
|
||||
}
|
||||
return Array.from(map.values());
|
||||
}
|
||||
|
||||
return (
|
||||
<DialogContext.Provider value={{
|
||||
loading,
|
||||
messages,
|
||||
messages: deduplicate(messages),
|
||||
setMessages,
|
||||
clearDialogCache: () => {
|
||||
setDialogsCache(dialogsCache.filter((cache) => cache.publicKey != props.dialog));
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user