wa-js icon indicating copy to clipboard operation
wa-js copied to clipboard

Criar opção para não sincronizar os status postados pelos contatos do celular

Open dandrade-pedbot opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. Uma das maiores causas de instabilidades e alto consumo de memória ram pela biblioteca, está na sincronização de status postados pelos clientes. Mensagens trocadas em conversas, utilizam pouca memória ram, pois é apenas texto, já os status são todos vídeos, portanto, um celular que possua por exemplo 5000 contatos salvos, recebe uma avalanche de status assim que conecta, jogando os recursos de memória ram lá em cima e por consequência trazendo instabilidade para biblioteca.

Describe the solution you'd like Seria interessante adicionar uma opção na inicialização do client, para escolher se deseja ou não sincronizar os status.

Caso não deseje sincronizar os status, é necessário realizar as seguintes supressões:

  • Assim que conecta o chip, não deve puxar os status na sincronização inicial;
  • Quando o chip já está conectado, não deve receber os novos status que os contatos estão postando;
  • É importante manter a sincronização dos status que são postados pelo aparelho conectado, pois caso algum contato responda esse status, e ele não estiver sincronizado na biblioteca, não vai ser possível realizar a vinculação que a mensagem recebida é a resposta de um status.

Describe alternatives you've considered Necessário seguir os critérios informados acima.

Additional context Já consegui realizar uma parte disso, que é a supressão da sincronização inicial dos status, segue abaixo as alterações para isso:

wa-js/src/whatsapp/functions/handleHistorySyncNotification.ts

/*!
 * 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 { exportModule } from '../exportModule';

export interface HistorySyncNotification {
  syncType: Number
}

export interface HistoryData {
  historySyncNotification: HistorySyncNotification
}

/** @whatsapp 889877
 * @whatsapp 889877 >= 2.2222.8
 */
export declare function handleHistorySyncNotification(args: HistoryData): Promise<any>;

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

wa-js/src/chat/events/handleStatusNotifications.ts:

/*!
 * 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 * as webpack from '../../webpack';
import { wrapModuleFunction } from '../../whatsapp/exportModule';
import { handleHistorySyncNotification } from '../../whatsapp/functions';

webpack.onInjected(() => register());

function register() {
  wrapModuleFunction(handleHistorySyncNotification, (func, ...args) => {
    const [data] = args;
    const dataString = JSON.stringify(data);
    const parsedData = JSON.parse(dataString);
    if (parsedData.historySyncNotification.syncType === 1) {
      return new Promise(() => {
        return;
      });
    }

    return func(...args);
  });
}

dandrade-pedbot avatar Mar 16 '23 12:03 dandrade-pedbot

I guess fixed by https://github.com/wppconnect-team/wa-js/commit/845bcf65635876794ef1f3e98557fc59756bb2f1 and https://github.com/wppconnect-team/wa-js/commit/6bf2e68db145f6821b3605cf6606afb74426a466

Saifallak avatar Apr 01 '23 22:04 Saifallak

Thanks @Saifallak , I did only the inicial syncronization, I need to work with new stories after sync

edgardmessias avatar Apr 03 '23 19:04 edgardmessias