feat: moved non libsession migration util functions into a separate file
parent
43276b069e
commit
6af27d85de
@ -0,0 +1,43 @@
|
|||||||
|
/* eslint-disable no-unused-expressions */
|
||||||
|
import * as BetterSqlite3 from '@signalapp/better-sqlite3';
|
||||||
|
import { isArray } from 'lodash';
|
||||||
|
import { CONVERSATIONS_TABLE } from '../database_utility';
|
||||||
|
import { getIdentityKeys, sqlNode } from '../sql';
|
||||||
|
|
||||||
|
export const hasDebugEnvVariable = Boolean(process.env.SESSION_DEBUG);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the logged in user conversation attributes and the keys.
|
||||||
|
* If the keys exists but a conversation for that pubkey does not exist yet, the keys are still returned
|
||||||
|
*/
|
||||||
|
export function getLoggedInUserConvoDuringMigration(db: BetterSqlite3.Database) {
|
||||||
|
const ourKeys = getIdentityKeys(db);
|
||||||
|
|
||||||
|
if (!ourKeys || !ourKeys.publicKeyHex || !ourKeys.privateEd25519) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ourConversation = db.prepare(`SELECT * FROM ${CONVERSATIONS_TABLE} WHERE id = $id;`).get({
|
||||||
|
id: ourKeys.publicKeyHex,
|
||||||
|
}) as Record<string, any> | null;
|
||||||
|
|
||||||
|
return { ourKeys, ourConversation: ourConversation || null };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBlockedNumbersDuringMigration(db: BetterSqlite3.Database) {
|
||||||
|
try {
|
||||||
|
const blockedItem = sqlNode.getItemById('blocked', db);
|
||||||
|
if (!blockedItem) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const foundBlocked = blockedItem?.value;
|
||||||
|
hasDebugEnvVariable && console.info('foundBlockedNumbers during migration', foundBlocked);
|
||||||
|
if (isArray(foundBlocked)) {
|
||||||
|
return foundBlocked;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
} catch (e) {
|
||||||
|
console.info('failed to read blocked numbers. Considering no blocked numbers', e.stack);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue