1
- import _ , { compact , isArray , isNumber , isObject , pick } from 'lodash' ;
1
+ import _ , { compact , isArray , isEmpty , isNumber , isObject , pick } from 'lodash' ;
2
2
import { OpenGroupData } from '../../../../data/opengroups' ;
3
3
import { handleOpenGroupV4Message } from '../../../../receiver/opengroup' ;
4
4
import { OpenGroupRequestCommonType } from '../opengroupV2/ApiUtil' ;
@@ -35,6 +35,7 @@ import { ConversationTypeEnum } from '../../../../models/conversationAttributes'
35
35
import { createSwarmMessageSentFromUs } from '../../../../models/messageFactory' ;
36
36
import { Data } from '../../../../data/data' ;
37
37
import { processMessagesUsingCache } from './sogsV3MutationCache' ;
38
+ import { destroyMessagesAndUpdateRedux } from '../../../../util/expiringMessages' ;
38
39
39
40
/**
40
41
* Get the convo matching those criteria and make sure it is an opengroup convo, or return null.
@@ -154,6 +155,7 @@ async function filterOutMessagesInvalidSignature(
154
155
return signaturesValidMessages ;
155
156
}
156
157
158
+ let totalDeletedMessages = 0 ;
157
159
const handleSogsV3DeletedMessages = async (
158
160
messages : Array < OpenGroupMessageV4 > ,
159
161
serverUrl : string ,
@@ -164,29 +166,38 @@ const handleSogsV3DeletedMessages = async (
164
166
if ( ! deletions . length ) {
165
167
return messages ;
166
168
}
169
+ totalDeletedMessages += deletions . length ;
170
+ console . warn (
171
+ JSON . stringify ( {
172
+ totalDeletedMessages,
173
+ } )
174
+ ) ;
167
175
const allIdsRemoved = deletions . map ( m => m . id ) ;
168
176
try {
169
177
const convoId = getOpenGroupV2ConversationId ( serverUrl , roomId ) ;
170
178
const convo = getConversationController ( ) . get ( convoId ) ;
171
179
const messageIds = await Data . getMessageIdsFromServerIds ( allIdsRemoved , convo . id ) ;
172
180
173
- // 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
174
-
175
- await Promise . all (
176
- ( messageIds || [ ] ) . map ( async id => {
177
- if ( convo ) {
178
- await convo . removeMessage ( id ) ;
179
- }
180
- await Data . removeMessage ( id ) ;
181
- } )
182
- ) ;
181
+ if ( messageIds && messageIds . length ) {
182
+ await destroyMessagesAndUpdateRedux (
183
+ messageIds . map ( messageId => ( {
184
+ conversationKey : convoId ,
185
+ messageId,
186
+ } ) )
187
+ ) ;
188
+ }
183
189
} catch ( e ) {
184
190
window ?. log ?. warn ( 'handleDeletions failed:' , e ) ;
185
191
}
186
192
return exceptDeletion ;
187
193
} ;
188
194
189
- // tslint:disable-next-line: cyclomatic-complexity
195
+ // tslint:disable-next-line: one-variable-per-declaration
196
+ let totalEmptyReactions = 0 ,
197
+ totalMessagesWithResolvedBlindedIdsIfFound = 0 ,
198
+ totalMessageReactions = 0 ;
199
+
200
+ // tslint:disable-next-line: max-func-body-length cyclomatic-complexity
190
201
const handleMessagesResponseV4 = async (
191
202
messages : Array < OpenGroupMessageV4 > ,
192
203
serverUrl : string ,
@@ -284,6 +295,9 @@ const handleMessagesResponseV4 = async (
284
295
285
296
const incomingMessageSeqNo = compact ( messages . map ( n => n . seqno ) ) ;
286
297
const maxNewMessageSeqNo = Math . max ( ...incomingMessageSeqNo ) ;
298
+
299
+ totalMessagesWithResolvedBlindedIdsIfFound += messagesWithResolvedBlindedIdsIfFound . length ;
300
+
287
301
for ( let index = 0 ; index < messagesWithResolvedBlindedIdsIfFound . length ; index ++ ) {
288
302
const msgToHandle = messagesWithResolvedBlindedIdsIfFound [ index ] ;
289
303
try {
@@ -309,6 +323,18 @@ const handleMessagesResponseV4 = async (
309
323
await OpenGroupData . saveV2OpenGroupRoom ( roomInfosRefreshed ) ;
310
324
311
325
const messagesWithReactions = messages . filter ( m => m . reactions !== undefined ) ;
326
+ const messagesWithEmptyReactions = messagesWithReactions . filter ( m => isEmpty ( m . reactions ) ) ;
327
+
328
+ totalMessageReactions += messagesWithReactions . length ;
329
+ totalEmptyReactions += messagesWithEmptyReactions . length ;
330
+ console . warn (
331
+ JSON . stringify ( {
332
+ totalMessagesWithResolvedBlindedIdsIfFound,
333
+ totalMessageReactions,
334
+ totalEmptyReactions,
335
+ } )
336
+ ) ;
337
+
312
338
if ( messagesWithReactions . length > 0 ) {
313
339
const conversationId = getOpenGroupV2ConversationId ( serverUrl , roomId ) ;
314
340
const groupConvo = getConversationController ( ) . get ( conversationId ) ;
@@ -526,6 +552,7 @@ export const handleBatchPollResults = async (
526
552
break ;
527
553
case 'pollInfo' :
528
554
await handlePollInfoResponse ( subResponse . code , subResponse . body , serverUrl ) ;
555
+
529
556
break ;
530
557
case 'inbox' :
531
558
await handleInboxOutboxMessages ( subResponse . body , serverUrl , false ) ;
0 commit comments