summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/activitypub.c b/activitypub.c
index 2306eb5..33ddd0f 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -156,6 +156,34 @@ int actor_request(snac *user, const char *actor, xs_dict **data)
156} 156}
157 157
158 158
159char *get_atto(const xs_dict *msg)
160/* gets the attributedTo field (an actor) */
161{
162 char *actor = xs_dict_get(msg, "attributedTo");
163
164 /* if the actor is a list of objects (like on Peertube videos), pick the Person */
165 if (xs_type(actor) == XSTYPE_LIST) {
166 xs_list *p = actor;
167 xs_dict *v;
168 actor = NULL;
169
170 while (actor == NULL && xs_list_iter(&p, &v)) {
171 if (xs_type(v) == XSTYPE_DICT) {
172 char *type = xs_dict_get(v, "type");
173 if (xs_type(type) == XSTYPE_STRING && strcmp(type, "Person") == 0) {
174 actor = xs_dict_get(v, "id");
175
176 if (xs_type(actor) != XSTYPE_STRING)
177 actor = NULL;
178 }
179 }
180 }
181 }
182
183 return actor;
184}
185
186
159int timeline_request(snac *snac, char **id, xs_str **wrk, int level) 187int timeline_request(snac *snac, char **id, xs_str **wrk, int level)
160/* ensures that an entry and its ancestors are in the timeline */ 188/* ensures that an entry and its ancestors are in the timeline */
161{ 189{
@@ -203,7 +231,7 @@ int timeline_request(snac *snac, char **id, xs_str **wrk, int level)
203 } 231 }
204 232
205 if (xs_match(type, "Note|Page|Article")) { 233 if (xs_match(type, "Note|Page|Article")) {
206 const char *actor = xs_dict_get(object, "attributedTo"); 234 const char *actor = get_atto(object);
207 235
208 /* request (and drop) the actor for this entry */ 236 /* request (and drop) the actor for this entry */
209 if (!xs_is_null(actor)) 237 if (!xs_is_null(actor))
@@ -531,7 +559,7 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg)
531 } 559 }
532 560
533 /* accept if it's by someone we follow */ 561 /* accept if it's by someone we follow */
534 char *atto = xs_dict_get(msg, "attributedTo"); 562 char *atto = get_atto(msg);
535 563
536 if (pub_msg && !xs_is_null(atto) && following_check(snac, atto)) 564 if (pub_msg && !xs_is_null(atto) && following_check(snac, atto))
537 return 3; 565 return 3;
@@ -543,7 +571,7 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg)
543 571
544 /* try to get the replied message */ 572 /* try to get the replied message */
545 if (valid_status(object_get(irt, &r_msg))) { 573 if (valid_status(object_get(irt, &r_msg))) {
546 atto = xs_dict_get(r_msg, "attributedTo"); 574 atto = get_atto(r_msg);
547 575
548 /* accept if the replied message is from someone we follow */ 576 /* accept if the replied message is from someone we follow */
549 if (pub_msg && !xs_is_null(atto) && following_check(snac, atto)) 577 if (pub_msg && !xs_is_null(atto) && following_check(snac, atto))
@@ -958,7 +986,7 @@ xs_dict *msg_admiration(snac *snac, char *object, char *type)
958 if (is_msg_public(a_msg)) 986 if (is_msg_public(a_msg))
959 rcpts = xs_list_append(rcpts, public_address); 987 rcpts = xs_list_append(rcpts, public_address);
960 988
961 rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo")); 989 rcpts = xs_list_append(rcpts, get_atto(a_msg));
962 990
963 msg = xs_dict_append(msg, "to", rcpts); 991 msg = xs_dict_append(msg, "to", rcpts);
964 } 992 }
@@ -1085,7 +1113,7 @@ xs_dict *msg_create(snac *snac, const xs_dict *object)
1085 xs_dict *msg = msg_base(snac, "Create", "@wrapper", snac->actor, NULL, object); 1113 xs_dict *msg = msg_base(snac, "Create", "@wrapper", snac->actor, NULL, object);
1086 xs_val *v; 1114 xs_val *v;
1087 1115
1088 if ((v = xs_dict_get(object, "attributedTo"))) 1116 if ((v = get_atto(object)))
1089 msg = xs_dict_append(msg, "attributedTo", v); 1117 msg = xs_dict_append(msg, "attributedTo", v);
1090 1118
1091 if ((v = xs_dict_get(object, "cc"))) 1119 if ((v = xs_dict_get(object, "cc")))
@@ -1213,7 +1241,7 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
1213 /* add this author as recipient */ 1241 /* add this author as recipient */
1214 char *a, *v; 1242 char *a, *v;
1215 1243
1216 if ((a = xs_dict_get(p_msg, "attributedTo")) && xs_list_in(to, a) == -1) 1244 if ((a = get_atto(p_msg)) && xs_list_in(to, a) == -1)
1217 to = xs_list_append(to, a); 1245 to = xs_list_append(to, a);
1218 1246
1219 /* add this author to the tag list as a mention */ 1247 /* add this author to the tag list as a mention */
@@ -1447,7 +1475,7 @@ int update_question(snac *user, const char *id)
1447 continue; 1475 continue;
1448 1476
1449 const char *name = xs_dict_get(obj, "name"); 1477 const char *name = xs_dict_get(obj, "name");
1450 const char *atto = xs_dict_get(obj, "attributedTo"); 1478 const char *atto = get_atto(obj);
1451 1479
1452 if (name && atto) { 1480 if (name && atto) {
1453 /* get the current count */ 1481 /* get the current count */
@@ -1799,7 +1827,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
1799 timeline_request(snac, &object, &wrk, 0); 1827 timeline_request(snac, &object, &wrk, 0);
1800 1828
1801 if (valid_status(object_get(object, &a_msg))) { 1829 if (valid_status(object_get(object, &a_msg))) {
1802 const char *who = xs_dict_get(a_msg, "attributedTo"); 1830 const char *who = get_atto(a_msg);
1803 1831
1804 if (who && !is_muted(snac, who)) { 1832 if (who && !is_muted(snac, who)) {
1805 /* bring the actor */ 1833 /* bring the actor */