summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authorGravatar Paul Martin2024-12-19 19:55:56 +0000
committerGravatar Paul Martin2024-12-20 00:18:32 +0000
commitfa253f008a0f4d028dbb9ef14c83d6699a133614 (patch)
tree1a5f52d469327385bfc7890de5926768801ef6ed /mastoapi.c
parentUpdated documentation. (diff)
downloadpenes-snac2-fa253f008a0f4d028dbb9ef14c83d6699a133614.tar.gz
penes-snac2-fa253f008a0f4d028dbb9ef14c83d6699a133614.tar.xz
penes-snac2-fa253f008a0f4d028dbb9ef14c83d6699a133614.zip
Implement mastoapi markers for notifications and home.
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c58
1 files changed, 51 insertions, 7 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 2c8c04d..c78c380 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -1788,6 +1788,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1788 xs *out = xs_list_new(); 1788 xs *out = xs_list_new();
1789 const xs_dict *v; 1789 const xs_dict *v;
1790 const xs_list *excl = xs_dict_get(args, "exclude_types[]"); 1790 const xs_list *excl = xs_dict_get(args, "exclude_types[]");
1791 const char *min_id = xs_dict_get(args, "min_id");
1791 const char *max_id = xs_dict_get(args, "max_id"); 1792 const char *max_id = xs_dict_get(args, "max_id");
1792 1793
1793 xs_list_foreach(l, v) { 1794 xs_list_foreach(l, v) {
@@ -1814,10 +1815,14 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1814 continue; 1815 continue;
1815 1816
1816 if (max_id) { 1817 if (max_id) {
1817 if (strcmp(fid, max_id) == 0) 1818 if (strcmp(fid, max_id) > 0)
1818 max_id = NULL; 1819 continue;
1820 }
1819 1821
1820 continue; 1822 if (min_id) {
1823 if (strcmp(fid, min_id) <= 0) {
1824 continue;
1825 }
1821 } 1826 }
1822 1827
1823 /* convert the type */ 1828 /* convert the type */
@@ -2298,9 +2303,22 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2298 } 2303 }
2299 else 2304 else
2300 if (strcmp(cmd, "/v1/markers") == 0) { /** **/ 2305 if (strcmp(cmd, "/v1/markers") == 0) { /** **/
2301 *body = xs_dup("{}"); 2306 if (logged_in) {
2302 *ctype = "application/json"; 2307 const xs_list *timeline = xs_dict_get(args, "timeline[]");
2303 status = HTTP_STATUS_OK; 2308 xs_str *json = NULL;
2309 if (!xs_is_null(timeline))
2310 json = xs_json_dumps(markers_get(&snac1, timeline), 4);
2311
2312 if (!xs_is_null(json))
2313 *body = json;
2314 else
2315 *body = xs_dup("{}");
2316
2317 *ctype = "application/json";
2318 status = HTTP_STATUS_OK;
2319 }
2320 else
2321 status = HTTP_STATUS_UNAUTHORIZED;
2304 } 2322 }
2305 else 2323 else
2306 if (strcmp(cmd, "/v1/followed_tags") == 0) { /** **/ 2324 if (strcmp(cmd, "/v1/followed_tags") == 0) { /** **/
@@ -2997,9 +3015,35 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
2997 } 3015 }
2998 } 3016 }
2999 } 3017 }
3018 }
3019 else if (strcmp(cmd, "/v1/markers") == 0) { /** **/
3020 xs_str *json = NULL;
3021 if (logged_in) {
3022 const xs_str *home_marker = xs_dict_get(args, "home[last_read_id]");
3023 if (xs_is_null(home_marker)) {
3024 const xs_dict *home = xs_dict_get(args, "home");
3025 if (!xs_is_null(home))
3026 home_marker = xs_dict_get(home, "last_read_id");
3027 }
3028
3029 const xs_str *notify_marker = xs_dict_get(args, "notifications[last_read_id]");
3030 if (xs_is_null(notify_marker)) {
3031 const xs_dict *notify = xs_dict_get(args, "notifications");
3032 if (!xs_is_null(notify))
3033 notify_marker = xs_dict_get(notify, "last_read_id");
3034 }
3035 json = xs_json_dumps(markers_set(&snac, home_marker, notify_marker), 4);
3036 }
3037 if (!xs_is_null(json))
3038 *body = json;
3000 else 3039 else
3001 status = HTTP_STATUS_UNPROCESSABLE_CONTENT; 3040 *body = xs_dup("{}");
3041
3042 *ctype = "application/json";
3043 status = HTTP_STATUS_OK;
3002 } 3044 }
3045 else
3046 status = HTTP_STATUS_UNPROCESSABLE_CONTENT;
3003 3047
3004 /* user cleanup */ 3048 /* user cleanup */
3005 if (logged_in) 3049 if (logged_in)