[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
No known key found for this signature in database
GPG Key ID: 96DA09D4B97BC2D5
7 changed files with 36 additions and 12 deletions

View File

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

View File

@ -135,7 +135,7 @@ class Security extends Controller
try {
// 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([
'nickname' => $sanitized_nickname,
'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]],
['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']);
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']]]);
}

View File

@ -52,7 +52,7 @@ class Actor extends Entity
// @codeCoverageIgnoreStart
private int $id;
private string $nickname;
private ?string $fullname;
private string $fullname;
private int $roles = 4;
private ?string $homepage;
private ?string $bio;
@ -86,13 +86,13 @@ class Actor extends Entity
return $this->nickname;
}
public function setFullname(?string $fullname): self
public function setFullname(string $fullname): self
{
$this->fullname = $fullname;
return $this;
}
public function getFullname(): ?string
public function getFullname(): string
{
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
{
return Cache::get('selftags-' . $this->id,

View File

@ -241,6 +241,11 @@ class Note extends Entity
return Actor::getNicknameById($this->actor_id);
}
public function getActorFullname(): string
{
return Actor::getFullnameById($this->actor_id);
}
public function getActorAvatarUrl(string $size = 'full'): string
{
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 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>
<details class="header-extra-actions">

View File

@ -1,4 +1,6 @@
{% 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 %}
<article class="h-entry hentry note">
@ -10,10 +12,12 @@
{# 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">
<strong class="note-author u-url">
{# Microformat's h-card properties indicates a face icon is a "u-logo" #}
{{ nickname }}
</strong>
<a href="{{ actor_url }}" class="note-author u-url">
<strong class="note-author-fullname">{{ fullname }}</strong>
<em class="note-author-nickname">{{ nickname }}</em>
<em class="note-author-instance">{{ nickname }}</em>
</a>
{% if app.user and note_actions_show %}
<div class="note-actions">
@ -30,7 +34,6 @@
</div>
<section tabindex="0" role="dialog" class="e-content entry-content note-content">
<div class="note-text" tabindex="0" title="{{ 'Note text content.' | trans }}">
{{ note.getRendered() | raw }}
</div>