From b6ad9b53d499fcbba31195b8e36f0cb18db90edb Mon Sep 17 00:00:00 2001 From: RenoXF Date: Tue, 4 Aug 2026 16:46:18 +0700 Subject: [PATCH] Refactor WhatsApp session management and database queries - Improved SSE handling in `src/server/sse/index.ts` by adding cleanup logic for unsubscribing and clearing intervals. - Removed obsolete message handling in `src/shutdown.ts` and `src/whatsapp/db-migration.ts`, including dropping unused tables. - Introduced `message-store.ts` to manage sent messages per device, optimizing memory usage. - Consolidated group-related queries into `src/whatsapp/queries/groups.ts` and removed unused message and media queries. - Updated `src/whatsapp/whatsapp-session.ts` to utilize the new message store and removed legacy media handling. - Enhanced code readability and maintainability by restructuring functions and improving error handling. --- src/server/client/client.css | 40 ------- src/server/client/index.html | 89 +------------- src/server/connections/index.ts | 10 +- src/server/contacts/index.ts | 82 ++++++------- src/server/index.ts | 7 +- src/server/messages/index.ts | 15 ++- src/server/messages/manage.ts | 197 ++++++++++++++++++++++--------- src/server/messages/media.ts | 26 ---- src/server/messages/send.ts | 88 +++++--------- src/server/sse/index.ts | 40 ++++--- src/shutdown.ts | 1 - src/whatsapp/db-migration.ts | 38 +----- src/whatsapp/index.ts | 2 +- src/whatsapp/message-store.ts | 181 ++++++++++++++++++++++++++++ src/whatsapp/queries/contacts.ts | 15 ++- src/whatsapp/queries/groups.ts | 40 +++++++ src/whatsapp/queries/index.ts | 48 ++++---- src/whatsapp/queries/media.ts | 34 ------ src/whatsapp/queries/messages.ts | 153 ------------------------ src/whatsapp/queries/status.ts | 66 ----------- src/whatsapp/session-media.ts | 69 ----------- src/whatsapp/whatsapp-session.ts | 142 +++++++--------------- 22 files changed, 557 insertions(+), 826 deletions(-) delete mode 100644 src/server/messages/media.ts create mode 100644 src/whatsapp/message-store.ts create mode 100644 src/whatsapp/queries/groups.ts delete mode 100644 src/whatsapp/queries/media.ts delete mode 100644 src/whatsapp/queries/messages.ts delete mode 100644 src/whatsapp/queries/status.ts delete mode 100644 src/whatsapp/session-media.ts diff --git a/src/server/client/client.css b/src/server/client/client.css index f13b416..a7173f5 100644 --- a/src/server/client/client.css +++ b/src/server/client/client.css @@ -18,7 +18,6 @@ --active: #2a3942; --accent: #00a884; --danger: #ef5350; - --unread: #00a884; --shadow: rgba(0,0,0,.4); } html, body { @@ -79,13 +78,6 @@ html, body { .chat-meta { display: flex; justify-content: space-between; align-items: baseline; } .chat-preview { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .chat-time { font-size: 11px; color: var(--text-secondary); white-space: nowrap; } -.chat-unread { - background: var(--unread); color: #fff; - border-radius: 50%; min-width: 20px; height: 20px; - display: flex; align-items: center; justify-content: center; - font-size: 11px; font-weight: 600; - position: absolute; top: -4px; right: -4px; -} /* ── Device Actions on Hover ── */ .device-actions { @@ -157,19 +149,6 @@ html, body { .msg.incoming .msg-footer { justify-content: flex-start; } .msg-check { color: #53bdeb; } .msg-check.delivered { color: var(--text-secondary); } -.msg-image { max-width: 260px; max-height: 260px; border-radius: 6px; display: block; cursor: pointer; object-fit: cover; } -.msg-audio { width: 100%; } -.msg-video { max-width: 260px; max-height: 260px; border-radius: 6px; } -.msg-document { - display: flex; align-items: center; gap: 10px; - padding: 8px; background: rgba(255,255,255,.05); border-radius: 6px; - cursor: pointer; -} -.msg-document i { font-size: 28px; color: var(--accent); } -.msg-doc-info { flex: 1; min-width: 0; } -.msg-doc-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } -.msg-doc-size { font-size: 11px; color: var(--text-secondary); } -.msg-sticker { width: 160px; border-radius: 8px; } /* ── Load More ── */ .load-more { @@ -246,25 +225,6 @@ html, body { .icon-btn:hover { background: var(--hover); color: var(--text); } .icon-btn.primary { color: var(--accent); } -/* ── Attachment Menu ── */ -.attach-menu { - position: absolute; bottom: 68px; left: 16px; - display: flex; gap: 12px; padding: 12px; - background: var(--panel-bg); border-radius: 10px; - box-shadow: 0 4px 12px var(--shadow); - z-index: 10; -} -.attach-item { - display: flex; flex-direction: column; - align-items: center; gap: 4px; cursor: pointer; -} -.attach-item i { - width: 48px; height: 48px; border-radius: 50%; - display: flex; align-items: center; justify-content: center; - font-size: 22px; color: #fff; -} -.attach-item span { font-size: 11px; color: var(--text-secondary); } - /* ── Device Dashboard ── */ .device-cards { display: flex; flex-wrap: wrap; gap: 16px; padding: 24px; } .device-card { diff --git a/src/server/client/index.html b/src/server/client/index.html index 9444694..cf0dc19 100644 --- a/src/server/client/index.html +++ b/src/server/client/index.html @@ -46,16 +46,8 @@ ×
- - -
@@ -65,10 +57,7 @@
- -