Browse Source

Implement limit= on notification fetches

Paul Martin 2 months ago
parent
commit
9686ccd916
1 changed files with 9 additions and 0 deletions
  1. 9 0
      mastoapi.c

+ 9 - 0
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)));