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 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 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. --- main.c | 16 ++++++++++++++++ mastoapi.c | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/main.c b/main.c index 83b73af..b4e7fa1 100644 --- a/main.c +++ b/main.c @@ -351,6 +351,22 @@ int main(int argc, char *argv[]) return 0; } + + if (strcmp(cmd, "assist") == 0) { /** **/ + /* undocumented: experimental (do not use) */ + xs *msg = msg_admiration(&snac, url, "Accept"); + + if (msg != NULL) { + enqueue_message(&snac, msg); + + if (dbglevel) { + xs_json_dump(msg, 4, stdout); + } + } + + return 0; + } + if (strcmp(cmd, "unboost") == 0) { /** **/ xs *msg = msg_repulsion(&snac, url, "Announce"); 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 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 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 --- data.c | 31 +++++++++++++++++++++++++++++++ mastoapi.c | 46 ++++++++++++++++++++++++++++------------------ snac.h | 2 ++ 3 files changed, 61 insertions(+), 18 deletions(-) (limited to 'mastoapi.c') diff --git a/data.c b/data.c index ca63084..33947ff 100644 --- a/data.c +++ b/data.c @@ -679,6 +679,37 @@ int index_desc_first(FILE *f, char md5[MD5_HEX_SIZE], int skip) return 1; } +int index_asc_first(FILE *f,char md5[MD5_HEX_SIZE], const char *seek_md5) +/* reads the first entry of an ascending index, starting from a given md5 */ +{ + fseek(f, SEEK_SET, 0); + while (fread(md5, MD5_HEX_SIZE, 1, f)) { + md5[MD5_HEX_SIZE - 1] = '\0'; + if (strcmp(md5,seek_md5) == 0) { + return index_asc_next(f, md5); + } + } + return 0; +} + +int index_asc_next(FILE *f, char md5[MD5_HEX_SIZE]) +/* reads the next entry of an ascending index */ +{ + for (;;) { + /* read an md5 */ + if (!fread(md5, MD5_HEX_SIZE, 1, f)) + return 0; + + /* deleted, skip */ + if (md5[0] != '-') + break; + } + + md5[MD5_HEX_SIZE - 1] = '\0'; + + return 1; +} + xs_list *index_list_desc(const char *fn, int skip, int show) /* returns an index as a list, in reverse order */ 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); diff --git a/snac.h b/snac.h index 5729a22..65ece5d 100644 --- a/snac.h +++ b/snac.h @@ -108,6 +108,8 @@ int index_len(const char *fn); xs_list *index_list(const char *fn, int max); int index_desc_next(FILE *f, char md5[MD5_HEX_SIZE]); int index_desc_first(FILE *f, char md5[MD5_HEX_SIZE], int skip); +int index_asc_next(FILE *f, char md5[MD5_HEX_SIZE]); +int index_asc_first(FILE *f, char md5[MD5_HEX_SIZE], const char *seek_md5); xs_list *index_list_desc(const char *fn, int skip, int show); int object_add(const char *id, const xs_dict *obj); -- cgit 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