Skip to content

Commit

Permalink
feat: Added option to disable all status sync (config.syncAllStatus)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Mar 31, 2023
1 parent 656fb5a commit 845bcf6
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/config/Config.ts
Expand Up @@ -75,4 +75,10 @@ export interface Config {
* @default false
*/
sendStatusToDevice: boolean;

/**
* Option to disable status sync
* @default false
*/
syncAllStatus: boolean;
}
1 change: 1 addition & 0 deletions src/config/defaultConfig.ts
Expand Up @@ -25,4 +25,5 @@ export const defaultConfig: Config = {
linkPreviewApiServers: null,
poweredBy: 'WA-JS',
sendStatusToDevice: false,
syncAllStatus: true,
};
1 change: 1 addition & 0 deletions src/status/index.ts
Expand Up @@ -15,6 +15,7 @@
*/

import './events';
import './patch';

export * from './defaultSendStatusOptions';
export * from './functions';
36 changes: 36 additions & 0 deletions src/status/patch.ts
@@ -0,0 +1,36 @@
/*!
* Copyright 2023 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 { config } from '..';
import * as webpack from '../webpack';
import { wrapModuleFunction } from '../whatsapp/exportModule';
import { handleStatusV3Messages } from '../whatsapp/functions';

webpack.onReady(applyPatch);

function applyPatch() {
wrapModuleFunction(handleStatusV3Messages, (func, ...args) => {
if (!config.syncAllStatus) {
args[0].statusV3Messages = args[0].statusV3Messages.filter(
(status: any) => {
return status.key.fromMe === true;
}
);
}

return func(...args);
});
}
6 changes: 4 additions & 2 deletions src/whatsapp/collections/StatusV3Collection.ts
Expand Up @@ -14,7 +14,9 @@
* limitations under the License.
*/

import { RawMessage } from '../../chat';
import { exportModule } from '../exportModule';
import { Wid } from '../misc';
import { StatusV3Model } from '../models';
import { BaseCollection } from '.';

Expand All @@ -27,9 +29,9 @@ export declare class StatusV3Collection extends BaseCollection<StatusV3Model> {
sync(e?: any): any;
logMetrics(e?: any): any;
hasSynced(): boolean;
handleUpdate(rawMsg?: any, checksum?: any, isMsgUpdate?: boolean): any;
handleUpdate(rawMsg?: RawMessage, checksum?: any, isMsgUpdate?: boolean): any;
updateChecksum(e?: any): any;
addStatusMessages(e?: any, t?: any): any;
addStatusMessages(wid: Wid, msgs: RawMessage[]): any;
getUnexpired(e?: any): any;
getMyStatus(): StatusV3Model;
static comparator(): any;
Expand Down
36 changes: 36 additions & 0 deletions src/whatsapp/functions/handleStatusV3Messages.ts
@@ -0,0 +1,36 @@
/*!
* Copyright 2023 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 84947
* @whatsapp 284947 >= 2.2222.8
* @whatsapp 359554 >= 2.2230.8
*/
export declare function handleStatusV3Messages(
data: any,
b: any,
c: any,
d: any
): Promise<any>;

exportModule(
exports,
{
handleStatusV3Messages: ['handleStatusV3Messages'],
},
(m) => m.handleStatusV3Messages
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Expand Up @@ -45,6 +45,7 @@ export * from './getSearchContext';
export * from './getVotes';
export * from './groupParticipants';
export * from './handleAck';
export * from './handleStatusV3Messages';
export * from './isAnimatedWebp';
export * from './isAuthenticated';
export * from './isRegistered';
Expand Down

0 comments on commit 845bcf6

Please sign in to comment.