From 233d7d8a10bbef5200b5026bb59acfe5d8a252fd Mon Sep 17 00:00:00 2001
From: default
Date: Wed, 28 Sep 2022 15:41:07 +0200
Subject: More HTML work.
---
html.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 92 insertions(+), 1 deletion(-)
(limited to 'html.c')
diff --git a/html.c b/html.c
index 8160b4e..b2c75fe 100644
--- a/html.c
+++ b/html.c
@@ -372,12 +372,84 @@ d_char *html_top_controls(snac *snac, d_char *s)
d_char *html_entry(snac *snac, d_char *s, char *msg, xs_set *seen, int level)
{
- char *id = xs_dict_get(msg, "id");
+ char *id = xs_dict_get(msg, "id");
+ char *type = xs_dict_get(msg, "type");
+ char *meta = xs_dict_get(msg, "_snac");
+ xs *actor_o = NULL;
+ char *actor;
/* return if already seen */
if (xs_set_add(seen, id) == 0)
return s;
+ if (strcmp(type, "Follow") == 0)
+ return s;
+
+ /* bring the main actor */
+ if ((actor = xs_dict_get(msg, "attributedTo")) == NULL)
+ return s;
+
+ if (!valid_status(actor_get(snac, actor, &actor_o)))
+ return s;
+
+ if (level == 0) {
+ char *referrer;
+
+ s = xs_str_cat(s, "
\n");
+
+ /* print the origin of the post, if any */
+ if ((referrer = xs_dict_get(meta, "referrer")) != NULL) {
+ xs *actor_r = NULL;
+
+ if (valid_status(actor_get(snac, referrer, &actor_r))) {
+ char *name;
+
+ if ((name = xs_dict_get(actor_r, "name")) == NULL)
+ name = xs_dict_get(actor_r, "preferredUsername");
+
+ xs *s1 = xs_fmt(
+ "
",
+ xs_dict_get(actor_r, "id"),
+ name,
+ "boosted"
+ );
+
+ s = xs_str_cat(s, s1);
+ }
+ }
+ }
+ else
+ s = xs_str_cat(s, "
\n");
+
+ s = html_msg_icon(snac, s, msg);
+
+ /* add the content */
+ {
+ xs *c = xs_dup(xs_dict_get(msg, "content"));
+
+ /* do some tweaks to the content */
+ c = xs_replace_i(c, "\r", "");
+
+ while (xs_endswith(c, "
"))
+ c = xs_crop(c, 0, -4);
+
+ c = xs_replace_i(c, "
", "
");
+
+ if (!xs_startswith(c, "
")) {
+ xs *s1 = c;
+ c = xs_fmt("
%s
", s1);
+ }
+
+ xs *s1 = xs_fmt("
\n%s", c);
+
+ s = xs_str_cat(s, s1);
+
+ s = xs_str_cat(s, "
\n");
+ }
+
+ s = xs_str_cat(s, "
\n");
+
return s;
}
@@ -394,12 +466,16 @@ d_char *html_timeline(snac *snac, char *list, int local)
if (!local)
s = html_top_controls(snac, s);
+ s = xs_str_cat(s, "
\n");
+
while (xs_list_iter(&list, &v)) {
xs *msg = timeline_get(snac, v);
s = html_entry(snac, s, msg, seen, 0);
}
+ s = xs_str_cat(s, "
\n");
+
#if 0
s = xs_str_cat(s, "
HI
\n");
@@ -415,6 +491,21 @@ d_char *html_timeline(snac *snac, char *list, int local)
s = xs_str_cat(s, "