summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c12
-rw-r--r--mastoapi.c39
-rw-r--r--snac.h10
3 files changed, 48 insertions, 13 deletions
diff --git a/data.c b/data.c
index 223ad45..f9c581f 100644
--- a/data.c
+++ b/data.c
@@ -1074,7 +1074,7 @@ d_char *timeline_list(snac *snac, const char *idx_name, int skip, int show)
1074 with a link to a cached author, because we need the Follow object 1074 with a link to a cached author, because we need the Follow object
1075 in case we need to unfollow (Undo + original Follow) */ 1075 in case we need to unfollow (Undo + original Follow) */
1076 1076
1077d_char *_following_fn(snac *snac, char *actor) 1077d_char *_following_fn(snac *snac, const char *actor)
1078{ 1078{
1079 xs *md5 = xs_md5_hex(actor, strlen(actor)); 1079 xs *md5 = xs_md5_hex(actor, strlen(actor));
1080 return xs_fmt("%s/following/%s.json", snac->basedir, md5); 1080 return xs_fmt("%s/following/%s.json", snac->basedir, md5);
@@ -1116,7 +1116,7 @@ int following_del(snac *snac, char *actor)
1116} 1116}
1117 1117
1118 1118
1119int following_check(snac *snac, char *actor) 1119int following_check(snac *snac, const char *actor)
1120/* checks if we are following this actor */ 1120/* checks if we are following this actor */
1121{ 1121{
1122 xs *fn = _following_fn(snac, actor); 1122 xs *fn = _following_fn(snac, actor);
@@ -1185,14 +1185,14 @@ d_char *following_list(snac *snac)
1185} 1185}
1186 1186
1187 1187
1188d_char *_muted_fn(snac *snac, char *actor) 1188d_char *_muted_fn(snac *snac, const char *actor)
1189{ 1189{
1190 xs *md5 = xs_md5_hex(actor, strlen(actor)); 1190 xs *md5 = xs_md5_hex(actor, strlen(actor));
1191 return xs_fmt("%s/muted/%s", snac->basedir, md5); 1191 return xs_fmt("%s/muted/%s", snac->basedir, md5);
1192} 1192}
1193 1193
1194 1194
1195void mute(snac *snac, char *actor) 1195void mute(snac *snac, const char *actor)
1196/* mutes a moron */ 1196/* mutes a moron */
1197{ 1197{
1198 xs *fn = _muted_fn(snac, actor); 1198 xs *fn = _muted_fn(snac, actor);
@@ -1207,7 +1207,7 @@ void mute(snac *snac, char *actor)
1207} 1207}
1208 1208
1209 1209
1210void unmute(snac *snac, char *actor) 1210void unmute(snac *snac, const char *actor)
1211/* actor is no longer a moron */ 1211/* actor is no longer a moron */
1212{ 1212{
1213 xs *fn = _muted_fn(snac, actor); 1213 xs *fn = _muted_fn(snac, actor);
@@ -1218,7 +1218,7 @@ void unmute(snac *snac, char *actor)
1218} 1218}
1219 1219
1220 1220
1221int is_muted(snac *snac, char *actor) 1221int is_muted(snac *snac, const char *actor)
1222/* check if someone is muted */ 1222/* check if someone is muted */
1223{ 1223{
1224 xs *fn = _muted_fn(snac, actor); 1224 xs *fn = _muted_fn(snac, actor);
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,
705 if (strcmp(cmd, "/v1/accounts/relationships") == 0) { 705 if (strcmp(cmd, "/v1/accounts/relationships") == 0) {
706 /* find if an account is followed, blocked, etc. */ 706 /* find if an account is followed, blocked, etc. */
707 /* the account to get relationships about is in args "id[]" */ 707 /* the account to get relationships about is in args "id[]" */
708 /* dummy by now */ 708
709 if (logged_in) { 709 if (logged_in) {
710 *body = xs_dup("[]"); 710 xs *res = xs_list_new();
711 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
730 rel = xs_dict_append(rel, "blocking",
731 is_muted(&snac1, actor) ? t : f);
732
733 rel = xs_dict_append(rel, "muting", f);
734 rel = xs_dict_append(rel, "muting_notifications", f);
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 }
742
743 *body = xs_json_dumps_pp(res, 4);
711 *ctype = "application/json"; 744 *ctype = "application/json";
712 status = 200; 745 status = 200;
713 } 746 }
747 else
748 status = 422;
714 } 749 }
715 else 750 else
716 if (xs_startswith(cmd, "/v1/accounts/")) { 751 if (xs_startswith(cmd, "/v1/accounts/")) {
diff --git a/snac.h b/snac.h
index 5cb639d..e912756 100644
--- a/snac.h
+++ b/snac.h
@@ -1,7 +1,7 @@
1/* snac - A simple, minimalistic ActivityPub instance */ 1/* snac - A simple, minimalistic ActivityPub instance */
2/* copyright (c) 2022 - 2023 grunfink / MIT license */ 2/* copyright (c) 2022 - 2023 grunfink / MIT license */
3 3
4#define VERSION "2.28" 4#define VERSION "2.29-dev"
5 5
6#define USER_AGENT "snac/" VERSION 6#define USER_AGENT "snac/" VERSION
7 7
@@ -114,13 +114,13 @@ d_char *local_list(snac *snac, int max);
114 114
115int following_add(snac *snac, char *actor, char *msg); 115int following_add(snac *snac, char *actor, char *msg);
116int following_del(snac *snac, char *actor); 116int following_del(snac *snac, char *actor);
117int following_check(snac *snac, char *actor); 117int following_check(snac *snac, const char *actor);
118int following_get(snac *snac, char *actor, d_char **data); 118int following_get(snac *snac, char *actor, d_char **data);
119d_char *following_list(snac *snac); 119d_char *following_list(snac *snac);
120 120
121void mute(snac *snac, char *actor); 121void mute(snac *snac, const char *actor);
122void unmute(snac *snac, char *actor); 122void unmute(snac *snac, const char *actor);
123int is_muted(snac *snac, char *actor); 123int is_muted(snac *snac, const char *actor);
124 124
125void hide(snac *snac, const char *id); 125void hide(snac *snac, const char *id);
126int is_hidden(snac *snac, const char *id); 126int is_hidden(snac *snac, const char *id);