fix: track hashes for disappearing message timer changes too

pull/3281/head
Audric Ackermann 11 months ago
parent 6ae0e3aac9
commit 97da52113a
No known key found for this signature in database

@ -647,6 +647,7 @@ export async function setDisappearingMessagesByConvoId(
fromSync: false, fromSync: false,
fromCurrentDevice: true, fromCurrentDevice: true,
fromConfigMessage: false, fromConfigMessage: false,
messageHash: null,
}); });
} else { } else {
await conversation.updateExpireTimer({ await conversation.updateExpireTimer({
@ -655,6 +656,7 @@ export async function setDisappearingMessagesByConvoId(
fromSync: false, fromSync: false,
fromCurrentDevice: true, fromCurrentDevice: true,
fromConfigMessage: false, fromConfigMessage: false,
messageHash: null,
}); });
} }
} }

@ -137,6 +137,7 @@ import { OpenGroupRequestCommonType } from '../data/types';
import { ConversationTypeEnum, CONVERSATION_PRIORITIES } from './types'; import { ConversationTypeEnum, CONVERSATION_PRIORITIES } from './types';
import { NetworkTime } from '../util/NetworkTime'; import { NetworkTime } from '../util/NetworkTime';
import { MessageQueue } from '../session/sending'; import { MessageQueue } from '../session/sending';
import type { WithMessageHashOrNull } from '../session/types/with';
type InMemoryConvoInfos = { type InMemoryConvoInfos = {
mentionedUs: boolean; mentionedUs: boolean;
@ -897,7 +898,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
fromCurrentDevice, fromCurrentDevice,
shouldCommitConvo = true, shouldCommitConvo = true,
existingMessage, existingMessage,
}: { messageHash,
}: WithMessageHashOrNull & {
providedDisappearingMode?: DisappearingMessageConversationModeType; providedDisappearingMode?: DisappearingMessageConversationModeType;
providedExpireTimer?: number; providedExpireTimer?: number;
providedSource?: string; providedSource?: string;
@ -1005,6 +1007,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
source, source,
fromSync, fromSync,
}, },
messageHash: messageHash || undefined,
}; };
if (!message) { if (!message) {

@ -327,6 +327,7 @@ export async function handleNewClosedGroup(
fromSync: false, fromSync: false,
fromCurrentDevice: false, fromCurrentDevice: false,
fromConfigMessage: false, fromConfigMessage: false,
messageHash: null, // legacy groups
}); });
await IncomingMessageCache.removeFromCache(envelope); await IncomingMessageCache.removeFromCache(envelope);

@ -278,6 +278,7 @@ async function handleUserProfileUpdate(result: IncomingUserResult): Promise<void
shouldCommitConvo: false, shouldCommitConvo: false,
fromCurrentDevice: false, fromCurrentDevice: false,
fromConfigMessage: true, fromConfigMessage: true,
messageHash: null,
}); });
changes = success; changes = success;
} }
@ -424,6 +425,7 @@ async function handleContactsUpdate(result: IncomingUserResult) {
fromCurrentDevice: false, fromCurrentDevice: false,
shouldCommitConvo: false, shouldCommitConvo: false,
fromConfigMessage: true, fromConfigMessage: true,
messageHash: null,
}); });
changes = changes || success; changes = changes || success;
} }
@ -657,6 +659,7 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
shouldCommitConvo: false, shouldCommitConvo: false,
fromCurrentDevice: false, fromCurrentDevice: false,
fromConfigMessage: true, fromConfigMessage: true,
messageHash: null, // legacy groups
}); });
changes = success; changes = success;
} }

@ -20,7 +20,7 @@ import { PreConditionFailed } from '../../session/utils/errors';
import { LibSessionUtil } from '../../session/utils/libsession/libsession_utils'; import { LibSessionUtil } from '../../session/utils/libsession/libsession_utils';
import { SessionUtilConvoInfoVolatile } from '../../session/utils/libsession/libsession_utils_convo_info_volatile'; import { SessionUtilConvoInfoVolatile } from '../../session/utils/libsession/libsession_utils_convo_info_volatile';
import { groupInfoActions } from '../../state/ducks/metaGroups'; import { groupInfoActions } from '../../state/ducks/metaGroups';
import { toFixedUint8ArrayOfLength } from '../../types/sqlSharedTypes'; import { stringify, toFixedUint8ArrayOfLength } from '../../types/sqlSharedTypes';
import { BlockedNumberController } from '../../util'; import { BlockedNumberController } from '../../util';
import { import {
MetaGroupWrapperActions, MetaGroupWrapperActions,
@ -282,6 +282,7 @@ async function handleGroupInfoChangeMessage({
fromCurrentDevice: false, fromCurrentDevice: false,
fromSync: false, fromSync: false,
fromConfigMessage: false, fromConfigMessage: false,
messageHash,
}); });
} }
break; break;
@ -591,6 +592,9 @@ async function handleGroupUpdatePromoteMessage({
groupSecretKey: groupKeypair.privateKey, groupSecretKey: groupKeypair.privateKey,
inviterIsApproved: authorIsApproved, inviterIsApproved: authorIsApproved,
}); });
window.log.info(
`received promote to group ${ed25519Str(groupPk)} group details: ${stringify(found)}`
);
await UserGroupsWrapperActions.setGroup(found); await UserGroupsWrapperActions.setGroup(found);
// force markedAsUnread to be true so it shows the unread banner (we only show the banner if there are unread messages on at least one msg/group request) // force markedAsUnread to be true so it shows the unread banner (we only show the banner if there are unread messages on at least one msg/group request)
@ -605,24 +609,35 @@ async function handleGroupUpdatePromoteMessage({
await deleteAllMessagesByConvoIdNoConfirmation(groupPk); await deleteAllMessagesByConvoIdNoConfirmation(groupPk);
} }
try { try {
await MetaGroupWrapperActions.init(groupPk, { let wrapperAlreadyInit = false;
metaDumped: null, try {
groupEd25519Secretkey: groupKeypair.privateKey, await MetaGroupWrapperActions.infoGet(groupPk);
userEd25519Secretkey: toFixedUint8ArrayOfLength(userEd25519Secretkey, 64).buffer, wrapperAlreadyInit = true;
groupEd25519Pubkey: toFixedUint8ArrayOfLength(HexString.fromHexStringNoPrefix(groupPk), 32) } catch (e) {
.buffer, // nothing to do
}); }
if (!wrapperAlreadyInit) {
await MetaGroupWrapperActions.init(groupPk, {
metaDumped: null,
groupEd25519Secretkey: groupKeypair.privateKey,
userEd25519Secretkey: toFixedUint8ArrayOfLength(userEd25519Secretkey, 64).buffer,
groupEd25519Pubkey: toFixedUint8ArrayOfLength(HexString.fromHexStringNoPrefix(groupPk), 32)
.buffer,
});
}
} catch (e) { } catch (e) {
window.log.warn( window.log.warn(
`handleGroupUpdatePromoteMessage: init of ${ed25519Str(groupPk)} failed with ${e.message}. Trying to just load admin keys` `handleGroupUpdatePromoteMessage: init of ${ed25519Str(groupPk)} failed with ${e.message}.`
);
}
try {
window.log.info(`Trying to just load admin keys for group ${ed25519Str(groupPk)}`);
await MetaGroupWrapperActions.loadAdminKeys(groupPk, groupKeypair.privateKey);
} catch (e2) {
window.log.warn(
`handleGroupUpdatePromoteMessage: loadAdminKeys of ${ed25519Str(groupPk)} failed with ${e2.message}`
); );
try {
await MetaGroupWrapperActions.loadAdminKeys(groupPk, groupKeypair.privateKey);
} catch (e2) {
window.log.warn(
`handleGroupUpdatePromoteMessage: loadAdminKeys of ${ed25519Str(groupPk)} failed with ${e.message}`
);
}
} }
await LibSessionUtil.saveDumpsToDb(UserUtils.getOurPubKeyStrFromCache()); await LibSessionUtil.saveDumpsToDb(UserUtils.getOurPubKeyStrFromCache());

@ -489,6 +489,7 @@ export async function handleMessageJob(
shouldCommitConvo: false, shouldCommitConvo: false,
fromCurrentDevice: false, fromCurrentDevice: false,
fromConfigMessage: false, fromConfigMessage: false,
messageHash,
// NOTE we don't commit yet because we want to get the message id, see below // NOTE we don't commit yet because we want to get the message id, see below
}); });
} else { } else {

@ -557,6 +557,7 @@ describe('DisappearingMessage', () => {
existingMessage: undefined, existingMessage: undefined,
fromCurrentDevice: false, fromCurrentDevice: false,
fromConfigMessage: false, fromConfigMessage: false,
messageHash: null,
}); });
await expect(promise).is.rejectedWith( await expect(promise).is.rejectedWith(
'updateExpireTimer() Disappearing messages are only supported int groups and private chats' 'updateExpireTimer() Disappearing messages are only supported int groups and private chats'
@ -587,6 +588,7 @@ describe('DisappearingMessage', () => {
existingMessage: undefined, existingMessage: undefined,
fromCurrentDevice: false, fromCurrentDevice: false,
fromConfigMessage: false, fromConfigMessage: false,
messageHash: null,
}); });
expect(updateSuccess, 'should be true').to.be.true; expect(updateSuccess, 'should be true').to.be.true;
}); });
@ -611,6 +613,7 @@ describe('DisappearingMessage', () => {
existingMessage: undefined, existingMessage: undefined,
fromCurrentDevice: false, fromCurrentDevice: false,
fromConfigMessage: false, fromConfigMessage: false,
messageHash: null,
}); });
expect(updateSuccess, 'should be true').to.be.true; expect(updateSuccess, 'should be true').to.be.true;
expect( expect(

Loading…
Cancel
Save