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 = (
args: WithGroupPubkey & {
toRemove: Array<PubkeyType>;
signatureTimestamp: number;
}
) => PrArrayMsgIds;
export type DeleteAllMessageHashesInConversationType = (
args: WithGroupPubkey & {
messageHashes: Array<string>;
signatureTimestamp: number;
}
) => PrArrayMsgIds;
@ -20,5 +22,6 @@ export type DeleteAllMessageHashesInConversationMatchingAuthorType = (
args: WithGroupPubkey & {
messageHashes: Array<string>;
author: PubkeyType;
signatureTimestamp: number;
}
) => PrArrayMsgIds;

@ -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);

@ -1059,7 +1059,11 @@ function removeAllMessagesInConversation(
}
function deleteAllMessageFromSendersInConversation(
{ groupPk, toRemove }: DataCallArgs<DeleteAllMessageFromSendersInConversationType>,
{
groupPk,
toRemove,
signatureTimestamp,
}: DataCallArgs<DeleteAllMessageFromSendersInConversationType>,
instance?: BetterSqlite3.Database
): AwaitedReturn<DeleteAllMessageFromSendersInConversationType> {
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<DeleteAllMessageHashesInConversationType>,
{
groupPk,
messageHashes,
signatureTimestamp,
}: DataCallArgs<DeleteAllMessageHashesInConversationType>,
instance?: BetterSqlite3.Database
): AwaitedReturn<DeleteAllMessageHashesInConversationType> {
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<DeleteAllMessageHashesInConversationMatchingAuthorType>,
instance?: BetterSqlite3.Database
): AwaitedReturn<DeleteAllMessageHashesInConversationMatchingAuthorType> {
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);
}

@ -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(

Loading…
Cancel
Save