From fc6a12514643c9d19d0ddfbda37d79a0ae42f6d2 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 28 Sep 2022 07:05:23 +0200 Subject: New function html_msg_icon(). --- html.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 146 insertions(+), 1 deletion(-) (limited to 'html.c') diff --git a/html.c b/html.c index 8745c8b..7f8e990 100644 --- a/html.c +++ b/html.c @@ -142,9 +142,154 @@ int login(snac *snac, char *headers) } +d_char *html_msg_icon(snac *snac, d_char *s, 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))) { + xs *name = NULL; + xs *avatar = NULL; + char *v; + + /* get the name */ + if ((v = xs_dict_get(actor, "name")) == NULL) { + if ((v = xs_dict_get(actor, "preferredUsername")) == NULL) { + v = "user"; + } + } + + name = 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); + + { + xs *s1 = xs_fmt("
\n", avatar);
+ s = xs_str_cat(s, s1);
+ }
+
+ {
+ xs *s1 = xs_fmt("%s",
+ actor, name);
+ s = xs_str_cat(s, s1);
+ }
+
+ if (strcmp(xs_dict_get(msg, "type"), "Note") == 0) {
+ xs *s1 = xs_fmt(" ยป", xs_dict_get(msg, "id"));
+ s = xs_str_cat(s, s1);
+ }
+
+ if (!is_msg_public(snac, msg))
+ s = xs_str_cat(s, " 🔒");
+
+ if ((v = xs_dict_get(msg, "published")) == NULL)
+ v = " ";
+
+ {
+ xs *s1 = xs_fmt("
\n\n", v);
+ s = xs_str_cat(s, s1);
+ }
+
+ s = xs_str_cat(s, "\n");
+ }
+
+ return s;
+}
+
+
+d_char *html_timeline(snac *snac, char *list, int local)
+/* returns the HTML for the timeline */
+{
+ d_char *s = xs_str_new(NULL);
+
+ s = xs_str_cat(s, "\n\n");
+
+ s = xs_str_cat(s, "