Skip to content

Commit

Permalink
feat: Added WPP.contact.list function (close #434)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jun 4, 2022
1 parent 29a00fb commit b7ed183
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/chat/functions/list.ts
Expand Up @@ -39,8 +39,10 @@ export interface ChatListOptions {
*
* @category Chat
*/
export async function list(options: ChatListOptions): Promise<ChatModel[]> {
let models = ChatStore.getModelsArray();
export async function list(
options: ChatListOptions = {}
): Promise<ChatModel[]> {
let models = ChatStore.getModelsArray().slice();

if (options.onlyUsers) {
models = models.filter((c) => c.isUser);
Expand Down
1 change: 1 addition & 0 deletions src/contact/functions/index.ts
Expand Up @@ -16,4 +16,5 @@

export { getProfilePictureUrl } from './getProfilePictureUrl';
export { getStatus } from './getStatus';
export { ContactListOptions, list } from './list';
export { queryExists } from './queryExists';
47 changes: 47 additions & 0 deletions src/contact/functions/list.ts
@@ -0,0 +1,47 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { ContactModel, ContactStore } from '../../whatsapp';

export interface ContactListOptions {
onlyMyContacts?: boolean;
}

/**
* Return a list of contacts
*
* @example
* ```javascript
* // All contacts
* const contats = await WPP.contact.list();
*
* // Only my contacts
* const contatcs = await WPP.contact.list({onlyMyContacts: true});
* ```
*
* @category Contact
*/
export async function list(
options: ContactListOptions = {}
): Promise<ContactModel[]> {
let models = ContactStore.getModelsArray().slice();

if (options.onlyMyContacts) {
models = models.filter((c) => c.isMyContact);
}

return models;
}

0 comments on commit b7ed183

Please sign in to comment.