What's the best way to check to see if a user has already voted on a message? In the JavaScript layer, it looks like MsgBase.vote_msg() will
What's the best way to check to see if a user has already voted on a
message? In the JavaScript layer, it looks like MsgBase.vote_msg()
will
var votes = msgBase.how_user_voted(
message_number,
msgBase.cfg.settings&SUB_NAME ? user.name : user.alias
);
Note that this is not tied to the "currently logged-in" user, so the second argument specifies the name (or alias) of the person whose vote you wish to look up for a given message. Depending on the settings of the sub, you'll have to look the user up by "real name" or alias.
The return value will be:
0 - user hasn't voted
1 - upvoted
2 - downvoted
Or, if the message was a poll, it's a bitfield:
if (votes&(1<<2)) {
// User selected answer 2
}
And so on.
Hi DM,
What's the best way to check to see if a user has already voted on a message? In the JavaScript layer, it looks like MsgBase.vote_msg() will return false if a user has already voted on the message - But I imagine there may be other reasons it could fail. Also, vote_msg() would only be called after prompting for an up/downvote; I'd rather let the user know they've already voted before prompting for an up/downvote.
Sysop: | Ragnarok |
---|---|
Location: | Dock Sud, Bs As, Argentina |
Users: | 136 |
Nodes: | 10 (0 / 10) |
Uptime: | 06:27:20 |
Calls: | 15,171 |
Calls today: | 4 |
Files: | 19,857 |
D/L today: |
7 files (164K bytes) |
Messages: | 1,691,377 |