feat+fix: send vote messages & vote update event (#3913)

* add send vote function

* Update index.d.ts

* fix and add required modules

* fix poll update in group chat

* adjustments to improvements

* add example usages

* fix eslint

---------

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
This commit is contained in:
RendyCraft047 2025-11-10 02:37:51 +07:00 • committed by GitHub
commit 0c36613cc7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -749,6 +749,32 @@ class Message extends Base {
async getPollVotes() {
return await this.client.getPollVotes(this.id._serialized);
}
/**
* Send votes to the poll message
* @param {Array<string>} selectedOptions Array of options selected.
* @returns {Promise}
*/
async vote(selectedOptions) {
if (this.type != MessageTypes.POLL_CREATION) throw 'Invalid usage! Can only be used with a pollCreation message';
await this.client.pupPage.evaluate(async (messageId, votes) => {
if (!messageId) return null;
if (!Array.isArray(votes)) votes = [votes];
let localIdSet = new Set();
const msg =
window.Store.Msg.get(messageId) || (await window.Store.Msg.getMessagesById([messageId]))?.messages?.[0];
if (!msg) return null;
msg.pollOptions.forEach(a => {
for (const option of votes) {
if (a.name === option) localIdSet.add(a.localId);
}
});
await window.Store.PollsSendVote.sendVote(msg, localIdSet);
}, this.id._serialized, selectedOptions);
}
}
module.exports = Message;