diff options
| author | 2023-04-23 08:44:26 +0200 | |
|---|---|---|
| committer | 2023-04-23 08:44:26 +0200 | |
| commit | 291f251cedc9277d6cacc0071c9d4c03cd0bf32b (patch) | |
| tree | f137b2f874682eb8e8371a7d5eb07e1ad9d5a5dc | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-291f251cedc9277d6cacc0071c9d4c03cd0bf32b.tar.gz snac2-291f251cedc9277d6cacc0071c9d4c03cd0bf32b.tar.xz snac2-291f251cedc9277d6cacc0071c9d4c03cd0bf32b.zip | |
Added mastoapi follow.
| -rw-r--r-- | activitypub.c | 4 | ||||
| -rw-r--r-- | data.c | 4 | ||||
| -rw-r--r-- | mastoapi.c | 115 | ||||
| -rw-r--r-- | snac.h | 8 |
4 files changed, 96 insertions, 35 deletions
diff --git a/activitypub.c b/activitypub.c index b842118..73225ac 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -209,7 +209,7 @@ int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg, | |||
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | 211 | ||
| 212 | d_char *get_actor_inbox(snac *snac, char *actor) | 212 | d_char *get_actor_inbox(snac *snac, const char *actor) |
| 213 | /* gets an actor's inbox */ | 213 | /* gets an actor's inbox */ |
| 214 | { | 214 | { |
| 215 | xs *data = NULL; | 215 | xs *data = NULL; |
| @@ -659,7 +659,7 @@ d_char *msg_delete(snac *snac, char *id) | |||
| 659 | } | 659 | } |
| 660 | 660 | ||
| 661 | 661 | ||
| 662 | d_char *msg_follow(snac *snac, char *url_or_uid) | 662 | xs_dict *msg_follow(snac *snac, const char *url_or_uid) |
| 663 | /* creates a 'Follow' message */ | 663 | /* creates a 'Follow' message */ |
| 664 | { | 664 | { |
| 665 | xs *actor_o = NULL; | 665 | xs *actor_o = NULL; |
| @@ -1081,7 +1081,7 @@ d_char *_following_fn(snac *snac, const char *actor) | |||
| 1081 | } | 1081 | } |
| 1082 | 1082 | ||
| 1083 | 1083 | ||
| 1084 | int following_add(snac *snac, char *actor, char *msg) | 1084 | int following_add(snac *snac, const char *actor, const xs_dict *msg) |
| 1085 | /* adds to the following list */ | 1085 | /* adds to the following list */ |
| 1086 | { | 1086 | { |
| 1087 | int ret = 201; /* created */ | 1087 | int ret = 201; /* created */ |
| @@ -1770,7 +1770,7 @@ void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries) | |||
| 1770 | } | 1770 | } |
| 1771 | 1771 | ||
| 1772 | 1772 | ||
| 1773 | void enqueue_output_by_actor(snac *snac, xs_dict *msg, xs_str *actor, int retries) | 1773 | void enqueue_output_by_actor(snac *snac, xs_dict *msg, const xs_str *actor, int retries) |
| 1774 | /* enqueues an output message for an actor */ | 1774 | /* enqueues an output message for an actor */ |
| 1775 | { | 1775 | { |
| 1776 | xs *inbox = get_actor_inbox(snac, actor); | 1776 | xs *inbox = get_actor_inbox(snac, actor); |
| @@ -622,6 +622,42 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 622 | } | 622 | } |
| 623 | 623 | ||
| 624 | 624 | ||
| 625 | xs_dict *mastoapi_relationship(snac *snac, const char *md5) | ||
| 626 | { | ||
| 627 | xs_dict *rel = NULL; | ||
| 628 | xs *actor_o = NULL; | ||
| 629 | |||
| 630 | if (valid_status(object_get_by_md5(md5, &actor_o))) { | ||
| 631 | xs *t = xs_val_new(XSTYPE_TRUE); | ||
| 632 | xs *f = xs_val_new(XSTYPE_FALSE); | ||
| 633 | rel = xs_dict_new(); | ||
| 634 | |||
| 635 | const char *actor = xs_dict_get(actor_o, "id"); | ||
| 636 | |||
| 637 | rel = xs_dict_append(rel, "id", md5); | ||
| 638 | rel = xs_dict_append(rel, "following", | ||
| 639 | following_check(snac, actor) ? t : f); | ||
| 640 | |||
| 641 | rel = xs_dict_append(rel, "showing_reblogs", t); | ||
| 642 | rel = xs_dict_append(rel, "notifying", f); | ||
| 643 | rel = xs_dict_append(rel, "followed_by", | ||
| 644 | follower_check(snac, actor) ? t : f); | ||
| 645 | |||
| 646 | rel = xs_dict_append(rel, "blocking", | ||
| 647 | is_muted(snac, actor) ? t : f); | ||
| 648 | |||
| 649 | rel = xs_dict_append(rel, "muting", f); | ||
| 650 | rel = xs_dict_append(rel, "muting_notifications", f); | ||
| 651 | rel = xs_dict_append(rel, "requested", f); | ||
| 652 | rel = xs_dict_append(rel, "domain_blocking", f); | ||
| 653 | rel = xs_dict_append(rel, "endorsed", f); | ||
| 654 | rel = xs_dict_append(rel, "note", ""); | ||
| 655 | } | ||
| 656 | |||
| 657 | return rel; | ||
| 658 | } | ||
| 659 | |||
| 660 | |||
| 625 | int process_auth_token(snac *snac, const xs_dict *req) | 661 | int process_auth_token(snac *snac, const xs_dict *req) |
| 626 | /* processes an authorization token, if there is one */ | 662 | /* processes an authorization token, if there is one */ |
| 627 | { | 663 | { |
| @@ -709,35 +745,12 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 709 | if (logged_in) { | 745 | if (logged_in) { |
| 710 | xs *res = xs_list_new(); | 746 | xs *res = xs_list_new(); |
| 711 | const char *md5 = xs_dict_get(args, "id[]"); | 747 | const char *md5 = xs_dict_get(args, "id[]"); |
| 712 | xs *actor_o = NULL; | ||
| 713 | |||
| 714 | if (!xs_is_null(md5) && valid_status(object_get_by_md5(md5, &actor_o))) { | ||
| 715 | xs *rel = xs_dict_new(); | ||
| 716 | xs *t = xs_val_new(XSTYPE_TRUE); | ||
| 717 | xs *f = xs_val_new(XSTYPE_FALSE); | ||
| 718 | |||
| 719 | const char *actor = xs_dict_get(actor_o, "id"); | ||
| 720 | |||
| 721 | rel = xs_dict_append(rel, "id", md5); | ||
| 722 | rel = xs_dict_append(rel, "following", | ||
| 723 | following_check(&snac1, actor) ? t : f); | ||
| 724 | |||
| 725 | rel = xs_dict_append(rel, "showing_reblogs", t); | ||
| 726 | rel = xs_dict_append(rel, "notifying", f); | ||
| 727 | rel = xs_dict_append(rel, "followed_by", | ||
| 728 | follower_check(&snac1, actor) ? t : f); | ||
| 729 | 748 | ||
| 730 | rel = xs_dict_append(rel, "blocking", | 749 | if (!xs_is_null(md5)) { |
| 731 | is_muted(&snac1, actor) ? t : f); | 750 | xs *rel = mastoapi_relationship(&snac1, md5); |
| 732 | 751 | ||
| 733 | rel = xs_dict_append(rel, "muting", f); | 752 | if (rel != NULL) |
| 734 | rel = xs_dict_append(rel, "muting_notifications", f); | 753 | res = xs_list_append(res, rel); |
| 735 | rel = xs_dict_append(rel, "requested", f); | ||
| 736 | rel = xs_dict_append(rel, "domain_blocking", f); | ||
| 737 | rel = xs_dict_append(rel, "endorsed", f); | ||
| 738 | rel = xs_dict_append(rel, "note", ""); | ||
| 739 | |||
| 740 | res = xs_list_append(res, rel); | ||
| 741 | } | 754 | } |
| 742 | 755 | ||
| 743 | *body = xs_json_dumps_pp(res, 4); | 756 | *body = xs_json_dumps_pp(res, 4); |
| @@ -1595,6 +1608,54 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 1595 | else | 1608 | else |
| 1596 | status = 401; | 1609 | status = 401; |
| 1597 | } | 1610 | } |
| 1611 | else | ||
| 1612 | if (xs_startswith(cmd, "/v1/accounts")) { | ||
| 1613 | if (logged_in) { | ||
| 1614 | /* account-related information */ | ||
| 1615 | xs *l = xs_split(cmd, "/"); | ||
| 1616 | const char *md5 = xs_list_get(l, 3); | ||
| 1617 | const char *opt = xs_list_get(l, 4); | ||
| 1618 | xs *rsp = NULL; | ||
| 1619 | |||
| 1620 | if (!xs_is_null(md5) && *md5) { | ||
| 1621 | xs *actor_o = NULL; | ||
| 1622 | |||
| 1623 | if (xs_is_null(opt)) { | ||
| 1624 | /* ? */ | ||
| 1625 | } | ||
| 1626 | else | ||
| 1627 | if (strcmp(opt, "follow") == 0) { | ||
| 1628 | if (valid_status(object_get_by_md5(md5, &actor_o))) { | ||
| 1629 | const char *actor = xs_dict_get(actor_o, "id"); | ||
| 1630 | |||
| 1631 | xs *msg = msg_follow(&snac, actor); | ||
| 1632 | |||
| 1633 | if (msg != NULL) { | ||
| 1634 | /* reload the actor from the message, in may be different */ | ||
| 1635 | actor = xs_dict_get(msg, "object"); | ||
| 1636 | |||
| 1637 | following_add(&snac, actor, msg); | ||
| 1638 | |||
| 1639 | enqueue_output_by_actor(&snac, msg, actor, 0); | ||
| 1640 | |||
| 1641 | rsp = mastoapi_relationship(&snac, md5); | ||
| 1642 | } | ||
| 1643 | } | ||
| 1644 | } | ||
| 1645 | else | ||
| 1646 | if (strcmp(opt, "unfollow") == 0) { | ||
| 1647 | } | ||
| 1648 | } | ||
| 1649 | |||
| 1650 | if (rsp != NULL) { | ||
| 1651 | *body = xs_json_dumps_pp(rsp, 4); | ||
| 1652 | *ctype = "application/json"; | ||
| 1653 | status = 200; | ||
| 1654 | } | ||
| 1655 | } | ||
| 1656 | else | ||
| 1657 | status = 401; | ||
| 1658 | } | ||
| 1598 | 1659 | ||
| 1599 | /* user cleanup */ | 1660 | /* user cleanup */ |
| 1600 | if (logged_in) | 1661 | if (logged_in) |
| @@ -112,7 +112,7 @@ xs_list *timeline_top_level(snac *snac, xs_list *list); | |||
| 112 | 112 | ||
| 113 | d_char *local_list(snac *snac, int max); | 113 | d_char *local_list(snac *snac, int max); |
| 114 | 114 | ||
| 115 | int following_add(snac *snac, char *actor, char *msg); | 115 | int following_add(snac *snac, const char *actor, const xs_dict *msg); |
| 116 | int following_del(snac *snac, char *actor); | 116 | int following_del(snac *snac, char *actor); |
| 117 | int following_check(snac *snac, const char *actor); | 117 | int following_check(snac *snac, const char *actor); |
| 118 | int following_get(snac *snac, char *actor, d_char **data); | 118 | int following_get(snac *snac, char *actor, d_char **data); |
| @@ -156,7 +156,7 @@ void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries); | |||
| 156 | void enqueue_output_raw(const char *keyid, const char *seckey, | 156 | void enqueue_output_raw(const char *keyid, const char *seckey, |
| 157 | xs_dict *msg, xs_str *inbox, int retries); | 157 | xs_dict *msg, xs_str *inbox, int retries); |
| 158 | void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries); | 158 | void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries); |
| 159 | void enqueue_output_by_actor(snac *snac, xs_dict *msg, xs_str *actor, int retries); | 159 | void enqueue_output_by_actor(snac *snac, xs_dict *msg, const xs_str *actor, int retries); |
| 160 | void enqueue_email(xs_str *msg, int retries); | 160 | void enqueue_email(xs_str *msg, int retries); |
| 161 | void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id); | 161 | void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id); |
| 162 | void enqueue_message(snac *snac, char *msg); | 162 | void enqueue_message(snac *snac, char *msg); |
| @@ -191,7 +191,7 @@ const char *default_avatar_base64(void); | |||
| 191 | 191 | ||
| 192 | d_char *msg_admiration(snac *snac, char *object, char *type); | 192 | d_char *msg_admiration(snac *snac, char *object, char *type); |
| 193 | d_char *msg_create(snac *snac, char *object); | 193 | d_char *msg_create(snac *snac, char *object); |
| 194 | d_char *msg_follow(snac *snac, char *actor); | 194 | xs_dict *msg_follow(snac *snac, const char *actor); |
| 195 | 195 | ||
| 196 | xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, | 196 | xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, |
| 197 | xs_str *in_reply_to, xs_list *attach, int priv); | 197 | xs_str *in_reply_to, xs_list *attach, int priv); |
| @@ -208,7 +208,7 @@ int send_to_inbox_raw(const char *keyid, const char *seckey, | |||
| 208 | xs_val **payload, int *p_size, int timeout); | 208 | xs_val **payload, int *p_size, int timeout); |
| 209 | int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg, | 209 | int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg, |
| 210 | xs_val **payload, int *p_size, int timeout); | 210 | xs_val **payload, int *p_size, int timeout); |
| 211 | d_char *get_actor_inbox(snac *snac, char *actor); | 211 | d_char *get_actor_inbox(snac *snac, const char *actor); |
| 212 | int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout); | 212 | int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout); |
| 213 | int is_msg_public(snac *snac, const xs_dict *msg); | 213 | int is_msg_public(snac *snac, const xs_dict *msg); |
| 214 | int is_msg_for_me(snac *snac, const xs_dict *msg); | 214 | int is_msg_for_me(snac *snac, const xs_dict *msg); |