diff options
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 153 |
1 files changed, 144 insertions, 9 deletions
@@ -1688,7 +1688,7 @@ xs_html *html_top_controls(snac *user) xs_html_text(L("Languages you usually post in:")), xs_html_sctag("br", NULL), xs_html_sctag("input", - xs_html_attr("type", "next"), + xs_html_attr("type", "text"), xs_html_attr("name", "post_langs"), xs_html_attr("value", post_langs), xs_html_attr("placeholder", L("en fr es de_AT")))), @@ -1891,7 +1891,7 @@ xs_html *html_entry_controls(snac *user, const char *actor, xs_html_attr("name", "redir"), xs_html_attr("value", redir)))); - if (!xs_startswith(id, user->actor)) { + if (!is_msg_mine(user, id)) { if (xs_list_in(likes, user->md5) == -1) { /* not already liked; add button */ xs_html_add(form, @@ -2387,6 +2387,23 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, /* c contains sanitized HTML */ xs_html_add(snac_content, xs_html_raw(c)); + + /* quoted post */ + const char *quoted_id = xs_or(xs_dict_get(msg, "quoteUri"), xs_dict_get(msg, "quoteUrl")); + + if (xs_is_string(quoted_id) && xs_match(quoted_id, "https://*|http://*")) { /** **/ + xs *quoted_post = NULL; + + if (valid_status(object_get(quoted_id, "ed_post))) { + xs_html_add(snac_content, + xs_html_tag("blockquote", + xs_html_attr("class", "snac-quoted-post"), + html_entry(user, quoted_post, 1, 1, NULL, 1))); + } + else + if (user) + enqueue_object_request(user, quoted_id, 0); + } } if (strcmp(type, "Question") == 0) { /** question content **/ @@ -2402,7 +2419,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, if (read_only) closed = 1; /* non-identified page; show as closed */ else - if (user && xs_startswith(id, user->actor)) + if (user && is_msg_mine(user, id)) closed = 1; /* we questioned; closed for us */ else if (user && was_question_voted(user, id)) @@ -2610,7 +2627,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, xs_html_attr("title", name)))); } else - if (xs_startswith(type, "video/")) { + if (xs_startswith(type, "video/") || strcmp(type, "Video") == 0) { xs_html_add(content_attachments, xs_html_tag("video", xs_html_attr("preload", "none"), @@ -3214,7 +3231,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only, continue; } /* hide non-public posts viewed from outside */ - if (read_only && scope != SCOPE_PUBLIC){ + if (read_only && (scope != SCOPE_PUBLIC && scope != SCOPE_UNLISTED)) { continue; } @@ -3331,10 +3348,11 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c /* content (user bio) */ const char *c = xs_dict_get(actor, "summary"); + const xs_val *tag = xs_dict_get(actor, "tag"); if (!xs_is_null(c)) { xs *sc = sanitize(c); - sc = replace_shortnames(sc, xs_dict_get(actor, "tag"), 2, proxy); + sc = replace_shortnames(sc, tag, 2, proxy); xs_html *snac_content = xs_html_tag("div", xs_html_attr("class", "snac-content")); @@ -3350,6 +3368,93 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c xs_html_add(snac_post, snac_content); } + /* add user metadata */ + xs_html *snac_metadata = xs_html_tag("div", + xs_html_attr("class", "snac-metadata")); + + int count = 0; + const xs_val *address = xs_dict_get(actor, "vcard:Address"); + if (xs_is_string(address)) { + xs_html_add(snac_metadata, + xs_html_tag("span", + xs_html_attr("class", "snac-property-name"), + xs_html_raw("📍 Location")), + xs_html_text(":"), + xs_html_raw(" "), + xs_html_tag("span", + xs_html_attr("class", "snac-property-value p-adr"), + xs_html_text(address)), + xs_html_sctag("br", NULL)); + + count++; + } + + const xs_val *birthday = xs_dict_get(actor, "vcard:bday"); + if (xs_is_string(birthday)) { + xs_html_add(snac_metadata, + xs_html_tag("span", + xs_html_attr("class", "snac-property-name"), + xs_html_raw("🎂 Birthday")), + xs_html_text(":"), + xs_html_raw(" "), + xs_html_tag("time", + xs_html_attr("class", "snac-property-value dt-bday"), + xs_html_text(birthday)), + xs_html_sctag("br", NULL)); + + count++; + } + + const xs_list *attachment = xs_dict_get(actor, "attachment"); + if (count > 0 && xs_list_len(attachment) > 0) { + xs_html_add(snac_metadata, + xs_html_sctag("hr", + xs_html_attr("class", "snac-property-divider"))); + } + + const xs_val *v; + xs_list_foreach(attachment, v) { + const char *type = xs_dict_get(v, "type"); + const char *name = xs_dict_get(v, "name"); + const char *value = xs_dict_get(v, "value"); + + if (!xs_is_null(type) && !xs_is_null(name) && + !xs_is_null(value) && strcmp(type, "PropertyValue") == 0) { + /* both the name and the value can contain emoji */ + xs *nam = sanitize(name); + nam = replace_shortnames(nam, tag, 1, proxy); + + /* todo: sometimes the value is transmitted as markdown and not html ._. */ + xs *val = sanitize(value); + val = replace_shortnames(val, tag, 1, proxy); + + /* delete <p> tags, because some software sends them */ + val = xs_replace_i(val, "<p>", ""); + val = xs_replace_i(val, "</p>", ""); + + xs_html_add(snac_metadata, + xs_html_tag("span", + xs_html_attr("class", "snac-property-name"), + xs_html_raw(nam)), + xs_html_text(":"), + xs_html_raw(" "), + xs_html_tag("span", + xs_html_attr("class", "snac-property-value"), + xs_html_raw(val)), + xs_html_sctag("br", NULL)); + + count++; + } + } + + if (count > 0) { + xs_html_add(snac_post, snac_metadata); + } + else { + /* free the html, by rendering it... */ + xs_free(xs_html_render(snac_metadata)); + } + /* buttons */ xs *btn_form_action = xs_fmt("%s/admin/action", user->actor); @@ -3555,9 +3660,13 @@ xs_str *html_notifications(snac *user, int skip, int show) if (valid_status(actor_get(actor_id, &actor))) a_name = actor_name(actor, proxy); - else + else { a_name = xs_dup(actor_id); + /* actor not here: request it */ + enqueue_actor_refresh(user, actor_id, 0); + } + xs *label_sanitized = sanitize(type); const char *label = label_sanitized; @@ -3630,7 +3739,7 @@ xs_str *html_notifications(snac *user, int skip, int show) xs_html_attr("class", "snac-post-with-desc"), html_label); - if (strcmp(type, "Follow") == 0 || strcmp(utype, "Follow") == 0 || strcmp(type, "Block") == 0) { + if (strcmp(type, "Block") == 0) { if (actor) xs_html_add(entry, xs_html_tag("div", @@ -3638,6 +3747,32 @@ xs_str *html_notifications(snac *user, int skip, int show) html_actor_icon(user, actor, NULL, NULL, NULL, -1, 0, proxy, NULL, NULL))); } else + if (strcmp(type, "Follow") == 0 || strcmp(utype, "Follow") == 0) { + if (actor) { + xs *action = xs_fmt("%s/admin/action", user->actor); + xs_html *button = NULL; + + if (following_check(user, actor_id)) + button = html_button("unfollow", L("Unfollow"), L("Stop following this user's activity")); + else + button = html_button("follow", L("Follow"), L("Start following this user's activity")); + + xs_html_add(entry, + xs_html_tag("div", + xs_html_attr("class", "snac-post"), + html_actor_icon(user, actor, NULL, NULL, NULL, -1, 0, proxy, NULL, NULL), + xs_html_tag("form", + xs_html_attr("method", "post"), + xs_html_attr("action", action), + xs_html_sctag("input", + xs_html_attr("type", "hidden"), + xs_html_attr("name", "actor"), + xs_html_attr("value", actor_id)), + button, + xs_html_sctag("br", NULL)))); + } + } + else if (strcmp(type, "Move") == 0) { const xs_dict *o_msg = xs_dict_get(noti, "msg"); const char *target; @@ -4880,7 +5015,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, } else { /* delete an entry */ - if (xs_startswith(id, snac.actor) && !is_draft(&snac, id)) { + if (is_msg_mine(&snac, id) && !is_draft(&snac, id)) { /* it's a post by us: generate a delete */ xs *msg = msg_delete(&snac, id); |