fix: migration started and working for note to self for user config

updated libsession to use setExpiry and getExpiry since we can't add new arguments to the getUserInfo and setUserInfo
pull/2861/head
William Grant 2 years ago
parent 2a6d8a6544
commit ff27913b66

@ -1581,6 +1581,7 @@ function updateToSessionSchemaVersion30(currentVersion: number, db: BetterSqlite
console.log(`updateToSessionSchemaVersion${targetVersion}: success!`); console.log(`updateToSessionSchemaVersion${targetVersion}: success!`);
} }
/** /**
* Get's the user's private and public keys from the database * Get's the user's private and public keys from the database
* @param db the database * @param db the database
@ -1636,18 +1637,12 @@ function updateToSessionSchemaVersion31(currentVersion: number, db: BetterSqlite
const ourDbProfileUrl = ourConversation.avatarPointer || ''; const ourDbProfileUrl = ourConversation.avatarPointer || '';
const ourDbProfileKey = fromHexToArray(ourConversation.profileKey || ''); const ourDbProfileKey = fromHexToArray(ourConversation.profileKey || '');
const ourConvoPriority = ourConversation.priority; const ourConvoPriority = ourConversation.priority;
// const ourConvoExpire = ourConversation.expireTimer || 0;
if (ourDbProfileUrl && !isEmpty(ourDbProfileKey)) { if (ourDbProfileUrl && !isEmpty(ourDbProfileKey)) {
userProfileWrapper.setUserInfo( userProfileWrapper.setUserInfo(ourDbName, ourConvoPriority, {
ourDbName, url: ourDbProfileUrl,
ourConvoPriority, key: ourDbProfileKey,
{ });
url: ourDbProfileUrl,
key: ourDbProfileKey,
}
// , ourConvoExpire
);
} }
insertContactIntoContactWrapper( insertContactIntoContactWrapper(
@ -1883,7 +1878,7 @@ function updateToSessionSchemaVersion33(currentVersion: number, db: BetterSqlite
throw new Error('privateEd25519 was empty. Considering no users are logged in'); throw new Error('privateEd25519 was empty. Considering no users are logged in');
} }
const { publicKeyHex } = keys; const { privateEd25519, publicKeyHex } = keys;
// Conversation changes // Conversation changes
// TODO can this be moved into libsession completely // TODO can this be moved into libsession completely
@ -1897,26 +1892,86 @@ function updateToSessionSchemaVersion33(currentVersion: number, db: BetterSqlite
db.prepare(`ALTER TABLE ${CONVERSATIONS_TABLE} ADD COLUMN hasOutdatedClient TEXT;`).run(); db.prepare(`ALTER TABLE ${CONVERSATIONS_TABLE} ADD COLUMN hasOutdatedClient TEXT;`).run();
// Note to Self // region Note to Self
db.prepare( const noteToSelfInfo = db
`UPDATE ${CONVERSATIONS_TABLE} SET .prepare(
`UPDATE ${CONVERSATIONS_TABLE} SET
expirationType = $expirationType expirationType = $expirationType
WHERE id = $id AND type = 'private' AND expireTimer > 0;` WHERE id = $id AND type = 'private' AND expireTimer > 0;`
).run({ expirationType: 'deleteAfterSend', id: publicKeyHex }); )
.run({ expirationType: 'deleteAfterSend', id: publicKeyHex });
if (noteToSelfInfo.changes) {
// Get expireTimer value
const ourConversation = db
.prepare(`SELECT * FROM ${CONVERSATIONS_TABLE} WHERE id = $id`)
.get({ id: publicKeyHex });
const expirySeconds = ourConversation.expireTimer || 0;
// Get existing config wrapper dump and update it
const userConfigWrapperDump = db
.prepare(`SELECT * FROM ${CONFIG_DUMP_TABLE} WHERE variant = 'UserConfig';`)
.get() as Record<string, any> | undefined;
if (userConfigWrapperDump) {
const userConfigData = (userConfigWrapperDump as any).data;
const userProfileWrapper = new UserConfigWrapperNode(privateEd25519, userConfigData);
userProfileWrapper.setExpiry(expirySeconds);
// dump the user wrapper content and save it to the DB
const userDump = userProfileWrapper.dump();
// Private Conversations const configDumpInfo = db
.prepare(
`INSERT OR REPLACE INTO ${CONFIG_DUMP_TABLE} (
publicKey,
variant,
data
) values (
$publicKey,
$variant,
$data
);`
)
.run({
publicKey: publicKeyHex,
variant: 'UserConfig',
data: userDump,
});
// TODO Cleanup logging
console.log(
'===================== configDumpInfo',
configDumpInfo,
'======================='
);
} else {
console.log(
'===================== userConfigWrapperDump not found ======================='
);
}
}
// endregion
// region Private Conversations
db.prepare( db.prepare(
`UPDATE ${CONVERSATIONS_TABLE} SET `UPDATE ${CONVERSATIONS_TABLE} SET
expirationType = $expirationType expirationType = $expirationType
WHERE type = 'private' AND expirationType = 'off' AND expireTimer > 0;` WHERE type = 'private' AND expirationType = 'off' AND expireTimer > 0;`
).run({ expirationType: 'deleteAfterRead' }); ).run({ expirationType: 'deleteAfterRead' });
// Groups // TODO add to Contact Wrapper
// if (privateConversationsInfo.changes) {}
// endregion
// region Groups
db.prepare( db.prepare(
`UPDATE ${CONVERSATIONS_TABLE} SET `UPDATE ${CONVERSATIONS_TABLE} SET
expirationType = $expirationType expirationType = $expirationType
WHERE type = 'group' AND id LIKE '05%' AND expireTimer > 0;` WHERE type = 'group' AND id LIKE '05%' AND expireTimer > 0;`
).run({ expirationType: 'deleteAfterSend' }); ).run({ expirationType: 'deleteAfterSend' });
// endregion
// Message changes // Message changes
db.prepare(`ALTER TABLE ${MESSAGES_TABLE} ADD COLUMN expirationType TEXT;`).run(); db.prepare(`ALTER TABLE ${MESSAGES_TABLE} ADD COLUMN expirationType TEXT;`).run();

@ -27,23 +27,14 @@ async function insertUserProfileIntoWrapper(convoId: string) {
)} ` )} `
); );
// const expirySeconds = ourConvo.get('expireTimer') || 0; // const expirySeconds = ourConvo.get('expireTimer') || 0;
// TODO setup getExpiry and setExpiry
if (dbProfileUrl && !isEmpty(dbProfileKey)) { if (dbProfileUrl && !isEmpty(dbProfileKey)) {
await UserConfigWrapperActions.setUserInfo( await UserConfigWrapperActions.setUserInfo(dbName, priority, {
dbName, url: dbProfileUrl,
priority, key: dbProfileKey,
{ });
url: dbProfileUrl,
key: dbProfileKey,
}
// expirySeconds
);
} else { } else {
await UserConfigWrapperActions.setUserInfo( await UserConfigWrapperActions.setUserInfo(dbName, priority, null);
dbName,
priority,
null
// , expirySeconds
);
} }
} }

@ -107,16 +107,27 @@ export const UserConfigWrapperActions: UserConfigWrapperActionsCalls = {
name: string, name: string,
priority: number, priority: number,
profilePic: { url: string; key: Uint8Array } | null profilePic: { url: string; key: Uint8Array } | null
// expireSeconds: number
) => ) =>
callLibSessionWorker([ callLibSessionWorker(['UserConfig', 'setUserInfo', name, priority, profilePic]) as Promise<
'UserConfig', ReturnType<UserConfigWrapperActionsCalls['setUserInfo']>
'setUserInfo', >,
name, // TODO blinded message request stuff later
priority, getEnableBlindedMsgRequest: async () =>
profilePic, callLibSessionWorker(['UserConfig', 'getEnableBlindedMsgRequest']) as Promise<
// expireSeconds, ReturnType<UserConfigWrapperActionsCalls['getEnableBlindedMsgRequest']>
]) as Promise<ReturnType<UserConfigWrapperActionsCalls['setUserInfo']>>, >,
setEnableBlindedMsgRequest: async (enable: boolean) =>
callLibSessionWorker(['UserConfig', 'setEnableBlindedMsgRequest', enable]) as Promise<
ReturnType<UserConfigWrapperActionsCalls['setEnableBlindedMsgRequest']>
>,
getExpiry: async () =>
callLibSessionWorker(['UserConfig', 'getExpiry']) as Promise<
ReturnType<UserConfigWrapperActionsCalls['getExpiry']>
>,
setExpiry: async (expirySeconds: number) =>
callLibSessionWorker(['UserConfig', 'setExpiry', expirySeconds]) as Promise<
ReturnType<UserConfigWrapperActionsCalls['setExpiry']>
>,
}; };
export const ContactsWrapperActions: ContactsWrapperActionsCalls = { export const ContactsWrapperActions: ContactsWrapperActionsCalls = {

Loading…
Cancel
Save