From 2e982c79e1385b568d407f6e45f2b062761dec12 Mon Sep 17 00:00:00 2001 From: grunfink Date: Sun, 27 Jul 2025 04:08:37 +0200 Subject: mastoapi: Fixed metadata in verify_credentials. --- mastoapi.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 7fb995a..798edec 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1271,8 +1271,31 @@ void credentials_get(char **body, char **ctype, int *status, snac snac) acct = xs_dict_append(acct, "header", header); acct = xs_dict_append(acct, "header_static", header); - const xs_dict *metadata = xs_dict_get(snac.config, "metadata"); - if (xs_type(metadata) == XSTYPE_DICT) { + xs *metadata = NULL; + const xs_dict *md = xs_dict_get(snac.config, "metadata"); + + if (xs_is_dict(md)) + metadata = xs_dup(md); + else + if (xs_is_string(md)) { + metadata = xs_dict_new(); + xs *l = xs_split(md, "\n"); + const char *ll; + + xs_list_foreach(l, ll) { + xs *kv = xs_split_n(ll, "=", 1); + const char *k = xs_list_get(kv, 0); + const char *v = xs_list_get(kv, 1); + + if (k && v) { + xs *kk = xs_strip_i(xs_dup(k)); + xs *vv = xs_strip_i(xs_dup(v)); + metadata = xs_dict_set(metadata, kk, vv); + } + } + } + + if (xs_is_dict(metadata)) { xs *fields = xs_list_new(); const xs_str *k; const xs_str *v; -- cgit v1.2.3 From 1a84c5eb6d7682842d605e67aa3178c27abcc5ca Mon Sep 17 00:00:00 2001 From: grunfink Date: Sun, 27 Jul 2025 04:23:31 +0200 Subject: mastoapi: the 'approve_followers' toggle can also be set from apps. --- mastoapi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 798edec..2331a86 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -3712,7 +3712,7 @@ int mastoapi_patch_handler(const xs_dict *req, const char *q_path, snac snac = {0}; int logged_in = process_auth_token(&snac, req); - if (xs_startswith(cmd, "/v1/accounts/update_credentials")) { + if (xs_startswith(cmd, "/v1/accounts/update_credentials")) { /** **/ /* Update user profile fields */ if (logged_in) { int c = 0; @@ -3768,9 +3768,13 @@ int mastoapi_patch_handler(const xs_dict *req, const char *q_path, snac.config = xs_dict_set(snac.config, "metadata", new_fields); } } + else + if (strcmp(k, "locked") == 0) { + snac.config = xs_dict_set(snac.config, "approve_followers", + xs_stock(strcmp(v, "true") == 0 ? XSTYPE_TRUE : XSTYPE_FALSE)); + } /* we don't have support for the following options, yet - discoverable (0/1) - - locked (0/1) */ } -- cgit v1.2.3 From 53216694cf4af93f153989a714c7878d45378789 Mon Sep 17 00:00:00 2001 From: grunfink Date: Fri, 1 Aug 2025 08:11:59 +0200 Subject: Updated some comments. --- mastoapi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 2331a86..08bb5f7 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2135,7 +2135,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, } else if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/ - /* snac does not schedule notes */ + /* TBD */ *body = xs_dup("[]"); *ctype = "application/json"; status = HTTP_STATUS_OK; @@ -2500,6 +2500,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, } else if (strcmp(cmd, "/v1/preferences") == 0) { /** **/ + /* TBD */ *body = xs_dup("{}"); *ctype = "application/json"; status = HTTP_STATUS_OK; -- cgit v1.2.3 From 7f18d1c7d762d76b28b6828c2f76bb7edf9e1577 Mon Sep 17 00:00:00 2001 From: grunfink Date: Thu, 14 Aug 2025 09:58:21 +0200 Subject: mastoapi: avoid repeating entries. --- mastoapi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 08bb5f7..42f3a47 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1397,6 +1397,9 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn initial_status = index_desc_first(f, md5, 0); } + xs_set entries; + xs_set_init(&entries); + if (initial_status) { do { xs *msg = NULL; @@ -1488,7 +1491,7 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn /* convert the Note into a Mastodon status */ xs *st = mastoapi_status(user, msg); - if (st != NULL) { + if (st != NULL && xs_set_add(&entries, md5) == 1) { if (ascending) out = xs_list_insert(out, 0, st); else @@ -1499,6 +1502,8 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn } while ((cnt < limit) && (*iterator)(f, md5)); } + xs_set_free(&entries); + int more = index_desc_next(f, md5); fclose(f); -- cgit v1.2.3