diff --git a/ts/data/sharedDataTypes.ts b/ts/data/sharedDataTypes.ts index d74153aeb..b7ba12572 100644 --- a/ts/data/sharedDataTypes.ts +++ b/ts/data/sharedDataTypes.ts @@ -7,12 +7,14 @@ export type DataCallArgs any> = Parameters[0]; export type DeleteAllMessageFromSendersInConversationType = ( args: WithGroupPubkey & { toRemove: Array; + signatureTimestamp: number; } ) => PrArrayMsgIds; export type DeleteAllMessageHashesInConversationType = ( args: WithGroupPubkey & { messageHashes: Array; + signatureTimestamp: number; } ) => PrArrayMsgIds; @@ -20,5 +22,6 @@ export type DeleteAllMessageHashesInConversationMatchingAuthorType = ( args: WithGroupPubkey & { messageHashes: Array; author: PubkeyType; + signatureTimestamp: number; } ) => PrArrayMsgIds; diff --git a/ts/interactions/conversations/unsendingInteractions.ts b/ts/interactions/conversations/unsendingInteractions.ts index 6e7a372ba..b1c97ef8d 100644 --- a/ts/interactions/conversations/unsendingInteractions.ts +++ b/ts/interactions/conversations/unsendingInteractions.ts @@ -137,7 +137,7 @@ async function unsendMessagesForEveryone( conversation, groupPk: destinationId, msgsToDelete, - allMessagesFrom: [], // currently we cannot remove all the messages from a specific pubkey + allMessagesFrom: [], // currently we cannot remove all the messages from a specific pubkey but we do already handle them on the receiving side }); } await deleteMessagesFromSwarmAndCompletelyLocally(conversation, msgsToDelete); diff --git a/ts/node/sql.ts b/ts/node/sql.ts index 3cae2d192..de7473cde 100644 --- a/ts/node/sql.ts +++ b/ts/node/sql.ts @@ -1059,7 +1059,11 @@ function removeAllMessagesInConversation( } function deleteAllMessageFromSendersInConversation( - { groupPk, toRemove }: DataCallArgs, + { + groupPk, + toRemove, + signatureTimestamp, + }: DataCallArgs, instance?: BetterSqlite3.Database ): AwaitedReturn { if (!groupPk || !toRemove.length) { @@ -1067,14 +1071,18 @@ function deleteAllMessageFromSendersInConversation( } return assertGlobalInstanceOrInstance(instance) .prepare( - `DELETE FROM ${MESSAGES_TABLE} WHERE conversationId = ? AND source IN ( ${toRemove.map(() => '?').join(', ')} ) RETURNING id` + `DELETE FROM ${MESSAGES_TABLE} WHERE conversationId = ? AND sent_at <= ? AND source IN ( ${toRemove.map(() => '?').join(', ')} ) RETURNING id` ) - .all(groupPk, ...toRemove) + .all(groupPk, signatureTimestamp, ...toRemove) .map(m => m.id); } function deleteAllMessageHashesInConversation( - { groupPk, messageHashes }: DataCallArgs, + { + groupPk, + messageHashes, + signatureTimestamp, + }: DataCallArgs, instance?: BetterSqlite3.Database ): AwaitedReturn { if (!groupPk || !messageHashes.length) { @@ -1082,9 +1090,9 @@ function deleteAllMessageHashesInConversation( } return assertGlobalInstanceOrInstance(instance) .prepare( - `DELETE FROM ${MESSAGES_TABLE} WHERE conversationId = ? AND messageHash IN ( ${messageHashes.map(() => '?').join(', ')} ) RETURNING id` + `DELETE FROM ${MESSAGES_TABLE} WHERE conversationId = ? AND sent_at <= ? AND messageHash IN ( ${messageHashes.map(() => '?').join(', ')} ) RETURNING id` ) - .all(groupPk, ...messageHashes) + .all(groupPk, signatureTimestamp, ...messageHashes) .map(m => m.id); } @@ -1093,18 +1101,18 @@ function deleteAllMessageHashesInConversationMatchingAuthor( author, groupPk, messageHashes, + signatureTimestamp, }: DataCallArgs, instance?: BetterSqlite3.Database ): AwaitedReturn { if (!groupPk || !author || !messageHashes.length) { return []; } - console.warn('messageHashes', messageHashes); return assertGlobalInstanceOrInstance(instance) .prepare( - `DELETE FROM ${MESSAGES_TABLE} WHERE conversationId = ? AND source = ? AND messageHash IN ( ${messageHashes.map(() => '?').join(', ')} ) RETURNING id` + `DELETE FROM ${MESSAGES_TABLE} WHERE conversationId = ? AND source = ? AND sent_at <= ? AND messageHash IN ( ${messageHashes.map(() => '?').join(', ')} ) RETURNING id` ) - .all(groupPk, author, ...messageHashes) + .all(groupPk, author, signatureTimestamp, ...messageHashes) .map(m => m.id); } diff --git a/ts/receiver/groupv2/handleGroupV2Message.ts b/ts/receiver/groupv2/handleGroupV2Message.ts index dcd8eed5f..a66a6050c 100644 --- a/ts/receiver/groupv2/handleGroupV2Message.ts +++ b/ts/receiver/groupv2/handleGroupV2Message.ts @@ -374,6 +374,7 @@ async function handleGroupDeleteMemberContentMessage({ author, groupPk, messageHashes: change.messageHashes, + signatureTimestamp, }); window.inboxStore.dispatch( @@ -401,10 +402,12 @@ async function handleGroupDeleteMemberContentMessage({ const deletedBySenders = await Data.deleteAllMessageFromSendersInConversation({ groupPk, toRemove, + signatureTimestamp, }); // this is step 2. const deletedByHashes = await Data.deleteAllMessageHashesInConversation({ groupPk, messageHashes: change.messageHashes, + signatureTimestamp, }); // this is step 3. window.inboxStore.dispatch(