Дедубликаия сообщений в диалогах

This commit is contained in:
RoyceDa
2026-02-16 23:29:39 +02:00
parent 441c29fe6b
commit 29af00403c
9 changed files with 23 additions and 3 deletions

3
.gitignore vendored
View File

@@ -13,4 +13,5 @@ CREDS
.env.development.local .env.development.local
.env.test.local .env.test.local
.env.production.local .env.production.local
app/servers.ts app/servers.ts
packs

View File

@@ -61,5 +61,6 @@ export const ALLOWED_DOMAINS_ZONES = [
'chat', 'chat',
'gg', 'gg',
'fm', 'fm',
'tv' 'tv',
'im'
]; ];

View File

@@ -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 ( return (
<DialogContext.Provider value={{ <DialogContext.Provider value={{
loading, loading,
messages, messages: deduplicate(messages),
setMessages, setMessages,
clearDialogCache: () => { clearDialogCache: () => {
setDialogsCache(dialogsCache.filter((cache) => cache.publicKey != props.dialog)); 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.