diff --git a/src/core/engines/gows/session.gows.core.ts b/src/core/engines/gows/session.gows.core.ts index 5894a4efa..2117d0170 100644 --- a/src/core/engines/gows/session.gows.core.ts +++ b/src/core/engines/gows/session.gows.core.ts @@ -539,38 +539,42 @@ export class WhatsappSessionGoWSCore extends WhatsappSession { msg?.Message?.protocolMessage?.key !== undefined ); }), - mergeMap(async (message): Promise => { - const afterMessage = await this.toWAMessage(message); - // Extract the revoked message ID from protocolMessage.key - const revokedMessageId = message.Message.protocolMessage.key?.ID; - return { - after: afterMessage, - before: null, - revokedMessageId: revokedMessageId, - _data: message, - }; - }), + mergeMap( + async (message): Promise => { + const afterMessage = await this.toWAMessage(message); + // Extract the revoked message ID from protocolMessage.key + const revokedMessageId = message.Message.protocolMessage.key?.ID; + return { + after: afterMessage, + before: null, + revokedMessageId: revokedMessageId, + _data: message, + }; + }, + ), ); this.events2.get(WAHAEvents.MESSAGE_REVOKED).switch(messagesRevoked$); // Handle edited messages const messagesEdited$ = messages$.pipe( filter((message) => IsEditedMessage(message.Message)), - mergeMap(async (message): Promise => { - const waMessage = await this.toWAMessage(message); - const content = normalizeMessageContent(message.Message); - // Extract the body from editedMessage using extractBody function - const body = extractBody(content.protocolMessage.editedMessage) || ''; - // Extract the original message ID from protocolMessage.key - // @ts-ignore - const editedMessageId = content.protocolMessage.key?.ID; - return { - ...waMessage, - body: body, - editedMessageId: editedMessageId, - _data: message, - }; - }), + mergeMap( + async (message): Promise => { + const waMessage = await this.toWAMessage(message); + const content = normalizeMessageContent(message.Message); + // Extract the body from editedMessage using extractBody function + const body = extractBody(content.protocolMessage.editedMessage) || ''; + // Extract the original message ID from protocolMessage.key + // @ts-ignore + const editedMessageId = content.protocolMessage.key?.ID; + return { + ...waMessage, + body: body, + editedMessageId: editedMessageId, + _data: message, + }; + }, + ), ); this.events2.get(WAHAEvents.MESSAGE_EDITED).switch(messagesEdited$); @@ -1874,6 +1878,14 @@ export class WhatsappSessionGoWSCore extends WhatsappSession { id: id, name: name || null, picture: picture, + isGroup: chat.id?.endsWith?.('@g.us') || false, + isReadOnly: chat.readOnly || false, + timestamp: chat.conversationTimestamp || chat.timestamp || null, + archived: chat.archived || false, + pinned: chat.pinned || false, + isMuted: chat.mute !== undefined ? chat.mute !== 0 : false, + muteExpiration: chat.mute || 0, + unreadCount: chat.unreadCount || 0, lastMessage: message, _chat: chat, }; diff --git a/src/core/engines/noweb/session.noweb.core.ts b/src/core/engines/noweb/session.noweb.core.ts index c23543cc5..90dfa6555 100644 --- a/src/core/engines/noweb/session.noweb.core.ts +++ b/src/core/engines/noweb/session.noweb.core.ts @@ -1300,10 +1300,19 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { {}, ); const message = messages.length > 0 ? messages[0] : null; + const chatAny = chat as any; return { id: id, name: name || null, picture: picture, + isGroup: chat.id?.endsWith?.('@g.us') || false, + isReadOnly: chatAny.readOnly || false, + timestamp: chatAny.conversationTimestamp || chatAny.t || null, + archived: chat.archived, + pinned: chatAny.pinned || chatAny.pin || false, + isMuted: chatAny.mute !== undefined ? chatAny.mute !== 0 : false, + muteExpiration: chatAny.mute || 0, + unreadCount: chat.unreadCount, lastMessage: message, _chat: chat, }; diff --git a/src/core/engines/webjs/session.webjs.core.ts b/src/core/engines/webjs/session.webjs.core.ts index 660123872..2d9ea9c3e 100644 --- a/src/core/engines/webjs/session.webjs.core.ts +++ b/src/core/engines/webjs/session.webjs.core.ts @@ -751,7 +751,7 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { const message = this.recreateMessage(messageId); const options = { // It's fine to sent just ids instead of Contact object - mentions: request.mentions as unknown as string[], + mentions: (request.mentions as unknown) as string[], linkPreview: request.linkPreview, }; return message.edit(request.text, options); @@ -940,6 +940,14 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { id: chat.id._serialized, name: chat.name || null, picture: picture, + isGroup: chat.isGroup || false, + isReadOnly: chat.isReadOnly || false, + timestamp: chat.timestamp || null, + archived: chat.archived || false, + pinned: chat.pinned || false, + isMuted: chat.isMuted || false, + muteExpiration: chat.muteExpiration || 0, + unreadCount: chat.unreadCount || 0, lastMessage: lastMessage, _chat: chat, }; @@ -1692,19 +1700,23 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { filter((evt: any) => this.jids.include(evt?.after?.id?.remote || evt?.before?.id?.remote), ), - map((event): WAMessageRevokedBody => { - const afterMessage = event.after ? this.toWAMessage(event.after) : null; - const beforeMessage = event.before - ? this.toWAMessage(event.before) - : null; - // Extract the revoked message ID from the protocolMessageKey.id field - const revokedMessageId = afterMessage?._data?.protocolMessageKey?.id; - return { - after: afterMessage, - before: beforeMessage, - revokedMessageId: revokedMessageId, - }; - }), + map( + (event): WAMessageRevokedBody => { + const afterMessage = event.after + ? this.toWAMessage(event.after) + : null; + const beforeMessage = event.before + ? this.toWAMessage(event.before) + : null; + // Extract the revoked message ID from the protocolMessageKey.id field + const revokedMessageId = afterMessage?._data?.protocolMessageKey?.id; + return { + after: afterMessage, + before: beforeMessage, + revokedMessageId: revokedMessageId, + }; + }, + ), ); this.events2.get(WAHAEvents.MESSAGE_REVOKED).switch(messagesRevoked$); @@ -1725,15 +1737,17 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { ); const messagesEdit$ = messageEdit$.pipe( filter((event: any) => this.jids.include(event?.message?.id?.remote)), - map((event): WAMessageEditedBody => { - const message = this.toWAMessage(event.message); - return { - ...message, - body: event.newBody, - editedMessageId: message._data?.id?.id, - _data: event, - }; - }), + map( + (event): WAMessageEditedBody => { + const message = this.toWAMessage(event.message); + return { + ...message, + body: event.newBody, + editedMessageId: message._data?.id?.id, + _data: event, + }; + }, + ), ); this.events2.get(WAHAEvents.MESSAGE_EDITED).switch(messagesEdit$); @@ -2145,8 +2159,7 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { } export class WEBJSEngineMediaProcessor - implements IMediaEngineProcessor -{ + implements IMediaEngineProcessor { hasMedia(message: Message): boolean { if (!message.hasMedia) { return false; diff --git a/src/structures/chats.dto.ts b/src/structures/chats.dto.ts index 5df4a393b..3722bc17c 100644 --- a/src/structures/chats.dto.ts +++ b/src/structures/chats.dto.ts @@ -230,6 +230,14 @@ export class ChatSummary { id: string; name: string | null; picture: string | null; + isGroup?: boolean; + isReadOnly?: boolean; + timestamp?: number; + archived?: boolean; + pinned?: boolean; + isMuted?: boolean; + muteExpiration?: number; + unreadCount?: number; lastMessage: any; _chat: any; }