• Voting

    From Nightfox@VERT/DIGDIST to Digital Man on Fri Nov 25 10:09:22 2016
    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.

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From echicken@VERT/ECBBS to Nightfox on Fri Nov 25 14:04:38 2016
    Re: Voting
    By: Nightfox to Digital Man on Fri Nov 25 2016 10:09:22

    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.

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com - 416-273-7230
    þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.com
  • From Nightfox@VERT/DIGDIST to echicken on Fri Nov 25 11:37:36 2016
    Re: Voting
    By: echicken to Nightfox on Fri Nov 25 2016 14:04:38

    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.

    Thanks.

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Fri Nov 25 14:09:20 2016
    Re: Voting
    By: Nightfox to Digital Man on Fri Nov 25 2016 10:09 am

    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.

    Use the new method: MsgBase.how_user_voted(msgnum, username_or_alias)
    If it returns zero, the user has not voted. If it returns non-zero, then it indicates that the user voted on message (msgnum) and how they voted. For a normal message, a return value of 1 means an up-vote while 2 means a down-vote. For polls, the return value is a bit-map of the answers given (1<<0 means answer 1, 1<<1 means answer 2, etc.).

    digital man

    Synchronet "Real Fact" #37:
    Synchronet's Windows Control Panel is built with Borland C++ Builder.
    Norco, CA WX: 74.5øF, 15.0% humidity, 3 mph ESE wind, 0.00 inches rain/24hrs ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ telnet://vert.synchro.net