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,
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,

@ -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<string>;
groupAdmins: string | Array<string>;
lastJoinedTimestamp: number;
}) {
const admins: Array<string> = maybeArrayJSONtoArray(maybeAdmins);
const members: Array<string> = 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`
);
}
}
}

@ -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;
// }

@ -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 || '',

@ -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<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({
id,
priority,
members: maybeMembers,
displayNameInProfile,
// expireTimer,
expirationType,
expireTimer,
encPubkeyHex,
encSeckeyHex,
groupAdmins: maybeAdmins,
lastJoinedTimestamp,
}: Pick<
ConversationAttributes,
'id' | 'priority' | 'displayNameInProfile' | 'lastJoinedTimestamp'
// | 'expireTimer'
> & {
}: {
id: string;
priority: number;
displayNameInProfile: string | undefined;
expirationType: string | undefined;
expireTimer: number | undefined;
encPubkeyHex: string;
encSeckeyHex: string;
members: string | Array<string>;
groupAdmins: string | Array<string>;
lastJoinedTimestamp: number;
}) {
const admins: Array<string> = maybeArrayJSONtoArray(maybeAdmins);
const members: Array<string> = 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,

Loading…
Cancel
Save