[MODULE][Left][UI][TAGS] Add Left module which handles fetching tags and followers, fix self tags

This commit is contained in:
Hugo Sales 2020-08-15 06:08:52 +00:00 committed by Hugo Sales
parent 31ccb2d07b
commit d548dc9284
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
4 changed files with 52 additions and 9 deletions

41
components/Left/Left.php Normal file
View File

@ -0,0 +1,41 @@
<?php
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
namespace Component\Left;
use App\Core\Event;
use App\Core\Module;
use App\Util\Common;
use Exception;
class Left extends Module
{
public function onEndTwigPopulateVars(array &$vars)
{
try {
$user = Common::user();
if ($user != null) {
$vars['user_nickname'] = $user->getNickname();
$vars['user_tags'] = $user->getActor()->getSelfTags();
}
} catch (Exception $e) {
}
return Event::next;
}
}

View File

@ -222,14 +222,14 @@ class GSActor extends Entity
return DB::findBy('gsactor_tag', ['tagger' => $this->id, 'tagged' => $this->id]);
}
public function setSelfTags(array $tags, array $pt_existing): void
public function setSelfTags(array $tags, array $existing): void
{
$tag_existing = F\map($pt_existing, function ($pt) { return $pt->getTag(); });
$tag_existing = F\map($existing, function ($pt) { return $pt->getTag(); });
$tag_to_add = array_diff($tags, $tag_existing);
$tag_to_remove = array_diff($tag_existing, $tags);
$pt_to_remove = F\filter($pt_existing, function ($pt) use ($tag_to_remove) { return in_array($pt->getTag(), $tag_to_remove); });
$pt_to_remove = F\filter($existing, function ($pt) use ($tag_to_remove) { return in_array($pt->getTag(), $tag_to_remove); });
foreach ($tag_to_add as $tag) {
$pt = new GSActorTag($this->id, $this->id, $tag);
$pt = GSActorTag::create(['tagger' => $this->id, 'tagged' => $this->id, 'tag' => $tag]);
DB::persist($pt);
}
foreach ($pt_to_remove as $pt) {

View File

@ -19,6 +19,7 @@
namespace App\Entity;
use App\Core\Entity;
use DateTimeInterface;
/**
@ -35,7 +36,7 @@ use DateTimeInterface;
* @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class GSActorTag
class GSActorTag extends Entity
{
// {{{ Autocode

View File

@ -18,12 +18,13 @@
<div class="left-nav">
<hr>
<div class='profile'>
<img src='{{ asset('assets/default-avatar.svg') }}' alt="Your avatar." class="icon icon-avatar">
<img src='{{ user_avatar }}' alt="Your avatar." class="icon icon-avatar">
<div class="info">
<b id="nick">{{ app.user.username }}</b>
<b id="nick">{{ user_nickname }}</b>
<div class="tags">
<i>coffee addict</i>
<i>lazy</i>
{% for tag in user_tags %}
<i> {{ tag }} </i>
{% endfor %}
</div>
<div class="stats">
<span>