summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c82
1 files changed, 67 insertions, 15 deletions
diff --git a/activitypub.c b/activitypub.c
index 34cc32f..ea4d8ea 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -10,6 +10,7 @@
10#include "xs_time.h" 10#include "xs_time.h"
11#include "xs_set.h" 11#include "xs_set.h"
12#include "xs_match.h" 12#include "xs_match.h"
13#include "xs_unicode.h"
13 14
14#include "snac.h" 15#include "snac.h"
15 16
@@ -178,6 +179,11 @@ const char *get_atto(const xs_dict *msg)
178 } 179 }
179 } 180 }
180 } 181 }
182 else
183 if (xs_type(actor) == XSTYPE_DICT) {
184 /* bandwagon.fm returns this */
185 actor = xs_dict_get(actor, "id");
186 }
181 187
182 return actor; 188 return actor;
183} 189}
@@ -701,6 +707,32 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg)
701 } 707 }
702 } 708 }
703 709
710 /* does this message contain a tag we are following? */
711 const xs_list *fw_tags = xs_dict_get(snac->config, "followed_hashtags");
712 if (pub_msg && xs_type(fw_tags) == XSTYPE_LIST) {
713 const xs_list *tags_in_msg = xs_dict_get(msg, "tag");
714 if (xs_type(tags_in_msg) == XSTYPE_LIST) {
715 const xs_dict *te;
716
717 /* iterate the tags in the message */
718 xs_list_foreach(tags_in_msg, te) {
719 if (xs_type(te) == XSTYPE_DICT) {
720 const char *type = xs_dict_get(te, "type");
721 const char *name = xs_dict_get(te, "name");
722
723 if (xs_type(type) == XSTYPE_STRING && xs_type(name) == XSTYPE_STRING) {
724 if (strcmp(type, "Hashtag") == 0) {
725 xs *lc_name = xs_utf8_to_lower(name);
726
727 if (xs_list_in(fw_tags, lc_name) != -1)
728 return 7;
729 }
730 }
731 }
732 }
733 }
734 }
735
704 return 0; 736 return 0;
705} 737}
706 738
@@ -1390,7 +1422,8 @@ xs_dict *msg_follow(snac *snac, const char *q)
1390 1422
1391 1423
1392xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, 1424xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
1393 const xs_str *in_reply_to, const xs_list *attach, int priv) 1425 const xs_str *in_reply_to, const xs_list *attach,
1426 int priv, const char *lang_str)
1394/* creates a 'Note' message */ 1427/* creates a 'Note' message */
1395{ 1428{
1396 xs *ntid = tid(0); 1429 xs *ntid = tid(0);
@@ -1552,6 +1585,20 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
1552 if (xs_list_len(atls)) 1585 if (xs_list_len(atls))
1553 msg = xs_dict_append(msg, "attachment", atls); 1586 msg = xs_dict_append(msg, "attachment", atls);
1554 1587
1588 /* set language content map */
1589 if (xs_type(lang_str) == XSTYPE_STRING) {
1590 /* split at the first _ */
1591 xs *l0 = xs_split(lang_str, "_");
1592 const char *lang = xs_list_get(l0, 0);
1593
1594 if (xs_type(lang) == XSTYPE_STRING && strlen(lang) == 2) {
1595 /* a valid ISO language id */
1596 xs *cmap = xs_dict_new();
1597 cmap = xs_dict_set(cmap, lang, xs_dict_get(msg, "content"));
1598 msg = xs_dict_set(msg, "contentMap", cmap);
1599 }
1600 }
1601
1555 return msg; 1602 return msg;
1556} 1603}
1557 1604
@@ -1593,7 +1640,7 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
1593 const xs_list *opts, int multiple, int end_secs) 1640 const xs_list *opts, int multiple, int end_secs)
1594/* creates a Question message */ 1641/* creates a Question message */
1595{ 1642{
1596 xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0); 1643 xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0, NULL);
1597 int max = 8; 1644 int max = 8;
1598 xs_set seen; 1645 xs_set seen;
1599 1646
@@ -2386,22 +2433,28 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
2386 xs *rcpts = recipient_list(snac, msg, 1); 2433 xs *rcpts = recipient_list(snac, msg, 1);
2387 xs_set inboxes; 2434 xs_set inboxes;
2388 const xs_str *actor; 2435 const xs_str *actor;
2389 int c;
2390 2436
2391 xs_set_init(&inboxes); 2437 xs_set_init(&inboxes);
2392 2438
2439 /* add this shared inbox first */
2440 xs *this_shared_inbox = xs_fmt("%s/shared-inbox", srv_baseurl);
2441 xs_set_add(&inboxes, this_shared_inbox);
2442 enqueue_output(snac, msg, this_shared_inbox, 0, 0);
2443
2393 /* iterate the recipients */ 2444 /* iterate the recipients */
2394 c = 0; 2445 xs_list_foreach(rcpts, actor) {
2395 while (xs_list_next(rcpts, &actor, &c)) { 2446 /* local users were served by this_shared_inbox */
2396 xs *inbox = get_actor_inbox(actor, 1); 2447 if (!xs_startswith(actor, srv_baseurl)) {
2397 2448 xs *inbox = get_actor_inbox(actor, 1);
2398 if (inbox != NULL) { 2449
2399 /* add to the set and, if it's not there, send message */ 2450 if (inbox != NULL) {
2400 if (xs_set_add(&inboxes, inbox) == 1) 2451 /* add to the set and, if it's not there, send message */
2401 enqueue_output(snac, msg, inbox, 0, 0); 2452 if (xs_set_add(&inboxes, inbox) == 1)
2453 enqueue_output(snac, msg, inbox, 0, 0);
2454 }
2455 else
2456 snac_log(snac, xs_fmt("cannot find inbox for %s", actor));
2402 } 2457 }
2403 else
2404 snac_log(snac, xs_fmt("cannot find inbox for %s", actor));
2405 } 2458 }
2406 2459
2407 /* if it's a public note or question, send to the collected inboxes */ 2460 /* if it's a public note or question, send to the collected inboxes */
@@ -2410,8 +2463,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
2410 xs *shibx = inbox_list(); 2463 xs *shibx = inbox_list();
2411 const xs_str *inbox; 2464 const xs_str *inbox;
2412 2465
2413 c = 0; 2466 xs_list_foreach(shibx, inbox) {
2414 while (xs_list_next(shibx, &inbox, &c)) {
2415 if (xs_set_add(&inboxes, inbox) == 1) 2467 if (xs_set_add(&inboxes, inbox) == 1)
2416 enqueue_output(snac, msg, inbox, 0, 0); 2468 enqueue_output(snac, msg, inbox, 0, 0);
2417 } 2469 }