mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
feat: get message by id
This commit is contained in:
@@ -610,6 +610,37 @@ class Client extends EventEmitter {
|
||||
return ContactFactory.create(this, contact);
|
||||
}
|
||||
|
||||
async getMessageById(messageId) {
|
||||
const msg = await this.pupPage.evaluate(async messageId => {
|
||||
let msg = window.Store.Msg.get(messageId);
|
||||
if(msg) return window.WWebJS.getMessageModel(msg);
|
||||
|
||||
const params = messageId.split('_');
|
||||
if(params.length !== 3) throw new Error('Invalid serialized message id specified');
|
||||
|
||||
const [fromMe, chatId, id] = params;
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
const fullMsgId = {
|
||||
fromMe: Boolean(fromMe),
|
||||
remote: chatWid,
|
||||
id,
|
||||
};
|
||||
|
||||
const msgKey = new window.Store.MsgKey(fullMsgId);
|
||||
const chat = await window.Store.Chat.find(msgKey.remote);
|
||||
const ctx = await chat.getSearchContext(msgKey);
|
||||
if(ctx.collection && ctx.collection.loadAroundPromise) {
|
||||
await ctx.collection.loadAroundPromise;
|
||||
}
|
||||
|
||||
msg = window.Store.Msg.get(messageId);
|
||||
if(msg) return window.WWebJS.getMessageModel(msg);
|
||||
}, messageId);
|
||||
|
||||
if(msg) return new Message(this, msg);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object with information about the invite code's group
|
||||
* @param {string} inviteCode
|
||||
|
||||
Reference in New Issue
Block a user