fix: sogs messages being skipped and not handled

pull/2414/head
Audric Ackermann 3 years ago
parent fac41bc6c4
commit 18ab715e93

@ -46,11 +46,6 @@ export type SwarmNode = Snode & {
address: string; address: string;
}; };
export type ServerToken = {
serverUrl: string;
token: string;
};
export const hasSyncedInitialConfigurationItem = 'hasSyncedInitialConfigurationItem'; export const hasSyncedInitialConfigurationItem = 'hasSyncedInitialConfigurationItem';
export const lastAvatarUploadTimestamp = 'lastAvatarUploadTimestamp'; export const lastAvatarUploadTimestamp = 'lastAvatarUploadTimestamp';
export const hasLinkPreviewPopupBeenDisplayed = 'hasLinkPreviewPopupBeenDisplayed'; export const hasLinkPreviewPopupBeenDisplayed = 'hasLinkPreviewPopupBeenDisplayed';

@ -34,10 +34,6 @@ export type OpenGroupV2Room = {
lastInboxIdFetched?: number; lastInboxIdFetched?: number;
lastOutboxIdFetched?: number; lastOutboxIdFetched?: number;
/**
* This value represents the rowId of the last message deleted. Not the id of the last message ID
*/
lastMessageDeletedServerID?: number;
/** /**
* This value is set with the current timestamp whenever we get new messages. * This value is set with the current timestamp whenever we get new messages.
*/ */

@ -1735,8 +1735,8 @@ function updateToLokiSchemaVersion27(currentVersion: number, db: BetterSqlite3.D
const allSessionV2ConvosIp = compact( const allSessionV2ConvosIp = compact(
getAllOpenGroupV2Conversations(db).filter(m => m?.id.includes(ipToRemove)) getAllOpenGroupV2Conversations(db).filter(m => m?.id.includes(ipToRemove))
); );
const allSessionV2ConvosDns = getAllOpenGroupV2Conversations(db).filter(m => const allSessionV2ConvosDns = compact(
m?.id.includes(domainNameToUse) getAllOpenGroupV2Conversations(db).filter(m => m?.id.includes(domainNameToUse))
); );
const duplicatesConvosIpAndDns = allSessionV2ConvosIp.filter(ip => { const duplicatesConvosIpAndDns = allSessionV2ConvosIp.filter(ip => {
@ -1861,9 +1861,21 @@ function updateToLokiSchemaVersion27(currentVersion: number, db: BetterSqlite3.D
}); });
rebuildFtsTable(db); rebuildFtsTable(db);
console.log('... done');
console.info(
'removing lastMessageDeletedServerID & lastMessageFetchedServerID from rooms table'
);
db.exec(
`UPDATE ${OPEN_GROUP_ROOMS_V2_TABLE} SET
json = json_remove(json, '$.lastMessageDeletedServerID', '$.lastMessageFetchedServerID', '$.token' );`
);
console.info(
'removing lastMessageDeletedServerID & lastMessageFetchedServerID from rooms table. done'
);
writeLokiSchemaVersion(targetVersion, db); writeLokiSchemaVersion(targetVersion, db);
console.log('... done');
})(); })();
console.log(`updateToLokiSchemaVersion${targetVersion}: success!`); console.log(`updateToLokiSchemaVersion${targetVersion}: success!`);
} }
@ -3912,6 +3924,7 @@ function cleanUpOldOpengroupsOnStart() {
console.info('cleanUpOldOpengroups: v2Convos is empty'); console.info('cleanUpOldOpengroups: v2Convos is empty');
return; return;
} }
console.info(`Count of v2 opengroup convos to clean: ${v2ConvosIds.length}`);
// For each opengroups, if it has more than 1000 messages, we remove all the messages older than 2 months. // For each opengroups, if it has more than 1000 messages, we remove all the messages older than 2 months.
// So this does not limit the size of opengroup history to 1000 messages but to 2 months. // So this does not limit the size of opengroup history to 1000 messages but to 2 months.
@ -3957,6 +3970,10 @@ function cleanUpOldOpengroupsOnStart() {
convoProps.unreadCount = unreadCount; convoProps.unreadCount = unreadCount;
saveConversation(convoProps); saveConversation(convoProps);
} }
} else {
console.info(
`Not cleaning messages older than 6 months in public convo: ${convoId}. message count: ${messagesInConvoBefore}`
);
} }
}); });

@ -145,7 +145,7 @@ const handleSogsV3DeletedMessages = async (
) => { ) => {
// FIXME those 2 `m.data === null` test should be removed when we add support for emoji-reacts // FIXME those 2 `m.data === null` test should be removed when we add support for emoji-reacts
const deletions = messages.filter(m => Boolean(m.deleted) || m.data === null); const deletions = messages.filter(m => Boolean(m.deleted) || m.data === null);
const exceptDeletion = messages.filter(m => !m.deleted && !m.data === null); const exceptDeletion = messages.filter(m => !(Boolean(m.deleted) || m.data === null));
if (!deletions.length) { if (!deletions.length) {
return messages; return messages;
} }
@ -170,6 +170,7 @@ const handleSogsV3DeletedMessages = async (
return exceptDeletion; return exceptDeletion;
}; };
// tslint:disable-next-line: cyclomatic-complexity
const handleMessagesResponseV4 = async ( const handleMessagesResponseV4 = async (
messages: Array<OpenGroupMessageV4>, messages: Array<OpenGroupMessageV4>,
serverUrl: string, serverUrl: string,
@ -268,7 +269,6 @@ const handleMessagesResponseV4 = async (
roomInfosRefreshed.maxMessageFetchedSeqNo = maxNewMessageSeqNo; roomInfosRefreshed.maxMessageFetchedSeqNo = maxNewMessageSeqNo;
} }
roomInfosRefreshed.lastFetchTimestamp = Date.now(); roomInfosRefreshed.lastFetchTimestamp = Date.now();
await OpenGroupData.saveV2OpenGroupRoom(roomInfosRefreshed); await OpenGroupData.saveV2OpenGroupRoom(roomInfosRefreshed);
} catch (e) { } catch (e) {
window?.log?.warn('handleNewMessages failed:', e); window?.log?.warn('handleNewMessages failed:', e);
@ -455,8 +455,8 @@ export const handleBatchPollResults = async (
await handleCapabilities(subrequestOptionsLookup, batchPollResults, serverUrl); await handleCapabilities(subrequestOptionsLookup, batchPollResults, serverUrl);
if (batchPollResults && isArray(batchPollResults.body)) { if (batchPollResults && isArray(batchPollResults.body)) {
await Promise.all( for (let index = 0; index < batchPollResults.body.length; index++) {
batchPollResults.body.map(async (subResponse: any, index: number) => { const subResponse = batchPollResults.body[index] as any;
// using subreqOptions as request type lookup, // using subreqOptions as request type lookup,
//assumes batch subresponse order matches the subrequest order //assumes batch subresponse order matches the subrequest order
const subrequestOption = subrequestOptionsLookup[index]; const subrequestOption = subrequestOptionsLookup[index];
@ -468,12 +468,13 @@ export const handleBatchPollResults = async (
break; break;
case 'messages': case 'messages':
// this will also include deleted messages explicitly with `data: null` & edited messages with a new data field & react changes with data not existing // this will also include deleted messages explicitly with `data: null` & edited messages with a new data field & react changes with data not existing
return handleMessagesResponseV4( await handleMessagesResponseV4(
subResponse.body, subResponse.body,
serverUrl, serverUrl,
subrequestOption, subrequestOption,
roomIdsStillPolled roomIdsStillPolled
); );
break;
case 'pollInfo': case 'pollInfo':
await handlePollInfoResponse( await handlePollInfoResponse(
subResponse.code, subResponse.code,
@ -491,7 +492,6 @@ export const handleBatchPollResults = async (
default: default:
window.log.error('No matching subrequest response body for type: ', responseType); window.log.error('No matching subrequest response body for type: ', responseType);
} }
}) }
);
} }
}; };

Loading…
Cancel
Save