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', }