commit 9fb84bcb3aa4c6a8061e4b892dc5bd1826b44715
parent 96576d2c5df41b91e915a31d5c0c039f4852f583
Author: default <nobody@localhost>
Date: Sun, 24 Nov 2024 08:54:43 +0100
The people page shows 'Approve' and 'Discard' buttons for pending follows.
Diffstat:
M | data.c | | | 20 | +++++++++++++++----- |
M | html.c | | | 29 | +++++++++++++++++++++++------ |
2 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/data.c b/data.c
@@ -1270,12 +1270,22 @@ xs_list *pending_list(snac *user)
const char *v;
xs_list_foreach(l, v) {
- const char *actor = xs_dict_get(v, "actor");
+ FILE *f;
+ xs *msg = NULL;
- if (xs_type(actor) == XSTYPE_STRING) {
- xs *md5 = xs_md5_hex(actor, strlen(actor));
- r = xs_list_append(r, md5);
- }
+ if ((f = fopen(v, "r")) == NULL)
+ continue;
+
+ msg = xs_json_load(f);
+ fclose(f);
+
+ if (msg == NULL)
+ continue;
+
+ const char *actor = xs_dict_get(msg, "actor");
+
+ if (xs_type(actor) == XSTYPE_STRING)
+ r = xs_list_append(r, actor);
}
return r;
diff --git a/html.c b/html.c
@@ -2470,10 +2470,9 @@ xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t, cons
xs_html_tag("summary",
xs_html_text("..."))));
- xs_list *p = list;
const char *actor_id;
- while (xs_list_iter(&p, &actor_id)) {
+ xs_list_foreach(list, actor_id) {
xs *md5 = xs_md5_hex(actor_id, strlen(actor_id));
xs *actor = NULL;
@@ -2542,6 +2541,14 @@ xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t, cons
html_button("limit", L("Limit"),
L("Block announces (boosts) from this user")));
}
+ if (pending_check(snac, actor_id)) {
+ xs_html_add(form,
+ html_button("approve", L("Approve"),
+ L("Approve this follow request")));
+
+ xs_html_add(form,
+ html_button("discard", L("Discard"), L("Discard this follow request")));
+ }
else {
xs_html_add(form,
html_button("follow", L("Follow"),
@@ -2596,13 +2603,23 @@ xs_str *html_people(snac *user)
xs *wing = following_list(user);
xs *wers = follower_list(user);
+ xs_html *lists = xs_html_tag("div",
+ xs_html_attr("class", "snac-posts"));
+
+ if (xs_is_true(xs_dict_get(user->config, "approve_followers"))) {
+ xs *pending = pending_list(user);
+ xs_html_add(lists,
+ html_people_list(user, pending, L("Pending follow confirmations"), "p", proxy));
+ }
+
+ xs_html_add(lists,
+ html_people_list(user, wing, L("People you follow"), "i", proxy),
+ html_people_list(user, wers, L("People that follow you"), "e", proxy));
+
xs_html *html = xs_html_tag("html",
html_user_head(user, NULL, NULL),
xs_html_add(html_user_body(user, 0),
- xs_html_tag("div",
- xs_html_attr("class", "snac-posts"),
- html_people_list(user, wing, L("People you follow"), "i", proxy),
- html_people_list(user, wers, L("People that follow you"), "e", proxy)),
+ lists,
html_footer()));
return xs_html_render_s(html, "<!DOCTYPE html>\n");