commit 9457a73

default  ·  2024-08-09 15:25:57 +0000 UTC
parent 61d8b46
Use mastoapi_timeline() also for the instance timeline and tags.
1 files changed,  +7, -79
+7, -79
  1@@ -1382,9 +1382,11 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn
  2         } while (cnt < limit && index_desc_next(f, md5));
  3     }
  4 
  5+    int more = index_desc_next(f, md5);
  6+
  7     fclose(f);
  8 
  9-    srv_debug(1, xs_fmt("mastoapi_timeline: %d %d", cnt, xs_list_len(out)));
 10+    srv_debug(1, xs_fmt("mastoapi_timeline: %d %d %d", cnt, xs_list_len(out), more));
 11 
 12     return out;
 13 }
 14@@ -1664,50 +1666,12 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 15     else
 16     if (strcmp(cmd, "/v1/timelines/public") == 0) { /** **/
 17         /* the instance public timeline (public timelines for all users) */
 18-
 19-        const char *limit_s = xs_dict_get(args, "limit");
 20-        int limit = 0;
 21-        int cnt   = 0;
 22-
 23-        if (!xs_is_null(limit_s))
 24-            limit = atoi(limit_s);
 25-
 26-        if (limit == 0)
 27-            limit = 20;
 28-
 29-        xs *timeline = timeline_instance_list(0, limit);
 30-        xs *out      = xs_list_new();
 31-        xs_list *p   = timeline;
 32-        const xs_str *md5;
 33-
 34         snac *user = NULL;
 35         if (logged_in)
 36             user = &snac1;
 37 
 38-        while (xs_list_iter(&p, &md5) && cnt < limit) {
 39-            xs *msg = NULL;
 40-
 41-            /* get the entry */
 42-            if (!valid_status(object_get_by_md5(md5, &msg)))
 43-                continue;
 44-
 45-            /* discard non-Notes */
 46-            const char *type = xs_dict_get(msg, "type");
 47-            if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0)
 48-                continue;
 49-
 50-            /* discard messages from private users */
 51-            if (is_msg_from_private_user(msg))
 52-                continue;
 53-
 54-            /* convert the Note into a Mastodon status */
 55-            xs *st = mastoapi_status(user, msg);
 56-
 57-            if (st != NULL) {
 58-                out = xs_list_append(out, st);
 59-                cnt++;
 60-            }
 61-        }
 62+        xs *ifn = instance_index_fn();
 63+        xs *out = mastoapi_timeline(user, args, ifn);
 64 
 65         *body  = xs_json_dumps(out, 4);
 66         *ctype = "application/json";
 67@@ -1715,48 +1679,12 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 68     }
 69     else
 70     if (xs_startswith(cmd, "/v1/timelines/tag/")) { /** **/
 71-        const char *limit_s = xs_dict_get(args, "limit");
 72-        int limit = 0;
 73-        int cnt   = 0;
 74-
 75-        if (!xs_is_null(limit_s))
 76-            limit = atoi(limit_s);
 77-
 78-        if (limit == 0)
 79-            limit = 20;
 80-
 81         /* get the tag */
 82         xs *l = xs_split(cmd, "/");
 83         const char *tag = xs_list_get(l, -1);
 84 
 85-        xs *timeline = tag_search(tag, 0, limit);
 86-        xs *out      = xs_list_new();
 87-        xs_list *p   = timeline;
 88-        const xs_str *md5;
 89-
 90-        while (xs_list_iter(&p, &md5) && cnt < limit) {
 91-            xs *msg = NULL;
 92-
 93-            /* get the entry */
 94-            if (!valid_status(object_get_by_md5(md5, &msg)))
 95-                continue;
 96-
 97-            /* skip non-public messages */
 98-            if (!is_msg_public(msg))
 99-                continue;
100-
101-            /* discard messages from private users */
102-            if (is_msg_from_private_user(msg))
103-                continue;
104-
105-            /* convert the Note into a Mastodon status */
106-            xs *st = mastoapi_status(NULL, msg);
107-
108-            if (st != NULL) {
109-                out = xs_list_append(out, st);
110-                cnt++;
111-            }
112-        }
113+        xs *ifn = tag_fn(tag);
114+        xs *out = mastoapi_timeline(NULL, args, ifn);
115 
116         *body  = xs_json_dumps(out, 4);
117         *ctype = "application/json";