commit 2caeb55

default  ·  2023-07-13 19:01:15 +0000 UTC
parent a05aa96
Added support for the 'Page' ActivityPub object.

So that you can follow and interact with lemmy channels.
2 files changed,  +30, -9
M html.c
+21, -7
 1@@ -152,18 +152,19 @@ int timeline_request(snac *snac, char **id, xs_str **wrk, int level)
 2     int status = 0;
 3 
 4     if (!xs_is_null(*id)) {
 5-        xs *object = NULL;
 6+        xs *msg = NULL;
 7 
 8         /* is the object already there? */
 9-        if (!valid_status(object_get(*id, &object))) {
10+        if (!valid_status(object_get(*id, &msg))) {
11             /* no; download it */
12-            status = activitypub_request(snac, *id, &object);
13+            status = activitypub_request(snac, *id, &msg);
14 
15             if (valid_status(status)) {
16-                char *type = xs_dict_get(object, "type");
17+                xs_dict *object  = msg;
18+                const char *type = xs_dict_get(object, "type");
19 
20                 /* get the id again from the object, as it may be different */
21-                char *nid = xs_dict_get(object, "id");
22+                const char *nid = xs_dict_get(object, "id");
23 
24                 if (wrk && strcmp(nid, *id) != 0) {
25                     snac_debug(snac, 1,
26@@ -173,8 +174,21 @@ int timeline_request(snac *snac, char **id, xs_str **wrk, int level)
27                     *id  = *wrk;
28                 }
29 
30-                if (!xs_is_null(type) && strcmp(type, "Note") == 0) {
31-                    char *actor = xs_dict_get(object, "attributedTo");
32+                if (xs_is_null(type))
33+                    type = "(null)";
34+
35+                srv_debug(0, xs_fmt("timeline_request type %s '%s'", *id, type));
36+
37+                if (strcmp(type, "Create") == 0) {
38+                    /* some software like lemmy nest Announce + Create + Note */
39+                    if (!xs_is_null(object = xs_dict_get(object, "object")))
40+                        type = xs_dict_get(object, "type");
41+                    else
42+                        type = "(null)";
43+                }
44+
45+                if (strcmp(type, "Note") == 0 || strcmp(type, "Page") == 0) {
46+                    const char *actor = xs_dict_get(object, "attributedTo");
47 
48                     /* request (and drop) the actor for this entry */
49                     if (!xs_is_null(actor))
M html.c
+9, -2
 1@@ -189,8 +189,9 @@ xs_str *html_msg_icon(snac *snac, xs_str *os, const xs_dict *msg)
 2         char *udate = NULL;
 3         char *url   = NULL;
 4         int priv    = 0;
 5+        const char *type = xs_dict_get(msg, "type");
 6 
 7-        if (strcmp(xs_dict_get(msg, "type"), "Note") == 0)
 8+        if (strcmp(type, "Note") == 0 || strcmp(type, "Question") == 0 || strcmp(type, "Page") == 0)
 9             url = xs_dict_get(msg, "id");
10 
11         priv = !is_msg_public(snac, msg);
12@@ -856,7 +857,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
13         return xs_str_cat(os, s);
14     }
15     else
16-    if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0) {
17+    if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0 && strcmp(type, "Page") != 0) {
18         /* skip oddities */
19         return os;
20     }
21@@ -974,6 +975,12 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
22     /* add the content */
23     s = xs_str_cat(s, "</div>\n<div class=\"e-content snac-content\">\n"); /** **/
24 
25+    if (!xs_is_null(v = xs_dict_get(msg, "name"))) {
26+        xs *es1 = encode_html(v);
27+        xs *s1  = xs_fmt("<h3 class=\"snac-entry-title\">%s</h3>\n", es1);
28+        s = xs_str_cat(s, s1);
29+    }
30+
31     /* is it sensitive? */
32     if (!xs_is_null(v = xs_dict_get(msg, "sensitive")) && xs_type(v) == XSTYPE_TRUE) {
33         if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0')