diff options
| author | 2025-08-19 21:38:44 +0200 | |
|---|---|---|
| committer | 2025-08-19 21:38:44 +0200 | |
| commit | eecfeec3745333451de6a2b1754f43f171e23e5d (patch) | |
| tree | 0521647efd7aba9cca0911acb387872f5f303f2d /mastoapi.c | |
| parent | Merge pull request 'master' (#9) from grunfink/snac2:master into master (diff) | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | penes-snac2-eecfeec3745333451de6a2b1754f43f171e23e5d.tar.gz penes-snac2-eecfeec3745333451de6a2b1754f43f171e23e5d.tar.xz penes-snac2-eecfeec3745333451de6a2b1754f43f171e23e5d.zip | |
Merge pull request 'updates holen' (#10) from grunfink/snac2:master into master
Reviewed-on: https://codeberg.org/zen/snac2/pulls/10
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 45 |
1 files changed, 39 insertions, 6 deletions
| @@ -1271,8 +1271,31 @@ void credentials_get(char **body, char **ctype, int *status, snac snac) | |||
| 1271 | acct = xs_dict_append(acct, "header", header); | 1271 | acct = xs_dict_append(acct, "header", header); |
| 1272 | acct = xs_dict_append(acct, "header_static", header); | 1272 | acct = xs_dict_append(acct, "header_static", header); |
| 1273 | 1273 | ||
| 1274 | const xs_dict *metadata = xs_dict_get(snac.config, "metadata"); | 1274 | xs *metadata = NULL; |
| 1275 | if (xs_type(metadata) == XSTYPE_DICT) { | 1275 | const xs_dict *md = xs_dict_get(snac.config, "metadata"); |
| 1276 | |||
| 1277 | if (xs_is_dict(md)) | ||
| 1278 | metadata = xs_dup(md); | ||
| 1279 | else | ||
| 1280 | if (xs_is_string(md)) { | ||
| 1281 | metadata = xs_dict_new(); | ||
| 1282 | xs *l = xs_split(md, "\n"); | ||
| 1283 | const char *ll; | ||
| 1284 | |||
| 1285 | xs_list_foreach(l, ll) { | ||
| 1286 | xs *kv = xs_split_n(ll, "=", 1); | ||
| 1287 | const char *k = xs_list_get(kv, 0); | ||
| 1288 | const char *v = xs_list_get(kv, 1); | ||
| 1289 | |||
| 1290 | if (k && v) { | ||
| 1291 | xs *kk = xs_strip_i(xs_dup(k)); | ||
| 1292 | xs *vv = xs_strip_i(xs_dup(v)); | ||
| 1293 | metadata = xs_dict_set(metadata, kk, vv); | ||
| 1294 | } | ||
| 1295 | } | ||
| 1296 | } | ||
| 1297 | |||
| 1298 | if (xs_is_dict(metadata)) { | ||
| 1276 | xs *fields = xs_list_new(); | 1299 | xs *fields = xs_list_new(); |
| 1277 | const xs_str *k; | 1300 | const xs_str *k; |
| 1278 | const xs_str *v; | 1301 | const xs_str *v; |
| @@ -1374,6 +1397,9 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn | |||
| 1374 | initial_status = index_desc_first(f, md5, 0); | 1397 | initial_status = index_desc_first(f, md5, 0); |
| 1375 | } | 1398 | } |
| 1376 | 1399 | ||
| 1400 | xs_set entries; | ||
| 1401 | xs_set_init(&entries); | ||
| 1402 | |||
| 1377 | if (initial_status) { | 1403 | if (initial_status) { |
| 1378 | do { | 1404 | do { |
| 1379 | xs *msg = NULL; | 1405 | xs *msg = NULL; |
| @@ -1465,7 +1491,7 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn | |||
| 1465 | /* convert the Note into a Mastodon status */ | 1491 | /* convert the Note into a Mastodon status */ |
| 1466 | xs *st = mastoapi_status(user, msg); | 1492 | xs *st = mastoapi_status(user, msg); |
| 1467 | 1493 | ||
| 1468 | if (st != NULL) { | 1494 | if (st != NULL && xs_set_add(&entries, md5) == 1) { |
| 1469 | if (ascending) | 1495 | if (ascending) |
| 1470 | out = xs_list_insert(out, 0, st); | 1496 | out = xs_list_insert(out, 0, st); |
| 1471 | else | 1497 | else |
| @@ -1476,6 +1502,8 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn | |||
| 1476 | } while ((cnt < limit) && (*iterator)(f, md5)); | 1502 | } while ((cnt < limit) && (*iterator)(f, md5)); |
| 1477 | } | 1503 | } |
| 1478 | 1504 | ||
| 1505 | xs_set_free(&entries); | ||
| 1506 | |||
| 1479 | int more = index_desc_next(f, md5); | 1507 | int more = index_desc_next(f, md5); |
| 1480 | 1508 | ||
| 1481 | fclose(f); | 1509 | fclose(f); |
| @@ -2112,7 +2140,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 2112 | } | 2140 | } |
| 2113 | else | 2141 | else |
| 2114 | if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/ | 2142 | if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/ |
| 2115 | /* snac does not schedule notes */ | 2143 | /* TBD */ |
| 2116 | *body = xs_dup("[]"); | 2144 | *body = xs_dup("[]"); |
| 2117 | *ctype = "application/json"; | 2145 | *ctype = "application/json"; |
| 2118 | status = HTTP_STATUS_OK; | 2146 | status = HTTP_STATUS_OK; |
| @@ -2477,6 +2505,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 2477 | } | 2505 | } |
| 2478 | else | 2506 | else |
| 2479 | if (strcmp(cmd, "/v1/preferences") == 0) { /** **/ | 2507 | if (strcmp(cmd, "/v1/preferences") == 0) { /** **/ |
| 2508 | /* TBD */ | ||
| 2480 | *body = xs_dup("{}"); | 2509 | *body = xs_dup("{}"); |
| 2481 | *ctype = "application/json"; | 2510 | *ctype = "application/json"; |
| 2482 | status = HTTP_STATUS_OK; | 2511 | status = HTTP_STATUS_OK; |
| @@ -3689,7 +3718,7 @@ int mastoapi_patch_handler(const xs_dict *req, const char *q_path, | |||
| 3689 | snac snac = {0}; | 3718 | snac snac = {0}; |
| 3690 | int logged_in = process_auth_token(&snac, req); | 3719 | int logged_in = process_auth_token(&snac, req); |
| 3691 | 3720 | ||
| 3692 | if (xs_startswith(cmd, "/v1/accounts/update_credentials")) { | 3721 | if (xs_startswith(cmd, "/v1/accounts/update_credentials")) { /** **/ |
| 3693 | /* Update user profile fields */ | 3722 | /* Update user profile fields */ |
| 3694 | if (logged_in) { | 3723 | if (logged_in) { |
| 3695 | int c = 0; | 3724 | int c = 0; |
| @@ -3745,9 +3774,13 @@ int mastoapi_patch_handler(const xs_dict *req, const char *q_path, | |||
| 3745 | snac.config = xs_dict_set(snac.config, "metadata", new_fields); | 3774 | snac.config = xs_dict_set(snac.config, "metadata", new_fields); |
| 3746 | } | 3775 | } |
| 3747 | } | 3776 | } |
| 3777 | else | ||
| 3778 | if (strcmp(k, "locked") == 0) { | ||
| 3779 | snac.config = xs_dict_set(snac.config, "approve_followers", | ||
| 3780 | xs_stock(strcmp(v, "true") == 0 ? XSTYPE_TRUE : XSTYPE_FALSE)); | ||
| 3781 | } | ||
| 3748 | /* we don't have support for the following options, yet | 3782 | /* we don't have support for the following options, yet |
| 3749 | - discoverable (0/1) | 3783 | - discoverable (0/1) |
| 3750 | - locked (0/1) | ||
| 3751 | */ | 3784 | */ |
| 3752 | } | 3785 | } |
| 3753 | 3786 | ||