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