summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2024-08-09 18:07:05 +0200
committerdefault <nobody@localhost>2024-08-09 18:07:05 +0200
commit35503ed2b4b557d369ca887719c8b79fa4eff37e (patch)
treeb6021107be568d915cb5b45aec85d99e0ff1d5bb
parent9457a7358a7b9e0fc5045a9906dd74d0cd6c6b27 (diff)
mastoapi: also use mastoapi_timeline() with lists.
-rw-r--r--data.c8
-rw-r--r--mastoapi.c63
-rw-r--r--snac.h1
3 files changed, 13 insertions, 59 deletions
diff --git a/data.c b/data.c
index cfedb04..7d31863 100644
--- a/data.c
+++ b/data.c
@@ -1944,6 +1944,12 @@ xs_val *list_maint(snac *user, const char *list, int op)
}
+xs_str *list_timeline_fn(snac *user, const char *list)
+{
+ return xs_fmt("%s/list/%s.idx", user->basedir, list);
+}
+
+
xs_list *list_timeline(snac *user, const char *list, int skip, int show)
/* returns the timeline of a list */
{
@@ -1952,7 +1958,7 @@ xs_list *list_timeline(snac *user, const char *list, int skip, int show)
if (!xs_is_hex(list))
return NULL;
- xs *fn = xs_fmt("%s/list/%s.idx", user->basedir, list);
+ xs *fn = list_timeline_fn(user, list);
if (mtime(fn) > 0.0)
l = index_list_desc(fn, skip, show);
diff --git a/mastoapi.c b/mastoapi.c
index 67f8016..f004587 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -1375,10 +1375,11 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn
/* convert the Note into a Mastodon status */
xs *st = mastoapi_status(user, msg);
- if (st != NULL)
+ if (st != NULL) {
out = xs_list_append(out, st);
+ cnt++;
+ }
- cnt++;
} while (cnt < limit && index_desc_next(f, md5));
}
@@ -1697,62 +1698,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
xs *l = xs_split(cmd, "/");
const char *list = xs_list_get(l, -1);
- xs *timeline = list_timeline(&snac1, list, 0, 2048);
- xs *out = xs_list_new();
- int c = 0;
- const char *md5;
-
- while (xs_list_next(timeline, &md5, &c)) {
- xs *msg = NULL;
-
- /* get the entry */
- if (!valid_status(timeline_get_by_md5(&snac1, md5, &msg)))
- continue;
-
- /* discard non-Notes */
- const char *id = xs_dict_get(msg, "id");
- const char *type = xs_dict_get(msg, "type");
- if (!xs_match(type, POSTLIKE_OBJECT_TYPE))
- continue;
-
- const char *from = NULL;
- if (strcmp(type, "Page") == 0)
- from = xs_dict_get(msg, "audience");
-
- if (from == NULL)
- from = get_atto(msg);
-
- if (from == NULL)
- continue;
-
- /* is this message from a person we don't follow? */
- if (strcmp(from, snac1.actor) && !following_check(&snac1, from)) {
- /* discard if it was not boosted */
- xs *idx = object_announces(id);
-
- if (xs_list_len(idx) == 0)
- continue;
- }
-
- /* discard notes from muted morons */
- if (is_muted(&snac1, from))
- continue;
-
- /* discard hidden notes */
- if (is_hidden(&snac1, id))
- continue;
-
- /* if it has a name and it's not a Page or a Video,
- it's a poll vote, so discard it */
- if (!xs_is_null(xs_dict_get(msg, "name")) && !xs_match(type, "Page|Video"))
- continue;
-
- /* convert the Note into a Mastodon status */
- xs *st = mastoapi_status(&snac1, msg);
-
- if (st != NULL)
- out = xs_list_append(out, st);
- }
+ xs *ifn = list_timeline_fn(&snac1, list);
+ xs *out = mastoapi_timeline(NULL, args, ifn);
*body = xs_json_dumps(out, 4);
*ctype = "application/json";
diff --git a/snac.h b/snac.h
index 70ba91d..58a513f 100644
--- a/snac.h
+++ b/snac.h
@@ -185,6 +185,7 @@ xs_str *tag_fn(const char *tag);
xs_list *tag_search(const char *tag, int skip, int show);
xs_val *list_maint(snac *user, const char *list, int op);
+xs_str *list_timeline_fn(snac *user, const char *list);
xs_list *list_timeline(snac *user, const char *list, int skip, int show);
xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int op);
void list_distribute(snac *user, const char *who, const xs_dict *post);