commit a6e13e4

default  ·  2024-12-04 05:25:46 +0000 UTC
parent e0ba66a
msg_collection() now includes an argument for totalItems.
1 files changed,  +11, -9
+11, -9
 1@@ -1038,15 +1038,14 @@ xs_dict *msg_base(snac *snac, const char *type, const char *id,
 2 }
 3 
 4 
 5-xs_dict *msg_collection(snac *snac, const char *id)
 6+xs_dict *msg_collection(snac *snac, const char *id, int items)
 7 /* creates an empty OrderedCollection message */
 8 {
 9     xs_dict *msg = msg_base(snac, "OrderedCollection", id, NULL, NULL, NULL);
10-    xs *ol = xs_list_new();
11+    xs *n = xs_number_new(items);
12 
13     msg = xs_dict_append(msg, "attributedTo", snac->actor);
14-    msg = xs_dict_append(msg, "orderedItems", ol);
15-    msg = xs_dict_append(msg, "totalItems",   xs_stock(0));
16+    msg = xs_dict_append(msg, "totalItems",   n);
17 
18     return msg;
19 }
20@@ -2850,7 +2849,6 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path,
21     if (strcmp(p_path, "outbox") == 0 || strcmp(p_path, "featured") == 0) {
22         xs *id = xs_fmt("%s/%s", snac.actor, p_path);
23         xs *list = xs_list_new();
24-        msg = msg_collection(&snac, id);
25         const char *v;
26         int tc = 0;
27 
28@@ -2872,14 +2870,18 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path,
29         }
30 
31         /* replace the 'orderedItems' with the latest posts */
32-        xs *items = xs_number_new(xs_list_len(list));
33+        msg = msg_collection(&snac, id, xs_list_len(list));
34         msg = xs_dict_set(msg, "orderedItems", list);
35-        msg = xs_dict_set(msg, "totalItems",   items);
36     }
37     else
38-    if (strcmp(p_path, "followers") == 0 || strcmp(p_path, "following") == 0) {
39+    if (strcmp(p_path, "followers") == 0) {
40         xs *id = xs_fmt("%s/%s", snac.actor, p_path);
41-        msg = msg_collection(&snac, id);
42+        msg = msg_collection(&snac, id, 0);
43+    }
44+    else
45+    if (strcmp(p_path, "following") == 0) {
46+        xs *id = xs_fmt("%s/%s", snac.actor, p_path);
47+        msg = msg_collection(&snac, id, 0);
48     }
49     else
50     if (xs_startswith(p_path, "p/")) {