commit fafeb6c

grunfink  ·  2024-12-30 07:11:00 +0000 UTC
parents e9f6db3, 655a448
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
1 files changed,  +13, -2
+13, -2
 1@@ -1348,7 +1348,7 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn
 2     if (limit == 0)
 3         limit = 20;
 4 
 5-    if (min_id == NULL && index_desc_first(f, md5, 0)) {
 6+    if (index_desc_first(f, md5, 0)) {
 7         do {
 8             xs *msg = NULL;
 9 
10@@ -1366,6 +1366,11 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn
11                     break;
12             }
13 
14+            if (min_id) {
15+                if (strcmp(md5, MID_TO_MD5(min_id)) == 0)
16+                    break;
17+            }
18+
19             /* get the entry */
20             if (user) {
21                 if (!valid_status(timeline_get_by_md5(user, md5, &msg)))
22@@ -1435,8 +1440,14 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn
23                 out = xs_list_append(out, st);
24                 cnt++;
25             }
26+            if (min_id) {
27+                while (cnt > limit) {
28+                    out = xs_list_del(out, 0);
29+                    cnt--;
30+                }
31+            }
32 
33-        } while (cnt < limit && index_desc_next(f, md5));
34+        } while ((min_id || (cnt < limit)) && index_desc_next(f, md5));
35     }
36 
37     int more = index_desc_next(f, md5);