From 845bcf65635876794ef1f3e98557fc59756bb2f1 Mon Sep 17 00:00:00 2001 From: Edgard Date: Thu, 30 Mar 2023 21:53:17 -0300 Subject: [PATCH] feat: Added option to disable all status sync (config.syncAllStatus) --- src/config/Config.ts | 6 ++++ src/config/defaultConfig.ts | 1 + src/status/index.ts | 1 + src/status/patch.ts | 36 +++++++++++++++++++ .../collections/StatusV3Collection.ts | 6 ++-- .../functions/handleStatusV3Messages.ts | 36 +++++++++++++++++++ src/whatsapp/functions/index.ts | 1 + 7 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/status/patch.ts create mode 100644 src/whatsapp/functions/handleStatusV3Messages.ts diff --git a/src/config/Config.ts b/src/config/Config.ts index 5e98d8fe69..236a722ac2 100644 --- a/src/config/Config.ts +++ b/src/config/Config.ts @@ -75,4 +75,10 @@ export interface Config { * @default false */ sendStatusToDevice: boolean; + + /** + * Option to disable status sync + * @default false + */ + syncAllStatus: boolean; } diff --git a/src/config/defaultConfig.ts b/src/config/defaultConfig.ts index 82e5121381..4773270a1a 100644 --- a/src/config/defaultConfig.ts +++ b/src/config/defaultConfig.ts @@ -25,4 +25,5 @@ export const defaultConfig: Config = { linkPreviewApiServers: null, poweredBy: 'WA-JS', sendStatusToDevice: false, + syncAllStatus: true, }; diff --git a/src/status/index.ts b/src/status/index.ts index 886242638f..b9022b475f 100644 --- a/src/status/index.ts +++ b/src/status/index.ts @@ -15,6 +15,7 @@ */ import './events'; +import './patch'; export * from './defaultSendStatusOptions'; export * from './functions'; diff --git a/src/status/patch.ts b/src/status/patch.ts new file mode 100644 index 0000000000..69e1957934 --- /dev/null +++ b/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); + }); +} diff --git a/src/whatsapp/collections/StatusV3Collection.ts b/src/whatsapp/collections/StatusV3Collection.ts index 6a8edfbb4b..3bc43215d3 100644 --- a/src/whatsapp/collections/StatusV3Collection.ts +++ b/src/whatsapp/collections/StatusV3Collection.ts @@ -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 '.'; @@ -27,9 +29,9 @@ export declare class StatusV3Collection extends BaseCollection { 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; diff --git a/src/whatsapp/functions/handleStatusV3Messages.ts b/src/whatsapp/functions/handleStatusV3Messages.ts new file mode 100644 index 0000000000..b48ac75adc --- /dev/null +++ b/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; + +exportModule( + exports, + { + handleStatusV3Messages: ['handleStatusV3Messages'], + }, + (m) => m.handleStatusV3Messages +); diff --git a/src/whatsapp/functions/index.ts b/src/whatsapp/functions/index.ts index f71cf94fb9..58af8daf86 100644 --- a/src/whatsapp/functions/index.ts +++ b/src/whatsapp/functions/index.ts @@ -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';