commit ecde1c2

default  ·  2023-06-07 10:04:59 +0000 UTC
parent e926fa2
New function enqueue_request_replies().

This way, the (potentially expensive and slow) call to
timeline_request_replies() is detached from actions like
replying a message from the web ui.
3 files changed,  +24, -4
M data.c
M snac.h
+9, -4
 1@@ -143,8 +143,6 @@ int actor_request(snac *snac, const char *actor, xs_dict **data)
 2 }
 3 
 4 
 5-void timeline_request_replies(snac *user, const char *id);
 6-
 7 int timeline_request(snac *snac, char **id, xs_str **wrk)
 8 /* ensures that an entry and its ancestors are in the timeline */
 9 {
10@@ -191,7 +189,7 @@ int timeline_request(snac *snac, char **id, xs_str **wrk)
11             }
12         }
13 
14-        timeline_request_replies(snac, *id);
15+        enqueue_request_replies(snac, *id);
16     }
17 
18     return status;
19@@ -1679,7 +1677,14 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
20             update_question(snac, id);
21     }
22     else
23-        snac_log(snac, xs_fmt("unexpected q_item type '%s'", type));
24+    if (strcmp(type, "request_replies") == 0) {
25+        const char *id = xs_dict_get(q_item, "message");
26+
27+        if (!xs_is_null(id))
28+            timeline_request_replies(snac, id);
29+    }
30+    else
31+        snac_log(snac, xs_fmt("unexpected user q_item type '%s'", type));
32 }
33 
34 
M data.c
+13, -0
 1@@ -1935,6 +1935,19 @@ void enqueue_close_question(snac *user, const char *id, int end_secs)
 2 }
 3 
 4 
 5+void enqueue_request_replies(snac *user, const char *id)
 6+/* enqueues a request for the replies of a message */
 7+{
 8+    xs *qmsg   = _new_qmsg("request_replies", id, 0);
 9+    char *ntid = xs_dict_get(qmsg, "ntid");
10+    xs *fn     = xs_fmt("%s/queue/%s.json", user->basedir, ntid);
11+
12+    qmsg = _enqueue_put(fn, qmsg);
13+
14+    snac_debug(user, 0, xs_fmt("enqueue_request_replies %s", id));
15+}
16+
17+
18 int was_question_voted(snac *user, const char *id)
19 /* returns true if the user voted in this poll */
20 {
M snac.h
+2, -0
 1@@ -165,6 +165,7 @@ void enqueue_email(xs_str *msg, int retries);
 2 void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id);
 3 void enqueue_message(snac *snac, char *msg);
 4 void enqueue_close_question(snac *user, const char *id, int end_secs);
 5+void enqueue_request_replies(snac *user, const char *id);
 6 int was_question_voted(snac *user, const char *id);
 7 
 8 xs_list *user_queue(snac *snac);
 9@@ -213,6 +214,7 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
10 
11 int activitypub_request(snac *snac, const char *url, xs_dict **data);
12 int actor_request(snac *snac, const char *actor, xs_dict **data);
13+void timeline_request_replies(snac *user, const char *id);
14 int send_to_inbox_raw(const char *keyid, const char *seckey,
15                   const xs_str *inbox, const xs_dict *msg,
16                   xs_val **payload, int *p_size, int timeout);