Skip to content

Commit

Permalink
feat: Added getGroupSizeLimit function (close wppconnect-team#1365)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jun 2, 2023
1 parent 8e8738b commit c04faf8
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/api/layers/retriever.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
Wid,
} from '../model';
import { SenderLayer } from './sender.layer';
import { ChatListOptions } from '@wppconnect/wa-js/dist/chat';

export class RetrieverLayer extends SenderLayer {
constructor(public page: Page, session?: string, options?: CreateConfig) {
Expand Down Expand Up @@ -113,17 +114,67 @@ export class RetrieverLayer extends SenderLayer {

/**
* Retrieves all chats
* Deprecated in favor of {@link listChats}
*
* @category Chat
* @returns array of [Chat]
* @deprecated Deprecated in favor of listChats.
*/
public async getAllChats(withNewMessageOnly = false) {
this.logger.warn(
'Deprecated: This function [getAllChats] is deprecated in favor of the getList function. Please update your code accordingly.'
);
if (withNewMessageOnly) {
return evaluateAndReturn(this.page, () => WAPI.getAllChatsWithNewMsg());
} else {
return evaluateAndReturn(this.page, () => WAPI.getAllChats());
}
}

/**
* Return list of chats
* * @example
* ```javascript
* // All chats
* const chats = await client.chatList();
*
* // Some chats
* const chats = client.chatList({count: 20});
*
* // 20 chats before specific chat
* const chats = client.chatList({count: 20, direction: 'before', id: '[number]@c.us'});
*
* // Only users chats
* const chats = await client.chatList({onlyUsers: true});
*
* // Only groups chats
* const chats = await client.chatList({onlyGroups: true});
*
* // Only with label Text
* const chats = await client.chatList({withLabels: ['Test']});
*
* // Only with label id
* const chats = await client.chatList({withLabels: ['1']});
*
* // Only with label with one of text or id
* const chats = await client.chatList({withLabels: ['Alfa','5']});
* ```
* @category Chat
* @returns array of [Chat]
*/
public async listChats(options?: ChatListOptions): Promise<Chat[]> {
return await evaluateAndReturn(
this.page,
async ({ options }) => {
const chats = await WPP.chat.list(options);

const serialized = chats.map((c) => WAPI._serializeChatObj(c));
return serialized;
},
{ options }
);
}

/**
* Checks if a number is a valid WA number
* @category Contact
Expand All @@ -140,10 +191,16 @@ export class RetrieverLayer extends SenderLayer {

/**
* Retrieves all chats with messages
* Deprecated in favor of {@link listChats}
*
* @category Chat
* @returns array of [Chat]
* @deprecated Deprecated in favor of listChats.
*/
public async getAllChatsWithMessages(withNewMessageOnly = false) {
this.logger.warn(
'Deprecated: This function [getAllChatsWithMessages] is deprecated in favor of the getList function. Please update your code accordingly.'
);
return evaluateAndReturn(
this.page,
(withNewMessageOnly: boolean) =>
Expand All @@ -154,10 +211,16 @@ export class RetrieverLayer extends SenderLayer {

/**
* Retrieve all groups
* Deprecated in favor of {@link listChats}
*
* @category Group
* @returns array of groups
* @deprecated Deprecated in favor of listChats.
*/
public async getAllGroups(withNewMessagesOnly = false): Promise<Chat[]> {
this.logger.warn(
'Deprecated: This function [getAllGroups] is deprecated in favor of the getList function. Please update your code accordingly.'
);
return await evaluateAndReturn(
this.page,
async ({ withNewMessagesOnly }) => {
Expand Down Expand Up @@ -506,4 +569,15 @@ export class RetrieverLayer extends SenderLayer {
msgId
);
}

/**
* Get the max number of participants for a group
*
* @category Group
*/
public async getGroupSizeLimit(): Promise<number> {
return await evaluateAndReturn(this.page, () =>
WPP.group.getGroupSizeLimit()
);
}
}

0 comments on commit c04faf8

Please sign in to comment.