summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-04-23 06:05:35 +0200
committerdefault <nobody@localhost>2023-04-23 06:05:35 +0200
commit88850bdc46447bb194872a86fd89e762e28a1789 (patch)
treea601175ad4a418fedba6c0ff1ce9e51a16ad3e4d /mastoapi.c
parent5b93e9069e64b2f25a6e17de9d7a2e0aee209ac5 (diff)
Attend mastoapi relationships.
Now, the follow/unfollow buttons appear on each account's page.
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 08941cf..86cf334 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -705,12 +705,47 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
if (strcmp(cmd, "/v1/accounts/relationships") == 0) {
/* find if an account is followed, blocked, etc. */
/* the account to get relationships about is in args "id[]" */
- /* dummy by now */
+
if (logged_in) {
- *body = xs_dup("[]");
+ xs *res = xs_list_new();
+ const char *md5 = xs_dict_get(args, "id[]");
+ xs *actor_o = NULL;
+
+ if (!xs_is_null(md5) && valid_status(object_get_by_md5(md5, &actor_o))) {
+ xs *rel = xs_dict_new();
+ xs *t = xs_val_new(XSTYPE_TRUE);
+ xs *f = xs_val_new(XSTYPE_FALSE);
+
+ const char *actor = xs_dict_get(actor_o, "id");
+
+ rel = xs_dict_append(rel, "id", md5);
+ rel = xs_dict_append(rel, "following",
+ following_check(&snac1, actor) ? t : f);
+
+ rel = xs_dict_append(rel, "showing_reblogs", t);
+ rel = xs_dict_append(rel, "notifying", f);
+ rel = xs_dict_append(rel, "followed_by",
+ follower_check(&snac1, actor) ? t : f);
+
+ rel = xs_dict_append(rel, "blocking",
+ is_muted(&snac1, actor) ? t : f);
+
+ rel = xs_dict_append(rel, "muting", f);
+ rel = xs_dict_append(rel, "muting_notifications", f);
+ rel = xs_dict_append(rel, "requested", f);
+ rel = xs_dict_append(rel, "domain_blocking", f);
+ rel = xs_dict_append(rel, "endorsed", f);
+ rel = xs_dict_append(rel, "note", "");
+
+ res = xs_list_append(res, rel);
+ }
+
+ *body = xs_json_dumps_pp(res, 4);
*ctype = "application/json";
status = 200;
}
+ else
+ status = 422;
}
else
if (xs_startswith(cmd, "/v1/accounts/")) {