summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
authorGravatar Alexandre Oliva2025-12-30 13:12:46 +0100
committerGravatar grunfink2025-12-30 13:12:46 +0100
commit93f82fae9e024ae4a7338701db762e390056e990 (patch)
tree8e8316a6771b393286c0b4ca43fc02ee643a8fb7 /html.c
parentintroduce separate people/ pages (diff)
downloadsnac2-93f82fae9e024ae4a7338701db762e390056e990.tar.gz
snac2-93f82fae9e024ae4a7338701db762e390056e990.tar.xz
snac2-93f82fae9e024ae4a7338701db762e390056e990.zip
Add posts by actor to people page
Select posts by the actor from the given timeline range. Since posts by the actor may be very sparse in the timeline, add a "More (x 10)" button to bump the show count, that controls how many timeline posts we'll filter *from*. We could conceivably keep searching the timeline until we find as many posts as requested or reach the end, but that could take a very long time. Just filtering the given ranges is much simpler, and probably sufficiently intuitive despite the potential initial surprise.
Diffstat (limited to 'html.c')
-rw-r--r--html.c85
1 files changed, 78 insertions, 7 deletions
diff --git a/html.c b/html.c
index c03c867..70c599f 100644
--- a/html.c
+++ b/html.c
@@ -3856,25 +3856,89 @@ xs_str *html_people(snac *user)
3856 return xs_html_render_s(html, "<!DOCTYPE html>\n"); 3856 return xs_html_render_s(html, "<!DOCTYPE html>\n");
3857} 3857}
3858 3858
3859xs_str *html_people_one(snac *user, const char *actor) 3859/* Filter list to display only posts by actor. We'll probably show
3860 fewer than show posts. Should we try harder to find some? */
3861xs_str *html_people_one(snac *user, const char *actor, const xs_list *list,
3862 int skip, int show, int show_more, const char *page)
3860{ 3863{
3861 const char *proxy = NULL; 3864 const char *proxy = NULL;
3865 xs_list *p = (xs_list *)list;
3866 const char *v;
3862 3867
3863 if (xs_is_true(xs_dict_get(srv_config, "proxy_media"))) 3868 if (xs_is_true(xs_dict_get(srv_config, "proxy_media")))
3864 proxy = user->actor; 3869 proxy = user->actor;
3865 3870
3871 xs_html *body = html_user_body(user, 0);
3872
3866 xs_html *lists = xs_html_tag("div", 3873 xs_html *lists = xs_html_tag("div",
3867 xs_html_attr("class", "snac-posts")); 3874 xs_html_attr("class", "snac-posts"));
3868 3875
3869 xs *foll = xs_list_append(xs_list_new(), actor); 3876 xs *foll = xs_list_append(xs_list_new(), actor);
3870 3877
3871 xs_html_add(lists, 3878 xs_html_add(lists,
3872 html_people_list(user, foll, L("People - single"), "p", proxy)); 3879 html_people_list(user, foll, L("Contact's posts"), "p", proxy));
3880
3881 xs_html_add(body, lists);
3882
3883 while (xs_list_iter(&p, &v)) {
3884 xs *msg = NULL;
3885 int status;
3886
3887 status = timeline_get_by_md5(user, v, &msg);
3888
3889 if (!valid_status(status))
3890 continue;
3891
3892 const char *by = xs_dict_get(msg, "attributedTo");
3893 if (!by || strcmp(actor, by) != 0)
3894 continue;
3895
3896 xs_html *entry = html_entry(user, msg, 0, 0, v, 1);
3897
3898 if (entry != NULL)
3899 xs_html_add(lists,
3900 entry);
3901 }
3902
3903 if (show_more) {
3904 xs *m = NULL;
3905 xs *m10 = NULL;
3906 xs *ss = xs_fmt("skip=%d&show=%d", skip + show, show);
3907
3908 xs *url = xs_dup(user == NULL ? srv_baseurl : user->actor);
3909
3910 if (page != NULL)
3911 url = xs_str_cat(url, page);
3912
3913 if (xs_str_in(url, "?") != -1)
3914 m = xs_fmt("%s&%s", url, ss);
3915 else
3916 m = xs_fmt("%s?%s", url, ss);
3917 m10 = xs_fmt("%s0", m);
3918
3919 xs_html *more_links = xs_html_tag("p",
3920 xs_html_tag("a",
3921 xs_html_attr("href", url),
3922 xs_html_attr("name", "snac-more"),
3923 xs_html_text(L("Back to top"))),
3924 xs_html_text(" - "),
3925 xs_html_tag("a",
3926 xs_html_attr("href", m),
3927 xs_html_attr("name", "snac-more"),
3928 xs_html_text(L("More..."))),
3929 xs_html_text(" - "),
3930 xs_html_tag("a",
3931 xs_html_attr("href", m10),
3932 xs_html_attr("name", "snac-more"),
3933 xs_html_text(L("More (x 10)..."))));
3934
3935 xs_html_add(body,
3936 more_links);
3937 }
3873 3938
3874 xs_html *html = xs_html_tag("html", 3939 xs_html *html = xs_html_tag("html",
3875 html_user_head(user, NULL, NULL), 3940 html_user_head(user, NULL, NULL),
3876 xs_html_add(html_user_body(user, 0), 3941 xs_html_add(body,
3877 lists,
3878 html_footer(user))); 3942 html_footer(user)));
3879 3943
3880 return xs_html_render_s(html, "<!DOCTYPE html>\n"); 3944 return xs_html_render_s(html, "<!DOCTYPE html>\n");
@@ -4578,7 +4642,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
4578 } 4642 }
4579 } 4643 }
4580 else 4644 else
4581 if (xs_startswith(p_path, "people/")) { /** the list of people **/ 4645 if (xs_startswith(p_path, "people/")) { /** a single actor **/
4582 if (!login(&snac, req)) { 4646 if (!login(&snac, req)) {
4583 *body = xs_dup(uid); 4647 *body = xs_dup(uid);
4584 status = HTTP_STATUS_UNAUTHORIZED; 4648 status = HTTP_STATUS_UNAUTHORIZED;
@@ -4587,11 +4651,18 @@ int html_get_handler(const xs_dict *req, const char *q_path,
4587 xs *actor_dict = NULL; 4651 xs *actor_dict = NULL;
4588 const char *actor_id = NULL; 4652 const char *actor_id = NULL;
4589 xs *actor = NULL; 4653 xs *actor = NULL;
4654 xs_list *page_lst = xs_split_n(p_path, "?", 2);
4655 xs *page = xs_str_cat(xs_str_new("/"), xs_list_get(page_lst, 0));
4656 xs_list *l = xs_split_n(page, "/", 3);
4657 const char *actor_md5 = xs_list_get(l, 2);
4590 4658
4591 if (valid_status(object_get_by_md5(p_path + strlen("people/"), &actor_dict)) && 4659 if (valid_status(object_get_by_md5(actor_md5, &actor_dict)) &&
4592 (actor_id = xs_dict_get(actor_dict, "id")) != NULL && 4660 (actor_id = xs_dict_get(actor_dict, "id")) != NULL &&
4593 valid_status(actor_get(actor_id, &actor))) { 4661 valid_status(actor_get(actor_id, &actor))) {
4594 *body = html_people_one(&snac, actor_id); 4662 int more = 0;
4663 xs *list = timeline_list(&snac, "private", skip, show, &more);
4664
4665 *body = html_people_one(&snac, actor_id, list, skip, show, more, page);
4595 *b_size = strlen(*body); 4666 *b_size = strlen(*body);
4596 status = HTTP_STATUS_OK; 4667 status = HTTP_STATUS_OK;
4597 } 4668 }