Browse Source

mastoapi: implement timeline min_id

Paul Martin 3 months ago
parent
commit
655a448adb
1 changed files with 13 additions and 2 deletions
  1. 13 2
      mastoapi.c

+ 13 - 2
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);