Merge pull request #11575 from annando/issue-11469

Issue 11469: Respect desktop notification settings
This commit is contained in:
Hypolite Petovan 2022-05-29 08:06:32 -04:00 committed by GitHub
commit 697b8a6cb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 23 deletions

View File

@ -23,25 +23,16 @@ use Friendica\App;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Content\Feature; use Friendica\Content\Feature;
use Friendica\Content\Nav; use Friendica\Content\Nav;
use Friendica\Core\ACL;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Group;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Notification;
use Friendica\Model\Profile;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Model\Verb;
use Friendica\Module\BaseSettings; use Friendica\Module\BaseSettings;
use Friendica\Module\Security\Login; use Friendica\Module\Security\Login;
use Friendica\Protocol\Activity;
use Friendica\Protocol\Email; use Friendica\Protocol\Email;
use Friendica\Util\Temporal;
use Friendica\Worker\Delivery;
function settings_init(App $a) function settings_init(App $a)
{ {

View File

@ -37,7 +37,6 @@ use Friendica\Core\Theme;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item as ItemModel; use Friendica\Model\Item as ItemModel;
use Friendica\Model\Photo;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User; use Friendica\Model\User;
@ -48,7 +47,6 @@ use Friendica\Protocol\Activity;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Profiler; use Friendica\Util\Profiler;
use Friendica\Util\Proxy;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\Temporal; use Friendica\Util\Temporal;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;

View File

@ -143,17 +143,7 @@ class Subscription
{ {
$type = \Friendica\Factory\Api\Mastodon\Notification::getType($Notification); $type = \Friendica\Factory\Api\Mastodon\Notification::getType($Notification);
$desktop_notification = !in_array($type, [Notification::TYPE_RESHARE, Notification::TYPE_LIKE]); if (DI::notify()->NotifyOnDesktop($Notification, $type)) {
if (DI::pConfig()->get($Notification->uid, 'system', 'notify_like') && ($type == Notification::TYPE_LIKE)) {
$desktop_notification = true;
}
if (DI::pConfig()->get($Notification->uid, 'system', 'notify_announce') && ($type == Notification::TYPE_RESHARE)) {
$desktop_notification = true;
}
if ($desktop_notification) {
DI::notify()->createFromNotification($Notification); DI::notify()->createFromNotification($Notification);
} }

View File

@ -187,6 +187,9 @@ class Ping extends BaseModule
$owner = User::getOwnerDataById(local_user()); $owner = User::getOwnerDataById(local_user());
$navNotifications = array_map(function (Entity\Notification $notification) use ($owner) { $navNotifications = array_map(function (Entity\Notification $notification) use ($owner) {
if (!DI::notify()->NotifyOnDesktop($notification)) {
return null;
}
if (($notification->type == Post\UserNotification::TYPE_NONE) && in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP])) { if (($notification->type == Post\UserNotification::TYPE_NONE) && in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP])) {
return null; return null;
} }

View File

@ -26,6 +26,7 @@ use Friendica\BaseRepository;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Plaintext; use Friendica\Content\Text\Plaintext;
use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
@ -37,6 +38,7 @@ use Friendica\Navigation\Notifications\Entity;
use Friendica\Navigation\Notifications\Exception; use Friendica\Navigation\Notifications\Exception;
use Friendica\Navigation\Notifications\Factory; use Friendica\Navigation\Notifications\Factory;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Object\Api\Mastodon\Notification;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Emailer; use Friendica\Util\Emailer;
@ -59,6 +61,9 @@ class Notify extends BaseRepository
/** @var IManageConfigValues */ /** @var IManageConfigValues */
protected $config; protected $config;
/** @var IManagePersonalConfigValues */
private $pConfig;
/** @var Emailer */ /** @var Emailer */
protected $emailer; protected $emailer;
@ -67,11 +72,12 @@ class Notify extends BaseRepository
protected static $table_name = 'notify'; protected static $table_name = 'notify';
public function __construct(Database $database, LoggerInterface $logger, L10n $l10n, BaseURL $baseUrl, IManageConfigValues $config, Emailer $emailer, Factory\Notification $notification, Factory\Notify $factory = null) public function __construct(Database $database, LoggerInterface $logger, L10n $l10n, BaseURL $baseUrl, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, Emailer $emailer, Factory\Notification $notification, Factory\Notify $factory = null)
{ {
$this->l10n = $l10n; $this->l10n = $l10n;
$this->baseUrl = $baseUrl; $this->baseUrl = $baseUrl;
$this->config = $config; $this->config = $config;
$this->pConfig = $pConfig;
$this->emailer = $emailer; $this->emailer = $emailer;
$this->notification = $notification; $this->notification = $notification;
@ -651,6 +657,27 @@ class Notify extends BaseRepository
return false; return false;
} }
public function NotifyOnDesktop(Entity\Notification $Notification, string $type = null): bool
{
if (is_null($type)) {
$type = \Friendica\Factory\Api\Mastodon\Notification::getType($Notification);
}
if (!in_array($type, [Notification::TYPE_RESHARE, Notification::TYPE_LIKE])) {
return true;
}
if ($this->pConfig->get($Notification->uid, 'system', 'notify_like') && ($type == Notification::TYPE_LIKE)) {
return true;
}
if ($this->pConfig->get($Notification->uid, 'system', 'notify_announce') && ($type == Notification::TYPE_RESHARE)) {
return true;
}
return false;
}
public function createFromNotification(Entity\Notification $Notification) public function createFromNotification(Entity\Notification $Notification)
{ {
$this->logger->info('Start', ['uid' => $Notification->uid, 'id' => $Notification->id, 'type' => $Notification->type]); $this->logger->info('Start', ['uid' => $Notification->uid, 'id' => $Notification->id, 'type' => $Notification->type]);