From 01ac2c5f21249f5255c937bf939f7ca1f726350a Mon Sep 17 00:00:00 2001 From: icleitoncosta Date: Tue, 9 Apr 2024 22:02:52 -0300 Subject: [PATCH] fix: Fixed WPP.chat.getVotes function --- src/whatsapp/functions/getTableVotes.ts | 30 ++++++++++++++++++++++++ src/whatsapp/functions/getVotes.ts | 15 ++++++++++++ src/whatsapp/functions/index.ts | 2 ++ src/whatsapp/functions/voteFromDbRow.ts | 31 +++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 src/whatsapp/functions/getTableVotes.ts create mode 100644 src/whatsapp/functions/voteFromDbRow.ts diff --git a/src/whatsapp/functions/getTableVotes.ts b/src/whatsapp/functions/getTableVotes.ts new file mode 100644 index 0000000000..b22818886c --- /dev/null +++ b/src/whatsapp/functions/getTableVotes.ts @@ -0,0 +1,30 @@ +/*! + * Copyright 2024 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 WAWebPollsVotesSchema => 2.3000.x + */ +export declare function getTableVotes(args?: any): any; + +exportModule( + exports, + { + getTableVotes: ['getTable'], + }, + (m) => m.getTable.toString().includes('poll') +); diff --git a/src/whatsapp/functions/getVotes.ts b/src/whatsapp/functions/getVotes.ts index 5122273b10..8d6f24a034 100644 --- a/src/whatsapp/functions/getVotes.ts +++ b/src/whatsapp/functions/getVotes.ts @@ -14,9 +14,12 @@ * limitations under the License. */ +import { injectFallbackModule } from '../../webpack'; import { exportModule } from '../exportModule'; import { MsgKey } from '../misc'; +import { getTableVotes } from './getTableVotes'; import { VoteData } from './upsertVotes'; +import { voteFromDbRow } from './voteFromDbRow'; /** * @whatsapp 816349 @@ -32,3 +35,15 @@ exportModule( }, (m) => m.getVotes && m.getVote ); + +// Fix for version => 2.3000.1012654901 +injectFallbackModule('getVotes', { + getVote: (msgKey: MsgKey) => msgKey, + getVotes: async (keys: MsgKey[]) => { + const votes = await getTableVotes().anyOf( + ['parentMsgKey'], + keys.map((key) => key.toString()) + ); + return votes.map((vote: any) => voteFromDbRow(vote)); + }, +}); diff --git a/src/whatsapp/functions/index.ts b/src/whatsapp/functions/index.ts index d4bb73891a..e5267d03c2 100644 --- a/src/whatsapp/functions/index.ts +++ b/src/whatsapp/functions/index.ts @@ -67,6 +67,7 @@ export * from './getPushname'; export * from './getQuotedMsgObj'; export * from './getReactions'; export * from './getSearchContext'; +export * from './getTableVotes'; export * from './getVotes'; export * from './getWhatsAppWebExternalBetaJoinedIdb'; export * from './GROUP_JID'; @@ -133,3 +134,4 @@ export * from './uploadMedia'; export * from './uploadProductImage'; export * from './uploadThumbnail'; export * from './upsertVotes'; +export * from './voteFromDbRow'; diff --git a/src/whatsapp/functions/voteFromDbRow.ts b/src/whatsapp/functions/voteFromDbRow.ts new file mode 100644 index 0000000000..9933b6d650 --- /dev/null +++ b/src/whatsapp/functions/voteFromDbRow.ts @@ -0,0 +1,31 @@ +/*! + * Copyright 2024 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 { MsgModel } from '../models'; + +/** + * @whatsapp WAWebPollsDbSerialization >= 2.3000.x + */ +export declare function voteFromDbRow(msg: MsgModel): Promise; + +exportModule( + exports, + { + voteFromDbRow: ['voteFromDbRow'], + }, + (m) => m.voteFromDbRow +);