Feat: get message by id (#1634)
* feat: get message by id Add the feature of getting messages by id. It's loads messages that are not loaded in the Store.Msg, and add them into the Store.Msg. I don't use the draft because this is already work * Fix typo * Fix for test * Update index.d.ts --------- Co-authored-by: Rajeh Taher <rajeh@reforward.dev> Co-authored-by: Codeboss <131376628+codebossdev@users.noreply.github.com>
This commit is contained in:
parent
41e59efa72
commit
b4d82d8425
2 changed files with 21 additions and 0 deletions
3
index.d.ts
vendored
3
index.d.ts
vendored
|
|
@ -60,6 +60,9 @@ declare namespace WAWebJS {
|
|||
/** Get contact instance by ID */
|
||||
getContactById(contactId: string): Promise<Contact>
|
||||
|
||||
/** Get message by ID */
|
||||
getMessageById(messageId: string): Promise<Message>
|
||||
|
||||
/** Get all current contact instances */
|
||||
getContacts(): Promise<Contact[]>
|
||||
|
||||
|
|
|
|||
|
|
@ -899,6 +899,24 @@ 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');
|
||||
|
||||
let messagesObject = await window.Store.Msg.getMessagesById([messageId]);
|
||||
if (messagesObject && messagesObject.messages.length) msg = messagesObject.messages[0];
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue