]> git.mxchange.org Git - friendica.git/commitdiff
[frio] Add Mute Author Server button to post actions
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 9 Jul 2023 20:14:53 +0000 (16:14 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 20 Aug 2023 18:27:09 +0000 (14:27 -0400)
src/App/Page.php
src/Content/Conversation.php
src/Module/Settings/Server/Action.php [new file with mode: 0644]
src/Object/Post.php
src/User/Settings/Entity/UserGServer.php
static/routes.config.php
view/theme/frio/js/textedit.js
view/theme/frio/templates/js_strings.tpl
view/theme/frio/templates/wall_thread.tpl

index 96bb59425efd151f405bd025d41dfb98a1058f70..e369d482e83610617105b9718b46bd2bca9d9d92 100644 (file)
@@ -245,10 +245,12 @@ class Page implements ArrayAccess
                 */
                $this->page['htmlhead'] = Renderer::replaceMacros($tpl, [
                        '$l10n' => [
-                               'delitem'        => $l10n->t('Delete this item?'),
-                               'blockAuthor'    => $l10n->t('Block this author? They won\'t be able to follow you nor see your public posts, and you won\'t be able to see their posts and their notifications.'),
-                               'ignoreAuthor'   => $l10n->t('Ignore this author? You won\'t be able to see their posts and their notifications.'),
-                               'collapseAuthor' => $l10n->t('Collapse this author\'s posts?'),
+                               'delitem'          => $l10n->t('Delete this item?'),
+                               'blockAuthor'      => $l10n->t("Block this author? They won't be able to follow you nor see your public posts, and you won't be able to see their posts and their notifications."),
+                               'ignoreAuthor'     => $l10n->t("Ignore this author? You won't be able to see their posts and their notifications."),
+                               'collapseAuthor'   => $l10n->t("Collapse this author's posts?"),
+                               'ignoreServer'     => $l10n->t("Ignore this author's server?"),
+                               'ignoreServerDesc' => $l10n->t("You won't see any content from this server including reshares in your Network page, the community pages and individual conversations."),
 
                                'likeError'     => $l10n->t('Like not successful'),
                                'dislikeError'  => $l10n->t('Dislike not successful'),
index 710422ee762cc162e411b8dd496a4c8e751fb2c3..caaaf21d11a20c3533802b0b730a286a1708260d 100644 (file)
@@ -1462,6 +1462,7 @@ class Conversation
                                'received'             => $item['received'],
                                'created_date'         => $item['created'],
                                'uriid'                => $item['uri-id'],
+                               'author_gsid'          => $item['author-gsid'],
                                'network'              => $item['network'],
                                'network_name'         => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network'], $item['author-gsid']),
                                'network_icon'         => ContactSelector::networkToIcon($item['network'], $item['author-link'], $item['author-gsid']),
diff --git a/src/Module/Settings/Server/Action.php b/src/Module/Settings/Server/Action.php
new file mode 100644 (file)
index 0000000..13c1cf5
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program 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.
+ *
+ * This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Settings\Server;
+
+use Friendica\App;
+use Friendica\Core\L10n;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
+use Friendica\Core\System;
+use Friendica\Module\Response;
+use Friendica\Network\HTTPException\BadRequestException;
+use Friendica\User\Settings\Repository\UserGServer;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
+
+class Action extends \Friendica\BaseModule
+{
+       /** @var IHandleUserSessions */
+       private $session;
+       /** @var UserGServer */
+       private $repository;
+
+       public function __construct(UserGServer $repository, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
+       {
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->session    = $session;
+               $this->repository = $repository;
+       }
+
+       public function post(array $request = [])
+       {
+               $userGServer = $this->repository->getOneByUserAndServer($this->session->getLocalUserId(), $this->parameters['gsid']);
+
+               switch ($this->parameters['action']) {
+                       case 'ignore':
+                               $userGServer->ignore();
+                               break;
+                       case 'unignore':
+                               $userGServer->unignore();
+                               break;
+                       default:
+                               throw new BadRequestException('Unknown user server action ' . $this->parameters['action']);
+               }
+
+               $this->repository->save($userGServer);
+
+               System::exit();
+       }
+}
index e7a178ef12f699891e638101ceaa6770c1160830..15a1350795f6459f0036e95853e51345cb14a12d 100644 (file)
@@ -38,6 +38,7 @@ use Friendica\Model\User;
 use Friendica\Protocol\Activity;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Network;
 use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
@@ -248,11 +249,12 @@ class Post
                        $pinned = DI::l10n()->t('Pinned item');
                }
 
-               $drop     = false;
-               $block    = false;
-               $ignore   = false;
-               $collapse = false;
-               $report   = false;
+               $drop         = false;
+               $block        = false;
+               $ignore       = false;
+               $collapse     = false;
+               $report       = false;
+               $ignoreServer = false;
                if (DI::userSession()->getLocalUserId()) {
                        $drop = [
                                'dropping' => $dropping,
@@ -282,6 +284,11 @@ class Post
                                'label' => DI::l10n()->t('Report post'),
                                'href'  => 'moderation/report/create?' . http_build_query(['cid' => $item['author-id'], 'uri-ids' => [$item['uri-id']]]),
                        ];
+                       if (!Network::isLocalLink($item['plink'])) {
+                               $ignoreServer = [
+                                       'label' => DI::l10n()->t("Ignore %s's server", $item['author-name']),
+                               ];
+                       }
                }
 
                $filer = DI::userSession()->getLocalUserId() ? DI::l10n()->t('Save to folder') : false;
@@ -557,6 +564,7 @@ class Post
                        'ignore_author'   => $ignore,
                        'collapse'        => $collapse,
                        'report'          => $report,
+                       'ignore_server'     => $ignoreServer,
                        'vote'            => $buttons,
                        'like_html'       => $responses['like']['output'],
                        'dislike_html'    => $responses['dislike']['output'],
@@ -571,6 +579,7 @@ class Post
                        'wait'            => DI::l10n()->t('Please wait'),
                        'thread_level'    => $thread_level,
                        'edited'          => $edited,
+                       'author_gsid'     => $item['author-gsid'],
                        'network'         => $item['network'],
                        'network_name'    => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network'], $item['author-gsid']),
                        'network_icon'    => ContactSelector::networkToIcon($item['network'], $item['author-link'], $item['author-gsid']),
index eb32ccc836737d02d123b562bb367ff88fe745fc..e5afdc51e745a83fba5efc1a09a64b45500fff14 100644 (file)
@@ -47,4 +47,46 @@ class UserGServer extends \Friendica\BaseEntity
                $this->ignored = $ignored;
                $this->gserver = $gserver;
        }
+
+       /**
+        * Toggle the ignored property.
+        *
+        * Chainable.
+        *
+        * @return $this
+        */
+       public function toggleIgnored(): UserGServer
+       {
+               $this->ignored = !$this->ignored;
+
+               return $this;
+       }
+
+       /**
+        * Set the ignored property.
+        *
+        * Chainable.
+        *
+        * @return $this
+        */
+       public function ignore(): UserGServer
+       {
+               $this->ignored = true;
+
+               return $this;
+       }
+
+       /**
+        * Unset the ignored property.
+        *
+        * Chainable.
+        *
+        * @return $this
+        */
+       public function unignore(): UserGServer
+       {
+               $this->ignored = false;
+
+               return $this;
+       }
 }
index 71595e5a825d767182b81050a1d2eb8ca2c4945c..edfd69ea20e9388c1f58e82f62c9846c08a89a14 100644 (file)
@@ -639,6 +639,9 @@ return [
        ],
 
        '/settings' => [
+               '/server' => [
+                       '/{gsid:\d+}/{action}' => [Module\Settings\Server\Action::class, [        R::POST]],
+               ],
                '[/]'         => [Module\Settings\Account::class,               [R::GET, R::POST]],
                '/account' => [
                        '[/]'     => [Module\Settings\Account::class,               [R::GET, R::POST]],
index 94f1dd158ae72e2e9c2b7f01db35d92b36520f1e..3a384bbb23eca75c8b749d1e3ad8a273bce9b957 100644 (file)
@@ -210,6 +210,10 @@ function confirmCollapse() {
        return confirm(aStr.collapseAuthor);
 }
 
+function confirmIgnoreServer() {
+       return confirm(aStr.ignoreServer + "\n" + aStr.ignoreServerDesc);
+}
+
 /**
  * Hide and removes an item element from the DOM after the deletion url is
  * successful, restore it else.
@@ -325,4 +329,34 @@ function collapseAuthor(url, elementId) {
                });
        }
 }
+
+
+/**
+ * Ignore author server
+ *
+ * @param {string} url The server ignore URL
+ * @param {string} elementId The DOM id of the item element
+ * @returns {undefined}
+ */
+function ignoreServer(url, elementId) {
+       if (confirmIgnoreServer()) {
+               $("body").css("cursor", "wait");
+
+               var $el = $(document.getElementById(elementId));
+
+               $el.fadeTo("fast", 0.33, function () {
+                       $.post(url)
+                               .then(function () {
+                                       $el.remove();
+                               })
+                               .fail(function () {
+                                       // @todo Show related error message
+                                       $el.fadeTo("fast", 1);
+                               })
+                               .always(function () {
+                                       $("body").css("cursor", "auto");
+                               });
+               });
+       }
+}
 // @license-end
index f979355d74f53425014329abdc63ccb087827e66..8077ceb9e37b631e558dce584426fe42e36d2dd8 100644 (file)
@@ -3,10 +3,12 @@
 They are loaded into the html <head> so that js functions can use them *}}
 <script type="text/javascript">
        const aStr = {
-               delitem        : "{{$l10n.delitem|escape:'javascript' nofilter}}",
-               blockAuthor    : "{{$l10n.blockAuthor|escape:'javascript' nofilter}}",
-               ignoreAuthor   : "{{$l10n.ignoreAuthor|escape:'javascript' nofilter}}",
-               collapseAuthor : "{{$l10n.collapseAuthor|escape:'javascript' nofilter}}",
+               delitem          : "{{$l10n.delitem|escape:'javascript' nofilter}}",
+               blockAuthor      : "{{$l10n.blockAuthor|escape:'javascript' nofilter}}",
+               ignoreAuthor     : "{{$l10n.ignoreAuthor|escape:'javascript' nofilter}}",
+               collapseAuthor   : "{{$l10n.collapseAuthor|escape:'javascript' nofilter}}",
+               ignoreServer     : "{{$l10n.ignoreServer|escape:'javascript' nofilter}}",
+               ignoreServerDesc : "{{$l10n.ignoreServerDesc|escape:'javascript' nofilter}}",
        };
        const aActErr = {
                like       : "{{$l10n.likeError|escape:'javascript' nofilter}}",
index e42225009f05b6828996ab3049916c34c6ac4dec..16494e1c0cf97684c003ab0cbdf37c78fc65e030 100644 (file)
@@ -401,13 +401,17 @@ as the value of $top_child_total (this is done at the end of this file)
                                         {{/if}}
                                         {{if $item.ignore_author}}
                                         <li role="menuitem">
-                                                <a class="btn-link navicon ignore" href="javascript:ignoreAuthor('item/ignore/{{$item.id}}', 'item-{{$item.guid}}');" title="{{$item.ignore_author.label}}"><i class="fa fa-ban" aria-hidden="true"></i> {{$item.ignore_author.label}}</a>
+                                                <a class="btn-link navicon ignore" href="javascript:ignoreAuthor('item/ignore/{{$item.id}}', 'item-{{$item.guid}}');" title="{{$item.ignore_author.label}}"><i class="fa fa-eye-slash" aria-hidden="true"></i> {{$item.ignore_author.label}}</a>
                                         </li>
                                         {{/if}}
                                         {{if $item.collapse}}
                                         <li role="menuitem">
-                                                <a class="btn-link navicon collapse" href="javascript:collapseAuthor('item/collapse/{{$item.id}}', 'item-{{$item.guid}}');" title="{{$item.collapse.label}}"><i class="fa fa-ban" aria-hidden="true"></i> {{$item.collapse.label}}</a>
+                                                <a class="btn-link navicon collapse" href="javascript:collapseAuthor('item/collapse/{{$item.id}}', 'item-{{$item.guid}}');" title="{{$item.collapse.label}}"><i class="fa fa-minus-square" aria-hidden="true"></i> {{$item.collapse.label}}</a>
                                         </li>
+                                        {{/if}}
+                                           {{if $item.ignore_server}}
+                                        <li role="menuitem">
+                                                <a class="btn-link navicon ignoreServer" href="javascript:ignoreServer('settings/server/{{$item.author_gsid}}/ignore', 'item-{{$item.guid}}');" title="{{$item.ignore_server.label}}"><i class="fa fa-eye-slash" aria-hidden="true"></i> {{$item.ignore_server.label}}</a>
                                         </li>
                                         {{/if}}
                                         {{if $item.report}}