From 703b0b4cdec617530b4d82466d180b1dbbb81c27 Mon Sep 17 00:00:00 2001 From: devlikepro Date: Mon, 9 Dec 2024 11:30:15 +0700 Subject: [PATCH] [core] Fix groups sort by --- src/core/engines/webjs/session.webjs.core.ts | 11 +++++++++++ src/structures/groups.dto.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/engines/webjs/session.webjs.core.ts b/src/core/engines/webjs/session.webjs.core.ts index 6535fa54..ebaa9bdb 100644 --- a/src/core/engines/webjs/session.webjs.core.ts +++ b/src/core/engines/webjs/session.webjs.core.ts @@ -55,6 +55,7 @@ import { } from '@waha/structures/enums.dto'; import { CreateGroupRequest, + GroupSortField, ParticipantsRequest, SettingsSecurityChangeInfo, } from '@waha/structures/groups.dto'; @@ -793,6 +794,16 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { public async getGroups(pagination: PaginationParams) { const chats = await this.whatsapp.getChats(); const groups = lodash.filter(chats, (chat) => chat.isGroup); + + switch (pagination.sortBy) { + case GroupSortField.ID: + pagination.sortBy = 'id._serialized'; + break; + case GroupSortField.SUBJECT: + pagination.sortBy = 'groupMetadata.subject'; + break; + } + const paginator = new PaginatorInMemory(pagination); return paginator.apply(groups); } diff --git a/src/structures/groups.dto.ts b/src/structures/groups.dto.ts index d397a0f3..70ac2f79 100644 --- a/src/structures/groups.dto.ts +++ b/src/structures/groups.dto.ts @@ -57,7 +57,7 @@ export class CreateGroupRequest { participants: Array; } -enum GroupSortField { +export enum GroupSortField { ID = 'id', SUBJECT = 'subject', }