fix: unsend in group: only apply change for msg sent before sig_ts

pull/3052/head
Audric Ackermann 1 year ago
parent 23a0fd6b3a
commit 626e2a368c

@ -7,12 +7,14 @@ export type DataCallArgs<T extends (args: any) => any> = Parameters<T>[0];
export type DeleteAllMessageFromSendersInConversationType = ( export type DeleteAllMessageFromSendersInConversationType = (
args: WithGroupPubkey & { args: WithGroupPubkey & {
toRemove: Array<PubkeyType>; toRemove: Array<PubkeyType>;
signatureTimestamp: number;
} }
) => PrArrayMsgIds; ) => PrArrayMsgIds;
export type DeleteAllMessageHashesInConversationType = ( export type DeleteAllMessageHashesInConversationType = (
args: WithGroupPubkey & { args: WithGroupPubkey & {
messageHashes: Array<string>; messageHashes: Array<string>;
signatureTimestamp: number;
} }
) => PrArrayMsgIds; ) => PrArrayMsgIds;
@ -20,5 +22,6 @@ export type DeleteAllMessageHashesInConversationMatchingAuthorType = (
args: WithGroupPubkey & { args: WithGroupPubkey & {
messageHashes: Array<string>; messageHashes: Array<string>;
author: PubkeyType; author: PubkeyType;
signatureTimestamp: number;
} }
) => PrArrayMsgIds; ) => PrArrayMsgIds;

@ -137,7 +137,7 @@ async function unsendMessagesForEveryone(
conversation, conversation,
groupPk: destinationId, groupPk: destinationId,
msgsToDelete, 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); await deleteMessagesFromSwarmAndCompletelyLocally(conversation, msgsToDelete);

@ -1059,7 +1059,11 @@ function removeAllMessagesInConversation(
} }
function deleteAllMessageFromSendersInConversation( function deleteAllMessageFromSendersInConversation(
{ groupPk, toRemove }: DataCallArgs<DeleteAllMessageFromSendersInConversationType>, {
groupPk,
toRemove,
signatureTimestamp,
}: DataCallArgs<DeleteAllMessageFromSendersInConversationType>,
instance?: BetterSqlite3.Database instance?: BetterSqlite3.Database
): AwaitedReturn<DeleteAllMessageFromSendersInConversationType> { ): AwaitedReturn<DeleteAllMessageFromSendersInConversationType> {
if (!groupPk || !toRemove.length) { if (!groupPk || !toRemove.length) {
@ -1067,14 +1071,18 @@ function deleteAllMessageFromSendersInConversation(
} }
return assertGlobalInstanceOrInstance(instance) return assertGlobalInstanceOrInstance(instance)
.prepare( .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); .map(m => m.id);
} }
function deleteAllMessageHashesInConversation( function deleteAllMessageHashesInConversation(
{ groupPk, messageHashes }: DataCallArgs<DeleteAllMessageHashesInConversationType>, {
groupPk,
messageHashes,
signatureTimestamp,
}: DataCallArgs<DeleteAllMessageHashesInConversationType>,
instance?: BetterSqlite3.Database instance?: BetterSqlite3.Database
): AwaitedReturn<DeleteAllMessageHashesInConversationType> { ): AwaitedReturn<DeleteAllMessageHashesInConversationType> {
if (!groupPk || !messageHashes.length) { if (!groupPk || !messageHashes.length) {
@ -1082,9 +1090,9 @@ function deleteAllMessageHashesInConversation(
} }
return assertGlobalInstanceOrInstance(instance) return assertGlobalInstanceOrInstance(instance)
.prepare( .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); .map(m => m.id);
} }
@ -1093,18 +1101,18 @@ function deleteAllMessageHashesInConversationMatchingAuthor(
author, author,
groupPk, groupPk,
messageHashes, messageHashes,
signatureTimestamp,
}: DataCallArgs<DeleteAllMessageHashesInConversationMatchingAuthorType>, }: DataCallArgs<DeleteAllMessageHashesInConversationMatchingAuthorType>,
instance?: BetterSqlite3.Database instance?: BetterSqlite3.Database
): AwaitedReturn<DeleteAllMessageHashesInConversationMatchingAuthorType> { ): AwaitedReturn<DeleteAllMessageHashesInConversationMatchingAuthorType> {
if (!groupPk || !author || !messageHashes.length) { if (!groupPk || !author || !messageHashes.length) {
return []; return [];
} }
console.warn('messageHashes', messageHashes);
return assertGlobalInstanceOrInstance(instance) return assertGlobalInstanceOrInstance(instance)
.prepare( .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); .map(m => m.id);
} }

@ -374,6 +374,7 @@ async function handleGroupDeleteMemberContentMessage({
author, author,
groupPk, groupPk,
messageHashes: change.messageHashes, messageHashes: change.messageHashes,
signatureTimestamp,
}); });
window.inboxStore.dispatch( window.inboxStore.dispatch(
@ -401,10 +402,12 @@ async function handleGroupDeleteMemberContentMessage({
const deletedBySenders = await Data.deleteAllMessageFromSendersInConversation({ const deletedBySenders = await Data.deleteAllMessageFromSendersInConversation({
groupPk, groupPk,
toRemove, toRemove,
signatureTimestamp,
}); // this is step 2. }); // this is step 2.
const deletedByHashes = await Data.deleteAllMessageHashesInConversation({ const deletedByHashes = await Data.deleteAllMessageHashesInConversation({
groupPk, groupPk,
messageHashes: change.messageHashes, messageHashes: change.messageHashes,
signatureTimestamp,
}); // this is step 3. }); // this is step 3.
window.inboxStore.dispatch( window.inboxStore.dispatch(

Loading…
Cancel
Save