fix: making progress with group migration

still getting overriden on render
pull/2971/head
William Grant 2 years ago
parent 45cfa6b38b
commit 37676e5666

@ -262,7 +262,6 @@ function getLegacyGroupInfoFromDBValues({
priority, priority,
members: maybeMembers, members: maybeMembers,
displayNameInProfile, displayNameInProfile,
// expireTimer,
encPubkeyHex, encPubkeyHex,
encSeckeyHex, encSeckeyHex,
groupAdmins: maybeAdmins, groupAdmins: maybeAdmins,
@ -270,7 +269,6 @@ function getLegacyGroupInfoFromDBValues({
}: Pick< }: Pick<
ConversationAttributes, ConversationAttributes,
'id' | 'priority' | 'displayNameInProfile' | 'lastJoinedTimestamp' 'id' | 'priority' | 'displayNameInProfile' | 'lastJoinedTimestamp'
// | 'expireTimer'
> & { > & {
encPubkeyHex: string; encPubkeyHex: string;
encSeckeyHex: string; encSeckeyHex: string;
@ -288,7 +286,6 @@ function getLegacyGroupInfoFromDBValues({
}); });
const legacyGroup: LegacyGroupInfo = { const legacyGroup: LegacyGroupInfo = {
pubkeyHex: id, pubkeyHex: id,
// disappearingTimerSeconds: !expireTimer ? 0 : expireTimer, // FIXME WILL add expirationMode here
name: displayNameInProfile || '', name: displayNameInProfile || '',
priority: priority || 0, priority: priority || 0,
members: wrappedMembers, members: wrappedMembers,

@ -10,10 +10,7 @@ import {
} from 'libsession_util_nodejs'; } from 'libsession_util_nodejs';
import { isEmpty, isEqual } from 'lodash'; import { isEmpty, isEqual } from 'lodash';
import { from_hex } from 'libsodium-wrappers-sumo'; import { from_hex } from 'libsodium-wrappers-sumo';
import { import { CONVERSATION_PRIORITIES } from '../../../models/conversationAttributes';
CONVERSATION_PRIORITIES,
ConversationAttributes,
} from '../../../models/conversationAttributes';
import { fromHexToArray } from '../../../session/utils/String'; import { fromHexToArray } from '../../../session/utils/String';
import { checkTargetMigration, hasDebugEnvVariable } from '../utils'; import { checkTargetMigration, hasDebugEnvVariable } from '../utils';
import { import {
@ -211,19 +208,17 @@ function getLegacyGroupInfoFromDBValues({
encSeckeyHex, encSeckeyHex,
groupAdmins: maybeAdmins, groupAdmins: maybeAdmins,
lastJoinedTimestamp, lastJoinedTimestamp,
}: Pick< }: {
ConversationAttributes, id: string;
| 'id' priority: number;
| 'priority' displayNameInProfile: string | undefined;
| 'displayNameInProfile' expirationType: string | undefined;
| 'lastJoinedTimestamp' expireTimer: number | undefined;
| 'expirationType'
| 'expireTimer'
> & {
encPubkeyHex: string; encPubkeyHex: string;
encSeckeyHex: string; encSeckeyHex: string;
members: string | Array<string>; members: string | Array<string>;
groupAdmins: string | Array<string>; groupAdmins: string | Array<string>;
lastJoinedTimestamp: number;
}) { }) {
const admins: Array<string> = maybeArrayJSONtoArray(maybeAdmins); const admins: Array<string> = maybeArrayJSONtoArray(maybeAdmins);
const members: Array<string> = maybeArrayJSONtoArray(maybeMembers); const members: Array<string> = maybeArrayJSONtoArray(maybeMembers);
@ -255,59 +250,43 @@ function getLegacyGroupInfoFromDBValues({
} }
function updateLegacyGroupInWrapper( function updateLegacyGroupInWrapper(
legacyGroup: Pick< legacyGroup: any,
ConversationAttributes,
| 'id'
| 'priority'
| 'displayNameInProfile'
| 'lastJoinedTimestamp'
| 'expirationType'
| 'expireTimer'
> & { members: string; groupAdmins: string }, // members and groupAdmins are still stringified here
userGroupConfigWrapper: UserGroupsWrapperNode, userGroupConfigWrapper: UserGroupsWrapperNode,
db: BetterSqlite3.Database, db: BetterSqlite3.Database,
version: number version: number
) { ) {
checkTargetMigration(version, targetVersion); checkTargetMigration(version, targetVersion);
const { if (legacyGroup !== null) {
priority, const priority = legacyGroup.priority || CONVERSATION_PRIORITIES.default;
id,
expirationType,
expireTimer,
groupAdmins,
members,
displayNameInProfile,
lastJoinedTimestamp,
} = legacyGroup;
const latestEncryptionKeyPairHex = sqlNode.getLatestClosedGroupEncryptionKeyPair( const latestEncryptionKeyPairHex = sqlNode.getLatestClosedGroupEncryptionKeyPair(
legacyGroup.id, legacyGroup.id,
db db
) as HexKeyPair | undefined; ) as HexKeyPair | undefined;
const wrapperLegacyGroup = getLegacyGroupInfoFromDBValues({ const wrapperLegacyGroup = getLegacyGroupInfoFromDBValues({
id, id: legacyGroup.id,
priority, priority,
expirationType, expirationType: legacyGroup.expirationType || 'off',
expireTimer, expireTimer: legacyGroup.expireTimer || 0,
groupAdmins, groupAdmins: legacyGroup.groupAdmins || [],
members, members: legacyGroup.members || [],
displayNameInProfile, displayNameInProfile: legacyGroup.displayNameInProfile || '',
encPubkeyHex: latestEncryptionKeyPairHex?.publicHex || '', encPubkeyHex: latestEncryptionKeyPairHex?.publicHex || '',
encSeckeyHex: latestEncryptionKeyPairHex?.privateHex || '', encSeckeyHex: latestEncryptionKeyPairHex?.privateHex || '',
lastJoinedTimestamp, lastJoinedTimestamp: legacyGroup.lastJoinedTimestamp || 0,
}); });
try { try {
hasDebugEnvVariable && hasDebugEnvVariable &&
console.info('Inserting legacy group into wrapper: ', wrapperLegacyGroup); console.info('Inserting legacy group into wrapper: ', wrapperLegacyGroup);
const success = userGroupConfigWrapper.setLegacyGroup(wrapperLegacyGroup); userGroupConfigWrapper.setLegacyGroup(wrapperLegacyGroup);
hasDebugEnvVariable && console.info('legacy group into wrapper success: ', success); } catch (e) {
} catch (e) { console.error(
console.error( `userGroupConfigWrapper.set during migration failed with ${e.message} for legacyGroup.id: "${legacyGroup.id}". Skipping that legacy group entirely`
`userGroupConfigWrapper.set during migration failed with ${e.message} for legacyGroup.id: "${legacyGroup.id}". Skipping that legacy group entirely` );
); }
} }
} }

@ -41,7 +41,7 @@ import {
} from '../util/storage'; } from '../util/storage';
import { deleteAllMessagesByConvoIdNoConfirmation } from '../interactions/conversationInteractions'; import { deleteAllMessagesByConvoIdNoConfirmation } from '../interactions/conversationInteractions';
// eslint-disable-next-line import/no-unresolved, import/extensions // 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 { import {
ContactsWrapperActions, ContactsWrapperActions,
ConvoInfoVolatileWrapperActions, ConvoInfoVolatileWrapperActions,
@ -545,6 +545,13 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
continue; continue;
} }
window.log.debug(
`WIP: handleLegacyGroupUpdate for ${fromWrapper.pubkeyHex}legacyGroupConvo `,
legacyGroupConvo,
'fromWrapper',
fromWrapper
);
const members = fromWrapper.members.map(m => m.pubkeyHex); const members = fromWrapper.members.map(m => m.pubkeyHex);
const admins = fromWrapper.members.filter(m => m.isAdmin).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 // 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
? legacyGroupConvo.get('active_at') ? legacyGroupConvo.get('active_at')
: latestEnvelopeTimestamp, : 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); await ClosedGroup.updateOrCreateClosedGroup(groupDetails);
let changes = await legacyGroupConvo.setPriorityFromWrapper(fromWrapper.priority, false); let changes = await legacyGroupConvo.setPriorityFromWrapper(fromWrapper.priority, false);
@ -574,16 +588,18 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
changes = true; changes = true;
} }
// FIXME Will unsure
// if (legacyGroupConvo.get('expireTimer') !== fromWrapper.disappearingTimerSeconds) { // if (legacyGroupConvo.get('expireTimer') !== fromWrapper.disappearingTimerSeconds) {
// // TODO Not sure about this
// await legacyGroupConvo.updateExpireTimer({ // await legacyGroupConvo.updateExpireTimer({
// providedExpirationType:
// !!fromWrapper.disappearingTimerSeconds && fromWrapper.disappearingTimerSeconds === 0
// ? 'off'
// : 'deleteAfterSend',
// providedExpireTimer: fromWrapper.disappearingTimerSeconds, // providedExpireTimer: fromWrapper.disappearingTimerSeconds,
// shouldCommit: false, // shouldCommit: false,
// fromSync: true, // fromSync: true,
// providedChangeTimestamp: latestEnvelopeTimestamp, // providedChangeTimestamp: latestEnvelopeTimestamp,
// fromConfigMessage: true, // fromConfigMessage: true,
// providedExpirationType:
// fromWrapper.disappearingTimerSeconds === 0 ? 'off' : 'deleteAfterSend',
// }); // });
// changes = true; // changes = true;
// } // }

@ -116,7 +116,8 @@ async function insertGroupsFromDBIntoWrapperAndRefresh(convoId: string): Promise
priority: foundConvo.get('priority'), priority: foundConvo.get('priority'),
members: foundConvo.get('members') || [], members: foundConvo.get('members') || [],
groupAdmins: foundConvo.get('groupAdmins') || [], 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'), displayNameInProfile: foundConvo.get('displayNameInProfile'),
encPubkeyHex: encryptionKeyPair?.publicHex || '', encPubkeyHex: encryptionKeyPair?.publicHex || '',
encSeckeyHex: encryptionKeyPair?.privateHex || '', encSeckeyHex: encryptionKeyPair?.privateHex || '',

@ -10,7 +10,6 @@ import {
import { from_hex } from 'libsodium-wrappers-sumo'; import { from_hex } from 'libsodium-wrappers-sumo';
import { isArray, isEmpty, isEqual } from 'lodash'; import { isArray, isEmpty, isEqual } from 'lodash';
import { OpenGroupV2Room } from '../data/opengroups'; import { OpenGroupV2Room } from '../data/opengroups';
import { ConversationAttributes } from '../models/conversationAttributes';
import { OpenGroupRequestCommonType } from '../session/apis/open_group_api/opengroupV2/ApiUtil'; import { OpenGroupRequestCommonType } from '../session/apis/open_group_api/opengroupV2/ApiUtil';
import { fromHexToArray } from '../session/utils/String'; import { fromHexToArray } from '../session/utils/String';
import { ConfigWrapperObjectTypes } from '../webworker/workers/browser/libsession_worker_functions'; import { ConfigWrapperObjectTypes } from '../webworker/workers/browser/libsession_worker_functions';
@ -208,27 +207,30 @@ export function maybeArrayJSONtoArray(arr: string | Array<string>): Array<string
} }
/** /**
* NOTE This code should always match the last known version of the same function used in a libsession migration (V31) * NOTE This code should always match the last known version of the same function used in a libsession migration (V34)
*/ */
export function getLegacyGroupInfoFromDBValues({ export function getLegacyGroupInfoFromDBValues({
id, id,
priority, priority,
members: maybeMembers, members: maybeMembers,
displayNameInProfile, displayNameInProfile,
// expireTimer, expirationType,
expireTimer,
encPubkeyHex, encPubkeyHex,
encSeckeyHex, encSeckeyHex,
groupAdmins: maybeAdmins, groupAdmins: maybeAdmins,
lastJoinedTimestamp, lastJoinedTimestamp,
}: Pick< }: {
ConversationAttributes, id: string;
'id' | 'priority' | 'displayNameInProfile' | 'lastJoinedTimestamp' priority: number;
// | 'expireTimer' displayNameInProfile: string | undefined;
> & { expirationType: string | undefined;
expireTimer: number | undefined;
encPubkeyHex: string; encPubkeyHex: string;
encSeckeyHex: string; encSeckeyHex: string;
members: string | Array<string>; members: string | Array<string>;
groupAdmins: string | Array<string>; groupAdmins: string | Array<string>;
lastJoinedTimestamp: number;
}) { }) {
const admins: Array<string> = maybeArrayJSONtoArray(maybeAdmins); const admins: Array<string> = maybeArrayJSONtoArray(maybeAdmins);
const members: Array<string> = maybeArrayJSONtoArray(maybeMembers); const members: Array<string> = maybeArrayJSONtoArray(maybeMembers);
@ -239,9 +241,16 @@ export function getLegacyGroupInfoFromDBValues({
pubkeyHex: m, pubkeyHex: m,
}; };
}); });
const legacyGroup: LegacyGroupInfo = { const legacyGroup: LegacyGroupInfo = {
pubkeyHex: id, pubkeyHex: id,
// disappearingTimerSeconds: !expireTimer ? 0 : expireTimer, // FIXME WILL add expirationMode here disappearingTimerSeconds:
expirationType &&
(expirationType as DisappearingMessageConversationType) !== 'off' &&
!!expireTimer &&
expireTimer > 0
? expireTimer
: 0,
name: displayNameInProfile || '', name: displayNameInProfile || '',
priority: priority || 0, priority: priority || 0,
members: wrappedMembers, members: wrappedMembers,

Loading…
Cancel
Save