[Avatar] We definitely don't need an event to retrieve avatar urls
This commit is contained in:
parent
2bd19fa087
commit
fda998e335
@ -43,6 +43,11 @@ class Avatar extends Component
|
|||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $tabs
|
||||||
|
*
|
||||||
|
* @throws \App\Util\Exception\ClientException
|
||||||
|
*/
|
||||||
public function onPopulateProfileSettingsTabs(Request $request, &$tabs): bool
|
public function onPopulateProfileSettingsTabs(Request $request, &$tabs): bool
|
||||||
{
|
{
|
||||||
// TODO avatar template shouldn't be on settings folder
|
// TODO avatar template shouldn't be on settings folder
|
||||||
@ -55,20 +60,6 @@ class Avatar extends Component
|
|||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onStartTwigPopulateVars(array &$vars): bool
|
|
||||||
{
|
|
||||||
if (Common::user() !== null) {
|
|
||||||
$vars['user_avatar'] = self::getAvatarUrl();
|
|
||||||
}
|
|
||||||
return Event::next;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onGetAvatarUrl(int $actor_id, ?string &$url): bool
|
|
||||||
{
|
|
||||||
$url = self::getAvatarUrl($actor_id);
|
|
||||||
return Event::next;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onAvatarUpdate(int $actor_id): bool
|
public function onAvatarUpdate(int $actor_id): bool
|
||||||
{
|
{
|
||||||
Cache::delete('avatar-' . $actor_id);
|
Cache::delete('avatar-' . $actor_id);
|
||||||
@ -98,11 +89,10 @@ class Avatar extends Component
|
|||||||
/**
|
/**
|
||||||
* Get the cached avatar associated with the given Actor id, or the current user if not given
|
* Get the cached avatar associated with the given Actor id, or the current user if not given
|
||||||
*/
|
*/
|
||||||
public static function getAvatarUrl(?int $actor_id = null, string $size = 'full'): string
|
public static function getAvatarUrl(int $actor_id, string $size = 'full'): string
|
||||||
{
|
{
|
||||||
$actor_id = $actor_id ?: Common::userId();
|
return Cache::get("avatar-url-{$actor_id}", function () use ($actor_id, $size) {
|
||||||
return Cache::get("avatar-url-{$actor_id}", function () use ($actor_id) {
|
return Router::url('avatar', ['actor_id' => $actor_id, 'size' => $size]);
|
||||||
return Router::url('avatar', ['actor_id' => $actor_id, 'size' => 'full']);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ class Left extends Component
|
|||||||
$vars['user_tags'] = $actor->getSelfTags();
|
$vars['user_tags'] = $actor->getSelfTags();
|
||||||
$vars['user_followers'] = $actor->getFollowersCount();
|
$vars['user_followers'] = $actor->getFollowersCount();
|
||||||
$vars['user_followed'] = $actor->getFollowedCount();
|
$vars['user_followed'] = $actor->getFollowedCount();
|
||||||
|
$vars['user_avatar'] = $actor->getAvatarUrl();
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error('Got an exception while populating variables for the left panel: ' . $e);
|
Log::error('Got an exception while populating variables for the left panel: ' . $e);
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
{% set actor_nickname = actor.nickname() %}
|
{% set actor_nickname = actor.getNickname() %}
|
||||||
|
{% set actor_avatar = actor.getAvatarUrl() %}
|
||||||
{% set actor_tags = actor.getSelfTags() %}
|
{% set actor_tags = actor.getSelfTags() %}
|
||||||
{% set actor_bio = actor.getBio() %}
|
{% set actor_bio = actor.getBio() %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<section class='section-widget section-widget-padded' title="{{ 'Your profile information.' | trans }}">
|
<section class='section-widget section-widget-padded' title="{{ 'Your profile information.' | trans }}">
|
||||||
<a id="user" href="{{ path('actor_view_nickname', {'nickname' : actor_nickname}) }}">
|
<a id="user" href="{{ path('actor_view_nickname', {'nickname' : actor_nickname}) }}">
|
||||||
<img src='{{ user_avatar }}' class="icon icon-avatar" alt="{{ 'Your account\'s avatar.' | trans }}">
|
<img src='{{ actor_avatar }}' class="icon icon-avatar" alt="{{ 'Your account\'s avatar.' | trans }}">
|
||||||
<div class="user-info">
|
<div class="user-info">
|
||||||
<strong id="user-nickname" title="{{ 'Your account\' nickname.' | trans }}">{{ actor_nickname }}</strong>
|
<strong id="user-nickname" title="{{ 'Your account\' nickname.' | trans }}">{{ actor_nickname }}</strong>
|
||||||
|
|
||||||
|
@ -24,11 +24,11 @@ namespace App\Entity;
|
|||||||
use App\Core\Cache;
|
use App\Core\Cache;
|
||||||
use App\Core\DB\DB;
|
use App\Core\DB\DB;
|
||||||
use App\Core\Entity;
|
use App\Core\Entity;
|
||||||
use App\Core\Event;
|
|
||||||
use App\Core\Router\Router;
|
use App\Core\Router\Router;
|
||||||
use App\Core\UserRoles;
|
use App\Core\UserRoles;
|
||||||
use App\Util\Exception\NicknameException;
|
use App\Util\Exception\NicknameException;
|
||||||
use App\Util\Nickname;
|
use App\Util\Nickname;
|
||||||
|
use Component\Avatar\Avatar;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Functional as F;
|
use Functional as F;
|
||||||
|
|
||||||
@ -215,11 +215,9 @@ class Actor extends Entity
|
|||||||
return DB::findOneBy('local_user', ['id' => $this->getId()]);
|
return DB::findOneBy('local_user', ['id' => $this->getId()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAvatarUrl()
|
public function getAvatarUrl(string $size = 'full')
|
||||||
{
|
{
|
||||||
$url = null;
|
return Avatar::getAvatarUrl($this->getId(), $size);
|
||||||
Event::handle('GetAvatarUrl', [$this->getId(), &$url]);
|
|
||||||
return $url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getFromId(int $id): ?self
|
public static function getFromId(int $id): ?self
|
||||||
|
@ -24,8 +24,8 @@ namespace App\Entity;
|
|||||||
use App\Core\Cache;
|
use App\Core\Cache;
|
||||||
use App\Core\DB\DB;
|
use App\Core\DB\DB;
|
||||||
use App\Core\Entity;
|
use App\Core\Entity;
|
||||||
use App\Core\Event;
|
|
||||||
use App\Core\VisibilityScope;
|
use App\Core\VisibilityScope;
|
||||||
|
use Component\Avatar\Avatar;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -220,11 +220,9 @@ class Note extends Entity
|
|||||||
return Actor::getNicknameFromId($this->actor_id);
|
return Actor::getNicknameFromId($this->actor_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAvatarUrl()
|
public function getActorAvatarUrl(string $size = 'full'): string
|
||||||
{
|
{
|
||||||
$url = null;
|
return Avatar::getAvatarUrl($this->getActorId(), $size);
|
||||||
Event::handle('GetAvatarUrl', [$this->getActorId(), &$url]);
|
|
||||||
return $url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllNotes(int $noteScope): array
|
public static function getAllNotes(int $noteScope): array
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
{% extends 'stdgrid.html.twig' %}
|
{% extends 'stdgrid.html.twig' %}
|
||||||
|
|
||||||
{% set id = actor.id %}
|
{% set id = actor.getId() %}
|
||||||
{% set nick = actor.nickname %}
|
{% set nickname = actor.getNickname() %}
|
||||||
|
|
||||||
{# TODO: how to get avatar in here? Tags and rest of profile info? #}
|
{% set avatar = actor.getAvatarUrl() %}
|
||||||
{% set avatar = actor.nickname %}
|
|
||||||
|
|
||||||
{% block title %}{{ nick }}'s profile{% endblock %}
|
{% block title %}{{ nickname }}'s profile{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<section class="section-widget section-widget-padded">
|
<section class="section-widget section-widget-padded">
|
||||||
<div class="section-title">
|
<div class="section-title">
|
||||||
<img class="icon icon-avatar" src="{{ avatar }}" alt="{{ nick }}'s avatar">{{ nick }}
|
<img class="icon icon-avatar" src="{{ avatar }}" alt="{{ nickname }}'s avatar">{{ nickname }}
|
||||||
</div>
|
</div>
|
||||||
{#
|
|
||||||
|
|
||||||
<div class="actor-nickname-and-tags">
|
<div class="actor-nickname-and-tags">
|
||||||
|
|
||||||
@ -37,7 +35,7 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<p>{{ '(No bio)' | trans }}</p>
|
<p>{{ '(No bio)' | trans }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>#}
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<main class="timeline" tabindex="0" role="feed">
|
<main class="timeline" tabindex="0" role="feed">
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
{% set nickname = note.getActorNickname() %}
|
{% set nickname = note.getActorNickname() %}
|
||||||
|
|
||||||
<aside class="note-sidebar">
|
<aside class="note-sidebar">
|
||||||
<img class="u-logo avatar" src="{{ note.getAvatarUrl() }}" alt="{{ nickname }}'s avatar" width="32px" height="32px">
|
<img class="u-logo avatar" src="{{ note.getActorAvatarUrl() }}" alt="{{ nickname }}'s avatar" width="32px" height="32px">
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<div class="note-wrapper">
|
<div class="note-wrapper">
|
||||||
|
Loading…
Reference in New Issue
Block a user