fix fromMe in chat.fetchMessages (#2314)

* fix fromMe

* Fix Test

* fix crash in getchat

---------

Co-authored-by: Shir Serlui <70711723+shirser121@users.noreply.github.com>
This commit is contained in:
Roi Greenberg 2023-08-08 18:16:02 +03:00 • committed by GitHub
commit 096e84b0a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -187,7 +187,7 @@ class Chat extends Base {
if (m.isNotification) {
return false; // dont include notification messages
}
if (searchOptions && searchOptions.fromMe && m.id.fromMe !== searchOptions.fromMe) {
if (searchOptions && searchOptions.fromMe !== undefined && m.id.fromMe !== searchOptions.fromMe) {
return false;
}
return true;

View file

@ -61,6 +61,16 @@ describe('Chat', function () {
expect(fetchedMsg.body).to.equal(msg.body);
});
it('can use fromMe=true when fetching messages sent in a chat to get only bot messages', async function () {
const messages = await chat.fetchMessages({fromMe: true});
expect(messages).to.have.lengthOf(2);
});
it('can use fromMe=false when fetching messages sent in a chat to get only non bot messages', async function () {
const messages = await chat.fetchMessages({fromMe: false});
expect(messages).to.have.lengthOf(0);
});
it('can get the related contact', async function () {
const contact = await chat.getContact();
expect(contact).to.be.instanceOf(Contact);