Skip to content

Commit 71cdaed

Browse files
committed
fix: force refetch of contacts config on multipart migration
1 parent a47ab1e commit 71cdaed

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

ts/node/migration/sessionMigrations.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const LOKI_SCHEMA_VERSIONS = [
113113
updateToSessionSchemaVersion42,
114114
updateToSessionSchemaVersion43,
115115
updateToSessionSchemaVersion44,
116+
updateToSessionSchemaVersion45,
116117
];
117118

118119
function updateToSessionSchemaVersion1(currentVersion: number, db: BetterSqlite3.Database) {
@@ -2100,6 +2101,39 @@ function updateToSessionSchemaVersion44(currentVersion: number, db: BetterSqlite
21002101
console.log(`updateToSessionSchemaVersion${targetVersion}: success!`);
21012102
}
21022103

2104+
function updateToSessionSchemaVersion45(currentVersion: number, db: BetterSqlite3.Database) {
2105+
const targetVersion = 45;
2106+
if (currentVersion >= targetVersion) {
2107+
return;
2108+
}
2109+
2110+
console.log(`updateToSessionSchemaVersion${targetVersion}: starting...`);
2111+
2112+
db.transaction(() => {
2113+
try {
2114+
const loggedInUser = getLoggedInUserConvoDuringMigration(db);
2115+
2116+
if (!loggedInUser || !loggedInUser?.ourKeys.publicKeyHex) {
2117+
throw new Error('publicKeyHex was empty. Considering no users are logged in');
2118+
}
2119+
2120+
const { publicKeyHex } = loggedInUser.ourKeys;
2121+
// if another of our device has pushed a multipart message and we have dropped it locally
2122+
// as we didn't support multi part yet, we need to refetch the message from the swarm.
2123+
// Note: this is only needed for our own contacts config.
2124+
db.prepare(
2125+
`DELETE FROM ${LAST_HASHES_TABLE} WHERE id = '${publicKeyHex}' AND namespace = 3;` // UserContacts
2126+
).run();
2127+
} catch (e) {
2128+
// if no users are logged in, we can just continue here. Nothing is due to clean
2129+
}
2130+
2131+
writeSessionSchemaVersion(targetVersion, db);
2132+
})();
2133+
2134+
console.log(`updateToSessionSchemaVersion${targetVersion}: success!`);
2135+
}
2136+
21032137
export function printTableColumns(table: string, db: BetterSqlite3.Database) {
21042138
console.info(db.pragma(`table_info('${table}');`));
21052139
}

0 commit comments

Comments
 (0)