|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
import _, { compact, isArray, isNumber, isObject, pick } from 'lodash';
|
|
|
|
|
import _, { compact, isArray, isEmpty, isNumber, isObject, pick } from 'lodash';
|
|
|
|
|
import { OpenGroupData } from '../../../../data/opengroups';
|
|
|
|
|
import { handleOpenGroupV4Message } from '../../../../receiver/opengroup';
|
|
|
|
|
import { OpenGroupRequestCommonType } from '../opengroupV2/ApiUtil';
|
|
|
|
@ -35,6 +35,7 @@ import { ConversationTypeEnum } from '../../../../models/conversationAttributes'
|
|
|
|
|
import { createSwarmMessageSentFromUs } from '../../../../models/messageFactory';
|
|
|
|
|
import { Data } from '../../../../data/data';
|
|
|
|
|
import { processMessagesUsingCache } from './sogsV3MutationCache';
|
|
|
|
|
import { destroyMessagesAndUpdateRedux } from '../../../../util/expiringMessages';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the convo matching those criteria and make sure it is an opengroup convo, or return null.
|
|
|
|
@ -154,6 +155,7 @@ async function filterOutMessagesInvalidSignature(
|
|
|
|
|
return signaturesValidMessages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let totalDeletedMessages = 0;
|
|
|
|
|
const handleSogsV3DeletedMessages = async (
|
|
|
|
|
messages: Array<OpenGroupMessageV4>,
|
|
|
|
|
serverUrl: string,
|
|
|
|
@ -164,29 +166,38 @@ const handleSogsV3DeletedMessages = async (
|
|
|
|
|
if (!deletions.length) {
|
|
|
|
|
return messages;
|
|
|
|
|
}
|
|
|
|
|
totalDeletedMessages += deletions.length;
|
|
|
|
|
console.warn(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
totalDeletedMessages,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
const allIdsRemoved = deletions.map(m => m.id);
|
|
|
|
|
try {
|
|
|
|
|
const convoId = getOpenGroupV2ConversationId(serverUrl, roomId);
|
|
|
|
|
const convo = getConversationController().get(convoId);
|
|
|
|
|
const messageIds = await Data.getMessageIdsFromServerIds(allIdsRemoved, convo.id);
|
|
|
|
|
|
|
|
|
|
// we shouldn't get too many messages to delete at a time, so no need to add a function to remove multiple messages for now
|
|
|
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
|
(messageIds || []).map(async id => {
|
|
|
|
|
if (convo) {
|
|
|
|
|
await convo.removeMessage(id);
|
|
|
|
|
}
|
|
|
|
|
await Data.removeMessage(id);
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
if (messageIds && messageIds.length) {
|
|
|
|
|
await destroyMessagesAndUpdateRedux(
|
|
|
|
|
messageIds.map(messageId => ({
|
|
|
|
|
conversationKey: convoId,
|
|
|
|
|
messageId,
|
|
|
|
|
}))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
window?.log?.warn('handleDeletions failed:', e);
|
|
|
|
|
}
|
|
|
|
|
return exceptDeletion;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// tslint:disable-next-line: cyclomatic-complexity
|
|
|
|
|
// tslint:disable-next-line: one-variable-per-declaration
|
|
|
|
|
let totalEmptyReactions = 0,
|
|
|
|
|
totalMessagesWithResolvedBlindedIdsIfFound = 0,
|
|
|
|
|
totalMessageReactions = 0;
|
|
|
|
|
|
|
|
|
|
// tslint:disable-next-line: max-func-body-length cyclomatic-complexity
|
|
|
|
|
const handleMessagesResponseV4 = async (
|
|
|
|
|
messages: Array<OpenGroupMessageV4>,
|
|
|
|
|
serverUrl: string,
|
|
|
|
@ -284,6 +295,9 @@ const handleMessagesResponseV4 = async (
|
|
|
|
|
|
|
|
|
|
const incomingMessageSeqNo = compact(messages.map(n => n.seqno));
|
|
|
|
|
const maxNewMessageSeqNo = Math.max(...incomingMessageSeqNo);
|
|
|
|
|
|
|
|
|
|
totalMessagesWithResolvedBlindedIdsIfFound += messagesWithResolvedBlindedIdsIfFound.length;
|
|
|
|
|
|
|
|
|
|
for (let index = 0; index < messagesWithResolvedBlindedIdsIfFound.length; index++) {
|
|
|
|
|
const msgToHandle = messagesWithResolvedBlindedIdsIfFound[index];
|
|
|
|
|
try {
|
|
|
|
@ -309,6 +323,18 @@ const handleMessagesResponseV4 = async (
|
|
|
|
|
await OpenGroupData.saveV2OpenGroupRoom(roomInfosRefreshed);
|
|
|
|
|
|
|
|
|
|
const messagesWithReactions = messages.filter(m => m.reactions !== undefined);
|
|
|
|
|
const messagesWithEmptyReactions = messagesWithReactions.filter(m => isEmpty(m.reactions));
|
|
|
|
|
|
|
|
|
|
totalMessageReactions += messagesWithReactions.length;
|
|
|
|
|
totalEmptyReactions += messagesWithEmptyReactions.length;
|
|
|
|
|
console.warn(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
totalMessagesWithResolvedBlindedIdsIfFound,
|
|
|
|
|
totalMessageReactions,
|
|
|
|
|
totalEmptyReactions,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (messagesWithReactions.length > 0) {
|
|
|
|
|
const conversationId = getOpenGroupV2ConversationId(serverUrl, roomId);
|
|
|
|
|
const groupConvo = getConversationController().get(conversationId);
|
|
|
|
@ -526,6 +552,7 @@ export const handleBatchPollResults = async (
|
|
|
|
|
break;
|
|
|
|
|
case 'pollInfo':
|
|
|
|
|
await handlePollInfoResponse(subResponse.code, subResponse.body, serverUrl);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case 'inbox':
|
|
|
|
|
await handleInboxOutboxMessages(subResponse.body, serverUrl, false);
|
|
|
|
|