Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions src/newsletter/functions/mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@
* limitations under the License.
*/

import { WPPError } from '../../util';
import { ChatModel, NewsletterStore } from '../../whatsapp';
import { muteNewsletter, unmuteNewsletter } from '../../whatsapp/functions';
import { CHANNEL_EVENT_SURFACE } from '../../whatsapp/enums';
import {
muteNewsletter,
toggleNewsletterAdminActivityMuteStateAction,
unmuteNewsletter,
} from '../../whatsapp/functions';
import { ensureNewsletter } from './ensureNewsletter';

const NEWSLETTER_MUTED_STATE = -1;
const NEWSLETTER_UNMUTED_STATE = 0;

/**
* Mute and unmute a newsletter
*
Expand All @@ -38,12 +47,27 @@ export async function mute(
newsletterId: string,
value?: boolean
): Promise<ChatModel> {
await ensureNewsletter(newsletterId);
if (value === false) {
const chat = await ensureNewsletter(newsletterId);

if (value != null && typeof value !== 'boolean') {
throw new WPPError('invalid_mute_value', 'Mute value must be boolean');
}

const eventSurface = CHANNEL_EVENT_SURFACE?.CHANNEL_UPDATES_HOME ?? 1;
const muteExpirationValue =
value === false ? NEWSLETTER_UNMUTED_STATE : NEWSLETTER_MUTED_STATE;

if (toggleNewsletterAdminActivityMuteStateAction) {
await toggleNewsletterAdminActivityMuteStateAction(
chat.id,
muteExpirationValue,
{ eventSurface }
);
} else if (value === false) {
await unmuteNewsletter([newsletterId]);
return NewsletterStore.get(newsletterId) as ChatModel;
} else {
await muteNewsletter([newsletterId]);
return NewsletterStore.get(newsletterId) as ChatModel;
}

return NewsletterStore.get(newsletterId) as ChatModel;
}
1 change: 1 addition & 0 deletions src/tools/updateModuleID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ async function start() {
'functions.revokeStatus',
'functions.muteNewsletter', // removed in version 2.3000.1032373751
'functions.unmuteNewsletter', // removed in version 2.3000.1032373751
'functions.toggleNewsletterAdminActivityMuteStateAction', // new in version >= 2.3000.1032373751
];

for (const moduleName of Object.keys(result)) {
Expand Down
38 changes: 38 additions & 0 deletions src/whatsapp/enums/CHANNEL_EVENT_SURFACE.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*!
* Copyright 2026 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 { exportModule } from '../exportModule';

/** @whatsapp WAWebWamEnumChannelEventSurface >= 2.3000.1032373751
*/
export declare enum CHANNEL_EVENT_SURFACE {
CHANNEL_UPDATES_HOME = 1,
CHANNEL_THREAD = 2,
CHANNEL_DIRECTORY = 3,
CHANNEL_DIRECTORY_SEARCH = 4,
CHANNEL_PROFILE = 5,
CHANNEL_UPDATES_HOME_SEARCH = 6,
CHANNEL_DIRECTORY_CATEGORIES = 7,
CHANNEL_DIRECTORY_CATEGORIES_SEARCH = 8,
}

exportModule(
exports,
{
CHANNEL_EVENT_SURFACE: 'CHANNEL_EVENT_SURFACE',
},
(m) => m.CHANNEL_EVENT_SURFACE
);
1 change: 1 addition & 0 deletions src/whatsapp/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

export * from './ACK';
export * from './CALL_STATES';
export * from './CHANNEL_EVENT_SURFACE';
export * from './GROUP_SETTING_TYPE';
export * from './KIC_ENTRY_POINT_TYP';
export * from './LogoutReason';
Expand Down
5 changes: 4 additions & 1 deletion src/whatsapp/exportModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ export function exportModule(
* I be creating other function for check expires based directily from files
* This will not directly affect the function call, it continues to work normally.
*/
const ignoreFailModules: string[] = ['revokeStatus'];
const ignoreFailModules: string[] = [
'revokeStatus',
'toggleNewsletterAdminActivityMuteStateAction',
];
if (!ignoreFailModules.includes(name)) {
console.error(description);
trackException(description);
Expand Down
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export * from './STATUS_JID';
export * from './statusEnable';
export * from './subscribePresence';
export * from './syncABPropsTask';
export * from './toggleNewsletterAdminActivityMuteStateAction';
export * from './toUserLid';
export * from './typeAttributeFromProtobuf';
export * from './unixTime';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*!
* Copyright 2026 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 { exportModule } from '../exportModule';
import { Wid } from '../misc';

/**
* @whatsapp WAWebNewsletterToggleAdminActivityMuteStateAction >= 2.3000.1032373751
*/
export declare const toggleNewsletterAdminActivityMuteStateAction:
| ((
newsletterId: Wid,
muteExpirationValue: number,
options: { eventSurface?: number }
) => Promise<void>)
| undefined;

exportModule(
exports,
{
toggleNewsletterAdminActivityMuteStateAction:
'toggleNewsletterAdminActivityMuteStateAction',
},
(m) => m.toggleNewsletterAdminActivityMuteStateAction
);