Skip to content

Commit

Permalink
Update vote counts after voting
Browse files Browse the repository at this point in the history
  • Loading branch information
colinleroy committed Oct 10, 2024
1 parent e73c439 commit 1a90ca6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/mastodon/api/poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ static const char *poll_selector = ".reblog.poll|(.multiple,.votes_count,"
"(.own_votes|join(\",\")),"
"(.options[]|(.title,.votes_count)))";

void poll_fill(poll *p, char from_reblog) {
void poll_fill(poll *p, char source) {
int r;
char n_lines;

if (from_reblog)
if (source == POLL_FROM_REBLOG)
n_lines = 0;
else
else if (source == POLL_FROM_STATUS)
n_lines = 7; /* strlen(".reblog") */
else if (source == POLL_FROM_VOTE)
n_lines = 13; /* strlen(".reblog.poll|") */

memset(p->own_votes, 0, MAX_POLL_OPTIONS);

Expand All @@ -63,7 +65,10 @@ void poll_fill(poll *p, char from_reblog) {

for (r = 0; r < p->options_count; r ++) {
char i = NUM_POLL_LINES + (r * 2);
p->options[r].title = strdup(lines[i]);
if (p->options[r].title == NULL) {
p->options[r].title = strdup(lines[i]);
} /* otherwise, it's a reload from votes, and
* titles won't have changed. */
p->options[r].votes_count = (size_t)atoi(lines[i + 1]);
}
}
Expand Down Expand Up @@ -96,6 +101,9 @@ void poll_update_vote(poll *p) {
surl_send_data(params, i);

surl_read_response_header();
if (surl_response_ok()) {
poll_fill(p, POLL_FROM_VOTE);
}
}

#pragma code-name(pop)
4 changes: 4 additions & 0 deletions src/mastodon/api/poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ typedef struct _poll_option poll_option;
#define MAX_POLL_OPTIONS 4
#define MAX_POLL_OPTION_LEN 49

#define POLL_FROM_STATUS 0
#define POLL_FROM_REBLOG 1
#define POLL_FROM_VOTE 2

struct _poll_option {
char *title;
size_t votes_count;
Expand Down
2 changes: 1 addition & 1 deletion src/mastodon/api/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static __fastcall__ char status_fill_from_json(status *s, char *id, char full, c
if (n_lines == 17) {
s->poll = poll_new();
s->poll->id = strdup(lines[16]);
poll_fill(s->poll, is_reblog);
poll_fill(s->poll, is_reblog /* POLL_FROM_REBLOG == 1, POLL_FROM_STATUS == 0 */);
}

}
Expand Down
5 changes: 5 additions & 0 deletions src/mastodon/cli/tl.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,11 @@ static void do_vote (status *status) {
}
vote:
poll_update_vote(status->poll);
/* update display */
gotoxy(0, 0);
writable_lines = 23;
print_status(status, 0, 1);

out:
set_hscrollwindow(0, scrw);
return;
Expand Down

0 comments on commit 1a90ca6

Please sign in to comment.