From bf7f502409efb859e18cb3000fbd925ea084b548 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Mon, 21 Nov 2016 09:30:16 +0000 Subject: [PATCH] Added new smbmsg_t element: user_voted, used to pass around the results of smb_voted_already(), e.g. to @-codes in a custom msg header. New @-codes (e.g. for custom message headers): @MSG_VOTED@ @MSG_UPVOTED@ @MSG_DOWNVOTED@ These all 3 act the same way: they display the PollAnswerChecked (checkmark) if the user voted on the currently displayed message/poll, if the user up-voted or if the user-downvoted. If the user did not vote, nothing is displayed. --- src/sbbs3/atcodes.cpp | 6 ++++++ src/sbbs3/getmsg.cpp | 20 ++++++++++---------- src/sbbs3/sbbs.h | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/sbbs3/atcodes.cpp b/src/sbbs3/atcodes.cpp index 52aa402e7c..f929c14dfa 100644 --- a/src/sbbs3/atcodes.cpp +++ b/src/sbbs3/atcodes.cpp @@ -1072,6 +1072,12 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen) safe_snprintf(str, maxlen, "%lu", current_msg->total_votes); return(str); } + if(!strcmp(sp,"MSG_VOTED")) + return (current_msg != NULL && current_msg->user_voted) ? text[PollAnswerChecked] : nulstr; + if(!strcmp(sp,"MSG_UPVOTED")) + return (current_msg != NULL && current_msg->user_voted == 1) ? text[PollAnswerChecked] : nulstr; + if(!strcmp(sp,"MSG_DOWNVOTED")) + return (current_msg != NULL && current_msg->user_voted == 2) ? text[PollAnswerChecked] : nulstr; if(!strcmp(sp,"SMB_AREA")) { if(smb.subnum!=INVALID_SUB && smb.subnum<cfg.total_subs) diff --git a/src/sbbs3/getmsg.cpp b/src/sbbs3/getmsg.cpp index 35cffde55a..700bb519ce 100644 --- a/src/sbbs3/getmsg.cpp +++ b/src/sbbs3/getmsg.cpp @@ -118,7 +118,7 @@ void sbbs_t::show_msgattr(smbmsg_t* msg) /****************************************************************************/ /* Displays a message header to the screen */ /****************************************************************************/ -void sbbs_t::show_msghdr(smbmsg_t* msg, uint16_t votes) +void sbbs_t::show_msghdr(smbmsg_t* msg) { char str[MAX_PATH+1]; char age[64]; @@ -155,8 +155,10 @@ void sbbs_t::show_msghdr(smbmsg_t* msg, uint16_t votes) bprintf(text[MsgFromNet],smb_netaddrstr(&msg->from_net,str)); } if(!(msg->hdr.attr&MSG_POLL) && (msg->upvotes || msg->downvotes)) - bprintf(text[MsgVotes], msg->upvotes, votes==1 ? text[PollAnswerChecked] : nulstr - ,msg->downvotes, votes==2 ? text[PollAnswerChecked] : nulstr, msg->upvotes - msg->downvotes); + bprintf(text[MsgVotes] + ,msg->upvotes, msg->user_voted==1 ? text[PollAnswerChecked] : nulstr + ,msg->downvotes, msg->user_voted==2 ? text[PollAnswerChecked] : nulstr + ,msg->upvotes - msg->downvotes); bprintf(text[MsgDate] ,timestr(msg->hdr.when_written.time) ,smb_zonestr(msg->hdr.when_written.zone,NULL) @@ -189,14 +191,12 @@ void sbbs_t::show_msg(smbmsg_t* msg, long mode, post_t* post) { char* txt; - uint16_t votes = 0; - if((msg->hdr.type == SMB_MSG_TYPE_NORMAL && (post->upvotes || post->downvotes)) || msg->hdr.type == SMB_MSG_TYPE_POLL) - votes = smb_voted_already(&smb, msg->hdr.number + msg->user_voted = smb_voted_already(&smb, msg->hdr.number ,cfg.sub[smb.subnum]->misc&SUB_NAME ? useron.name : useron.alias, NET_NONE, NULL); - show_msghdr(msg, votes); + show_msghdr(msg); if(msg->hdr.type == SMB_MSG_TYPE_POLL && post != NULL && smb.subnum < cfg.total_subs) { char* answer; @@ -241,12 +241,12 @@ void sbbs_t::show_msg(smbmsg_t* msg, long mode, post_t* post) else if((msg->hdr.auxattr&POLL_RESULTS_MASK) == POLL_RESULTS_CLOSED) results_visible = (msg->hdr.auxattr&POLL_CLOSED) ? true : false; else if((msg->hdr.auxattr&POLL_RESULTS_MASK) != POLL_RESULTS_SECRET) - results_visible = votes ? true : false; + results_visible = msg->user_voted ? true : false; if(results_visible) { safe_snprintf(str, sizeof(str), text[PollAnswerFmt] ,width, width, answer, post->votes[answers], pct); backfill(str, pct); - if(votes&(1<<answers)) + if(msg->user_voted&(1<<answers)) bputs(text[PollAnswerChecked]); } else { attr(cfg.color[clr_unfill]); @@ -255,7 +255,7 @@ void sbbs_t::show_msg(smbmsg_t* msg, long mode, post_t* post) CRLF; answers++; } - if(!votes && !(useron.misc&EXPERT) && !(msg->hdr.auxattr&POLL_CLOSED) && !(useron.rest&FLAG('V'))) + if(!msg->user_voted && !(useron.misc&EXPERT) && !(msg->hdr.auxattr&POLL_CLOSED) && !(useron.rest&FLAG('V'))) mnemonics("\r\nTo vote in this poll, hit ~V now.\r\n"); return; } diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h index 4d134ec352..dcd6fe94d8 100644 --- a/src/sbbs3/sbbs.h +++ b/src/sbbs3/sbbs.h @@ -642,7 +642,7 @@ public: /* getmsg.cpp */ int loadmsg(smbmsg_t *msg, ulong number); void show_msgattr(smbmsg_t*); - void show_msghdr(smbmsg_t* msg, uint16_t votes); + void show_msghdr(smbmsg_t* msg); void show_msg(smbmsg_t* msg, long mode, post_t* post = NULL); void msgtotxt(smbmsg_t* msg, char *str, bool header, ulong mode); ulong getlastmsg(uint subnum, uint32_t *ptr, time_t *t); -- GitLab