diff --git a/index.d.ts b/index.d.ts index fa36547..ec7ff4c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1038,6 +1038,8 @@ declare namespace WAWebJS { timestamp: number, /** Amount of messages unread */ unreadCount: number, + /** Last message fo chat */ + lastMessage: Message, /** Archives this chat */ archive: () => Promise, diff --git a/src/structures/Chat.js b/src/structures/Chat.js index 241d297..0e0ae78 100644 --- a/src/structures/Chat.js +++ b/src/structures/Chat.js @@ -75,6 +75,12 @@ class Chat extends Base { */ this.muteExpiration = data.muteExpiration; + /** + * Last message fo chat + * @type {Message} + */ + this.lastMessage = data.lastMessage ? new Message(super.client, data.lastMessage) : undefined; + return super._patch(data); } diff --git a/src/util/Injected.js b/src/util/Injected.js index b32d50b..c9a7638 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -427,7 +427,15 @@ exports.LoadUtils = () => { await window.Store.GroupMetadata.update(chatWid); res.groupMetadata = chat.groupMetadata.serialize(); } - + + res.lastMessage = null; + if (res.msgs && res.msgs.length) { + const lastMessage = window.Store.Msg.get(chat.lastReceivedKey._serialized); + if (lastMessage) { + res.lastMessage = window.WWebJS.getMessageModel(lastMessage); + } + } + delete res.msgs; delete res.msgUnsyncedButtonReplyMsgs; delete res.unsyncedButtonReplies;