summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-11-02 06:41:40 +0100
committerdefault <nobody@localhost>2022-11-02 06:41:40 +0100
commit2fd5f6fc617623e5cdb8016707843e2950d8a42d (patch)
tree4b0d6de56b6530613b03f062bd6f89ba6e552311
parent9fafa78dc23100eb6de908be6a69b547005b60f6 (diff)
Split html_actor_icon() from html_msg_icon().
-rw-r--r--html.c141
1 files changed, 80 insertions, 61 deletions
diff --git a/html.c b/html.c
index dc5ee19..f49274e 100644
--- a/html.c
+++ b/html.c
@@ -37,94 +37,113 @@ int login(snac *snac, char *headers)
}
-d_char *html_msg_icon(snac *snac, d_char *os, char *msg)
+d_char *html_actor_icon(snac *snac, d_char *os, char *actor, char *date, char *url, int priv)
{
- char *actor_id;
- xs *actor = NULL;
-
xs *s = xs_str_new(NULL);
- if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL)
- actor_id = xs_dict_get(msg, "actor");
-
- if (actor_id && valid_status(actor_get(snac, actor_id, &actor))) {
- xs *name = NULL;
- xs *avatar = NULL;
- char *p, *v;
+ 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";
- }
+ /* 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";
}
+ }
- name = xs_dup(v);
+ name = xs_dup(v);
- /* replace the :shortnames: */
- if (!xs_is_null(p = xs_dict_get(actor, "tag"))) {
- /* iterate the tags */
- while (xs_list_iter(&p, &v)) {
- char *t = xs_dict_get(v, "type");
+ /* replace the :shortnames: */
+ if (!xs_is_null(p = xs_dict_get(actor, "tag"))) {
+ /* iterate the tags */
+ while (xs_list_iter(&p, &v)) {
+ char *t = xs_dict_get(v, "type");
- if (t && strcmp(t, "Emoji") == 0) {
- char *n = xs_dict_get(v, "name");
- char *i = xs_dict_get(v, "icon");
+ if (t && strcmp(t, "Emoji") == 0) {
+ char *n = xs_dict_get(v, "name");
+ char *i = xs_dict_get(v, "icon");
- if (n && i) {
- char *u = xs_dict_get(i, "url");
- xs *img = xs_fmt("<img src=\"%s\" style=\"height: 1em\"/>", u);
+ if (n && i) {
+ char *u = xs_dict_get(i, "url");
+ xs *img = xs_fmt("<img src=\"%s\" style=\"height: 1em\"/>", u);
- name = xs_replace_i(name, n, img);
- }
+ name = xs_replace_i(name, n, img);
}
}
}
+ }
- /* get the avatar */
- if ((v = xs_dict_get(actor, "icon")) != NULL &&
- (v = xs_dict_get(v, "url")) != NULL) {
- avatar = xs_dup(v);
- }
+ /* get the avatar */
+ if ((v = xs_dict_get(actor, "icon")) != NULL &&
+ (v = xs_dict_get(v, "url")) != NULL) {
+ avatar = xs_dup(v);
+ }
- if (avatar == NULL)
- avatar = xs_fmt("data:image/png;base64, %s", susie);
+ if (avatar == NULL)
+ avatar = xs_fmt("data:image/png;base64, %s", susie);
- {
- xs *s1 = xs_fmt("<p><img class=\"snac-avatar\" src=\"%s\" alt=\"\"/>\n", avatar);
- s = xs_str_cat(s, s1);
- }
+ {
+ xs *s1 = xs_fmt("<p><img class=\"snac-avatar\" src=\"%s\" alt=\"\"/>\n", avatar);
+ s = xs_str_cat(s, s1);
+ }
- {
- xs *s1 = xs_fmt("<a href=\"%s\" class=\"p-author h-card snac-author\">%s</a>",
- actor_id, name);
- s = xs_str_cat(s, s1);
- }
+ {
+ xs *s1 = xs_fmt("<a href=\"%s\" class=\"p-author h-card snac-author\">%s</a>",
+ xs_dict_get(actor, "id"), name);
+ s = xs_str_cat(s, s1);
+ }
- if (strcmp(xs_dict_get(msg, "type"), "Note") == 0) {
- xs *s1 = xs_fmt(" <a href=\"%s\">»</a>", xs_dict_get(msg, "id"));
- s = xs_str_cat(s, s1);
- }
+ if (!xs_is_null(url)) {
+ xs *s1 = xs_fmt(" <a href=\"%s\">»</a>", url);
+ s = xs_str_cat(s, s1);
+ }
- if (!is_msg_public(snac, msg))
- s = xs_str_cat(s, " <span title=\"private\">&#128274;</span>");
+ if (priv)
+ s = xs_str_cat(s, " <span title=\"private\">&#128274;</span>");
- if ((v = xs_dict_get(msg, "published")) == NULL) {
- s = xs_str_cat(s, "<br>\n<time>&nbsp;</time>\n");
- }
- else {
- xs *sd = xs_crop(xs_dup(v), 0, 10);
- xs *s1 = xs_fmt(
- "<br>\n<time class=\"dt-published snac-pubdate\">%s</time>\n", sd);
+ if (xs_is_null(date)) {
+ s = xs_str_cat(s, "<br>\n&nbsp;\n");
+ }
+ else {
+ xs *sd = xs_crop(xs_dup(date), 0, 10);
+ xs *s1 = xs_fmt(
+ "<br>\n<time class=\"dt-published snac-pubdate\">%s</time>\n", sd);
- s = xs_str_cat(s, s1);
- }
+ s = xs_str_cat(s, s1);
}
return xs_str_cat(os, s);
}
+d_char *html_msg_icon(snac *snac, d_char *os, char *msg)
+{
+ char *actor_id;
+ xs *actor = NULL;
+
+ if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL)
+ actor_id = xs_dict_get(msg, "actor");
+
+ if (actor_id && valid_status(actor_get(snac, actor_id, &actor))) {
+ char *date = NULL;
+ char *url = NULL;
+ int priv = 0;
+
+ if (strcmp(xs_dict_get(msg, "type"), "Note") == 0)
+ url = xs_dict_get(msg, "id");
+
+ priv = !is_msg_public(snac, msg);
+
+ date = xs_dict_get(msg, "published");
+
+ os = html_actor_icon(snac, os, actor, date, url, priv);
+ }
+
+ return os;
+}
+
+
d_char *html_user_header(snac *snac, d_char *s, int local)
/* creates the HTML header */
{