From: Hypolite Petovan Date: Sun, 9 Jul 2023 20:14:53 +0000 (-0400) Subject: [frio] Add Mute Author Server button to post actions X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4c6334ea13c0774e31b83a1cc7713c0560f7d66d;p=friendica.git [frio] Add Mute Author Server button to post actions --- diff --git a/src/App/Page.php b/src/App/Page.php index 96bb59425e..e369d482e8 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -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'), diff --git a/src/Content/Conversation.php b/src/Content/Conversation.php index 710422ee76..caaaf21d11 100644 --- a/src/Content/Conversation.php +++ b/src/Content/Conversation.php @@ -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 index 0000000000..13c1cf5c74 --- /dev/null +++ b/src/Module/Settings/Server/Action.php @@ -0,0 +1,68 @@ +. + * + */ + +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(); + } +} diff --git a/src/Object/Post.php b/src/Object/Post.php index e7a178ef12..15a1350795 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -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']), diff --git a/src/User/Settings/Entity/UserGServer.php b/src/User/Settings/Entity/UserGServer.php index eb32ccc836..e5afdc51e7 100644 --- a/src/User/Settings/Entity/UserGServer.php +++ b/src/User/Settings/Entity/UserGServer.php @@ -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; + } } diff --git a/static/routes.config.php b/static/routes.config.php index 71595e5a82..edfd69ea20 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -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]], diff --git a/view/theme/frio/js/textedit.js b/view/theme/frio/js/textedit.js index 94f1dd158a..3a384bbb23 100644 --- a/view/theme/frio/js/textedit.js +++ b/view/theme/frio/js/textedit.js @@ -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 diff --git a/view/theme/frio/templates/js_strings.tpl b/view/theme/frio/templates/js_strings.tpl index f979355d74..8077ceb9e3 100644 --- a/view/theme/frio/templates/js_strings.tpl +++ b/view/theme/frio/templates/js_strings.tpl @@ -3,10 +3,12 @@ They are loaded into the html so that js functions can use them *}}