Prechádzať zdrojové kódy

Use the metadata pronouns.

violette 6 mesiacov pred
rodič
commit
f5ad346f7d
3 zmenil súbory, kde vykonal 40 pridanie a 0 odobranie
  1. 1 0
      doc/style.css
  2. 38 0
      html.c
  3. 1 0
      utils.c

+ 1 - 0
doc/style.css

@@ -40,3 +40,4 @@ blockquote { font-style: italic; }
   a { color: #7799dd }
   a:visited { color: #aa99dd }
 }
+select { max-width: 40%; }

+ 38 - 0
html.c

@@ -162,6 +162,31 @@ xs_str *actor_name(xs_dict *actor, const char *proxy)
 }
 
 
+xs_str *actor_pronouns(xs_dict *actor)
+/* gets the actor name */
+{
+    const xs_list *attachment;
+    const xs_dict *d;
+    const char *pronouns = "";
+    char *ret;
+
+    if (!xs_is_null((attachment = xs_dict_get(actor, "attachment")))) {
+        xs_list_foreach(attachment, d) {
+            char *prop = xs_utf8_to_lower(xs_dict_get(d, "name"));
+            /* make sure that we are reading the correct metadata */
+            if (strlen(prop) == 8 && strcmp(prop, "pronouns") == 0)
+                pronouns = xs_dict_get(d, "value");
+        }
+    }
+
+    /* <p> breaks page, cannot nest them */
+    ret = xs_replace_i(xs_dup(pronouns), "<p>", "");
+    ret = xs_replace_i(ret, "</p>", "");
+
+    return ret;
+}
+
+
 xs_str *format_text_with_emoji(snac *user, const char *text, int ems, const char *proxy)
 /* needed when we have local text with no tags attached */
 {
@@ -195,6 +220,10 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
     int fwer = 0;
 
     xs *name = actor_name(actor, proxy);
+    xs *pronouns = actor_pronouns(actor);
+    char pronouns_c = 0;
+    if (*pronouns != '\0')
+        pronouns_c = 1;
 
     /* get the avatar */
     if ((v = xs_dict_get(actor, "icon")) != NULL) {
@@ -251,6 +280,15 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
                 xs_html_text("»")));
     }
 
+    if (pronouns_c > 0)
+        xs_html_add(actor_icon,
+            xs_html_text(" "),
+            xs_html_tag("span",
+                xs_html_attr("class",   "snac-pronouns"),
+                xs_html_attr("title",   "user's pronouns"),
+                xs_html_raw(pronouns)));
+
+
     if (strcmp(xs_dict_get(actor, "type"), "Service") == 0) {
         xs_html_add(actor_icon,
             xs_html_text(" "),

+ 1 - 0
utils.c

@@ -88,6 +88,7 @@ static const char * const default_css =
     "  a { color: #7799dd }\n"
     "  a:visited { color: #aa99dd }\n"
     "}\n"
+    "select { max-width: 40%; }\n"
 ;
 
 const char *snac_blurb =