Refactor and code designing

This commit is contained in:
2026-03-02 03:30:22 +01:00
parent 6d7465ff18
commit e231f4ed05
80 changed files with 6690 additions and 4670 deletions

View File

@@ -321,13 +321,11 @@ function rowToBan(r) {
/* ------------------------------------------------------------------ */
function registerDatabaseIpc() {
// ── Lifecycle ──────────────────────────────────────────────────────
ipcMain.handle('db:initialize', async () => {
await initDatabase();
return true;
});
// ── Messages ───────────────────────────────────────────────────────
ipcMain.handle('db:saveMessage', (_e, message) => {
db.run(
`INSERT OR REPLACE INTO messages
@@ -390,7 +388,6 @@ function registerDatabaseIpc() {
persist();
});
// ── Reactions ──────────────────────────────────────────────────────
ipcMain.handle('db:saveReaction', (_e, reaction) => {
const check = db.exec(
'SELECT 1 FROM reactions WHERE messageId = ? AND userId = ? AND emoji = ?',
@@ -416,7 +413,6 @@ function registerDatabaseIpc() {
return rows.map(rowToReaction);
});
// ── Users ──────────────────────────────────────────────────────────
ipcMain.handle('db:saveUser', (_e, user) => {
db.run(
`INSERT OR REPLACE INTO users
@@ -486,7 +482,6 @@ function registerDatabaseIpc() {
persist();
});
// ── Rooms ──────────────────────────────────────────────────────────
ipcMain.handle('db:saveRoom', (_e, room) => {
db.run(
`INSERT OR REPLACE INTO rooms
@@ -542,7 +537,6 @@ function registerDatabaseIpc() {
persist();
});
// ── Bans ───────────────────────────────────────────────────────────
ipcMain.handle('db:saveBan', (_e, ban) => {
db.run(
`INSERT OR REPLACE INTO bans
@@ -579,7 +573,6 @@ function registerDatabaseIpc() {
return rows.some((r) => String(r.oderId) === userId);
});
// ── Attachments ─────────────────────────────────────────────────────
ipcMain.handle('db:saveAttachment', (_e, attachment) => {
db.run(
`INSERT OR REPLACE INTO attachments
@@ -610,7 +603,6 @@ function registerDatabaseIpc() {
persist();
});
// ── Utilities ──────────────────────────────────────────────────────
ipcMain.handle('db:clearAllData', () => {
db.run('DELETE FROM messages');
db.run('DELETE FROM users');