From 90838f07c69d21f1629e208e503257ffd9c91fe0 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 23 Feb 2023 09:22:13 +0100 Subject: [PATCH] Minor actor name code refactoring. --- html.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/html.c b/html.c index 6abadaa..a733834 100644 --- a/html.c +++ b/html.c @@ -37,19 +37,16 @@ int login(snac *snac, char *headers) } -d_char *html_actor_icon(snac *snac, d_char *os, char *actor, - const char *date, const char *udate, const char *url, int priv) +xs_str *actor_name(xs_dict *actor) +/* gets the actor name */ { - xs *s = xs_str_new(NULL); + xs_list *p; + char *v; + xs_str *name; - xs *name = NULL; - xs *avatar = NULL; - char *p, *v; - - /* get the name */ if (xs_is_null((v = xs_dict_get(actor, "name"))) || *v == '\0') { - if (xs_is_null(v = xs_dict_get(actor, "preferredUsername"))) { - v = "user"; + if (xs_is_null(v = xs_dict_get(actor, "preferredUsername")) || *v == '\0') { + v = "anonymous"; } } @@ -75,6 +72,20 @@ d_char *html_actor_icon(snac *snac, d_char *os, char *actor, } } + return name; +} + + +d_char *html_actor_icon(snac *snac, d_char *os, char *actor, + const char *date, const char *udate, const char *url, int priv) +{ + xs *s = xs_str_new(NULL); + + xs *avatar = NULL; + char *v; + + xs *name = actor_name(actor); + /* get the avatar */ if ((v = xs_dict_get(actor, "icon")) != NULL && (v = xs_dict_get(v, "url")) != NULL) { @@ -708,10 +719,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, cons } else if (valid_status(object_get_by_md5(p, &actor_r))) { - char *name; - - if ((name = xs_dict_get(actor_r, "name")) == NULL) - name = xs_dict_get(actor_r, "preferredUsername"); + xs *name = actor_name(actor_r); if (!xs_is_null(name)) { xs *s1 = xs_fmt(