commit fafeb6c3f0aab31cececf929972ab592a33f7c3c
parent e9f6db3761e67b666e8ff5dded171a688694291b
Author: grunfink <grunfink@noreply.codeberg.org>
Date: Mon, 30 Dec 2024 07:11:00 +0000
Merge pull request 'mastoapi: implement timeline min_id' (#254) from nowster/snac2:min_id into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/254
Diffstat:
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/mastoapi.c b/mastoapi.c
@@ -1348,7 +1348,7 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn
if (limit == 0)
limit = 20;
- if (min_id == NULL && index_desc_first(f, md5, 0)) {
+ if (index_desc_first(f, md5, 0)) {
do {
xs *msg = NULL;
@@ -1366,6 +1366,11 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn
break;
}
+ if (min_id) {
+ if (strcmp(md5, MID_TO_MD5(min_id)) == 0)
+ break;
+ }
+
/* get the entry */
if (user) {
if (!valid_status(timeline_get_by_md5(user, md5, &msg)))
@@ -1435,8 +1440,14 @@ 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 (cnt < limit && index_desc_next(f, md5));
+ } while ((min_id || (cnt < limit)) && index_desc_next(f, md5));
}
int more = index_desc_next(f, md5);