improve syncing and storing

This commit is contained in:
grimhilt
2023-03-29 16:23:24 +02:00
parent 94c7a7176b
commit e0482eb511
15 changed files with 245 additions and 347 deletions

View File

@@ -22,8 +22,20 @@ async function findRoomByOwner(ownerId) {
return await execQueryAsync(query, values);
}
async function getUserIdOfMailbox(boxId) {
const query = `
SELECT app_account.user_id
FROM mailbox
INNER JOIN app_account ON app_account.account_id = mailbox.account_id
WHERE mailbox.mailbox_id = ?
`;
const values = [boxId];
return await execQueryAsync(query, values);
}
module.exports = {
getAddresseId,
getFieldId,
findRoomByOwner,
getUserIdOfMailbox
};

View File

@@ -3,8 +3,9 @@ const { db, execQueryAsync, execQueryAsyncWithId, execQuery } = require("./db.js
const { queryFromId, queryToId, queryCcId } = require("./utils/addressQueries.js");
async function createRoom(roomName, ownerId, messageId) {
if (!roomName) roomName = "No room name";
roomName = transformEmojis(roomName);
const query = `INSERT INTO app_room (room_name, owner_id, message_id) VALUES (?, ?, ?)`;
const query = `INSERT IGNORE INTO app_room (room_name, owner_id, message_id) VALUES (?, ?, ?)`;
const values = [roomName.substring(0, 255), ownerId, messageId];
return await execQueryAsyncWithId(query, values);
// todo add members
@@ -54,7 +55,7 @@ function updateLastUpdateThread(threadId) {
function incrementNotSeenThread(threadId) {
// todo
// also increment parent room
// also increment root room
}
async function isRoomGroup(roomId) {

View File

@@ -126,6 +126,7 @@ CREATE TABLE app_room (
notSeen INT NOT NULL DEFAULT 0,
lastUpdate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY (room_id),
UNIQUE KEY (owner_id, message_id, isGroup),
FOREIGN KEY (owner_id) REFERENCES address(address_id),
FOREIGN KEY (message_id) REFERENCES message(message_id)
);