commit ed957b4

default  ·  2023-04-12 13:28:43 +0000 UTC
parent 0184297
Added support for like and boost lists.
1 files changed,  +47, -20
+47, -20
 1@@ -412,19 +412,10 @@ xs_str *mastoapi_id(const xs_dict *msg)
 2 #define MID_TO_MD5(id) (id + 10)
 3 
 4 
 5-xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
 6-/* converts an ActivityPub note to a Mastodon status */
 7+xs_dict *mastoapi_account(snac *snac, const xs_dict *actor)
 8+/* converts an ActivityPub actor to a Mastodon account */
 9 {
10-    xs *actor = NULL;
11-    actor_get(snac, xs_dict_get(msg, "attributedTo"), &actor);
12-
13-    /* if the author is not here, discard */
14-    if (actor == NULL)
15-        return NULL;
16-
17-    /** shave the yak converting an ActivityPub Note to a Mastodon status **/
18-
19-    xs *acct = xs_dict_new();
20+    xs_dict *acct = xs_dict_new();
21 
22     const char *display_name = xs_dict_get(actor, "name");
23     if (xs_is_null(display_name) || *display_name == '\0')
24@@ -454,6 +445,24 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
25 
26     acct = xs_dict_append(acct, "avatar", avatar);
27 
28+    return acct;
29+}
30+
31+
32+xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
33+/* converts an ActivityPub note to a Mastodon status */
34+{
35+    xs *actor = NULL;
36+    actor_get(snac, xs_dict_get(msg, "attributedTo"), &actor);
37+
38+    /* if the author is not here, discard */
39+    if (actor == NULL)
40+        return NULL;
41+
42+    xs *acct = mastoapi_account(snac, actor);
43+
44+    /** shave the yak converting an ActivityPub Note to a Mastodon status **/
45+
46     xs *f   = xs_val_new(XSTYPE_FALSE);
47     xs *t   = xs_val_new(XSTYPE_TRUE);
48     xs *n   = xs_val_new(XSTYPE_NULL);
49@@ -462,8 +471,8 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
50     xs *ixc = NULL;
51 
52     char *tmp;
53-    id = xs_dict_get(msg, "id");
54-    xs *mid = mastoapi_id(msg);
55+    char *id = xs_dict_get(msg, "id");
56+    xs *mid  = mastoapi_id(msg);
57 
58     xs_dict *st = xs_dict_new();
59 
60@@ -916,12 +925,30 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
61                     out = xs_dict_append(out, "descendants", des);
62                 }
63                 else
64-                if (strcmp(op, "reblogged_by") == 0) {
65-                    /* return the list of boosts */
66-                }
67-                else
68-                if (strcmp(op, "favourited_by") == 0) {
69-                    /* return the list of likes */
70+                if (strcmp(op, "reblogged_by") == 0 ||
71+                    strcmp(op, "favourited_by") == 0) {
72+                    /* return the list of likes or boosts */
73+                    out = xs_list_new();
74+
75+                    xs *l = NULL;
76+
77+                    if (op[0] == 'r')
78+                        l = object_announces(xs_dict_get(msg, "id"));
79+                    else
80+                        l = object_likes(xs_dict_get(msg, "id"));
81+
82+                    xs_list *p = l;
83+                    xs_str *v;
84+
85+                    while (xs_list_iter(&p, &v)) {
86+                        xs *actor2 = NULL;
87+
88+                        if (valid_status(object_get_by_md5(v, &actor2))) {
89+                            xs *acct2 = mastoapi_account(&snac, actor2);
90+
91+                            out = xs_list_append(out, acct2);
92+                        }
93+                    }
94                 }
95             }
96             else