fix: fixed a bug with delete attachments before not working locally

pull/3052/head
Audric Ackermann 7 months ago
parent c9cd6a974f
commit c2e5c358f1
No known key found for this signature in database

@ -342,19 +342,53 @@ export const OverlayRightPanelSettings = () => {
)}
{hasClosedGroupV2QAButtons() && isGroupV2 ? (
<PanelIconButton
iconType={'group'}
text={'trigger avatar message'}
onClick={() => {
if (!PubKey.is03Pubkey(selectedConvoKey)) {
throw new Error('triggerFakeAvatarUpdate needs a 03 pubkey');
}
window.inboxStore?.dispatch(
groupInfoActions.triggerFakeAvatarUpdate({ groupPk: selectedConvoKey }) as any
);
}}
dataTestId="edit-group-name"
/>
<>
<PanelIconButton
iconType={'group'}
text={'trigger avatar message'}
onClick={() => {
if (!PubKey.is03Pubkey(selectedConvoKey)) {
throw new Error('triggerFakeAvatarUpdate needs a 03 pubkey');
}
window.inboxStore?.dispatch(
groupInfoActions.triggerFakeAvatarUpdate({ groupPk: selectedConvoKey }) as any
);
}}
dataTestId="edit-group-name"
/>
<PanelIconButton
iconType={'group'}
text={'trigger delete message before now'}
onClick={() => {
if (!PubKey.is03Pubkey(selectedConvoKey)) {
throw new Error('We need a 03 pubkey');
}
window.inboxStore?.dispatch(
groupInfoActions.triggerFakeDeleteMsgBeforeNow({
groupPk: selectedConvoKey,
messagesWithAttachmentsOnly: false,
}) as any
);
}}
dataTestId="edit-group-name"
/>
<PanelIconButton
iconType={'group'}
text={'delete message with attachments before now'}
onClick={() => {
if (!PubKey.is03Pubkey(selectedConvoKey)) {
throw new Error('We need a 03 pubkey');
}
window.inboxStore?.dispatch(
groupInfoActions.triggerFakeDeleteMsgBeforeNow({
groupPk: selectedConvoKey,
messagesWithAttachmentsOnly: true,
}) as any
);
}}
dataTestId="edit-group-name"
/>
</>
) : null}
{showAddRemoveModeratorsButton && (

@ -17,6 +17,7 @@ import { ConvoHub } from '../../../conversations';
import { ProfileManager } from '../../../profile_manager/ProfileManager';
import { UserUtils } from '../../../utils';
import { GroupSync } from '../../../utils/job_runners/jobs/GroupSyncJob';
import { destroyMessagesAndUpdateRedux } from '../../../disappearing_messages';
/**
* This is a basic optimization to avoid running the logic when the `deleteBeforeSeconds`
@ -52,8 +53,7 @@ async function handleMetaMergeResults(groupPk: GroupPubkeyType) {
isNumber(infos.deleteBeforeSeconds) &&
isFinite(infos.deleteBeforeSeconds) &&
infos.deleteBeforeSeconds > 0 &&
(lastAppliedRemoveMsgSentBeforeSeconds.get(groupPk) || Number.MAX_SAFE_INTEGER) >
infos.deleteBeforeSeconds
(lastAppliedRemoveMsgSentBeforeSeconds.get(groupPk) || 0) < infos.deleteBeforeSeconds
) {
// delete any messages in this conversation sent before that timestamp (in seconds)
const deletedMsgIds = await Data.removeAllMessagesInConversationSentBefore({
@ -74,7 +74,7 @@ async function handleMetaMergeResults(groupPk: GroupPubkeyType) {
isNumber(infos.deleteAttachBeforeSeconds) &&
isFinite(infos.deleteAttachBeforeSeconds) &&
infos.deleteAttachBeforeSeconds > 0 &&
(lastAppliedRemoveAttachmentSentBeforeSeconds.get(groupPk) || Number.MAX_SAFE_INTEGER) >
(lastAppliedRemoveAttachmentSentBeforeSeconds.get(groupPk) || 0) <
infos.deleteAttachBeforeSeconds
) {
// delete any attachments in this conversation sent before that timestamp (in seconds)
@ -87,12 +87,10 @@ async function handleMetaMergeResults(groupPk: GroupPubkeyType) {
impactedMsgModels.map(m => m.id)
);
for (let index = 0; index < impactedMsgModels.length; index++) {
const msg = impactedMsgModels[index];
await destroyMessagesAndUpdateRedux(
impactedMsgModels.map(m => ({ conversationKey: groupPk, messageId: m.id }))
);
// eslint-disable-next-line no-await-in-loop
await msg?.cleanup();
}
lastAppliedRemoveAttachmentSentBeforeSeconds.set(groupPk, infos.deleteAttachBeforeSeconds);
}
}
@ -239,7 +237,7 @@ async function handleGroupSharedConfigMessages(
window.inboxStore?.dispatch(
groupInfoActions.refreshGroupDetailsFromWrapper({
groupPk,
})as any
}) as any
);
} catch (e) {
window.log.warn(

@ -988,6 +988,57 @@ const triggerFakeAvatarUpdate = createAsyncThunk(
}
);
const triggerFakeDeleteMsgBeforeNow = createAsyncThunk(
'group/triggerFakeDeleteMsgBeforeNow',
async (
{
groupPk,
messagesWithAttachmentsOnly,
}: {
groupPk: GroupPubkeyType;
messagesWithAttachmentsOnly: boolean;
},
payloadCreator
): Promise<void> => {
const state = payloadCreator.getState() as StateType;
if (!state.groups.infos[groupPk]) {
throw new PreConditionFailed(
'triggerFakeDeleteMsgBeforeNow group not present in redux slice'
);
}
const convo = ConvoHub.use().get(groupPk);
const group = await UserGroupsWrapperActions.getGroup(groupPk);
if (!convo || !group || !group.secretKey || isEmpty(group.secretKey)) {
throw new Error(
'triggerFakeDeleteMsgBeforeNow: tried to make change to group but we do not have the admin secret key'
);
}
const nowSeconds = Math.floor(NetworkTime.now() / 1000);
const infoGet = await MetaGroupWrapperActions.infoGet(groupPk);
if (messagesWithAttachmentsOnly) {
infoGet.deleteAttachBeforeSeconds = nowSeconds;
} else {
infoGet.deleteBeforeSeconds = nowSeconds;
}
await MetaGroupWrapperActions.infoSet(groupPk, infoGet);
const extraStoreRequests = await StoreGroupRequestFactory.makeGroupMessageSubRequest([], group);
const batchResult = await GroupSync.pushChangesToGroupSwarmIfNeeded({
groupPk,
extraStoreRequests,
});
if (!batchResult) {
window.log.warn(
`failed to send deleteBeforeSeconds/deleteAttachBeforeSeconds message for group ${ed25519Str(groupPk)}`
);
throw new Error('failed to send deleteBeforeSeconds/deleteAttachBeforeSeconds message');
}
}
);
/**
* This action is used to trigger a change when the local user does a change to a group v2 members list.
* GroupV2 added members can be added two ways: with and without the history of messages.
@ -1363,6 +1414,7 @@ export const groupInfoActions = {
handleMemberLeftMessage,
currentDeviceGroupNameChange,
triggerFakeAvatarUpdate,
triggerFakeDeleteMsgBeforeNow,
...metaGroupSlice.actions,
};

Loading…
Cancel
Save