From 6b1721c977294ee28f54150579c36514aa3ee62a Mon Sep 17 00:00:00 2001 From: default Date: Tue, 7 May 2024 19:40:28 +0200 Subject: [PATCH] List timelines can now be (manually) navigated from the web UI. URLs are {srv_baseurl}/{user}/list/{list_id} (you must know the list id). --- data.c | 24 +++++++++++++++++++----- html.c | 23 +++++++++++++++++++++++ mastoapi.c | 2 +- snac.h | 1 + 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/data.c b/data.c index b9c1141..5b4936b 100644 --- a/data.c +++ b/data.c @@ -1836,6 +1836,23 @@ xs_val *list_maint(snac *user, const char *list, int op) } +xs_list *list_timeline(snac *user, const char *list, int skip, int show) +/* returns the timeline of a list */ +{ + xs_list *l = NULL; + + if (!xs_is_hex(list)) + return NULL; + + xs *fn = xs_fmt("%s/list/%s.idx", user->basedir, list); + + if (mtime(fn) > 0.0) + l = index_list_desc(fn, skip, show); + + return l; +} + + xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op) /* list content management */ { @@ -1869,11 +1886,8 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op break; - case 3: /** list timeline **/ - fn = xs_replace_i(fn, ".lst", ".idx"); - - l = index_list_desc(fn, 0, 2048); - + default: + srv_log(xs_fmt("ERROR: list_content: bad op %d", op)); break; } diff --git a/html.c b/html.c index ee5c2cd..b34fc81 100644 --- a/html.c +++ b/html.c @@ -2658,6 +2658,29 @@ int html_get_handler(const xs_dict *req, const char *q_path, } } else + if (xs_startswith(p_path, "list/")) { /** list timelines **/ + if (!login(&snac, req)) { + *body = xs_dup(uid); + status = 401; + } + else { + xs *l = xs_split(p_path, "/"); + char *lid = xs_list_get(l, -1); + + xs *list = list_timeline(&snac, lid, skip, show); + xs *next = list_timeline(&snac, lid, skip + show, 1); + + if (list != NULL) { + xs *base = xs_fmt("/list/%s", lid); + + *body = html_timeline(&snac, list, 0, skip, show, + xs_list_len(next), NULL, base, 0); + *b_size = strlen(*body); + status = 200; + } + } + } + else if (xs_startswith(p_path, "p/")) { /** a timeline with just one entry **/ if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE) return 403; diff --git a/mastoapi.c b/mastoapi.c index 1f7f0b2..d39a6f9 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1669,7 +1669,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *l = xs_split(cmd, "/"); char *list = xs_list_get(l, -1); - xs *timeline = list_content(&snac1, list, NULL, 3); + xs *timeline = list_timeline(&snac1, list, 0, 2048); xs *out = xs_list_new(); int c = 0; char *md5; diff --git a/snac.h b/snac.h index 481a1ae..ab8fc7c 100644 --- a/snac.h +++ b/snac.h @@ -175,6 +175,7 @@ void tag_index(const char *id, const xs_dict *obj); xs_list *tag_search(char *tag, int skip, int show); xs_val *list_maint(snac *user, const char *list, int op); +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);