diff options
| author | 2022-11-02 06:41:40 +0100 | |
|---|---|---|
| committer | 2022-11-02 06:41:40 +0100 | |
| commit | 2fd5f6fc617623e5cdb8016707843e2950d8a42d (patch) | |
| tree | 4b0d6de56b6530613b03f062bd6f89ba6e552311 /html.c | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-2fd5f6fc617623e5cdb8016707843e2950d8a42d.tar.gz snac2-2fd5f6fc617623e5cdb8016707843e2950d8a42d.tar.xz snac2-2fd5f6fc617623e5cdb8016707843e2950d8a42d.zip | |
Split html_actor_icon() from html_msg_icon().
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 141 |
1 files changed, 80 insertions, 61 deletions
| @@ -37,94 +37,113 @@ int login(snac *snac, char *headers) | |||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | d_char *html_msg_icon(snac *snac, d_char *os, char *msg) | 40 | d_char *html_actor_icon(snac *snac, d_char *os, char *actor, char *date, char *url, int priv) |
| 41 | { | 41 | { |
| 42 | char *actor_id; | ||
| 43 | xs *actor = NULL; | ||
| 44 | |||
| 45 | xs *s = xs_str_new(NULL); | 42 | xs *s = xs_str_new(NULL); |
| 46 | 43 | ||
| 47 | if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL) | 44 | xs *name = NULL; |
| 48 | actor_id = xs_dict_get(msg, "actor"); | 45 | xs *avatar = NULL; |
| 49 | 46 | char *p, *v; | |
| 50 | if (actor_id && valid_status(actor_get(snac, actor_id, &actor))) { | ||
| 51 | xs *name = NULL; | ||
| 52 | xs *avatar = NULL; | ||
| 53 | char *p, *v; | ||
| 54 | 47 | ||
| 55 | /* get the name */ | 48 | /* get the name */ |
| 56 | if (xs_is_null((v = xs_dict_get(actor, "name"))) || *v == '\0') { | 49 | if (xs_is_null((v = xs_dict_get(actor, "name"))) || *v == '\0') { |
| 57 | if (xs_is_null(v = xs_dict_get(actor, "preferredUsername"))) { | 50 | if (xs_is_null(v = xs_dict_get(actor, "preferredUsername"))) { |
| 58 | v = "user"; | 51 | v = "user"; |
| 59 | } | ||
| 60 | } | 52 | } |
| 53 | } | ||
| 61 | 54 | ||
| 62 | name = xs_dup(v); | 55 | name = xs_dup(v); |
| 63 | 56 | ||
| 64 | /* replace the :shortnames: */ | 57 | /* replace the :shortnames: */ |
| 65 | if (!xs_is_null(p = xs_dict_get(actor, "tag"))) { | 58 | if (!xs_is_null(p = xs_dict_get(actor, "tag"))) { |
| 66 | /* iterate the tags */ | 59 | /* iterate the tags */ |
| 67 | while (xs_list_iter(&p, &v)) { | 60 | while (xs_list_iter(&p, &v)) { |
| 68 | char *t = xs_dict_get(v, "type"); | 61 | char *t = xs_dict_get(v, "type"); |
| 69 | 62 | ||
| 70 | if (t && strcmp(t, "Emoji") == 0) { | 63 | if (t && strcmp(t, "Emoji") == 0) { |
| 71 | char *n = xs_dict_get(v, "name"); | 64 | char *n = xs_dict_get(v, "name"); |
| 72 | char *i = xs_dict_get(v, "icon"); | 65 | char *i = xs_dict_get(v, "icon"); |
| 73 | 66 | ||
| 74 | if (n && i) { | 67 | if (n && i) { |
| 75 | char *u = xs_dict_get(i, "url"); | 68 | char *u = xs_dict_get(i, "url"); |
| 76 | xs *img = xs_fmt("<img src=\"%s\" style=\"height: 1em\"/>", u); | 69 | xs *img = xs_fmt("<img src=\"%s\" style=\"height: 1em\"/>", u); |
| 77 | 70 | ||
| 78 | name = xs_replace_i(name, n, img); | 71 | name = xs_replace_i(name, n, img); |
| 79 | } | ||
| 80 | } | 72 | } |
| 81 | } | 73 | } |
| 82 | } | 74 | } |
| 75 | } | ||
| 83 | 76 | ||
| 84 | /* get the avatar */ | 77 | /* get the avatar */ |
| 85 | if ((v = xs_dict_get(actor, "icon")) != NULL && | 78 | if ((v = xs_dict_get(actor, "icon")) != NULL && |
| 86 | (v = xs_dict_get(v, "url")) != NULL) { | 79 | (v = xs_dict_get(v, "url")) != NULL) { |
| 87 | avatar = xs_dup(v); | 80 | avatar = xs_dup(v); |
| 88 | } | 81 | } |
| 89 | 82 | ||
| 90 | if (avatar == NULL) | 83 | if (avatar == NULL) |
| 91 | avatar = xs_fmt("data:image/png;base64, %s", susie); | 84 | avatar = xs_fmt("data:image/png;base64, %s", susie); |
| 92 | 85 | ||
| 93 | { | 86 | { |
| 94 | xs *s1 = xs_fmt("<p><img class=\"snac-avatar\" src=\"%s\" alt=\"\"/>\n", avatar); | 87 | xs *s1 = xs_fmt("<p><img class=\"snac-avatar\" src=\"%s\" alt=\"\"/>\n", avatar); |
| 95 | s = xs_str_cat(s, s1); | 88 | s = xs_str_cat(s, s1); |
| 96 | } | 89 | } |
| 97 | 90 | ||
| 98 | { | 91 | { |
| 99 | xs *s1 = xs_fmt("<a href=\"%s\" class=\"p-author h-card snac-author\">%s</a>", | 92 | xs *s1 = xs_fmt("<a href=\"%s\" class=\"p-author h-card snac-author\">%s</a>", |
| 100 | actor_id, name); | 93 | xs_dict_get(actor, "id"), name); |
| 101 | s = xs_str_cat(s, s1); | 94 | s = xs_str_cat(s, s1); |
| 102 | } | 95 | } |
| 103 | 96 | ||
| 104 | if (strcmp(xs_dict_get(msg, "type"), "Note") == 0) { | 97 | if (!xs_is_null(url)) { |
| 105 | xs *s1 = xs_fmt(" <a href=\"%s\">»</a>", xs_dict_get(msg, "id")); | 98 | xs *s1 = xs_fmt(" <a href=\"%s\">»</a>", url); |
| 106 | s = xs_str_cat(s, s1); | 99 | s = xs_str_cat(s, s1); |
| 107 | } | 100 | } |
| 108 | 101 | ||
| 109 | if (!is_msg_public(snac, msg)) | 102 | if (priv) |
| 110 | s = xs_str_cat(s, " <span title=\"private\">🔒</span>"); | 103 | s = xs_str_cat(s, " <span title=\"private\">🔒</span>"); |
| 111 | 104 | ||
| 112 | if ((v = xs_dict_get(msg, "published")) == NULL) { | 105 | if (xs_is_null(date)) { |
| 113 | s = xs_str_cat(s, "<br>\n<time> </time>\n"); | 106 | s = xs_str_cat(s, "<br>\n \n"); |
| 114 | } | 107 | } |
| 115 | else { | 108 | else { |
| 116 | xs *sd = xs_crop(xs_dup(v), 0, 10); | 109 | xs *sd = xs_crop(xs_dup(date), 0, 10); |
| 117 | xs *s1 = xs_fmt( | 110 | xs *s1 = xs_fmt( |
| 118 | "<br>\n<time class=\"dt-published snac-pubdate\">%s</time>\n", sd); | 111 | "<br>\n<time class=\"dt-published snac-pubdate\">%s</time>\n", sd); |
| 119 | 112 | ||
| 120 | s = xs_str_cat(s, s1); | 113 | s = xs_str_cat(s, s1); |
| 121 | } | ||
| 122 | } | 114 | } |
| 123 | 115 | ||
| 124 | return xs_str_cat(os, s); | 116 | return xs_str_cat(os, s); |
| 125 | } | 117 | } |
| 126 | 118 | ||
| 127 | 119 | ||
| 120 | d_char *html_msg_icon(snac *snac, d_char *os, char *msg) | ||
| 121 | { | ||
| 122 | char *actor_id; | ||
| 123 | xs *actor = NULL; | ||
| 124 | |||
| 125 | if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL) | ||
| 126 | actor_id = xs_dict_get(msg, "actor"); | ||
| 127 | |||
| 128 | if (actor_id && valid_status(actor_get(snac, actor_id, &actor))) { | ||
| 129 | char *date = NULL; | ||
| 130 | char *url = NULL; | ||
| 131 | int priv = 0; | ||
| 132 | |||
| 133 | if (strcmp(xs_dict_get(msg, "type"), "Note") == 0) | ||
| 134 | url = xs_dict_get(msg, "id"); | ||
| 135 | |||
| 136 | priv = !is_msg_public(snac, msg); | ||
| 137 | |||
| 138 | date = xs_dict_get(msg, "published"); | ||
| 139 | |||
| 140 | os = html_actor_icon(snac, os, actor, date, url, priv); | ||
| 141 | } | ||
| 142 | |||
| 143 | return os; | ||
| 144 | } | ||
| 145 | |||
| 146 | |||
| 128 | d_char *html_user_header(snac *snac, d_char *s, int local) | 147 | d_char *html_user_header(snac *snac, d_char *s, int local) |
| 129 | /* creates the HTML header */ | 148 | /* creates the HTML header */ |
| 130 | { | 149 | { |