aboutsummaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authorgreen <dandelions@disroot.org>2025-04-24 15:49:55 +0200
committergreen <dandelions@disroot.org>2025-04-26 02:37:13 +0200
commitec21e1596ab285813d5774224dfed77cbb30d23e (patch)
tree811b98992389a4110614d491ec46840bbfe33bc5 /mastoapi.c
parent53e662c25c3c403f92d042277dfcbd29253b9f68 (diff)
mastoapi: support lists for users
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c55
1 files changed, 40 insertions, 15 deletions
diff --git a/mastoapi.c b/mastoapi.c
index d93afc5..bea835c 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -1500,6 +1500,37 @@ xs_str *timeline_link_header(const char *endpoint, xs_list *timeline)
}
+xs_list *mastoapi_account_lists(snac *user, const char *uid)
+/* returns the list of list an user is in */
+{
+ xs_list *out = xs_list_new();
+ xs *actor_md5 = uid ? xs_md5_hex(uid, strlen(uid)) : NULL;
+ xs *lol = list_maint(user, NULL, 0);
+
+ const xs_list *li;
+ xs_list_foreach(lol, li) {
+ const char *list_id = xs_list_get(li, 0);
+ const char *list_title = xs_list_get(li, 1);
+ if (uid) {
+ xs *users = list_content(user, list_id, NULL, 0);
+ if (xs_list_in(users, actor_md5) == -1)
+ continue;
+ }
+
+ xs *d = xs_dict_new();
+
+ d = xs_dict_append(d, "id", list_id);
+ d = xs_dict_append(d, "title", list_title);
+ d = xs_dict_append(d, "replies_policy", "list");
+ d = xs_dict_append(d, "exclusive", xs_stock(XSTYPE_FALSE));
+
+ out = xs_list_append(out, d);
+ }
+
+ return out;
+}
+
+
int mastoapi_get_handler(const xs_dict *req, const char *q_path,
char **body, int *b_size, char **ctype, xs_str **link)
{
@@ -1723,6 +1754,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
if (strcmp(opt, "followers") == 0) {
out = xs_list_new();
}
+ else
+ if (strcmp(opt, "lists") == 0) {
+ out = mastoapi_account_lists(&snac1, uid);
+ }
user_free(&snac2);
}
@@ -1744,6 +1779,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
/* implement empty response so apps like Tokodon don't show an error */
out = xs_list_new();
}
+ else
+ if (strcmp(opt, "lists") == 0) {
+ out = mastoapi_account_lists(&snac1, uid);
+ }
}
}
@@ -1975,21 +2014,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
else
if (strcmp(cmd, "/v1/lists") == 0) { /** list of lists **/
if (logged_in) {
- xs *lol = list_maint(&snac1, NULL, 0);
- xs *l = xs_list_new();
- int c = 0;
- const xs_list *li;
-
- while (xs_list_next(lol, &li, &c)) {
- xs *d = xs_dict_new();
-
- d = xs_dict_append(d, "id", xs_list_get(li, 0));
- d = xs_dict_append(d, "title", xs_list_get(li, 1));
- d = xs_dict_append(d, "replies_policy", "list");
- d = xs_dict_append(d, "exclusive", xs_stock(XSTYPE_FALSE));
-
- l = xs_list_append(l, d);
- }
+ xs *l = mastoapi_account_lists(&snac1, NULL);
*body = xs_json_dumps(l, 4);
*ctype = "application/json";