summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c115
1 files changed, 88 insertions, 27 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 86cf334..894996d 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -622,6 +622,42 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
622} 622}
623 623
624 624
625xs_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
625int process_auth_token(snac *snac, const xs_dict *req) 661int 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)