Commit ae7c2f8b authored by rswindell's avatar rswindell
Browse files

Poll display support:

* uses new text.dat strings:
- PollVoteNotice
- PollAnswerNumber
- PollAnswerFmt
- PollAnswerChecked

The actual answer of a poll is still crude (uses the old crufty uselect scheme)
and doesn't support multiple-choice polls. This will be addressed.
parent 04c26f15
......@@ -150,7 +150,7 @@ void sbbs_t::show_msghdr(smbmsg_t* msg)
if(msg->from_net.addr!=NULL && strchr(msg->from,'@')==NULL)
bprintf(text[MsgFromNet],smb_netaddrstr(&msg->from_net,str));
}
if(msg->upvotes || msg->downvotes)
if(!(msg->hdr.attr&MSG_POLL) && (msg->upvotes || msg->downvotes))
bprintf(text[MsgVotes], msg->upvotes, msg->downvotes);
bprintf(text[MsgDate]
,timestr(msg->hdr.when_written.time)
......@@ -182,13 +182,16 @@ ulong sbbs_t::total_votes(post_t* post)
/****************************************************************************/
void sbbs_t::show_msg(smbmsg_t* msg, long mode, post_t* post)
{
char* text;
char* txt;
show_msghdr(msg);
if(msg->hdr.type == SMB_MSG_TYPE_POLL && post != NULL) {
char* answer;
int longest_answer = 0;
uint16_t votes = smb_voted_already(&smb, msg->hdr.number
,cfg.sub[smb.subnum]->misc&SUB_NAME ? useron.name : useron.alias, NET_NONE, NULL);
for(int i = 0; i < msg->total_hfields; i++) {
if(msg->hfield[i].type != SMB_POLL_ANSWER)
continue;
......@@ -203,21 +206,32 @@ void sbbs_t::show_msg(smbmsg_t* msg, long mode, post_t* post)
continue;
answer = (char*)msg->hfield_dat[i];
ulong total = total_votes(post);
bprintf("%2u: %-*s [%-4u %3g%%]\r\n", answers+1, longest_answer, answer, post->votes[answers]
,total ? ((float)post->votes[answers] / total)*100.0 : 0.0);
float pct = total ? ((float)post->votes[answers] / total)*100.0F : 0.0F;
char str[128];
int width = longest_answer;
if(width < cols/3) width = cols/3;
else if(width > cols-20)
width = cols-20;
bprintf(text[PollAnswerNumber], answers+1);
safe_snprintf(str, sizeof(str), text[PollAnswerFmt]
,width, width, answer, post->votes[answers], pct);
backfill(str, pct);
if(votes&(1<<answers))
bputs(text[PollAnswerChecked]);
CRLF;
answers++;
}
return;
}
if((text=smb_getmsgtxt(&smb,msg,(console&CON_RAW_IN) ? 0:GETMSGTXT_PLAIN)) != NULL) {
if((txt=smb_getmsgtxt(&smb,msg,(console&CON_RAW_IN) ? 0:GETMSGTXT_PLAIN)) != NULL) {
if(!(console&CON_RAW_IN))
mode|=P_WORDWRAP;
putmsg(text, mode);
smb_freemsgtxt(text);
putmsg(txt, mode);
smb_freemsgtxt(txt);
}
if((text=smb_getmsgtxt(&smb,msg,GETMSGTXT_TAIL_ONLY))!=NULL) {
putmsg(text, mode&(~P_WORDWRAP));
smb_freemsgtxt(text);
if((txt=smb_getmsgtxt(&smb,msg,GETMSGTXT_TAIL_ONLY))!=NULL) {
putmsg(txt, mode&(~P_WORDWRAP));
smb_freemsgtxt(txt);
}
}
......
......@@ -282,7 +282,7 @@ post_t * sbbs_t::loadposts(uint32_t *posts, uint subnum, ulong ptr, long mode, u
break;
default:
for(int b=0; b < 16; b++) {
if(idx.vote&(1<<b))
if(idx.votes&(1<<b))
post[u].votes[b]++;
}
}
......@@ -1035,18 +1035,21 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
case 'V': /* Vote in reply to message */
{
smbmsg_t vote;
const char* notice=NULL;
if(cfg.sub[subnum]->misc&SUB_NOVOTING) {
bputs(text[VotingNotAllowed]);
domsg = false;
break;
}
if(smb_voted_already(&smb, msg.hdr.number
,cfg.sub[subnum]->misc&SUB_NAME ? useron.name : useron.alias, NET_NONE, NULL)) {
bputs(text[VotedAlready]);
domsg = false;
break;
}
if(useron.rest&FLAG('V')) {
bputs(text[R_Voting]);
domsg = false;
......@@ -1065,18 +1068,18 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
domsg = false;
break;
}
vote.hdr.vote = (1<<i);
vote.hdr.votes = (1<<i);
vote.hdr.attr = MSG_VOTE;
notice = text[PollVoteNotice];
} else {
mnemonics(text[VoteMsgUpDownOrQuit]);
long cmd = getkeys("UDQ", 0);
if(cmd != 'U' && cmd != 'D')
break;
vote.hdr.attr = (cmd == 'U' ? MSG_UPVOTE : MSG_DOWNVOTE);
notice = text[vote.hdr.attr&MSG_UPVOTE ? MsgUpVoteNotice : MsgDownVoteNotice];
}
vote.hdr.thread_back = msg.hdr.number;
vote.hdr.when_written.time = vote.hdr.when_imported.time = time32(NULL);
vote.hdr.when_written.zone = vote.hdr.when_imported.zone = sys_timezone(&cfg);
smb_hfield_str(&vote, SENDER, (cfg.sub[subnum]->misc&SUB_NAME) ? useron.name : useron.alias);
if(msg.id != NULL)
......@@ -1089,7 +1092,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
msg_client_hfields(&vote, &client);
smb_hfield_str(&vote, SENDERSERVER, startup->host_name);
if((i=votemsg(&cfg, &smb, &vote, text[vote.hdr.attr&MSG_UPVOTE ? MsgUpVoteNotice : MsgDownVoteNotice])) != SMB_SUCCESS)
if((i=votemsg(&cfg, &smb, &vote, notice)) != SMB_SUCCESS)
errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
break;
......
......@@ -830,6 +830,10 @@ enum {
,MsgVotes
,MsgUpVoteNotice
,MsgDownVoteNotice
,PollVoteNotice
,PollAnswerNumber
,PollAnswerFmt
,PollAnswerChecked
,TOTAL_TEXT
};
......
......@@ -1301,4 +1301,10 @@ const char * const text_defaults[TOTAL_TEXT]={
,"\x0d\x0a\x01\x6e\x01\x68\x4f\x6e\x20\x25\x73\x2c\x20\x69\x6e\x20\x01\x63\x25\x73\x20\x01\x6e\x01\x63\x25\x73\x0d\x0a\x01\x68\x01"
"\x6d\x25\x73\x20\x01\x72\x44\x6f\x77\x6e\x01\x6e\x01\x6d\x2d\x76\x6f\x74\x65\x64\x20\x79\x6f\x75\x72\x20\x6d\x65\x73\x73\x61\x67"
"\x65\x3a\x20\x01\x6e\x01\x68\x25\x73\x0d\x0a"
,"\x0d\x0a\x01\x6e\x01\x68\x4f\x6e\x20\x25\x73\x2c\x20\x69\x6e\x20\x01\x63\x25\x73\x20\x01\x6e\x01\x63\x25\x73\x0d\x0a\x01\x68\x01"
"\x6d\x25\x73\x20\x76\x6f\x74\x65\x64\x20\x69\x6e\x20\x79\x6f\x75\x72\x20\x70\x6f\x6c\x6c\x3a\x20\x01\x6e\x01\x68\x25\x73\x0d\x0a"
""
,"\x01\x6e\x01\x63\x01\x68\x25\x32\x75\x01\x6e\x01\x63\x3a\x20"
,"\x25\x2d\x2a\x2e\x2a\x73\x20\x5b\x25\x2d\x34\x75\x20\x25\x33\x2e\x30\x66\x25\x25\x5d"
,"\x20\xfb"
};
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