summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-06-02 11:48:43 +0200
committerGravatar default2023-06-02 11:48:43 +0200
commit13ab8c73e53622c6bacc52d3004c4a16a6f2f077 (patch)
tree471a987b2a91229d0b2e42a9ce7768f313a74baf
parentFixed bug in notify() (the poll id was not set). (diff)
downloadpenes-snac2-13ab8c73e53622c6bacc52d3004c4a16a6f2f077.tar.gz
penes-snac2-13ab8c73e53622c6bacc52d3004c4a16a6f2f077.tar.xz
penes-snac2-13ab8c73e53622c6bacc52d3004c4a16a6f2f077.zip
More notify tweaks (I'm getting sick of this).
-rw-r--r--activitypub.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/activitypub.c b/activitypub.c
index 67b4739..a25a46c 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -522,12 +522,21 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor,
522 522
523 /* updated poll? */ 523 /* updated poll? */
524 if (strcmp(type, "Update") == 0 && strcmp(utype, "Question") == 0) { 524 if (strcmp(type, "Update") == 0 && strcmp(utype, "Question") == 0) {
525 const xs_dict *poll;
526 const char *poll_id;
527
528 if ((poll = xs_dict_get(msg, "object")) == NULL)
529 return;
530
525 /* if it's not closed, discard */ 531 /* if it's not closed, discard */
526 if (xs_is_null(xs_dict_get(msg, "closed"))) 532 if (xs_is_null(xs_dict_get(poll, "closed")))
533 return;
534
535 if ((poll_id = xs_dict_get(poll, "id")) == NULL)
527 return; 536 return;
528 537
529 /* if it's not ours and we didn't vote, discard */ 538 /* if it's not ours and we didn't vote, discard */
530 if (!xs_startswith(id, snac->actor) && !was_question_voted(snac, id)) 539 if (!xs_startswith(poll_id, snac->actor) && !was_question_voted(snac, poll_id))
531 return; 540 return;
532 } 541 }
533 542
@@ -1193,16 +1202,17 @@ int update_question(snac *user, const char *id)
1193 msg = xs_dict_set(msg, xs_dict_get(msg, "oneOf") != NULL ? "oneOf" : "anyOf", nopts); 1202 msg = xs_dict_set(msg, xs_dict_get(msg, "oneOf") != NULL ? "oneOf" : "anyOf", nopts);
1194 1203
1195 /* due date? */ 1204 /* due date? */
1205 int closed = 0;
1196 const char *end_time = xs_dict_get(msg, "endTime"); 1206 const char *end_time = xs_dict_get(msg, "endTime");
1197 if (!xs_is_null(end_time)) { 1207 if (!xs_is_null(end_time)) {
1198 xs *now = xs_str_utctime(0, ISO_DATE_SPEC); 1208 xs *now = xs_str_utctime(0, ISO_DATE_SPEC);
1199 1209
1200 /* it's now greater than the endTime? */ 1210 /* is now greater than the endTime? */
1201 if (strcmp(now, end_time) >= 0) { 1211 if (strcmp(now, end_time) >= 0) {
1202 xs *et = xs_dup(end_time); 1212 xs *et = xs_dup(end_time);
1203 msg = xs_dict_set(msg, "closed", et); 1213 msg = xs_dict_set(msg, "closed", et);
1204 1214
1205 notify(user, "Update", "Question", user->actor, msg); 1215 closed = 1;
1206 } 1216 }
1207 } 1217 }
1208 1218
@@ -1222,6 +1232,11 @@ int update_question(snac *user, const char *id)
1222 1232
1223 enqueue_message(user, u_msg); 1233 enqueue_message(user, u_msg);
1224 1234
1235 if (closed) {
1236 xs *c_msg = msg_update(user, msg);
1237 notify(user, "Update", "Question", user->actor, c_msg);
1238 }
1239
1225 return 0; 1240 return 0;
1226} 1241}
1227 1242