Simplify the logic to fallback to the FQN when no display name is available

This commit is contained in:
Bat 2018-07-26 16:36:19 +02:00
parent 15477875da
commit 5980c7b299
7 changed files with 17 additions and 40 deletions

View File

@ -370,6 +370,11 @@ impl User {
pub fn to_json(&self, conn: &PgConnection) -> serde_json::Value { pub fn to_json(&self, conn: &PgConnection) -> serde_json::Value {
let mut json = serde_json::to_value(self).unwrap(); let mut json = serde_json::to_value(self).unwrap();
json["fqn"] = serde_json::Value::String(self.get_fqn(conn)); json["fqn"] = serde_json::Value::String(self.get_fqn(conn));
json["name"] = if self.display_name.len() > 0 {
json!(self.display_name)
} else {
json!(self.get_fqn(conn))
};
json json
} }

View File

@ -11,12 +11,7 @@
<p> <p>
{{ "{{ count }} authors in this blog: " | _n(singular="One author in this blog: ", count = n_authors) }} {{ "{{ count }} authors in this blog: " | _n(singular="One author in this blog: ", count = n_authors) }}
{% for author in authors %} {% for author in authors %}
{% if author.display_name %} <a class="author" href="/@/{{ author.fqn }}">{{ author.name }}</a>{% if not loop.last %},{% endif %}
{% set name = author.display_name %}
{% else %}
{% set name = author.username %}
{% endif %}
<a class="author" href="/@/{{ author.fqn }}">{{ name }}</a>{% if not loop.last %},{% endif %}
{% endfor %} {% endfor %}
</p> </p>
<p> <p>

View File

@ -1,9 +1,4 @@
{% macro post_card(article) %} {% macro post_card(article) %}
{% if article.author.display_name %}
{% set name = article.author.display_name %}
{% else %}
{% set name = article.author.username %}
{% endif %}
<div class="card"> <div class="card">
<h3><a href="{{ article.url }}">{{ article.post.title }}</a></h3> <h3><a href="{{ article.url }}">{{ article.post.title }}</a></h3>
<main <main
@ -14,7 +9,7 @@
link_1='<a href="/@/', link_1='<a href="/@/',
link_2=article.author.fqn, link_2=article.author.fqn,
link_3='/">', link_3='/">',
name=name, name=article.author.name,
link_4="</a>") link_4="</a>")
}} }}
⋅ {{ article.date | date(format="%B %e") }} ⋅ {{ article.date | date(format="%B %e") }}
@ -49,7 +44,7 @@
{% macro comment(comm) %} {% macro comment(comm) %}
<div class="comment" id="comment-{{ comm.id }}"> <div class="comment" id="comment-{{ comm.id }}">
<a class="author" href="{{ comm.author.ap_url }}"> <a class="author" href="{{ comm.author.ap_url }}">
<span class="display-name">{{ comm.author.display_name | default(value=comm.author.username) }}</span> <span class="display-name">{{ comm.author.name }}</span>
<small>@{{ comm.author.username }}</small> <small>@{{ comm.author.username }}</small>
</a> </a>
<div class="text">{{ comm.content | safe }}</div> <div class="text">{{ comm.content | safe }}</div>

View File

@ -14,7 +14,7 @@
<i class="fa fa-comment left-icon"></i> <i class="fa fa-comment left-icon"></i>
<main class="grow"> <main class="grow">
<h3><a href="{{ notification.object.post.url }}#comment-{{ notification.object.id }}"> <h3><a href="{{ notification.object.post.url }}#comment-{{ notification.object.id }}">
{{ "{{ user }} commented your article." | _(user=notification.object.user.display_name | escape) }} {{ "{{ user }} commented your article." | _(user=notification.object.user.name | escape) }}
</a></h3> </a></h3>
<p><a href="{{ notification.object.post.url }}">{{ notification.object.post.post.title }}</a></p> <p><a href="{{ notification.object.post.url }}">{{ notification.object.post.post.title }}</a></p>
</main> </main>
@ -24,7 +24,7 @@
<i class="fa fa-user-plus left-icon"></i> <i class="fa fa-user-plus left-icon"></i>
<main class="grow"> <main class="grow">
<h3><a href="/@/{{ notification.object.follower.fqn }}/"> <h3><a href="/@/{{ notification.object.follower.fqn }}/">
{{ "{{ user }} is now following you." | _(user=notification.object.follower.display_name | escape) }} {{ "{{ user }} is now following you." | _(user=notification.object.follower.name | escape) }}
</a></h3> </a></h3>
</main> </main>
<p><small>{{ notification.creation_date | date(format="%B %e, %H:%m") }}</small></p> <p><small>{{ notification.creation_date | date(format="%B %e, %H:%m") }}</small></p>
@ -33,7 +33,7 @@
<i class="fa fa-heart left-icon"></i> <i class="fa fa-heart left-icon"></i>
<main class="grow"> <main class="grow">
<h3> <h3>
{{ "{{ user }} liked your article." | _(user=notification.object.user.display_name | escape) }} {{ "{{ user }} liked your article." | _(user=notification.object.user.name | escape) }}
</h3> </h3>
<p><a href="{{ notification.object.post.url }}">{{ notification.object.post.post.title }}</a></p> <p><a href="{{ notification.object.post.url }}">{{ notification.object.post.post.title }}</a></p>
</main> </main>
@ -43,7 +43,7 @@
<i class="fa fa-at left-icon"></i> <i class="fa fa-at left-icon"></i>
<main class="grow"> <main class="grow">
<h3><a href="{{ notification.object.url }}"> <h3><a href="{{ notification.object.url }}">
{{ "{{ user }} mentioned you." | _(user=notification.object.user.display_name | escape) }} {{ "{{ user }} mentioned you." | _(user=notification.object.user.name | escape) }}
</a></h3> </a></h3>
</main> </main>
<p><small>{{ notification.creation_date | date(format="%B %e, %H:%m") }}</small></p> <p><small>{{ notification.creation_date | date(format="%B %e, %H:%m") }}</small></p>
@ -52,7 +52,7 @@
<i class="fa fa-retweet left-icon"></i> <i class="fa fa-retweet left-icon"></i>
<main class="grow"> <main class="grow">
<h3> <h3>
{{ "{{ user }} reshared your article." | _(user=notification.object.user.display_name | escape) }} {{ "{{ user }} reshared your article." | _(user=notification.object.user.name | escape) }}
</h3> </h3>
<p><a href="{{ notification.object.post.url }}">{{ notification.object.post.post.title }}</a></p> <p><a href="{{ notification.object.post.url }}">{{ notification.object.post.post.title }}</a></p>
</main> </main>

View File

@ -12,18 +12,11 @@
{% block content %} {% block content %}
<h1 class="article">{{ post.title }}</h1> <h1 class="article">{{ post.title }}</h1>
<p class="article-info"> <p class="article-info">
{% if author.display_name %}
{% set name = author.display_name %}
{% else %}
{% set name = author.username %}
{% endif %}
<span class="author">{{ "Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}" | _( <span class="author">{{ "Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}" | _(
link_1='<a href="/@/', link_1='<a href="/@/',
url=author.fqn, url=author.fqn,
link_2='/">', link_2='/">',
name=name, name=author.name,
link_3="</a>" link_3="</a>"
) )
}}</a></span> }}</a></span>

View File

@ -2,13 +2,7 @@
{% import "macros" as macros %} {% import "macros" as macros %}
{% block title %} {% block title %}
{% if user.display_name %} {{ "{{ name | escape }}'s followers" | _(name=user.name) }}
{% set name = user.display_name %}
{% else %}
{% set name = user.username %}
{% endif %}
{{ "{{ name | escape }}'s followers" | _(name=name) }}
{% endblock title %} {% endblock title %}
{% block content %} {% block content %}
@ -17,13 +11,8 @@
<h2>{{ "Followers" | _ }}</h2> <h2>{{ "Followers" | _ }}</h2>
<div class="cards"> <div class="cards">
{% for follower in followers %} {% for follower in followers %}
{% if follower.display_name %}
{% set follower_name = follower.display_name %}
{% else %}
{% set follower_name = follower.username %}
{% endif %}
<div class="card"> <div class="card">
<h3><a href="/@/{{ follower.fqn }}/">{{ follower_name }}</a> <small>@{{ follower.fqn }}</small></h3> <h3><a href="/@/{{ follower.fqn }}/">{{ follower.name }}</a> <small>@{{ follower.fqn }}</small></h3>
<main><p>{{ follower.summary | safe }}</p></main> <main><p>{{ follower.summary | safe }}</p></main>
</div> </div>
{% endfor %} {% endfor %}

View File

@ -1,6 +1,6 @@
<div class="user"> <div class="user">
<h1> <h1>
{{ name }} {{ user.name }}
{% if user.is_admin %} {% if user.is_admin %}
<span class="badge">{{ "Admin" | _ }}</span> <span class="badge">{{ "Admin" | _ }}</span>
{% endif %} {% endif %}