Skip to content

Commit

Permalink
fix: Fixed WPP.chat.getVotes function (#1821)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta authored Apr 10, 2024
1 parent 84e3466 commit 9f717e9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/whatsapp/functions/getTableVotes.ts
Original file line number Diff line number Diff line change
@@ -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')
);
15 changes: 15 additions & 0 deletions src/whatsapp/functions/getVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
},
});
2 changes: 2 additions & 0 deletions src/whatsapp/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -133,3 +134,4 @@ export * from './uploadMedia';
export * from './uploadProductImage';
export * from './uploadThumbnail';
export * from './upsertVotes';
export * from './voteFromDbRow';
31 changes: 31 additions & 0 deletions src/whatsapp/functions/voteFromDbRow.ts
Original file line number Diff line number Diff line change
@@ -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<any>;

exportModule(
exports,
{
voteFromDbRow: ['voteFromDbRow'],
},
(m) => m.voteFromDbRow
);

0 comments on commit 9f717e9

Please sign in to comment.