From 37676e56669d893ed17dcd04603b8aa1bdceb20b Mon Sep 17 00:00:00 2001 From: William Grant Date: Tue, 22 Aug 2023 17:15:07 +1000 Subject: [PATCH] fix: making progress with group migration still getting overriden on render --- ts/node/migration/helpers/v31.ts | 3 - ts/node/migration/helpers/v34.ts | 93 +++++++------------ ts/receiver/configMessage.ts | 24 ++++- .../libsession_utils_user_groups.ts | 3 +- ts/types/sqlSharedTypes.ts | 27 ++++-- 5 files changed, 76 insertions(+), 74 deletions(-) diff --git a/ts/node/migration/helpers/v31.ts b/ts/node/migration/helpers/v31.ts index 71ba35b8c..d1314b3cb 100644 --- a/ts/node/migration/helpers/v31.ts +++ b/ts/node/migration/helpers/v31.ts @@ -262,7 +262,6 @@ function getLegacyGroupInfoFromDBValues({ priority, members: maybeMembers, displayNameInProfile, - // expireTimer, encPubkeyHex, encSeckeyHex, groupAdmins: maybeAdmins, @@ -270,7 +269,6 @@ function getLegacyGroupInfoFromDBValues({ }: Pick< ConversationAttributes, 'id' | 'priority' | 'displayNameInProfile' | 'lastJoinedTimestamp' - // | 'expireTimer' > & { encPubkeyHex: string; encSeckeyHex: string; @@ -288,7 +286,6 @@ function getLegacyGroupInfoFromDBValues({ }); const legacyGroup: LegacyGroupInfo = { pubkeyHex: id, - // disappearingTimerSeconds: !expireTimer ? 0 : expireTimer, // FIXME WILL add expirationMode here name: displayNameInProfile || '', priority: priority || 0, members: wrappedMembers, diff --git a/ts/node/migration/helpers/v34.ts b/ts/node/migration/helpers/v34.ts index 0cadab880..8c962907b 100644 --- a/ts/node/migration/helpers/v34.ts +++ b/ts/node/migration/helpers/v34.ts @@ -10,10 +10,7 @@ import { } from 'libsession_util_nodejs'; import { isEmpty, isEqual } from 'lodash'; import { from_hex } from 'libsodium-wrappers-sumo'; -import { - CONVERSATION_PRIORITIES, - ConversationAttributes, -} from '../../../models/conversationAttributes'; +import { CONVERSATION_PRIORITIES } from '../../../models/conversationAttributes'; import { fromHexToArray } from '../../../session/utils/String'; import { checkTargetMigration, hasDebugEnvVariable } from '../utils'; import { @@ -211,19 +208,17 @@ function getLegacyGroupInfoFromDBValues({ encSeckeyHex, groupAdmins: maybeAdmins, lastJoinedTimestamp, -}: Pick< - ConversationAttributes, - | 'id' - | 'priority' - | 'displayNameInProfile' - | 'lastJoinedTimestamp' - | 'expirationType' - | 'expireTimer' -> & { +}: { + id: string; + priority: number; + displayNameInProfile: string | undefined; + expirationType: string | undefined; + expireTimer: number | undefined; encPubkeyHex: string; encSeckeyHex: string; members: string | Array; groupAdmins: string | Array; + lastJoinedTimestamp: number; }) { const admins: Array = maybeArrayJSONtoArray(maybeAdmins); const members: Array = maybeArrayJSONtoArray(maybeMembers); @@ -255,59 +250,43 @@ function getLegacyGroupInfoFromDBValues({ } function updateLegacyGroupInWrapper( - legacyGroup: Pick< - ConversationAttributes, - | 'id' - | 'priority' - | 'displayNameInProfile' - | 'lastJoinedTimestamp' - | 'expirationType' - | 'expireTimer' - > & { members: string; groupAdmins: string }, // members and groupAdmins are still stringified here + legacyGroup: any, userGroupConfigWrapper: UserGroupsWrapperNode, db: BetterSqlite3.Database, version: number ) { checkTargetMigration(version, targetVersion); - const { - priority, - id, - expirationType, - expireTimer, - groupAdmins, - members, - displayNameInProfile, - lastJoinedTimestamp, - } = legacyGroup; + if (legacyGroup !== null) { + const priority = legacyGroup.priority || CONVERSATION_PRIORITIES.default; - const latestEncryptionKeyPairHex = sqlNode.getLatestClosedGroupEncryptionKeyPair( - legacyGroup.id, - db - ) as HexKeyPair | undefined; + const latestEncryptionKeyPairHex = sqlNode.getLatestClosedGroupEncryptionKeyPair( + legacyGroup.id, + db + ) as HexKeyPair | undefined; - const wrapperLegacyGroup = getLegacyGroupInfoFromDBValues({ - id, - priority, - expirationType, - expireTimer, - groupAdmins, - members, - displayNameInProfile, - encPubkeyHex: latestEncryptionKeyPairHex?.publicHex || '', - encSeckeyHex: latestEncryptionKeyPairHex?.privateHex || '', - lastJoinedTimestamp, - }); + const wrapperLegacyGroup = getLegacyGroupInfoFromDBValues({ + id: legacyGroup.id, + priority, + expirationType: legacyGroup.expirationType || 'off', + expireTimer: legacyGroup.expireTimer || 0, + groupAdmins: legacyGroup.groupAdmins || [], + members: legacyGroup.members || [], + displayNameInProfile: legacyGroup.displayNameInProfile || '', + encPubkeyHex: latestEncryptionKeyPairHex?.publicHex || '', + encSeckeyHex: latestEncryptionKeyPairHex?.privateHex || '', + lastJoinedTimestamp: legacyGroup.lastJoinedTimestamp || 0, + }); - try { - hasDebugEnvVariable && - console.info('Inserting legacy group into wrapper: ', wrapperLegacyGroup); - const success = userGroupConfigWrapper.setLegacyGroup(wrapperLegacyGroup); - hasDebugEnvVariable && console.info('legacy group into wrapper success: ', success); - } catch (e) { - console.error( - `userGroupConfigWrapper.set during migration failed with ${e.message} for legacyGroup.id: "${legacyGroup.id}". Skipping that legacy group entirely` - ); + try { + hasDebugEnvVariable && + console.info('Inserting legacy group into wrapper: ', wrapperLegacyGroup); + userGroupConfigWrapper.setLegacyGroup(wrapperLegacyGroup); + } catch (e) { + console.error( + `userGroupConfigWrapper.set during migration failed with ${e.message} for legacyGroup.id: "${legacyGroup.id}". Skipping that legacy group entirely` + ); + } } } diff --git a/ts/receiver/configMessage.ts b/ts/receiver/configMessage.ts index 25c20031e..84a2e82db 100644 --- a/ts/receiver/configMessage.ts +++ b/ts/receiver/configMessage.ts @@ -41,7 +41,7 @@ import { } from '../util/storage'; import { deleteAllMessagesByConvoIdNoConfirmation } from '../interactions/conversationInteractions'; // eslint-disable-next-line import/no-unresolved, import/extensions -import { ConfigWrapperObjectTypes } from '../../ts/webworker/workers/browser/libsession_worker_functions'; +import { ConfigWrapperObjectTypes } from '../webworker/workers/browser/libsession_worker_functions'; import { ContactsWrapperActions, ConvoInfoVolatileWrapperActions, @@ -545,6 +545,13 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) { continue; } + window.log.debug( + `WIP: handleLegacyGroupUpdate for ${fromWrapper.pubkeyHex}legacyGroupConvo `, + legacyGroupConvo, + 'fromWrapper', + fromWrapper + ); + const members = fromWrapper.members.map(m => m.pubkeyHex); const admins = fromWrapper.members.filter(m => m.isAdmin).map(m => m.pubkeyHex); // then for all the existing legacy group in the wrapper, we need to override the field of what we have in the DB with what is in the wrapper @@ -559,8 +566,15 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) { legacyGroupConvo.get('active_at') < latestEnvelopeTimestamp ? legacyGroupConvo.get('active_at') : latestEnvelopeTimestamp, + expirationType: + !!fromWrapper.disappearingTimerSeconds && fromWrapper.disappearingTimerSeconds === 0 + ? 'off' + : 'deleteAfterSend', + expireTimer: fromWrapper.disappearingTimerSeconds, }; + window.log.debug(`WIP: groupDetails for ${fromWrapper.pubkeyHex} `, groupDetails); + await ClosedGroup.updateOrCreateClosedGroup(groupDetails); let changes = await legacyGroupConvo.setPriorityFromWrapper(fromWrapper.priority, false); @@ -574,16 +588,18 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) { changes = true; } - // FIXME Will unsure // if (legacyGroupConvo.get('expireTimer') !== fromWrapper.disappearingTimerSeconds) { + // // TODO Not sure about this // await legacyGroupConvo.updateExpireTimer({ + // providedExpirationType: + // !!fromWrapper.disappearingTimerSeconds && fromWrapper.disappearingTimerSeconds === 0 + // ? 'off' + // : 'deleteAfterSend', // providedExpireTimer: fromWrapper.disappearingTimerSeconds, // shouldCommit: false, // fromSync: true, // providedChangeTimestamp: latestEnvelopeTimestamp, // fromConfigMessage: true, - // providedExpirationType: - // fromWrapper.disappearingTimerSeconds === 0 ? 'off' : 'deleteAfterSend', // }); // changes = true; // } diff --git a/ts/session/utils/libsession/libsession_utils_user_groups.ts b/ts/session/utils/libsession/libsession_utils_user_groups.ts index d1b9629f1..c0acc0ef0 100644 --- a/ts/session/utils/libsession/libsession_utils_user_groups.ts +++ b/ts/session/utils/libsession/libsession_utils_user_groups.ts @@ -116,7 +116,8 @@ async function insertGroupsFromDBIntoWrapperAndRefresh(convoId: string): Promise priority: foundConvo.get('priority'), members: foundConvo.get('members') || [], groupAdmins: foundConvo.get('groupAdmins') || [], - // expireTimer: foundConvo.get('expireTimer'), // FIXME WILL add expirationMode here + expirationType: foundConvo.get('expirationType') || 'off', + expireTimer: foundConvo.get('expireTimer') || 0, displayNameInProfile: foundConvo.get('displayNameInProfile'), encPubkeyHex: encryptionKeyPair?.publicHex || '', encSeckeyHex: encryptionKeyPair?.privateHex || '', diff --git a/ts/types/sqlSharedTypes.ts b/ts/types/sqlSharedTypes.ts index fb1a853eb..b6d5b1df3 100644 --- a/ts/types/sqlSharedTypes.ts +++ b/ts/types/sqlSharedTypes.ts @@ -10,7 +10,6 @@ import { import { from_hex } from 'libsodium-wrappers-sumo'; import { isArray, isEmpty, isEqual } from 'lodash'; import { OpenGroupV2Room } from '../data/opengroups'; -import { ConversationAttributes } from '../models/conversationAttributes'; import { OpenGroupRequestCommonType } from '../session/apis/open_group_api/opengroupV2/ApiUtil'; import { fromHexToArray } from '../session/utils/String'; import { ConfigWrapperObjectTypes } from '../webworker/workers/browser/libsession_worker_functions'; @@ -208,27 +207,30 @@ export function maybeArrayJSONtoArray(arr: string | Array): Array & { +}: { + id: string; + priority: number; + displayNameInProfile: string | undefined; + expirationType: string | undefined; + expireTimer: number | undefined; encPubkeyHex: string; encSeckeyHex: string; members: string | Array; groupAdmins: string | Array; + lastJoinedTimestamp: number; }) { const admins: Array = maybeArrayJSONtoArray(maybeAdmins); const members: Array = maybeArrayJSONtoArray(maybeMembers); @@ -239,9 +241,16 @@ export function getLegacyGroupInfoFromDBValues({ pubkeyHex: m, }; }); + const legacyGroup: LegacyGroupInfo = { pubkeyHex: id, - // disappearingTimerSeconds: !expireTimer ? 0 : expireTimer, // FIXME WILL add expirationMode here + disappearingTimerSeconds: + expirationType && + (expirationType as DisappearingMessageConversationType) !== 'off' && + !!expireTimer && + expireTimer > 0 + ? expireTimer + : 0, name: displayNameInProfile || '', priority: priority || 0, members: wrappedMembers,