From 1fd14a850dd1100429fd38023666b6d53fb6c9af Mon Sep 17 00:00:00 2001 From: default Date: Wed, 2 Nov 2022 10:13:14 +0100 Subject: [PATCH] People page started. --- activitypub.c | 10 +++- html.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 140 insertions(+), 4 deletions(-) diff --git a/activitypub.c b/activitypub.c index f3c7093..164c6e6 100644 --- a/activitypub.c +++ b/activitypub.c @@ -530,8 +530,14 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char if (rcpts == NULL) to = xs_list_new(); - else - to = xs_dup(rcpts); + else { + if (xs_type(rcpts) == XSTYPE_STRING) { + to = xs_list_new(); + to = xs_list_append(to, rcpts); + } + else + to = xs_dup(rcpts); + } /* format the content */ not_really_markdown(content, &fc2); diff --git a/html.c b/html.c index f49274e..80b7f43 100644 --- a/html.c +++ b/html.c @@ -194,7 +194,10 @@ d_char *html_user_header(snac *snac, d_char *s, int local) s1 = xs_fmt("%s\n", snac->actor, L("admin")); else - s1 = xs_fmt("%s\n", snac->actor, L("public")); + s1 = xs_fmt( + "%s - %s\n", + snac->actor, L("public"), + snac->actor, L("people")); s = xs_str_cat(s, s1); } @@ -817,6 +820,116 @@ d_char *html_timeline(snac *snac, char *list, int local) } +d_char *html_people(snac *snac) +{ + d_char *s = xs_str_new(NULL); + xs *wers = NULL; + xs *wing = NULL; + char *p, *v; + + s = html_user_header(snac, s, 0); + + s = xs_str_cat(s, "

"); + s = xs_str_cat(s, L("People you follow")); + s = xs_str_cat(s, "

\n"); + + s = xs_str_cat(s, "

"); + s = xs_str_cat(s, L("People that follows you")); + s = xs_str_cat(s, "

\n"); + + p = wers = follower_list(snac); + while (xs_list_iter(&p, &v)) { + char *actor_id = xs_dict_get(v, "actor"); + xs *md5 = xs_md5_hex(actor_id, strlen(actor_id)); + xs *actor; + + if (valid_status(actor_get(snac, actor_id, &actor))) { + s = xs_str_cat(s, "
\n"); + + s = html_actor_icon(snac, s, actor, NULL, NULL, 0); + + + /* content (user bio) */ + char *c = xs_dict_get(actor, "summary"); + + if (!xs_is_null(c)) { + s = xs_str_cat(s, "
\n"); + + xs *sc = sanitize(c); + + if (xs_startswith(sc, "

")) + s = xs_str_cat(s, sc); + else { + xs *s1 = xs_fmt("

%s

", sc); + s = xs_str_cat(s, s1); + } + + s = xs_str_cat(s, "
\n"); + } + + + /* buttons */ + s = xs_str_cat(s, "
\n"); + + xs *s1 = xs_fmt( + "
\n" + "\n" + "\n", + + snac->actor, actor_id, + L("DM"), + md5 + ); + s = xs_str_cat(s, s1); + + s = html_button(s, "unfollow", L("Unfollow")); + + if (is_muted(snac, actor_id)) + s = html_button(s, "unmute", L("Unmute")); + else + s = html_button(s, "mute", L("MUTE")); + + s = xs_str_cat(s, "
\n"); + + /* the post textarea */ + xs *s2 = xs_fmt( + "

\n" + "
\n" + "\n" + "\n" + "

\n" + "

\n" + "

\n", + + md5, + snac->actor, md5, + actor_id, + L("Post") + ); + s = xs_str_cat(s, s2); + + s = xs_str_cat(s, "
\n"); + + s = xs_str_cat(s, "
\n"); + } + } + + s = html_user_footer(snac, s); + + s = xs_str_cat(s, "\n\n"); + + return s; +} + + int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype) { int status = 404; @@ -889,6 +1002,18 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char * } } else + if (strcmp(p_path, "people") == 0) { + /* the list of people */ + + if (!login(&snac, req)) + status = 401; + else { + *body = html_people(&snac); + *b_size = strlen(*body); + status = 200; + } + } + else if (xs_startswith(p_path, "p/")) { /* a timeline with just one entry */ xs *id = xs_fmt("%s/%s", snac.actor, p_path); @@ -980,6 +1105,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, char *in_reply_to = xs_dict_get(p_vars, "in_reply_to"); char *attach_url = xs_dict_get(p_vars, "attach_url"); char *attach_file = xs_dict_get(p_vars, "attach"); + char *to = xs_dict_get(p_vars, "to"); xs *attach_list = xs_list_new(); /* is attach_url set? */ @@ -1010,7 +1136,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, xs *c_msg = NULL; xs *content_2 = xs_replace(content, "\r", ""); - msg = msg_note(&snac, content_2, NULL, in_reply_to, attach_list); + msg = msg_note(&snac, content_2, to, in_reply_to, attach_list); c_msg = msg_create(&snac, msg); @@ -1051,6 +1177,10 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, mute(&snac, actor); } else + if (strcmp(action, L("Unmute")) == 0) { + unmute(&snac, actor); + } + else if (strcmp(action, L("Follow")) == 0) { xs *msg = msg_follow(&snac, actor);