fix: log but continue if there are errors while clearing out sogs inboxes

pull/2660/head
William Grant 3 years ago
parent c1c380ba9d
commit 4c64997607

@ -65,7 +65,15 @@ async function deleteEverythingAndNetworkData() {
// clear each inbox per sogs // clear each inbox per sogs
for (const roomInfo of allRoomInfos.values()) { for (const roomInfo of allRoomInfos.values()) {
// TODO CONTINUE testing - use a dummy account with some message requests and then if we restore from seed there should be no message requests. // TODO CONTINUE testing - use a dummy account with some message requests and then if we restore from seed there should be no message requests.
await clearInbox(roomInfo); try {
const success = await clearInbox(roomInfo);
if (!success) {
throw Error(`Failed to clear inbox for ${roomInfo.conversationId}`);
}
} catch (error) {
window.log.info(`DeleteAccount =>`, error);
continue;
}
} }
} }

@ -16,8 +16,8 @@ type OpenGroupClearInboxResponse = {
export const clearInbox = async (roomInfos: OpenGroupRequestCommonType): Promise<boolean> => { export const clearInbox = async (roomInfos: OpenGroupRequestCommonType): Promise<boolean> => {
let success = false; let success = false;
const converationId = getOpenGroupV2ConversationId(roomInfos.serverUrl, roomInfos.roomId); const conversationId = getOpenGroupV2ConversationId(roomInfos.serverUrl, roomInfos.roomId);
const conversation = await Data.getConversationById(converationId); const conversation = await Data.getConversationById(conversationId);
if (!conversation) { if (!conversation) {
window.log.warn('clearInbox Matching conversation not found in db'); window.log.warn('clearInbox Matching conversation not found in db');
@ -40,27 +40,27 @@ export const clearInbox = async (roomInfos: OpenGroupRequestCommonType): Promise
); );
if (!result) { if (!result) {
throw new Error('Could not clearInbox, res is invalid'); throw new Error(`Could not clearInbox, res is invalid for ${conversationId}`);
} }
const rawMessage = const rawMessage =
(result.body && (result.body[0].body as OpenGroupClearInboxResponse)) || null; (result.body && (result.body[0].body as OpenGroupClearInboxResponse)) || null;
if (!rawMessage) { if (!rawMessage) {
throw new Error('clearInbox parsing failed'); throw new Error(`clearInbox parsing failed for ${conversationId}`);
} }
try { try {
if (batchGlobalIsSuccess(result) && batchFirstSubIsSuccess(result)) { if (batchGlobalIsSuccess(result) && batchFirstSubIsSuccess(result)) {
success = true; success = true;
window.log.info(`clearInbox ${rawMessage.deleted} messages deleted from ${converationId} `); window.log.info(`clearInbox ${rawMessage.deleted} messages deleted for ${conversationId} `);
} }
} catch (e) { } catch (e) {
window?.log?.error("clearInbox Can't decode JSON body"); window?.log?.error(`clearInbox Can't decode JSON body for ${conversationId}`);
} }
} }
if (!success) { if (!success) {
window.log.info(`clearInbox message deletion failed for ${converationId} `); window.log.info(`clearInbox message deletion failed for ${conversationId}`);
} }
return success; return success;
}; };

Loading…
Cancel
Save