remove unused functions in Data.ts and sql.js
This commit is contained in:
parent
d844c5141e
commit
7e77a3f3b6
151
app/sql.js
151
app/sql.js
|
@ -33,8 +33,6 @@ module.exports = {
|
|||
removePasswordHash,
|
||||
|
||||
getIdentityKeyById,
|
||||
removeAllIdentityKeys,
|
||||
getAllIdentityKeys,
|
||||
|
||||
removeAllSignedPreKeys,
|
||||
removeAllContactPreKeys,
|
||||
|
@ -45,9 +43,7 @@ module.exports = {
|
|||
createOrUpdateItem,
|
||||
getItemById,
|
||||
getAllItems,
|
||||
bulkAddItems,
|
||||
removeItemById,
|
||||
removeAllItems,
|
||||
|
||||
getSwarmNodesForPubkey,
|
||||
updateSwarmNodesForPubkey,
|
||||
|
@ -56,7 +52,6 @@ module.exports = {
|
|||
|
||||
getConversationCount,
|
||||
saveConversation,
|
||||
saveConversations,
|
||||
getConversationById,
|
||||
savePublicServerToken,
|
||||
getPublicServerTokenByServerUrl,
|
||||
|
@ -64,7 +59,6 @@ module.exports = {
|
|||
removeConversation,
|
||||
getAllConversations,
|
||||
getAllPublicConversations,
|
||||
getPublicConversationsByServer,
|
||||
getPubkeysInPublicConversation,
|
||||
getAllConversationIds,
|
||||
getAllGroupsInvolvingId,
|
||||
|
@ -90,7 +84,6 @@ module.exports = {
|
|||
getMessageById,
|
||||
getAllMessages,
|
||||
getAllMessageIds,
|
||||
getAllUnsentMessages,
|
||||
getMessagesBySentAt,
|
||||
getSeenMessagesByHashList,
|
||||
getLastHashBySnode,
|
||||
|
@ -105,7 +98,6 @@ module.exports = {
|
|||
updateUnprocessedAttempts,
|
||||
updateUnprocessedWithData,
|
||||
getUnprocessedById,
|
||||
saveUnprocesseds,
|
||||
removeUnprocessed,
|
||||
removeAllUnprocessed,
|
||||
|
||||
|
@ -130,10 +122,6 @@ module.exports = {
|
|||
removeAllClosedGroupEncryptionKeyPairs,
|
||||
};
|
||||
|
||||
function generateUUID() {
|
||||
return uuidv4();
|
||||
}
|
||||
|
||||
function objectToJSON(data) {
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
|
@ -1265,35 +1253,30 @@ const IDENTITY_KEYS_TABLE = 'identityKeys';
|
|||
async function getIdentityKeyById(id, instance) {
|
||||
return getById(IDENTITY_KEYS_TABLE, id, instance);
|
||||
}
|
||||
async function removeAllIdentityKeys() {
|
||||
return removeAllFromTable(IDENTITY_KEYS_TABLE);
|
||||
}
|
||||
async function getAllIdentityKeys() {
|
||||
return getAllFromTable(IDENTITY_KEYS_TABLE);
|
||||
}
|
||||
|
||||
// those removeAll calls are currently only used to cleanup the db from old data
|
||||
// TODO remove those and move those removeAll in a migration
|
||||
const PRE_KEYS_TABLE = 'preKeys';
|
||||
|
||||
async function removeAllPreKeys() {
|
||||
return removeAllFromTable(PRE_KEYS_TABLE);
|
||||
}
|
||||
|
||||
const CONTACT_PRE_KEYS_TABLE = 'contactPreKeys';
|
||||
|
||||
async function removeAllContactPreKeys() {
|
||||
return removeAllFromTable(CONTACT_PRE_KEYS_TABLE);
|
||||
}
|
||||
|
||||
const CONTACT_SIGNED_PRE_KEYS_TABLE = 'contactSignedPreKeys';
|
||||
|
||||
async function removeAllContactSignedPreKeys() {
|
||||
return removeAllFromTable(CONTACT_SIGNED_PRE_KEYS_TABLE);
|
||||
}
|
||||
|
||||
const SIGNED_PRE_KEYS_TABLE = 'signedPreKeys';
|
||||
async function removeAllSignedPreKeys() {
|
||||
return removeAllFromTable(SIGNED_PRE_KEYS_TABLE);
|
||||
}
|
||||
const SESSIONS_TABLE = 'sessions';
|
||||
async function removeAllSessions() {
|
||||
return removeAllFromTable(SESSIONS_TABLE);
|
||||
}
|
||||
|
||||
const GUARD_NODE_TABLE = 'guardNodes';
|
||||
|
||||
|
@ -1342,20 +1325,9 @@ async function getAllItems() {
|
|||
const rows = await db.all('SELECT json FROM items ORDER BY id ASC;');
|
||||
return map(rows, row => jsonToObject(row.json));
|
||||
}
|
||||
async function bulkAddItems(array) {
|
||||
return bulkAdd(ITEMS_TABLE, array);
|
||||
}
|
||||
async function removeItemById(id) {
|
||||
return removeById(ITEMS_TABLE, id);
|
||||
}
|
||||
async function removeAllItems() {
|
||||
return removeAllFromTable(ITEMS_TABLE);
|
||||
}
|
||||
|
||||
const SESSIONS_TABLE = 'sessions';
|
||||
async function removeAllSessions() {
|
||||
return removeAllFromTable(SESSIONS_TABLE);
|
||||
}
|
||||
|
||||
async function createOrUpdate(table, data) {
|
||||
const { id } = data;
|
||||
|
@ -1378,20 +1350,6 @@ async function createOrUpdate(table, data) {
|
|||
);
|
||||
}
|
||||
|
||||
async function bulkAdd(table, array) {
|
||||
let promise;
|
||||
|
||||
db.serialize(() => {
|
||||
promise = Promise.all([
|
||||
db.run('BEGIN TRANSACTION;'),
|
||||
...map(array, data => createOrUpdate(table, data)),
|
||||
db.run('COMMIT TRANSACTION;'),
|
||||
]);
|
||||
});
|
||||
|
||||
await promise;
|
||||
}
|
||||
|
||||
async function getById(table, id, instance) {
|
||||
const row = await (db || instance).get(
|
||||
`SELECT * FROM ${table} WHERE id = $id;`,
|
||||
|
@ -1428,11 +1386,6 @@ async function removeAllFromTable(table) {
|
|||
await db.run(`DELETE FROM ${table};`);
|
||||
}
|
||||
|
||||
async function getAllFromTable(table) {
|
||||
const rows = await db.all(`SELECT json FROM ${table};`);
|
||||
return rows.map(row => jsonToObject(row.json));
|
||||
}
|
||||
|
||||
// Conversations
|
||||
|
||||
async function getSwarmNodesForPubkey(pubkey) {
|
||||
|
@ -1524,22 +1477,6 @@ async function saveConversation(data) {
|
|||
);
|
||||
}
|
||||
|
||||
async function saveConversations(arrayOfConversations) {
|
||||
let promise;
|
||||
|
||||
db.serialize(() => {
|
||||
promise = Promise.all([
|
||||
db.run('BEGIN TRANSACTION;'),
|
||||
...map(arrayOfConversations, conversation =>
|
||||
saveConversation(conversation)
|
||||
),
|
||||
db.run('COMMIT TRANSACTION;'),
|
||||
]);
|
||||
});
|
||||
|
||||
await promise;
|
||||
}
|
||||
|
||||
async function updateConversation(data) {
|
||||
const {
|
||||
id,
|
||||
|
@ -1667,19 +1604,6 @@ async function getAllPublicConversations() {
|
|||
return map(rows, row => jsonToObject(row.json));
|
||||
}
|
||||
|
||||
async function getPublicConversationsByServer(server) {
|
||||
const rows = await db.all(
|
||||
`SELECT * FROM ${CONVERSATIONS_TABLE} WHERE
|
||||
server = $server
|
||||
ORDER BY id ASC;`,
|
||||
{
|
||||
$server: server,
|
||||
}
|
||||
);
|
||||
|
||||
return map(rows, row => jsonToObject(row.json));
|
||||
}
|
||||
|
||||
async function getPubkeysInPublicConversation(id) {
|
||||
const rows = await db.all(
|
||||
`SELECT DISTINCT source FROM ${MESSAGES_TABLE} WHERE
|
||||
|
@ -1874,7 +1798,7 @@ async function saveMessage(data, { forceSave } = {}) {
|
|||
|
||||
const toCreate = {
|
||||
...data,
|
||||
id: id || generateUUID(),
|
||||
id: id || uuidv4(),
|
||||
};
|
||||
|
||||
await db.run(
|
||||
|
@ -2105,16 +2029,6 @@ async function getMessageBySender({ source, sourceDevice, sent_at }) {
|
|||
return map(rows, row => jsonToObject(row.json));
|
||||
}
|
||||
|
||||
async function getAllUnsentMessages() {
|
||||
const rows = await db.all(`
|
||||
SELECT json FROM ${MESSAGES_TABLE} WHERE
|
||||
type IN ('outgoing') AND
|
||||
NOT sent
|
||||
ORDER BY sent_at DESC;
|
||||
`);
|
||||
return map(rows, row => jsonToObject(row.json));
|
||||
}
|
||||
|
||||
async function getUnreadByConversation(conversationId) {
|
||||
const rows = await db.all(
|
||||
`SELECT json FROM ${MESSAGES_TABLE} WHERE
|
||||
|
@ -2257,6 +2171,7 @@ async function getNextExpiringMessage() {
|
|||
return map(rows, row => jsonToObject(row.json));
|
||||
}
|
||||
|
||||
/* Unproccessed a received messages not yet processed */
|
||||
async function saveUnprocessed(data, { forceSave } = {}) {
|
||||
const { id, timestamp, version, attempts, envelope, senderIdentity } = data;
|
||||
if (!id) {
|
||||
|
@ -2314,22 +2229,6 @@ async function saveUnprocessed(data, { forceSave } = {}) {
|
|||
return id;
|
||||
}
|
||||
|
||||
async function saveUnprocesseds(arrayOfUnprocessed, { forceSave } = {}) {
|
||||
let promise;
|
||||
|
||||
db.serialize(() => {
|
||||
promise = Promise.all([
|
||||
db.run('BEGIN TRANSACTION;'),
|
||||
...map(arrayOfUnprocessed, unprocessed =>
|
||||
saveUnprocessed(unprocessed, { forceSave })
|
||||
),
|
||||
db.run('COMMIT TRANSACTION;'),
|
||||
]);
|
||||
});
|
||||
|
||||
await promise;
|
||||
}
|
||||
|
||||
async function updateUnprocessedAttempts(id, attempts) {
|
||||
await db.run('UPDATE unprocessed SET attempts = $attempts WHERE id = $id;', {
|
||||
$id: id,
|
||||
|
@ -2484,7 +2383,20 @@ async function removeAll() {
|
|||
db.serialize(() => {
|
||||
promise = Promise.all([
|
||||
db.run('BEGIN TRANSACTION;'),
|
||||
...getRemoveConfigurationPromises(),
|
||||
db.run('DELETE FROM identityKeys;'),
|
||||
db.run('DELETE FROM items;'),
|
||||
db.run('DELETE FROM preKeys;'),
|
||||
db.run('DELETE FROM sessions;'),
|
||||
db.run('DELETE FROM signedPreKeys;'),
|
||||
db.run('DELETE FROM unprocessed;'),
|
||||
db.run('DELETE FROM contactPreKeys;'),
|
||||
db.run('DELETE FROM contactSignedPreKeys;'),
|
||||
db.run('DELETE FROM servers;'),
|
||||
db.run('DELETE FROM lastHashes;'),
|
||||
db.run(`DELETE FROM ${SENDER_KEYS_TABLE};`),
|
||||
db.run(`DELETE FROM ${NODES_FOR_PUBKEY_TABLE};`),
|
||||
db.run(`DELETE FROM ${CLOSED_GROUP_V2_KEY_PAIRS_TABLE};`),
|
||||
db.run('DELETE FROM seenMessages;'),
|
||||
db.run(`DELETE FROM ${CONVERSATIONS_TABLE};`),
|
||||
db.run(`DELETE FROM ${MESSAGES_TABLE};`),
|
||||
db.run('DELETE FROM attachment_downloads;'),
|
||||
|
@ -2496,25 +2408,6 @@ async function removeAll() {
|
|||
await promise;
|
||||
}
|
||||
|
||||
function getRemoveConfigurationPromises() {
|
||||
return [
|
||||
db.run('DELETE FROM identityKeys;'),
|
||||
db.run('DELETE FROM items;'),
|
||||
db.run('DELETE FROM preKeys;'),
|
||||
db.run('DELETE FROM sessions;'),
|
||||
db.run('DELETE FROM signedPreKeys;'),
|
||||
db.run('DELETE FROM unprocessed;'),
|
||||
db.run('DELETE FROM contactPreKeys;'),
|
||||
db.run('DELETE FROM contactSignedPreKeys;'),
|
||||
db.run('DELETE FROM servers;'),
|
||||
db.run('DELETE FROM lastHashes;'),
|
||||
db.run(`DELETE FROM ${SENDER_KEYS_TABLE};`),
|
||||
db.run(`DELETE FROM ${NODES_FOR_PUBKEY_TABLE};`),
|
||||
db.run(`DELETE FROM ${CLOSED_GROUP_V2_KEY_PAIRS_TABLE};`),
|
||||
db.run('DELETE FROM seenMessages;'),
|
||||
];
|
||||
}
|
||||
|
||||
async function removeAllConversations() {
|
||||
await removeAllFromTable(CONVERSATIONS_TABLE);
|
||||
}
|
||||
|
|
|
@ -73,10 +73,6 @@ const channelsToMake = {
|
|||
getPasswordHash,
|
||||
|
||||
getIdentityKeyById,
|
||||
|
||||
removeAllIdentityKeys,
|
||||
getAllIdentityKeys,
|
||||
|
||||
removeAllPreKeys,
|
||||
removeAllSignedPreKeys,
|
||||
removeAllContactPreKeys,
|
||||
|
@ -88,9 +84,7 @@ const channelsToMake = {
|
|||
createOrUpdateItem,
|
||||
getItemById,
|
||||
getAllItems,
|
||||
bulkAddItems,
|
||||
removeItemById,
|
||||
removeAllItems,
|
||||
|
||||
removeAllSessions,
|
||||
|
||||
|
@ -98,7 +92,6 @@ const channelsToMake = {
|
|||
updateSwarmNodesForPubkey,
|
||||
|
||||
saveConversation,
|
||||
saveConversations,
|
||||
getConversationById,
|
||||
updateConversation,
|
||||
removeConversation,
|
||||
|
@ -106,7 +99,6 @@ const channelsToMake = {
|
|||
getAllConversations,
|
||||
getAllConversationIds,
|
||||
getAllPublicConversations,
|
||||
getPublicConversationsByServer,
|
||||
getPubkeysInPublicConversation,
|
||||
savePublicServerToken,
|
||||
getPublicServerTokenByServerUrl,
|
||||
|
@ -119,7 +111,6 @@ const channelsToMake = {
|
|||
saveMessage,
|
||||
cleanSeenMessages,
|
||||
cleanLastHashes,
|
||||
saveSeenMessageHash,
|
||||
updateLastHash,
|
||||
saveSeenMessageHashes,
|
||||
saveMessages,
|
||||
|
@ -134,7 +125,6 @@ const channelsToMake = {
|
|||
getMessageIdsFromServerIds,
|
||||
getMessageById,
|
||||
getAllMessages,
|
||||
getAllUnsentMessages,
|
||||
getAllMessageIds,
|
||||
getMessagesBySentAt,
|
||||
getExpiredMessages,
|
||||
|
@ -148,7 +138,6 @@ const channelsToMake = {
|
|||
getAllUnprocessed,
|
||||
getUnprocessedById,
|
||||
saveUnprocessed,
|
||||
saveUnprocesseds,
|
||||
updateUnprocessedAttempts,
|
||||
updateUnprocessedWithData,
|
||||
removeUnprocessed,
|
||||
|
@ -442,14 +431,6 @@ export async function getIdentityKeyById(
|
|||
return keysToArrayBuffer(IDENTITY_KEY_KEYS, data);
|
||||
}
|
||||
|
||||
export async function removeAllIdentityKeys(): Promise<void> {
|
||||
await channels.removeAllIdentityKeys();
|
||||
}
|
||||
export async function getAllIdentityKeys() {
|
||||
const keys = await channels.getAllIdentityKeys();
|
||||
return keys.map((key: any) => keysToArrayBuffer(IDENTITY_KEY_KEYS, key));
|
||||
}
|
||||
|
||||
// Those removeAll are not used anymore except to cleanup the app since we removed all of those tables
|
||||
export async function removeAllPreKeys(): Promise<void> {
|
||||
await channels.removeAllPreKeys();
|
||||
|
@ -508,20 +489,9 @@ export async function getAllItems(): Promise<Array<StorageItem>> {
|
|||
return Array.isArray(keys) ? keysToArrayBuffer(keys, item) : item;
|
||||
});
|
||||
}
|
||||
export async function bulkAddItems(array: Array<StorageItem>): Promise<void> {
|
||||
const updated = _.map(array, data => {
|
||||
const { id } = data;
|
||||
const keys = (ITEM_KEYS as any)[id];
|
||||
return Array.isArray(keys) ? keysFromArrayBuffer(keys, data) : data;
|
||||
});
|
||||
await channels.bulkAddItems(updated);
|
||||
}
|
||||
export async function removeItemById(id: string): Promise<void> {
|
||||
await channels.removeItemById(id);
|
||||
}
|
||||
export async function removeAllItems(): Promise<void> {
|
||||
await channels.removeAllItems();
|
||||
}
|
||||
// Sessions
|
||||
export async function removeAllSessions(): Promise<void> {
|
||||
await channels.removeAllSessions();
|
||||
|
@ -585,13 +555,6 @@ export async function saveConversation(data: ConversationType): Promise<void> {
|
|||
await channels.saveConversation(cleaned);
|
||||
}
|
||||
|
||||
export async function saveConversations(
|
||||
data: Array<ConversationType>
|
||||
): Promise<void> {
|
||||
const cleaned = data.map(d => _.omit(d, 'isOnline'));
|
||||
await channels.saveConversations(cleaned);
|
||||
}
|
||||
|
||||
export async function getConversationById(
|
||||
id: string
|
||||
): Promise<ConversationModel | undefined> {
|
||||
|
@ -670,17 +633,6 @@ export async function getPublicServerTokenByServerUrl(
|
|||
const token = await channels.getPublicServerTokenByServerUrl(serverUrl);
|
||||
return token;
|
||||
}
|
||||
|
||||
export async function getPublicConversationsByServer(
|
||||
server: string
|
||||
): Promise<ConversationCollection> {
|
||||
const conversations = await channels.getPublicConversationsByServer(server);
|
||||
|
||||
const collection = new ConversationCollection();
|
||||
collection.add(conversations);
|
||||
return collection;
|
||||
}
|
||||
|
||||
export async function getAllGroupsInvolvingId(
|
||||
id: string
|
||||
): Promise<ConversationCollection> {
|
||||
|
@ -739,13 +691,6 @@ export async function updateLastHash(data: any): Promise<void> {
|
|||
await channels.updateLastHash(_cleanData(data));
|
||||
}
|
||||
|
||||
export async function saveSeenMessageHash(data: {
|
||||
expiresAt: number;
|
||||
hash: string;
|
||||
}): Promise<void> {
|
||||
await channels.saveSeenMessageHash(_cleanData(data));
|
||||
}
|
||||
|
||||
export async function saveMessage(
|
||||
data: MessageModel,
|
||||
options?: { forceSave: boolean }
|
||||
|
@ -804,11 +749,6 @@ export async function getAllMessages(): Promise<MessageCollection> {
|
|||
return new MessageCollection(messages);
|
||||
}
|
||||
|
||||
export async function getAllUnsentMessages(): Promise<MessageCollection> {
|
||||
const messages = await channels.getAllUnsentMessages();
|
||||
return new MessageCollection(messages);
|
||||
}
|
||||
|
||||
export async function getAllMessageIds(): Promise<Array<string>> {
|
||||
const ids = await channels.getAllMessageIds();
|
||||
return ids;
|
||||
|
@ -953,17 +893,6 @@ export async function saveUnprocessed(
|
|||
return id;
|
||||
}
|
||||
|
||||
export async function saveUnprocesseds(
|
||||
arrayOfUnprocessed: Array<any>,
|
||||
options?: {
|
||||
forceSave: boolean;
|
||||
}
|
||||
): Promise<any> {
|
||||
await channels.saveUnprocesseds(_cleanData(arrayOfUnprocessed), {
|
||||
forceSave: options?.forceSave || false,
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateUnprocessedAttempts(
|
||||
id: string,
|
||||
attempts: number
|
||||
|
|
Loading…
Reference in New Issue