diff options
| author | 2023-07-13 21:01:15 +0200 | |
|---|---|---|
| committer | 2023-07-13 21:01:15 +0200 | |
| commit | 2caeb550b94c8b08d9eebb62f6f05e14df15e666 (patch) | |
| tree | b4d9bbd0cced4271caecce940800a5303edd7d84 | |
| parent | Added a maximum level of recursion to timeline_request(). (diff) | |
| download | snac2-2caeb550b94c8b08d9eebb62f6f05e14df15e666.tar.gz snac2-2caeb550b94c8b08d9eebb62f6f05e14df15e666.tar.xz snac2-2caeb550b94c8b08d9eebb62f6f05e14df15e666.zip | |
Added support for the 'Page' ActivityPub object.
So that you can follow and interact with lemmy channels.
| -rw-r--r-- | activitypub.c | 28 | ||||
| -rw-r--r-- | html.c | 11 |
2 files changed, 30 insertions, 9 deletions
diff --git a/activitypub.c b/activitypub.c index 4843067..b3c7367 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -152,18 +152,19 @@ int timeline_request(snac *snac, char **id, xs_str **wrk, int level) | |||
| 152 | int status = 0; | 152 | int status = 0; |
| 153 | 153 | ||
| 154 | if (!xs_is_null(*id)) { | 154 | if (!xs_is_null(*id)) { |
| 155 | xs *object = NULL; | 155 | xs *msg = NULL; |
| 156 | 156 | ||
| 157 | /* is the object already there? */ | 157 | /* is the object already there? */ |
| 158 | if (!valid_status(object_get(*id, &object))) { | 158 | if (!valid_status(object_get(*id, &msg))) { |
| 159 | /* no; download it */ | 159 | /* no; download it */ |
| 160 | status = activitypub_request(snac, *id, &object); | 160 | status = activitypub_request(snac, *id, &msg); |
| 161 | 161 | ||
| 162 | if (valid_status(status)) { | 162 | if (valid_status(status)) { |
| 163 | char *type = xs_dict_get(object, "type"); | 163 | xs_dict *object = msg; |
| 164 | const char *type = xs_dict_get(object, "type"); | ||
| 164 | 165 | ||
| 165 | /* get the id again from the object, as it may be different */ | 166 | /* get the id again from the object, as it may be different */ |
| 166 | char *nid = xs_dict_get(object, "id"); | 167 | const char *nid = xs_dict_get(object, "id"); |
| 167 | 168 | ||
| 168 | if (wrk && strcmp(nid, *id) != 0) { | 169 | if (wrk && strcmp(nid, *id) != 0) { |
| 169 | snac_debug(snac, 1, | 170 | snac_debug(snac, 1, |
| @@ -173,8 +174,21 @@ int timeline_request(snac *snac, char **id, xs_str **wrk, int level) | |||
| 173 | *id = *wrk; | 174 | *id = *wrk; |
| 174 | } | 175 | } |
| 175 | 176 | ||
| 176 | if (!xs_is_null(type) && strcmp(type, "Note") == 0) { | 177 | if (xs_is_null(type)) |
| 177 | char *actor = xs_dict_get(object, "attributedTo"); | 178 | type = "(null)"; |
| 179 | |||
| 180 | srv_debug(0, xs_fmt("timeline_request type %s '%s'", *id, type)); | ||
| 181 | |||
| 182 | if (strcmp(type, "Create") == 0) { | ||
| 183 | /* some software like lemmy nest Announce + Create + Note */ | ||
| 184 | if (!xs_is_null(object = xs_dict_get(object, "object"))) | ||
| 185 | type = xs_dict_get(object, "type"); | ||
| 186 | else | ||
| 187 | type = "(null)"; | ||
| 188 | } | ||
| 189 | |||
| 190 | if (strcmp(type, "Note") == 0 || strcmp(type, "Page") == 0) { | ||
| 191 | const char *actor = xs_dict_get(object, "attributedTo"); | ||
| 178 | 192 | ||
| 179 | /* request (and drop) the actor for this entry */ | 193 | /* request (and drop) the actor for this entry */ |
| 180 | if (!xs_is_null(actor)) | 194 | if (!xs_is_null(actor)) |
| @@ -189,8 +189,9 @@ xs_str *html_msg_icon(snac *snac, xs_str *os, const xs_dict *msg) | |||
| 189 | char *udate = NULL; | 189 | char *udate = NULL; |
| 190 | char *url = NULL; | 190 | char *url = NULL; |
| 191 | int priv = 0; | 191 | int priv = 0; |
| 192 | const char *type = xs_dict_get(msg, "type"); | ||
| 192 | 193 | ||
| 193 | if (strcmp(xs_dict_get(msg, "type"), "Note") == 0) | 194 | if (strcmp(type, "Note") == 0 || strcmp(type, "Question") == 0 || strcmp(type, "Page") == 0) |
| 194 | url = xs_dict_get(msg, "id"); | 195 | url = xs_dict_get(msg, "id"); |
| 195 | 196 | ||
| 196 | priv = !is_msg_public(snac, msg); | 197 | priv = !is_msg_public(snac, msg); |
| @@ -856,7 +857,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, | |||
| 856 | return xs_str_cat(os, s); | 857 | return xs_str_cat(os, s); |
| 857 | } | 858 | } |
| 858 | else | 859 | else |
| 859 | if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0) { | 860 | if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0 && strcmp(type, "Page") != 0) { |
| 860 | /* skip oddities */ | 861 | /* skip oddities */ |
| 861 | return os; | 862 | return os; |
| 862 | } | 863 | } |
| @@ -974,6 +975,12 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, | |||
| 974 | /* add the content */ | 975 | /* add the content */ |
| 975 | s = xs_str_cat(s, "</div>\n<div class=\"e-content snac-content\">\n"); /** **/ | 976 | s = xs_str_cat(s, "</div>\n<div class=\"e-content snac-content\">\n"); /** **/ |
| 976 | 977 | ||
| 978 | if (!xs_is_null(v = xs_dict_get(msg, "name"))) { | ||
| 979 | xs *es1 = encode_html(v); | ||
| 980 | xs *s1 = xs_fmt("<h3 class=\"snac-entry-title\">%s</h3>\n", es1); | ||
| 981 | s = xs_str_cat(s, s1); | ||
| 982 | } | ||
| 983 | |||
| 977 | /* is it sensitive? */ | 984 | /* is it sensitive? */ |
| 978 | if (!xs_is_null(v = xs_dict_get(msg, "sensitive")) && xs_type(v) == XSTYPE_TRUE) { | 985 | if (!xs_is_null(v = xs_dict_get(msg, "sensitive")) && xs_type(v) == XSTYPE_TRUE) { |
| 979 | if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0') | 986 | if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0') |