Дедубликаия сообщений в диалогах
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -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
|
||||||
|
|||||||
@@ -61,5 +61,6 @@ export const ALLOWED_DOMAINS_ZONES = [
|
|||||||
'chat',
|
'chat',
|
||||||
'gg',
|
'gg',
|
||||||
'fm',
|
'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 (
|
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.
Binary file not shown.
Reference in New Issue
Block a user