From 26187da5217ab2b7642a93de57c9c8cc18ee0d17 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 13 May 2022 14:36:16 +1000 Subject: [PATCH] force duplicates to -10 and 0 for closed groups between HF --- ts/models/conversation.ts | 8 ++++---- ts/models/message.ts | 8 ++++---- ts/session/sending/MessageSender.ts | 26 +++++++++++++++++++------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 2d0080e2e..8ae1feebf 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -1004,7 +1004,7 @@ export class ConversationModel extends Backbone.Model { public triggerUIRefresh() { updatesToDispatch.set(this.id, this.getConversationModelProps()); - trotthledAllConversationsDispatch(); + throttledAllConversationsDispatch(); } public async commit() { @@ -1741,7 +1741,7 @@ export class ConversationModel extends Backbone.Model { } } -const trotthledAllConversationsDispatch = _.debounce( +const throttledAllConversationsDispatch = _.debounce( () => { if (updatesToDispatch.size === 0) { return; @@ -1750,8 +1750,8 @@ const trotthledAllConversationsDispatch = _.debounce( updatesToDispatch.clear(); }, - 2000, - { maxWait: 2000, trailing: true, leading: true } + 500, + { trailing: true, leading: true, maxWait: 1000 } ); const updatesToDispatch: Map = new Map(); diff --git a/ts/models/message.ts b/ts/models/message.ts index 00a1734a4..043e68bca 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -1164,7 +1164,7 @@ export class MessageModel extends Backbone.Model { } private dispatchMessageUpdate() { updatesToDispatch.set(this.id, this.getMessageModelProps()); - trotthledAllMessagesDispatch(); + throttledAllMessagesDispatch(); } /** @@ -1321,7 +1321,7 @@ export function sliceQuoteText(quotedText: string | undefined | null) { return quotedText.slice(0, 60); } -const trotthledAllMessagesDispatch = _.debounce( +const throttledAllMessagesDispatch = _.debounce( () => { if (updatesToDispatch.size === 0) { return; @@ -1329,8 +1329,8 @@ const trotthledAllMessagesDispatch = _.debounce( window.inboxStore?.dispatch(messagesChanged([...updatesToDispatch.values()])); updatesToDispatch.clear(); }, - 2000, - { trailing: true, maxWait: 5000 } + 500, + { trailing: true, leading: true, maxWait: 1000 } ); const updatesToDispatch: Map = new Map(); diff --git a/ts/session/sending/MessageSender.ts b/ts/session/sending/MessageSender.ts index 6ededfe7e..0eac5bfe5 100644 --- a/ts/session/sending/MessageSender.ts +++ b/ts/session/sending/MessageSender.ts @@ -17,7 +17,7 @@ import { getNowWithNetworkOffset, storeOnNode } from '../apis/snode_api/SNodeAPI import { getSwarmFor } from '../apis/snode_api/snodePool'; import { firstTrue } from '../utils/Promise'; import { MessageSender } from '.'; -import { getMessageById } from '../../../ts/data/data'; +import { getMessageById, Snode } from '../../../ts/data/data'; import { getConversationController } from '../conversations'; import { ed25519Str } from '../onions/onionPath'; import { EmptySwarmError } from '../utils/errors'; @@ -151,6 +151,8 @@ export async function sendMessageToSnode( }; hardfork190Happened:${hardfork190Happened}; hardfork191Happened:${hardfork191Happened} to namespace:${namespace}` ); + const isBetweenBothHF = hardfork190Happened && !hardfork191Happened; + // send parameters const params = { pubKey, @@ -163,13 +165,26 @@ export async function sendMessageToSnode( }; const usedNodes = _.slice(swarm, 0, DEFAULT_CONNECTIONS); + if (!usedNodes || usedNodes.length === 0) { + throw new EmptySwarmError(pubKey, 'Ran out of swarm nodes to query'); + } - let successfulSendHash: any; + let successfulSendHash: string | undefined; const promises = usedNodes.map(async usedNode => { // No pRetry here as if this is a bad path it will be handled and retried in lokiOnionFetch. // the only case we could care about a retry would be when the usedNode is not correct, // but considering we trigger this request with a few snode in //, this should be fine. const successfulSend = await storeOnNode(usedNode, params); + + if (isBetweenBothHF && isClosedGroup) { + window.log.warn( + 'closedGroup and betweenHF case. Forcing duplicating to 0 and -10 inboxes...' + ); + await storeOnNode(usedNode, { ...params, namespace: 0 }); + window.log.warn( + 'closedGroup and betweenHF case. Forcing duplicating to 0 and -10 inboxes done' + ); + } if (successfulSend) { if (_.isString(successfulSend)) { successfulSendHash = successfulSend; @@ -180,7 +195,7 @@ export async function sendMessageToSnode( return undefined; }); - let snode; + let snode: Snode | undefined; try { const firstSuccessSnode = await firstTrue(promises); snode = firstSuccessSnode; @@ -191,12 +206,9 @@ export async function sendMessageToSnode( ); throw e; } - if (!usedNodes || usedNodes.length === 0) { - throw new EmptySwarmError(pubKey, 'Ran out of swarm nodes to query'); - } // If message also has a sync message, save that hash. Otherwise save the hash from the regular message send i.e. only closed groups in this case. - if (messageId && (isSyncMessage || isClosedGroup)) { + if (messageId && (isSyncMessage || isClosedGroup) && successfulSendHash) { const message = await getMessageById(messageId); if (message) { await message.updateMessageHash(successfulSendHash);