feat: add preview message to chats

This commit is contained in:
2026-09-16 04:33:48 +08:00
parent d0edccf15d
commit 9b59c1f127
5 changed files with 11 additions and 4 deletions
+3 -1
View File
@@ -2,7 +2,7 @@
// ==UserScript== // ==UserScript==
// @name WhatsApp Web Bridge // @name WhatsApp Web Bridge
// @namespace https://rul.sh/ // @namespace https://rul.sh/
// @version 0.0.2 // @version 0.0.3
// @description WhatsApp Web WebSocket bridge // @description WhatsApp Web WebSocket bridge
// @match https://web.whatsapp.com/* // @match https://web.whatsapp.com/*
// @updateURL https://git.rul.sh/khairul169/whatsapp-bridge/raw/branch/main/dist/whatsapp-bridge.user.js // @updateURL https://git.rul.sh/khairul169/whatsapp-bridge/raw/branch/main/dist/whatsapp-bridge.user.js
@@ -93,6 +93,7 @@
return Object.keys(result).length ? result : String(id); return Object.keys(result).length ? result : String(id);
} }
function serializeChat(chat) { function serializeChat(chat) {
const rawPreviewMessage = safeProperty(chat, "previewMessage");
return { return {
id: serializeId(chat.id), id: serializeId(chat.id),
accountLid: chat.accountLid, accountLid: chat.accountLid,
@@ -103,6 +104,7 @@
isReadOnly: chat.isReadOnly, isReadOnly: chat.isReadOnly,
archived: chat.archived, archived: chat.archived,
unreadCount: chat.unreadCount, unreadCount: chat.unreadCount,
previewMessage: rawPreviewMessage ? serialize(rawPreviewMessage) : null,
timestamp: chat.t, timestamp: chat.t,
lastMessage: chat.lastMessage ? serialize(chat.lastMessage) : null lastMessage: chat.lastMessage ? serialize(chat.lastMessage) : null
}; };
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -14,7 +14,7 @@ await esbuild.build({
// ==UserScript== // ==UserScript==
// @name WhatsApp Web Bridge // @name WhatsApp Web Bridge
// @namespace https://rul.sh/ // @namespace https://rul.sh/
// @version 0.0.2 // @version 0.0.3
// @description WhatsApp Web WebSocket bridge // @description WhatsApp Web WebSocket bridge
// @match https://web.whatsapp.com/* // @match https://web.whatsapp.com/*
// @updateURL https://git.rul.sh/khairul169/whatsapp-bridge/raw/branch/main/dist/whatsapp-bridge.user.js // @updateURL https://git.rul.sh/khairul169/whatsapp-bridge/raw/branch/main/dist/whatsapp-bridge.user.js
+2
View File
@@ -70,6 +70,8 @@ export interface ChatDTO {
lastMessage?: MessageDTO | null; lastMessage?: MessageDTO | null;
contact?: ContactDTO | null; contact?: ContactDTO | null;
groupMetadata?: GroupMetadataDTO | null; groupMetadata?: GroupMetadataDTO | null;
previewMessage?: MessageDTO | null;
} }
export interface GroupMetadataDTO { export interface GroupMetadataDTO {
+3
View File
@@ -137,6 +137,8 @@ export function serializeId(id: any): SerializedId | string | null {
} }
export function serializeChat(chat: any): ChatDTO { export function serializeChat(chat: any): ChatDTO {
const rawPreviewMessage = safeProperty<any>(chat, "previewMessage");
return { return {
id: serializeId(chat.id), id: serializeId(chat.id),
accountLid: chat.accountLid, accountLid: chat.accountLid,
@@ -148,6 +150,7 @@ export function serializeChat(chat: any): ChatDTO {
isReadOnly: chat.isReadOnly, isReadOnly: chat.isReadOnly,
archived: chat.archived, archived: chat.archived,
unreadCount: chat.unreadCount, unreadCount: chat.unreadCount,
previewMessage: rawPreviewMessage ? serialize(rawPreviewMessage) : null,
timestamp: chat.t, timestamp: chat.t,
lastMessage: chat.lastMessage ? serialize(chat.lastMessage) : null, lastMessage: chat.lastMessage ? serialize(chat.lastMessage) : null,