diff options
| author | 2023-04-23 06:05:35 +0200 | |
|---|---|---|
| committer | 2023-04-23 06:05:35 +0200 | |
| commit | 88850bdc46447bb194872a86fd89e762e28a1789 (patch) | |
| tree | a601175ad4a418fedba6c0ff1ce9e51a16ad3e4d | |
| parent | Added mastoapi code for account search. (diff) | |
| download | snac2-88850bdc46447bb194872a86fd89e762e28a1789.tar.gz snac2-88850bdc46447bb194872a86fd89e762e28a1789.tar.xz snac2-88850bdc46447bb194872a86fd89e762e28a1789.zip | |
Attend mastoapi relationships.
Now, the follow/unfollow buttons appear on each account's page.
| -rw-r--r-- | data.c | 12 | ||||
| -rw-r--r-- | mastoapi.c | 39 | ||||
| -rw-r--r-- | snac.h | 10 |
3 files changed, 48 insertions, 13 deletions
| @@ -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 | ||
| 1077 | d_char *_following_fn(snac *snac, char *actor) | 1077 | d_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 | ||
| 1119 | int following_check(snac *snac, char *actor) | 1119 | int 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 | ||
| 1188 | d_char *_muted_fn(snac *snac, char *actor) | 1188 | d_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 | ||
| 1195 | void mute(snac *snac, char *actor) | 1195 | void 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 | ||
| 1210 | void unmute(snac *snac, char *actor) | 1210 | void 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 | ||
| 1221 | int is_muted(snac *snac, char *actor) | 1221 | int 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); |
| @@ -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/")) { |
| @@ -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 | ||
| 115 | int following_add(snac *snac, char *actor, char *msg); | 115 | int following_add(snac *snac, char *actor, char *msg); |
| 116 | int following_del(snac *snac, char *actor); | 116 | int following_del(snac *snac, char *actor); |
| 117 | int following_check(snac *snac, 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); |
| 119 | d_char *following_list(snac *snac); | 119 | d_char *following_list(snac *snac); |
| 120 | 120 | ||
| 121 | void mute(snac *snac, char *actor); | 121 | void mute(snac *snac, const char *actor); |
| 122 | void unmute(snac *snac, char *actor); | 122 | void unmute(snac *snac, const char *actor); |
| 123 | int is_muted(snac *snac, char *actor); | 123 | int is_muted(snac *snac, const char *actor); |
| 124 | 124 | ||
| 125 | void hide(snac *snac, const char *id); | 125 | void hide(snac *snac, const char *id); |
| 126 | int is_hidden(snac *snac, const char *id); | 126 | int is_hidden(snac *snac, const char *id); |