Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit bf7f5024 authored by rswindell's avatar rswindell

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.
parent 4c4ae973
......@@ -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)
......
......@@ -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;
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment