\n",
md5,
snac->actor, md5,
ct,
id,
L("Post")
);
s = xs_str_cat(s, s1);
}
s = xs_str_cat(s, "
\n");
return xs_str_cat(os, s);
}
d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, int level)
{
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;
/* do not show non-public messages in the public timeline */
if (local && !is_msg_public(snac, msg))
return os;
/* return if already seen */
if (xs_set_add(seen, id) == 0)
return os;
xs *s = xs_str_new(NULL);
if (strcmp(type, "Follow") == 0) {
s = xs_str_cat(s, "
\n");
xs *s1 = xs_fmt("
%s
\n", L("follows you"));
s = xs_str_cat(s, s1);
s = html_msg_icon(snac, s, msg);
s = xs_str_cat(s, "
\n");
return xs_str_cat(os, s);
}
/* bring the main actor */
if ((actor = xs_dict_get(msg, "attributedTo")) == NULL)
return os;
/* ignore muted morons immediately */
if (is_muted(snac, actor))
return os;
if (!valid_status(actor_get(snac, actor, &actor_o)))
return os;
/* if this is our post, add the score */
if (xs_startswith(id, snac->actor)) {
int likes = xs_list_len(xs_dict_get(meta, "liked_by"));
int boosts = xs_list_len(xs_dict_get(meta, "announced_by"));
xs *s1 = xs_fmt(
"
%d ★ %d ↺
\n",
likes, boosts);
s = xs_str_cat(s, s1);
}
if (level == 0) {
char *p;
s = xs_str_cat(s, "
\n");
/* print the origin of the post, if any */
if (!xs_is_null(p = xs_dict_get(meta, "referrer"))) {
xs *actor_r = NULL;
if (valid_status(actor_get(snac, p, &actor_r))) {
char *name;
if ((name = xs_dict_get(actor_r, "name")) == NULL)
name = xs_dict_get(actor_r, "preferredUsername");
xs *s1 = xs_fmt(
"
\n",
xs_dict_get(actor_r, "id"),
name,
L("boosted")
);
s = xs_str_cat(s, s1);
}
}
else
if (!xs_is_null((p = xs_dict_get(meta, "parent"))) && *p) {
/* this may happen if any of the autor or the parent aren't here */
xs *s1 = xs_fmt(
"
",
snac->actor, xs_dict_get(snac->config, "name"), L("liked")
);
s = xs_str_cat(s, s1);
}
}
else
s = xs_str_cat(s, "
\n");
s = html_msg_icon(snac, s, msg);
/* add the content */
s = xs_str_cat(s, "
\n");
{
xs *c = xs_dup(xs_dict_get(msg, "content"));
char *p, *v;
/* 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);
}
/* replace the :shortnames: */
if (!xs_is_null(p = xs_dict_get(msg, "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 (n && i) {
char *u = xs_dict_get(i, "url");
xs *img = xs_fmt("", u);
c = xs_replace_i(c, n, img);
}
}
}
}
s = xs_str_cat(s, c);
}
s = xs_str_cat(s, "\n");
/* add the attachments */
char *attach;
if ((attach = xs_dict_get(msg, "attachment")) != NULL) {
char *v;
while (xs_list_iter(&attach, &v)) {
char *t = xs_dict_get(v, "mediaType");
if (xs_is_null(t))
continue;
if (xs_startswith(t, "image/")) {
char *url = xs_dict_get(v, "url");
char *name = xs_dict_get(v, "name");
if (url != NULL) {
xs *s1 = xs_fmt("\n",
url, xs_is_null(name) ? "" : name);
s = xs_str_cat(s, s1);
}
}
else
if (xs_startswith(t, "video/")) {
char *url = xs_dict_get(v, "url");
if (url != NULL) {
xs *s1 = xs_fmt("\n", url);
s = xs_str_cat(s, s1);
}
}
}
}
s = xs_str_cat(s, "
\n");
/** controls **/
if (!local)
s = html_entry_controls(snac, s, msg);
/** children **/
char *children = xs_dict_get(meta, "children");
if (xs_list_len(children)) {
int left = xs_list_len(children);
char *id;
if (level < 4)
s = xs_str_cat(s, "
\n");
else
s = xs_str_cat(s, "
\n");
if (left > 3)
s = xs_str_cat(s, "...\n");
while (xs_list_iter(&children, &id)) {
xs *chd = timeline_find(snac, id);
if (left == 3)
s = xs_str_cat(s, "\n");
if (chd != NULL)
s = html_entry(snac, s, chd, seen, local, level + 1);
else
snac_debug(snac, 2, xs_fmt("cannot read from timeline child %s", id));
left--;
}
s = xs_str_cat(s, "
\n");
}
s = xs_str_cat(s, "
\n");
return xs_str_cat(os, s);
}
d_char *html_user_footer(snac *snac, d_char *s)
{
xs *s1 = xs_fmt(
"\n",
srv_baseurl,
L("about this site")
);
return xs_str_cat(s, s1);
}
d_char *html_timeline(snac *snac, char *list, int local)
/* returns the HTML for the timeline */
{
d_char *s = xs_str_new(NULL);
xs_set *seen = xs_set_new(4096);
char *v;
double t = ftime();
s = html_user_header(snac, s, local);
if (!local)
s = html_top_controls(snac, s);
s = xs_str_cat(s, "\n");
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, local, 0);
}
s = xs_str_cat(s, "