From 932227bbac7fe740bff1e38bf92b58edef19e32f Mon Sep 17 00:00:00 2001 From: default Date: Wed, 8 Jan 2025 16:59:14 +0100 Subject: Bumped copyright year. --- mastoapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 62108ad..4b89d12 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1,5 +1,5 @@ /* snac - A simple, minimalistic ActivityPub instance */ -/* copyright (c) 2022 - 2024 grunfink et al. / MIT license */ +/* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ #ifndef NO_MASTODON_API -- cgit v1.2.3 From 9d4d740220c79e13d2c1f95ba91405f24c90b287 Mon Sep 17 00:00:00 2001 From: default Date: Sat, 11 Jan 2025 01:48:19 +0100 Subject: mastoapi: obey the "unlisted" visibility set by apps. --- mastoapi.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 4b89d12..16065ec 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2650,8 +2650,14 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, } /* prepare the message */ - xs *msg = msg_note(&snac, content, NULL, irt, attach_list, - strcmp(visibility, "public") == 0 ? 0 : 1, language); + int scope = 1; + if (strcmp(visibility, "unlisted") == 0) + scope = 2; + else + if (strcmp(visibility, "public") == 0) + scope = 0; + + xs *msg = msg_note(&snac, content, NULL, irt, attach_list, scope, language); if (!xs_is_null(summary) && *summary) { msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE)); -- cgit v1.2.3 From f88a32dbe0805fceb3fb75b01de61616d7953f5e Mon Sep 17 00:00:00 2001 From: default Date: Sun, 12 Jan 2025 11:30:16 +0100 Subject: mastoapi: fixed Events not being shown. --- mastoapi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 16065ec..21e2a78 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1428,9 +1428,9 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn continue; } - /* if it has a name and it's not a Page or a Video, + /* if it has a name and it's not an object that may have one, it's a poll vote, so discard it */ - if (!xs_is_null(xs_dict_get(msg, "name")) && !xs_match(type, "Page|Video")) + if (!xs_is_null(xs_dict_get(msg, "name")) && !xs_match(type, "Page|Video|Audio|Event")) continue; /* convert the Note into a Mastodon status */ -- cgit v1.2.3 From 9686ccd916464a1280082a4abba7a5fa3574dd0c Mon Sep 17 00:00:00 2001 From: Paul Martin Date: Tue, 14 Jan 2025 22:17:46 +0000 Subject: Implement limit= on notification fetches --- mastoapi.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 21e2a78..3e823ed 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1816,6 +1816,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, const xs_list *excl = xs_dict_get(args, "exclude_types[]"); const char *min_id = xs_dict_get(args, "min_id"); const char *max_id = xs_dict_get(args, "max_id"); + const char *limit = xs_dict_get(args, "limit"); + int limit_count = 0; + if (!xs_is_null(limit)) { + limit_count = atoi(limit); + } if (dbglevel) { xs *js = xs_json_dumps(args, 0); @@ -1903,6 +1908,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, } out = xs_list_append(out, mn); + if (!xs_is_null(limit)) { + if (--limit_count <= 0) + break; + } } srv_debug(1, xs_fmt("mastoapi_notifications count %d", xs_list_len(out))); -- cgit v1.2.3 From b5c5c5cb9e1c728a83596dcc7c4191d012fe1332 Mon Sep 17 00:00:00 2001 From: Paul Martin Date: Wed, 15 Jan 2025 00:40:32 +0000 Subject: Implement faster min_id handling --- mastoapi.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 21e2a78..c25f78b 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1339,6 +1339,9 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn const char *since_id = xs_dict_get(args, "since_id"); const char *min_id = xs_dict_get(args, "min_id"); /* unsupported old-to-new navigation */ const char *limit_s = xs_dict_get(args, "limit"); + int (*iterator)(FILE *, char *); + int initial_status = 0; + int ascending = 0; int limit = 0; int cnt = 0; @@ -1348,27 +1351,40 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn if (limit == 0) limit = 20; - if (index_desc_first(f, md5, 0)) { + if (min_id) { + iterator = &index_asc_next; + initial_status = index_asc_first(f, md5, MID_TO_MD5(min_id)); + ascending = 1; + } + else { + iterator = &index_desc_next; + initial_status = index_desc_first(f, md5, 0); + } + + if (initial_status) { do { xs *msg = NULL; /* only return entries older that max_id */ if (max_id) { - if (strcmp(md5, MID_TO_MD5(max_id)) == 0) + if (strcmp(md5, MID_TO_MD5(max_id)) == 0) { max_id = NULL; - - continue; + if (ascending) + break; + } + if (!ascending) + continue; } /* only returns entries newer than since_id */ if (since_id) { - if (strcmp(md5, MID_TO_MD5(since_id)) == 0) - break; - } - - if (min_id) { - if (strcmp(md5, MID_TO_MD5(min_id)) == 0) - break; + if (strcmp(md5, MID_TO_MD5(since_id)) == 0) { + if (!ascending) + break; + since_id = NULL; + } + if (ascending) + continue; } /* get the entry */ @@ -1440,14 +1456,8 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn out = xs_list_append(out, st); cnt++; } - if (min_id) { - while (cnt > limit) { - out = xs_list_del(out, 0); - cnt--; - } - } - } while ((min_id || (cnt < limit)) && index_desc_next(f, md5)); + } while ((cnt < limit) && (*iterator)(f, md5)); } int more = index_desc_next(f, md5); -- cgit v1.2.3 From e6baf0d45c9b55f0b1532a0069b59ca06ac8fbc1 Mon Sep 17 00:00:00 2001 From: Paul Martin Date: Tue, 21 Jan 2025 23:26:50 +0000 Subject: When reading timeline in ascending order, return results in descending order --- mastoapi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 3250a20..54b4333 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1453,7 +1453,10 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn xs *st = mastoapi_status(user, msg); if (st != NULL) { - out = xs_list_append(out, st); + if (ascending) + out = xs_list_insert(out, 0, st); + else + out = xs_list_append(out, st); cnt++; } -- cgit v1.2.3