diff options
| author | 2023-02-23 09:22:13 +0100 | |
|---|---|---|
| committer | 2023-02-23 09:22:13 +0100 | |
| commit | 90838f07c69d21f1629e208e503257ffd9c91fe0 (patch) | |
| tree | a4f83743c82f7cf5b4d5cc9fc768888e6a66a69e | |
| parent | Updated TODO. (diff) | |
| download | penes-snac2-90838f07c69d21f1629e208e503257ffd9c91fe0.tar.gz penes-snac2-90838f07c69d21f1629e208e503257ffd9c91fe0.tar.xz penes-snac2-90838f07c69d21f1629e208e503257ffd9c91fe0.zip | |
Minor actor name code refactoring.
| -rw-r--r-- | html.c | 36 |
1 files changed, 22 insertions, 14 deletions
| @@ -37,19 +37,16 @@ int login(snac *snac, char *headers) | |||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | d_char *html_actor_icon(snac *snac, d_char *os, char *actor, | 40 | xs_str *actor_name(xs_dict *actor) |
| 41 | const char *date, const char *udate, const char *url, int priv) | 41 | /* gets the actor name */ |
| 42 | { | 42 | { |
| 43 | xs *s = xs_str_new(NULL); | 43 | xs_list *p; |
| 44 | 44 | char *v; | |
| 45 | xs *name = NULL; | 45 | xs_str *name; |
| 46 | xs *avatar = NULL; | ||
| 47 | char *p, *v; | ||
| 48 | 46 | ||
| 49 | /* get the name */ | ||
| 50 | if (xs_is_null((v = xs_dict_get(actor, "name"))) || *v == '\0') { | 47 | if (xs_is_null((v = xs_dict_get(actor, "name"))) || *v == '\0') { |
| 51 | if (xs_is_null(v = xs_dict_get(actor, "preferredUsername"))) { | 48 | if (xs_is_null(v = xs_dict_get(actor, "preferredUsername")) || *v == '\0') { |
| 52 | v = "user"; | 49 | v = "anonymous"; |
| 53 | } | 50 | } |
| 54 | } | 51 | } |
| 55 | 52 | ||
| @@ -75,6 +72,20 @@ d_char *html_actor_icon(snac *snac, d_char *os, char *actor, | |||
| 75 | } | 72 | } |
| 76 | } | 73 | } |
| 77 | 74 | ||
| 75 | return name; | ||
| 76 | } | ||
| 77 | |||
| 78 | |||
| 79 | d_char *html_actor_icon(snac *snac, d_char *os, char *actor, | ||
| 80 | const char *date, const char *udate, const char *url, int priv) | ||
| 81 | { | ||
| 82 | xs *s = xs_str_new(NULL); | ||
| 83 | |||
| 84 | xs *avatar = NULL; | ||
| 85 | char *v; | ||
| 86 | |||
| 87 | xs *name = actor_name(actor); | ||
| 88 | |||
| 78 | /* get the avatar */ | 89 | /* get the avatar */ |
| 79 | if ((v = xs_dict_get(actor, "icon")) != NULL && | 90 | if ((v = xs_dict_get(actor, "icon")) != NULL && |
| 80 | (v = xs_dict_get(v, "url")) != NULL) { | 91 | (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 | |||
| 708 | } | 719 | } |
| 709 | else | 720 | else |
| 710 | if (valid_status(object_get_by_md5(p, &actor_r))) { | 721 | if (valid_status(object_get_by_md5(p, &actor_r))) { |
| 711 | char *name; | 722 | xs *name = actor_name(actor_r); |
| 712 | |||
| 713 | if ((name = xs_dict_get(actor_r, "name")) == NULL) | ||
| 714 | name = xs_dict_get(actor_r, "preferredUsername"); | ||
| 715 | 723 | ||
| 716 | if (!xs_is_null(name)) { | 724 | if (!xs_is_null(name)) { |
| 717 | xs *s1 = xs_fmt( | 725 | xs *s1 = xs_fmt( |