mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
Compare commits
5 Commits
v1.15.2
...
message-by
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
308ab9826c | ||
|
|
6cf9c2a0f3 | ||
|
|
60761399ca | ||
|
|
7a8e922696 | ||
|
|
841719ff4c |
@@ -617,6 +617,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
|
||||
|
||||
@@ -349,7 +349,18 @@ END:VCARD`;
|
||||
expect(msg.vCards[1]).to.match(/BEGIN:VCARD/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Get Messages', function() {
|
||||
it ('can get a message by it\'s ID', async function() {
|
||||
const chat = await client.getChatById(remoteId);
|
||||
const [message] = await chat.fetchMessages({limit: 1});
|
||||
const messageById = await client.getMessageById(message.id._serialized);
|
||||
expect(messageById).to.exist;
|
||||
expect(messageById).to.be.instanceOf(Message);
|
||||
expect(messageById).to.be.equal(message);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Get Chats', function () {
|
||||
it('can get a chat by its ID', async function () {
|
||||
const chat = await client.getChatById(remoteId);
|
||||
@@ -385,7 +396,6 @@ END:VCARD`;
|
||||
expect(contact).to.be.instanceOf(Contact);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Numbers and Users', function () {
|
||||
it('can verify that a user is registered', async function () {
|
||||
const isRegistered = await client.isRegisteredUser(remoteId);
|
||||
@@ -414,4 +424,4 @@ END:VCARD`;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user