Skip to content

Commit

Permalink
feat: Added option onlyCommunities for WPP.chat.list function
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jul 7, 2023
1 parent ae4bb79 commit 590c9ce
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/chat/functions/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface ChatListOptions {
id?: Wid;
count?: number;
direction?: 'after' | 'before';
onlyCommunities?: boolean;
onlyGroups?: boolean;
onlyUsers?: boolean;
onlyWithUnreadMessage?: boolean;
Expand All @@ -53,6 +54,9 @@ export interface ChatListOptions {
* // Only groups chats
* const chats = await WPP.chat.list({onlyGroups: true});
*
* // Only communities chats
* const chats = await WPP.chat.list({onlyCommunities: true});
*
* // Only with label Text
* const chats = await WPP.chat.list({withLabels: ['Test']});
*
Expand Down Expand Up @@ -85,6 +89,13 @@ export async function list(
models = models.filter((c) => c.isGroup);
}

if (options.onlyCommunities) {
models = models.filter(
(c) =>
c.isGroup && c.groupMetadata?.groupType === 'DEFAULT_ANNOUNCEMENT_GROUP'
);
}

if (options.onlyWithUnreadMessage) {
models = models.filter((c) => c.hasUnread);
}
Expand Down
32 changes: 31 additions & 1 deletion src/whatsapp/models/GroupMetadataModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ interface Props {
id: Wid;
creation?: any;
owner?: any;
subject?: string;
subjectTime?: any;
desc?: string;
descId?: string;
descTime?: any;
Expand All @@ -36,23 +38,51 @@ interface Props {
announce?: any;
noFrequentlyForwarded?: any;
ephemeralDuration?: any;
membershipApprovalMode?: any;
growthLockExpiration?: any;
growthLockType?: any;
reportToAdminMode?: any;
size?: any;
numSubgroups?: any;
support?: any;
suspended?: any;
terminated?: any;
uniqueShortNameMap?: any;
isLidAddressingMode: boolean;
isParentGroup: boolean;
isParentGroupClosed: boolean;
parentGroup?: any;
defaultSubgroup?: any;
unjoinedSubgroups?: any;
joinedSubgroups?: any;
allowNonAdminSubGroupCreation?: any;
lastActivityTimestamp?: any;
lastSeenActivityTimestamp?: any;
lastReportToAdminTimestamp?: any;
incognito?: any;
}

interface Session {
stale?: any;
deviceStale?: any;
trusted?: any;
inviteCode?: any;
groupInviteCodePromise?: any;
revokeGroupInvitePromise?: any;
revokeGroupV4AddInvitePromise?: any;
participantQueryPromise?: any;
deviceQueryPromise?: any;
unjoinedSubgroupsQueryPromise?: any;
displayedDesc?: any;
revokeGroupsV4AddInvitePromise?: any;
cachedDeviceCount?: any;
cachedDeviceSizeBucket?: any;
}

interface Derived {
groupInviteLink?: any;
groupType?: string;
isIncognitoCag?: boolean;
isUnnamed?: boolean;
}

/** @whatsapp 14423
Expand Down

0 comments on commit 590c9ce

Please sign in to comment.