From 2a01add13ea75de45d5c8b5203da1a382fc767ad Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Sun, 15 Nov 2020 14:05:32 +0530 Subject: [PATCH] Better search for numbers + chat fix --- src/WAConnection/4.Events.ts | 6 +++--- src/WAConnection/5.User.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/WAConnection/4.Events.ts b/src/WAConnection/4.Events.ts index f4f5675..41e154a 100644 --- a/src/WAConnection/4.Events.ts +++ b/src/WAConnection/4.Events.ts @@ -1,7 +1,7 @@ import * as QR from 'qrcode-terminal' import { WAConnection as Base } from './3.Connect' import { WAMessageStatusUpdate, WAMessage, WAContact, WAChat, WAMessageProto, WA_MESSAGE_STUB_TYPE, WA_MESSAGE_STATUS_TYPE, PresenceUpdate, BaileysEvent, DisconnectReason, WAOpenResult, Presence, AuthenticationCredentials, WAParticipantAction, WAGroupMetadata, WAUser, WANode } from './Constants' -import { whatsappID, unixTimestampSeconds, isGroupID, GET_MESSAGE_ID, WA_MESSAGE_ID, waMessageKey, newMessagesDB, shallowChanges } from './Utils' +import { whatsappID, unixTimestampSeconds, isGroupID, GET_MESSAGE_ID, WA_MESSAGE_ID, waMessageKey, newMessagesDB, shallowChanges, toNumber } from './Utils' import KeyedDB from '@adiwajshing/keyed-db' import { Mutex } from './Mutex' @@ -404,7 +404,7 @@ export class WAConnection extends Base { } // only update if it's an actual message if (message.message) { - this.chatUpdateTime (chat) + this.chatUpdateTime (chat, toNumber(message.messageTimestamp)) chatUpdate.t = chat.t } chatUpdate.messages = newMessagesDB([ message ]) @@ -473,7 +473,7 @@ export class WAConnection extends Base { } } } - protected chatUpdateTime = chat => this.chats.updateKey (chat, c => c.t = unixTimestampSeconds()) + protected chatUpdateTime = (chat, stamp: number) => this.chats.updateKey (chat, c => c.t = stamp) /** sets the profile picture of a chat */ protected async setProfilePicture (chat: WAChat) { chat.imgUrl = await this.getProfilePicture (chat.jid).catch (err => '') diff --git a/src/WAConnection/5.User.ts b/src/WAConnection/5.User.ts index 4b3783f..65850a5 100644 --- a/src/WAConnection/5.User.ts +++ b/src/WAConnection/5.User.ts @@ -107,7 +107,7 @@ export class WAConnection extends Base { const searchString = options.searchString?.toLowerCase() const chats = this.chats.paginated (before, count, options && (chat => ( (typeof options?.custom !== 'function' || options?.custom(chat)) && - (typeof searchString === 'undefined' || chat.name?.toLowerCase().includes (searchString) || chat.jid?.startsWith(searchString)) + (typeof searchString === 'undefined' || chat.name?.toLowerCase().includes (searchString) || chat.jid?.includes(searchString)) ))) let loadPP = this.loadProfilePicturesForChatsAutomatically if (typeof options.loadProfilePicture !== 'undefined') loadPP = options.loadProfilePicture