updated filters

This commit is contained in:
Adhiraj
2020-09-07 12:16:51 +05:30
parent 13ab46d0e1
commit 61994f165d
4 changed files with 26 additions and 19 deletions

View File

@@ -39,6 +39,13 @@ WAConnectionTest('Messages', conn => {
quoted.key.fromMe ? conn.user.jid : quoted.key.id
)
})
it('should upload media successfully', async () => {
const content = await fs.readFile('./Media/sonata.mp3')
// run 10 uploads
for (let i = 0; i < 10;i++) {
await conn.prepareMessageContent (content, MessageType.audio, { filename: 'audio.mp3', mimetype: Mimetype.mp4Audio })
}
})
it('should send a gif', async () => {
const content = await fs.readFile('./Media/ma_gif.mp4')
const message = await sendAndRetreiveMessage(conn, content, MessageType.video, { mimetype: Mimetype.gif })

View File

@@ -95,12 +95,12 @@ export class WAConnection extends Base {
* @param searchString optionally search for users
* @returns the chats & the cursor to fetch the next page
*/
async loadChats (count: number, before: number | null, searchString?: string) {
let db = this.chats
if (searchString) {
db = db.filter (value => value.name?.includes (searchString) || value.jid?.startsWith(searchString))
}
const chats = db.paginated (before, count)
async loadChats (count: number, before: number | null, filters?: {searchString?: string, archived?: boolean, unread?: boolean}) {
const chats = this.chats.paginated (before, count, filters && (chat => (
(typeof filters?.archived === 'undefined' || chat.archive === filters.archived.toString()) &&
(typeof filters?.searchString === 'undefined' || chat.name?.includes (filters.searchString) || chat.jid?.startsWith(filters.searchString)) &&
(typeof filters?.unread === 'undefined' || (filters?.unread ? chat.count !== 0 : chat.count === 0))
)))
await Promise.all (
chats.map (async chat => (
chat.imgUrl === undefined && await this.setProfilePicture (chat)