-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Merge branch 'add-polls' into polls-ext * added listener to poll votes * added isUnvote property * added option for custom message secret * usage example updated * added logic for catching removed votes * usage example updated * fixed logic for poll vote events * temp usage example * No more `isCurrentState` * messageSecret converted to array Co-authored-by: tuyuribr <[email protected]> * docs updated * we already have messageSecret in vote.parentMessage * PollVote.selectedOptions changed to be similar to pollOptions * docs fixed * window.injectToFunction clarifications * minor clarifications * fix: typo * style: fix broken link in readme file --------- Co-authored-by: tuyuribr <[email protected]>
- Loading branch information
Showing
8 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
const Message = require('./Message'); | ||
const Base = require('./Base'); | ||
|
||
/** | ||
* Selected poll option structure | ||
* @typedef {Object} SelectedPollOption | ||
* @property {number} id The local selected or deselected option ID | ||
* @property {string} name The option name | ||
*/ | ||
|
||
/** | ||
* Represents a Poll Vote on WhatsApp | ||
* @extends {Base} | ||
*/ | ||
class PollVote extends Base { | ||
constructor(client, data) { | ||
super(client); | ||
|
||
if (data) this._patch(data); | ||
} | ||
|
||
_patch(data) { | ||
/** | ||
* The person who voted | ||
* @type {string} | ||
*/ | ||
this.voter = data.sender; | ||
|
||
/** | ||
* The selected poll option(s) | ||
* If it's an empty array, the user hasn't selected any options on the poll, | ||
* may occur when they deselected all poll options | ||
* @type {SelectedPollOption[]} | ||
*/ | ||
this.selectedOptions = | ||
data.selectedOptionLocalIds.length > 0 | ||
? data.selectedOptionLocalIds.map((e) => ({ | ||
name: data.parentMessage.pollOptions.find((x) => x.localId === e).name, | ||
localId: e | ||
})) | ||
: []; | ||
|
||
/** | ||
* Timestamp the option was selected or deselected at | ||
* @type {number} | ||
*/ | ||
this.interractedAtTs = data.senderTimestampMs; | ||
|
||
/** | ||
* The poll creation message associated with the poll vote | ||
* @type {Message} | ||
*/ | ||
this.parentMessage = new Message(this.client, data.parentMessage); | ||
|
||
return super._patch(data); | ||
} | ||
} | ||
|
||
module.exports = PollVote; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters