[TWIG][Cards] Fullname is now displayed as the note author, nickname as an identification.

[CONTROLLER][Security] Fullname is set on resgistration to enable it to be shown by default in notes.
[CONTROLLER][UserPanel] Fullname extra step added.
[CSS] Fullname and nickname representation work.
This commit is contained in:
Eliseu Amaro 2021-10-26 14:47:28 +01:00
parent 51c984849f
commit 3e2fefa8af
Signed by: eliseuamaro
GPG Key ID: 96DA09D4B97BC2D5
7 changed files with 36 additions and 12 deletions

View File

@ -154,7 +154,6 @@ embed header {
.note-author { .note-author {
font-size: var(--default); font-size: var(--default);
font-weight: bold;
display: -webkit-box; display: -webkit-box;
display: -webkit-flex; display: -webkit-flex;
display: -moz-box; display: -moz-box;
@ -170,6 +169,15 @@ embed header {
-ms-grid-row-align: center; -ms-grid-row-align: center;
align-self: center align-self: center
} }
.note-author-fullname {
font-weight: bold;
}
.note-author-nickname {
opacity: 0.5;
}
.note-author-nickname::before {
content: '@';
}
.note-actions { .note-actions {
display: -webkit-box; display: -webkit-box;

View File

@ -135,7 +135,7 @@ class Security extends Controller
try { try {
// This already checks if the nickname is being used // This already checks if the nickname is being used
$actor = Actor::create(['nickname' => $sanitized_nickname]); $actor = Actor::create(['nickname' => $sanitized_nickname, 'fullname' => $sanitized_nickname]);
$user = LocalUser::create([ $user = LocalUser::create([
'nickname' => $sanitized_nickname, 'nickname' => $sanitized_nickname,
'outgoing_email' => $data['email'], 'outgoing_email' => $data['email'],

View File

@ -102,8 +102,9 @@ class UserPanel extends AbstractController
['self_tags', TextType::class, ['label' => _m('Self Tags'), 'required' => false, 'help' => _m('Tags for yourself (letters, numbers, -, ., and _), comma- or space-separated.'), 'transformer' => ArrayTransformer::class]], ['self_tags', TextType::class, ['label' => _m('Self Tags'), 'required' => false, 'help' => _m('Tags for yourself (letters, numbers, -, ., and _), comma- or space-separated.'), 'transformer' => ArrayTransformer::class]],
['save_personal_info', SubmitType::class, ['label' => _m('Save personal info')]], ['save_personal_info', SubmitType::class, ['label' => _m('Save personal info')]],
]; ];
$extra_step = function ($data, $extra_args) use ($user) { $extra_step = function ($data, $extra_args) use ($user, $actor) {
$user->setNickname($data['nickname']); $user->setNickname($data['nickname']);
if (!$data['full_name'] && !$actor->getFullname()) { $actor->setFullname($data['nickname']); }
}; };
return Form::handle($form_definition, $request, $actor, $extra, $extra_step, [['self_tags' => $extra['self_tags']]]); return Form::handle($form_definition, $request, $actor, $extra, $extra_step, [['self_tags' => $extra['self_tags']]]);
} }

View File

@ -52,7 +52,7 @@ class Actor extends Entity
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
private int $id; private int $id;
private string $nickname; private string $nickname;
private ?string $fullname; private string $fullname;
private int $roles = 4; private int $roles = 4;
private ?string $homepage; private ?string $homepage;
private ?string $bio; private ?string $bio;
@ -86,13 +86,13 @@ class Actor extends Entity
return $this->nickname; return $this->nickname;
} }
public function setFullname(?string $fullname): self public function setFullname(string $fullname): self
{ {
$this->fullname = $fullname; $this->fullname = $fullname;
return $this; return $this;
} }
public function getFullname(): ?string public function getFullname(): string
{ {
return $this->fullname; return $this->fullname;
} }
@ -234,6 +234,13 @@ class Actor extends Entity
}); });
} }
public static function getFullnameById(int $id): string
{
return Cache::get('actor-fullname-id-' . $id, function () use ($id) {
return self::getById($id)->getFullname();
});
}
public function getSelfTags(bool $_test_force_recompute = false): array public function getSelfTags(bool $_test_force_recompute = false): array
{ {
return Cache::get('selftags-' . $this->id, return Cache::get('selftags-' . $this->id,

View File

@ -241,6 +241,11 @@ class Note extends Entity
return Actor::getNicknameById($this->actor_id); return Actor::getNicknameById($this->actor_id);
} }
public function getActorFullname(): string
{
return Actor::getFullnameById($this->actor_id);
}
public function getActorAvatarUrl(string $size = 'full'): string public function getActorAvatarUrl(string $size = 'full'): string
{ {
return Avatar::getAvatarUrl($this->getActorId(), $size); return Avatar::getAvatarUrl($this->getActorId(), $size);

View File

@ -71,7 +71,7 @@
<a id="anchor-main-page" class="anchor-hidden" title="{{ 'Press tab to access instance\'s main page.' | trans }}"></a> <a id="anchor-main-page" class="anchor-hidden" title="{{ 'Press tab to access instance\'s main page.' | trans }}"></a>
<a class="accessibility-target header-instance" href="{{ path('main_public') }}" tabindex="0" title="{{ 'This instance\'s name. Access public timeline.' | trans }}"> <a class="accessibility-target header-instance" href="{{ path('main_public') }}" tabindex="0" title="{{ 'This instance\'s name. Access public timeline.' | trans }}">
<h1>{{ icon('logo', 'icon icon-logo') | raw }}{{ config('site', 'name') }} </h1> <h1>{{ icon('logo', 'icon icon-logo') | raw }}{{ config('site', 'name') }}</h1>
</a> </a>
<details class="header-extra-actions"> <details class="header-extra-actions">

View File

@ -1,4 +1,6 @@
{% set nickname = note.getActorNickname() %} {% set nickname = note.getActorNickname() %}
{% set fullname = note.getActorFullname() %}
{% set actor_url = note.getActor().getUrl() %}
{% if note_actions_show is not defined %} {% set note_actions_show = true %} {% endif %} {% if note_actions_show is not defined %} {% set note_actions_show = true %} {% endif %}
<article class="h-entry hentry note"> <article class="h-entry hentry note">
@ -10,10 +12,12 @@
{# TODO: this should link to the note's user profile? #} {# TODO: this should link to the note's user profile? #}
<div tabindex="0" title="{{ 'Begin a note by the user: ' | trans }} {{ nickname }}." class="note-info"> <div tabindex="0" title="{{ 'Begin a note by the user: ' | trans }} {{ nickname }}." class="note-info">
<strong class="note-author u-url"> {# Microformat's h-card properties indicates a face icon is a "u-logo" #}
{# Microformat's h-card properties indicates a face icon is a "u-logo" #} <a href="{{ actor_url }}" class="note-author u-url">
{{ nickname }} <strong class="note-author-fullname">{{ fullname }}</strong>
</strong> <em class="note-author-nickname">{{ nickname }}</em>
<em class="note-author-instance">{{ nickname }}</em>
</a>
{% if app.user and note_actions_show %} {% if app.user and note_actions_show %}
<div class="note-actions"> <div class="note-actions">
@ -30,7 +34,6 @@
</div> </div>
<section tabindex="0" role="dialog" class="e-content entry-content note-content"> <section tabindex="0" role="dialog" class="e-content entry-content note-content">
<div class="note-text" tabindex="0" title="{{ 'Note text content.' | trans }}"> <div class="note-text" tabindex="0" title="{{ 'Note text content.' | trans }}">
{{ note.getRendered() | raw }} {{ note.getRendered() | raw }}
</div> </div>