commit 655a448adb0d861a15f6e7443c879928fd654f20
parent 2384a5409bc3a8a6ede4bf33bb1584a6bfae39af
Author: Paul Martin <pm@nowster.org.uk>
Date: Tue, 24 Dec 2024 20:35:58 +0000
mastoapi: implement timeline min_id
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);