From 82bcc4b465f73a5d1f2eebcf3813452bc1c37fbd Mon Sep 17 00:00:00 2001 From: default Date: Mon, 27 Jan 2025 16:59:08 +0100 Subject: Minor optimization in timeline retrieving. Functions now receive an optional int *more, set to 1 if there are more than the 'show' requested. --- html.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index 3b63cfc..bd94e9f 100644 --- a/html.c +++ b/html.c @@ -3314,21 +3314,17 @@ int html_get_handler(const xs_dict *req, const char *q_path, } else { xs *list = NULL; - xs *next = NULL; + int more = 0; - if (xs_is_true(xs_dict_get(srv_config, "strict_public_timelines"))) { - list = timeline_simple_list(&snac, "public", skip, show); - next = timeline_simple_list(&snac, "public", skip + show, 1); - } - else { - list = timeline_list(&snac, "public", skip, show); - next = timeline_list(&snac, "public", skip + show, 1); - } + if (xs_is_true(xs_dict_get(srv_config, "strict_public_timelines"))) + list = timeline_simple_list(&snac, "public", skip, show, &more); + else + list = timeline_list(&snac, "public", skip, show, &more); xs *pins = pinned_list(&snac); pins = xs_list_cat(pins, list); - *body = html_timeline(&snac, pins, 1, skip, show, xs_list_len(next), NULL, "", 1, error); + *body = html_timeline(&snac, pins, 1, skip, show, more, NULL, "", 1, error); *b_size = strlen(*body); status = HTTP_STATUS_OK; @@ -3490,13 +3486,14 @@ int html_get_handler(const xs_dict *req, const char *q_path, xs_dict_get(req, "if-none-match"), etag); } else { + int more = 0; + snac_debug(&snac, 1, xs_fmt("building timeline")); - xs *list = timeline_list(&snac, "private", skip, show); - xs *next = timeline_list(&snac, "private", skip + show, 1); + xs *list = timeline_list(&snac, "private", skip, show, &more); *body = html_timeline(&snac, list, 0, skip, show, - xs_list_len(next), NULL, "/admin", 1, error); + more, NULL, "/admin", 1, error); *b_size = strlen(*body); status = HTTP_STATUS_OK; @@ -3702,7 +3699,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, int cnt = xs_number_get(xs_dict_get_def(srv_config, "max_public_entries", "20")); - xs *elems = timeline_simple_list(&snac, "public", 0, cnt); + xs *elems = timeline_simple_list(&snac, "public", 0, cnt, NULL); xs *bio = xs_dup(xs_dict_get(snac.config, "bio")); xs *rss_title = xs_fmt("%s (@%s@%s)", -- cgit v1.2.3 From 1766d6bf92eb433841c03ccb096c636a4c5dc968 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 27 Jan 2025 20:20:40 +0100 Subject: Added a 'No more unseen posts' mark. --- html.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'html.c') diff --git a/html.c b/html.c index bd94e9f..771d2af 100644 --- a/html.c +++ b/html.c @@ -2648,10 +2648,31 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only, xs_html_add(body, posts); + int mark_shown = 0; + while (xs_list_iter(&p, &v)) { xs *msg = NULL; int status; + /* "already seen" mark? */ + if (strcmp(v, MD5_ALREADY_SEEN_MARK) == 0) { + if (skip == 0 && !mark_shown) { + xs *s = xs_fmt("%s/admin#top", user->actor); + + xs_html_add(posts, + xs_html_text(L("No more unseen posts")), + xs_html_text(" - "), + xs_html_tag("a", + xs_html_attr("href", s), + xs_html_text(L("Back to top"))), + xs_html_sctag("hr", NULL)); + } + + mark_shown = 1; + + continue; + } + if (utl && user && !is_pinned_by_md5(user, v)) status = timeline_get_by_md5(user, v, &msg); else @@ -3473,6 +3494,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, } } else { + /** the private timeline **/ double t = history_mtime(&snac, "timeline.html_"); /* if enabled by admin, return a cached page if its timestamp is: @@ -3492,6 +3514,8 @@ int html_get_handler(const xs_dict *req, const char *q_path, xs *list = timeline_list(&snac, "private", skip, show, &more); + timeline_add_mark(&snac); + *body = html_timeline(&snac, list, 0, skip, show, more, NULL, "/admin", 1, error); -- cgit v1.2.3 From d9d2dedbc053b35aee02ba7f408e056ab03368c0 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 28 Jan 2025 07:48:31 +0100 Subject: Set the CSS class snac-no-more-unseen-posts. --- html.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index 771d2af..c27ab99 100644 --- a/html.c +++ b/html.c @@ -2660,12 +2660,13 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only, xs *s = xs_fmt("%s/admin#top", user->actor); xs_html_add(posts, - xs_html_text(L("No more unseen posts")), - xs_html_text(" - "), - xs_html_tag("a", - xs_html_attr("href", s), - xs_html_text(L("Back to top"))), - xs_html_sctag("hr", NULL)); + xs_html_tag("div", + xs_html_attr("class", "snac-no-more-unseen-posts"), + xs_html_text(L("No more unseen posts")), + xs_html_text(" - "), + xs_html_tag("a", + xs_html_attr("href", s), + xs_html_text(L("Back to top"))))); } mark_shown = 1; -- cgit v1.2.3 From 06ba1174ca7084a3d691aa8c2b552b708d04b8db Mon Sep 17 00:00:00 2001 From: default Date: Tue, 28 Jan 2025 10:04:23 +0100 Subject: Some tweaks to the already seen mark code. --- html.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index c27ab99..8f8b524 100644 --- a/html.c +++ b/html.c @@ -2657,7 +2657,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only, /* "already seen" mark? */ if (strcmp(v, MD5_ALREADY_SEEN_MARK) == 0) { if (skip == 0 && !mark_shown) { - xs *s = xs_fmt("%s/admin#top", user->actor); + xs *s = xs_fmt("%s/admin", user->actor); xs_html_add(posts, xs_html_tag("div", @@ -2665,7 +2665,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only, xs_html_text(L("No more unseen posts")), xs_html_text(" - "), xs_html_tag("a", - xs_html_attr("href", s), + xs_html_attr("href", s), xs_html_text(L("Back to top"))))); } -- cgit v1.2.3 From 4acb3f65db21b1be6c16cf017aae890bb6dd4eea Mon Sep 17 00:00:00 2001 From: default Date: Wed, 29 Jan 2025 09:24:09 +0100 Subject: Call timeline_add_mark() after history_add() for better timestamp checks. --- html.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index 8f8b524..6365afb 100644 --- a/html.c +++ b/html.c @@ -3515,8 +3515,6 @@ int html_get_handler(const xs_dict *req, const char *q_path, xs *list = timeline_list(&snac, "private", skip, show, &more); - timeline_add_mark(&snac); - *body = html_timeline(&snac, list, 0, skip, show, more, NULL, "/admin", 1, error); @@ -3525,6 +3523,8 @@ int html_get_handler(const xs_dict *req, const char *q_path, if (save) history_add(&snac, "timeline.html_", *body, *b_size, etag); + + timeline_add_mark(&snac); } } } -- cgit v1.2.3