\n", es1);
s = xs_str_cat(s, s1);
}
/* is it sensitive? */
if (!xs_is_null(v = xs_dict_get(msg, "sensitive")) && xs_type(v) == XSTYPE_TRUE) {
if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0')
v = "...";
/* only show it when not in the public timeline and the config setting is "open" */
char *cw = xs_dict_get(snac->config, "cw");
if (xs_is_null(cw) || local)
cw = "";
xs *es1 = encode_html(v);
xs *s1 = xs_fmt("%s [%s]\n", cw, es1, L("SENSITIVE CONTENT"));
s = xs_str_cat(s, s1);
sensitive = 1;
}
#if 0
{
xs *md5 = xs_md5_hex(id, strlen(id));
xs *s1 = xs_fmt("
%s
\n", md5);
s = xs_str_cat(s, s1);
}
#endif
{
const char *content = xs_dict_get(msg, "content");
xs *c = sanitize(xs_is_null(content) ? "" : content);
char *p, *v;
/* do some tweaks to the content */
c = xs_replace_i(c, "\r", "");
while (xs_endswith(c, "
"))
c = xs_crop_i(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, n);
c = xs_replace_i(c, n, img);
}
}
}
}
if (strcmp(type, "Question") == 0) { /** question content **/
xs_list *oo = xs_dict_get(msg, "oneOf");
xs_list *ao = xs_dict_get(msg, "anyOf");
xs_list *p;
xs_dict *v;
int closed = 0;
if (xs_dict_get(msg, "closed"))
closed = 2;
else
if (xs_startswith(id, snac->actor))
closed = 1; /* we questioned; closed for us */
else
if (was_question_voted(snac, id))
closed = 1; /* we already voted; closed for us */
/* get the appropriate list of options */
p = oo != NULL ? oo : ao;
if (closed) {
/* closed poll */
c = xs_str_cat(c, "
\n");
while (xs_list_iter(&p, &v)) {
const char *name = xs_dict_get(v, "name");
const xs_dict *replies = xs_dict_get(v, "replies");
if (name && replies) {
int nr = xs_number_get(xs_dict_get(replies, "totalItems"));
xs *es1 = encode_html(name);
xs *l = xs_fmt("
%s:
%d
\n", es1, nr);
c = xs_str_cat(c, l);
}
}
c = xs_str_cat(c, "
\n");
}
else {
/* poll still active */
xs *s1 = xs_fmt("
\n"
"\n
\n\n", L("Vote"));
s1 = xs_str_cat(s1, s2);
c = xs_str_cat(c, s1);
}
/* if it's *really* closed, say it */
if (closed == 2) {
xs *s1 = xs_fmt("
%s
\n", L("Closed"));
c = xs_str_cat(c, s1);
}
else {
/* show when the poll closes */
const char *end_time = xs_dict_get(msg, "endTime");
if (!xs_is_null(end_time)) {
time_t t0 = time(NULL);
time_t t1 = xs_parse_iso_date(end_time, 0);
if (t1 > 0 && t1 > t0) {
time_t diff_time = t1 - t0;
xs *tf = xs_str_time_diff(diff_time);
char *p = tf;
/* skip leading zeros */
for (; *p == '0' || *p == ':'; p++);
xs *es1 = encode_html(p);
xs *s1 = xs_fmt("
%s %s
", L("Closes in"), es1);
c = xs_str_cat(c, s1);
}
}
}
}
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;
/* make custom css for attachments easier */
s = xs_str_cat(s, "
\n");
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) {
if (xs_is_null(name))
name = "";
xs *es1 = encode_html(name);
xs *s1 = xs_fmt(
"\n",
url, url, es1, es1);
s = xs_str_cat(s, s1);
}
}
else
if (xs_startswith(t, "video/")) {
char *url = xs_dict_get(v, "url");
char *name = xs_dict_get(v, "name");
if (url != NULL) {
if (xs_is_null(name))
name = "No description";
xs *es1 = encode_html(name);
xs *s1 = xs_fmt("\n", url, url, es1);
s = xs_str_cat(s, s1);
}
}
else
if (xs_startswith(t, "audio/")) {
char *url = xs_dict_get(v, "url");
char *name = xs_dict_get(v, "name");
if (url != NULL) {
if (xs_is_null(name))
name = "No description";
xs *es1 = encode_html(name);
xs *s1 = xs_fmt("\n", url, url, es1);
s = xs_str_cat(s, s1);
}
}
else {
char *url = xs_dict_get(v, "url");
char *name = xs_dict_get(v, "name");
if (url != NULL) {
if (xs_is_null(name))
name = "No description";
xs *es1 = encode_html(name);
xs *s1 = xs_fmt("Attachment: %s", url, es1);
s = xs_str_cat(s, s1);
}
}
}
s = xs_str_cat(s, "
\n");
}
if (sensitive)
s = xs_str_cat(s, "
\n");
s = xs_str_cat(s, "
\n");
/** controls **/
if (!local)
s = html_entry_controls(snac, s, msg, md5);
/** children **/
if (!hide_children) {
xs *children = object_children(id);
int left = xs_list_len(children);
if (left) {
char *p, *cmd5;
int older_open = 0;
xs *ss = xs_str_new(NULL);
int n_children = 0;
ss = xs_str_cat(ss, "...
\n");
if (level < 4)
ss = xs_str_cat(ss, "
\n");
else
ss = xs_str_cat(ss, "
\n");
if (left > 3) {
xs *s1 = xs_fmt("%s\n", L("Older..."));
ss = xs_str_cat(ss, s1);
older_open = 1;
}
p = children;
while (xs_list_iter(&p, &cmd5)) {
xs *chd = NULL;
timeline_get_by_md5(snac, cmd5, &chd);
if (older_open && left <= 3) {
ss = xs_str_cat(ss, "\n");
older_open = 0;
}
if (chd != NULL && xs_is_null(xs_dict_get(chd, "name"))) {
ss = html_entry(snac, ss, chd, local, level + 1, cmd5, hide_children);
n_children++;
}
else
snac_debug(snac, 2, xs_fmt("cannot read from timeline child %s", cmd5));
left--;
}
if (older_open)
ss = xs_str_cat(ss, "\n");
ss = xs_str_cat(ss, "
\n");
ss = xs_str_cat(ss, "\n");
if (n_children)
s = xs_str_cat(s, ss);
}
}
s = xs_str_cat(s, "
\n
\n");
return xs_str_cat(os, s);
}
xs_str *html_user_footer(xs_str *s)
{
xs *s1 = xs_fmt(
"\n",
srv_baseurl,
L("about this site"),
WHAT_IS_SNAC_URL
);
return xs_str_cat(s, s1);
}
xs_str *html_timeline(snac *snac, const xs_list *list, int local, int skip, int show, int show_more)
/* returns the HTML for the timeline */
{
xs_str *s = xs_str_new(NULL);
xs_list *p = (xs_list *)list;
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(&p, &v)) {
xs *msg = NULL;
if (!valid_status(timeline_get_by_md5(snac, v, &msg)))
continue;
s = html_entry(snac, s, msg, local, 0, v, 0);
}
s = xs_str_cat(s, "