Skip to content

Commit

Permalink
[core] Fix groups sort by
Browse files Browse the repository at this point in the history
  • Loading branch information
devlikepro committed Dec 9, 2024
1 parent d558953 commit 703b0b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/core/engines/webjs/session.webjs.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
} from '@waha/structures/enums.dto';
import {
CreateGroupRequest,
GroupSortField,
ParticipantsRequest,
SettingsSecurityChangeInfo,
} from '@waha/structures/groups.dto';
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/structures/groups.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class CreateGroupRequest {
participants: Array<Participant>;
}

enum GroupSortField {
export enum GroupSortField {
ID = 'id',
SUBJECT = 'subject',
}
Expand Down

0 comments on commit 703b0b4

Please sign in to comment.