Merge pull request #2300 from oxen-io/force-duplicate-closedgr-between-hf

force duplicates to -10 and 0 for closed groups between HF
pull/2301/head
Audric Ackermann 4 years ago committed by GitHub
commit c9d14d62b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1004,7 +1004,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public triggerUIRefresh() { public triggerUIRefresh() {
updatesToDispatch.set(this.id, this.getConversationModelProps()); updatesToDispatch.set(this.id, this.getConversationModelProps());
trotthledAllConversationsDispatch(); throttledAllConversationsDispatch();
} }
public async commit() { public async commit() {
@ -1741,7 +1741,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
} }
const trotthledAllConversationsDispatch = _.debounce( const throttledAllConversationsDispatch = _.debounce(
() => { () => {
if (updatesToDispatch.size === 0) { if (updatesToDispatch.size === 0) {
return; return;
@ -1750,8 +1750,8 @@ const trotthledAllConversationsDispatch = _.debounce(
updatesToDispatch.clear(); updatesToDispatch.clear();
}, },
2000, 500,
{ maxWait: 2000, trailing: true, leading: true } { trailing: true, leading: true, maxWait: 1000 }
); );
const updatesToDispatch: Map<string, ReduxConversationType> = new Map(); const updatesToDispatch: Map<string, ReduxConversationType> = new Map();

@ -1164,7 +1164,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
} }
private dispatchMessageUpdate() { private dispatchMessageUpdate() {
updatesToDispatch.set(this.id, this.getMessageModelProps()); updatesToDispatch.set(this.id, this.getMessageModelProps());
trotthledAllMessagesDispatch(); throttledAllMessagesDispatch();
} }
/** /**
@ -1321,7 +1321,7 @@ export function sliceQuoteText(quotedText: string | undefined | null) {
return quotedText.slice(0, 60); return quotedText.slice(0, 60);
} }
const trotthledAllMessagesDispatch = _.debounce( const throttledAllMessagesDispatch = _.debounce(
() => { () => {
if (updatesToDispatch.size === 0) { if (updatesToDispatch.size === 0) {
return; return;
@ -1329,8 +1329,8 @@ const trotthledAllMessagesDispatch = _.debounce(
window.inboxStore?.dispatch(messagesChanged([...updatesToDispatch.values()])); window.inboxStore?.dispatch(messagesChanged([...updatesToDispatch.values()]));
updatesToDispatch.clear(); updatesToDispatch.clear();
}, },
2000, 500,
{ trailing: true, maxWait: 5000 } { trailing: true, leading: true, maxWait: 1000 }
); );
const updatesToDispatch: Map<string, MessageModelPropsWithoutConvoProps> = new Map(); const updatesToDispatch: Map<string, MessageModelPropsWithoutConvoProps> = new Map();

@ -17,7 +17,7 @@ import { getNowWithNetworkOffset, storeOnNode } from '../apis/snode_api/SNodeAPI
import { getSwarmFor } from '../apis/snode_api/snodePool'; import { getSwarmFor } from '../apis/snode_api/snodePool';
import { firstTrue } from '../utils/Promise'; import { firstTrue } from '../utils/Promise';
import { MessageSender } from '.'; import { MessageSender } from '.';
import { getMessageById } from '../../../ts/data/data'; import { getMessageById, Snode } from '../../../ts/data/data';
import { getConversationController } from '../conversations'; import { getConversationController } from '../conversations';
import { ed25519Str } from '../onions/onionPath'; import { ed25519Str } from '../onions/onionPath';
import { EmptySwarmError } from '../utils/errors'; import { EmptySwarmError } from '../utils/errors';
@ -151,6 +151,8 @@ export async function sendMessageToSnode(
}; hardfork190Happened:${hardfork190Happened}; hardfork191Happened:${hardfork191Happened} to namespace:${namespace}` }; hardfork190Happened:${hardfork190Happened}; hardfork191Happened:${hardfork191Happened} to namespace:${namespace}`
); );
const isBetweenBothHF = hardfork190Happened && !hardfork191Happened;
// send parameters // send parameters
const params = { const params = {
pubKey, pubKey,
@ -163,13 +165,26 @@ export async function sendMessageToSnode(
}; };
const usedNodes = _.slice(swarm, 0, DEFAULT_CONNECTIONS); 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 => { const promises = usedNodes.map(async usedNode => {
// No pRetry here as if this is a bad path it will be handled and retried in lokiOnionFetch. // 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, // 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. // but considering we trigger this request with a few snode in //, this should be fine.
const successfulSend = await storeOnNode(usedNode, params); 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 (successfulSend) {
if (_.isString(successfulSend)) { if (_.isString(successfulSend)) {
successfulSendHash = successfulSend; successfulSendHash = successfulSend;
@ -180,7 +195,7 @@ export async function sendMessageToSnode(
return undefined; return undefined;
}); });
let snode; let snode: Snode | undefined;
try { try {
const firstSuccessSnode = await firstTrue(promises); const firstSuccessSnode = await firstTrue(promises);
snode = firstSuccessSnode; snode = firstSuccessSnode;
@ -191,12 +206,9 @@ export async function sendMessageToSnode(
); );
throw e; 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 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); const message = await getMessageById(messageId);
if (message) { if (message) {
await message.updateMessageHash(successfulSendHash); await message.updateMessageHash(successfulSendHash);

Loading…
Cancel
Save