feat: get pinned messages (#3004)
* feat: add getPinnedMessage method * docs: add docs for the method * chore: fix eslint * refactor: change logic of getting pinned messages * refactor: combine all PinnedMsgUtils * chore: remove comments and mark as ready for review * style: fix typo Co-authored-by: crazynds <36674096+crazynds@users.noreply.github.com> --------- Co-authored-by: crazynds <36674096+crazynds@users.noreply.github.com>
This commit is contained in:
parent
44418e66c2
commit
18b1d32825
4 changed files with 38 additions and 1 deletions
|
|
@ -1143,6 +1143,29 @@ class Client extends EventEmitter {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instances of all pinned messages in a chat
|
||||
* @param {string} chatId The chat ID
|
||||
* @returns {Promise<[Message]|[]>}
|
||||
*/
|
||||
async getPinnedMessages(chatId) {
|
||||
const pinnedMsgs = await this.pupPage.evaluate(async (chatId) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
const chat = window.Store.Chat.get(chatWid) ?? await window.Store.Chat.find(chatWid);
|
||||
if (!chat) return [];
|
||||
|
||||
const msgs = await window.Store.PinnedMsgUtils.getTable().equals(['chatId'], chatWid.toString());
|
||||
|
||||
const pinnedMsgs = msgs.map((msg) => window.Store.Msg.get(msg.parentMsgKey));
|
||||
|
||||
return !pinnedMsgs.length
|
||||
? []
|
||||
: pinnedMsgs.map((msg) => window.WWebJS.getMessageModel(msg));
|
||||
}, chatId);
|
||||
|
||||
return pinnedMsgs.map((msg) => new Message(this, msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object with information about the invite code's group
|
||||
* @param {string} inviteCode
|
||||
|
|
|
|||
Loading…
Reference in a new issue