feat: getPollVotes (#3807)
* Add required module * Add getPollVotes function * Add getPollVotes function * Add getPollVotes function * Add Message.getPollVotes * Add Message.getPollVotes
This commit is contained in:
parent
87a310a2de
commit
7c7851f4d4
4 changed files with 41 additions and 0 deletions
|
|
@ -2414,6 +2414,32 @@ class Client extends EventEmitter {
|
|||
return serialized;
|
||||
}, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Poll Votes
|
||||
* @param {string} messageId
|
||||
* @return {Promise<Array<PollVote>>}
|
||||
*/
|
||||
async getPollVotes(messageId) {
|
||||
const msg = await this.getMessageById(messageId);
|
||||
if (!msg) return [];
|
||||
if (msg.type != 'poll_creation') throw 'Invalid usage! Can only be used with a pollCreation message';
|
||||
|
||||
const pollVotes = await this.pupPage.evaluate( async (msg) => {
|
||||
const msgKey = window.Store.MsgKey.fromString(msg.id._serialized);
|
||||
let pollVotes = await window.Store.PollsVotesSchema.getTable().equals(['parentMsgKey'], msgKey.toString());
|
||||
|
||||
return pollVotes.map(item => {
|
||||
const typedArray = new Uint8Array(item.selectedOptionLocalIds);
|
||||
return {
|
||||
...item,
|
||||
selectedOptionLocalIds: Array.from(typedArray)
|
||||
};
|
||||
});
|
||||
}, msg);
|
||||
|
||||
return pollVotes.map((pollVote) => new PollVote(this.client, {...pollVote, parentMessage: msg}));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Client;
|
||||
|
|
|
|||
Loading…
Reference in a new issue