mirror of
https://github.com/friendica/friendica
synced 2024-11-19 23:03:41 +00:00
Merge pull request #11575 from annando/issue-11469
Issue 11469: Respect desktop notification settings
This commit is contained in:
commit
697b8a6cb8
5 changed files with 32 additions and 23 deletions
|
@ -23,25 +23,16 @@ use Friendica\App;
|
|||
use Friendica\BaseModule;
|
||||
use Friendica\Content\Feature;
|
||||
use Friendica\Content\Nav;
|
||||
use Friendica\Core\ACL;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Group;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Notification;
|
||||
use Friendica\Model\Profile;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Model\Verb;
|
||||
use Friendica\Module\BaseSettings;
|
||||
use Friendica\Module\Security\Login;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\Email;
|
||||
use Friendica\Util\Temporal;
|
||||
use Friendica\Worker\Delivery;
|
||||
|
||||
function settings_init(App $a)
|
||||
{
|
||||
|
|
|
@ -37,7 +37,6 @@ use Friendica\Core\Theme;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Item as ItemModel;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Model\Tag;
|
||||
use Friendica\Model\User;
|
||||
|
@ -48,7 +47,6 @@ use Friendica\Protocol\Activity;
|
|||
use Friendica\Util\Crypto;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Profiler;
|
||||
use Friendica\Util\Proxy;
|
||||
use Friendica\Util\Strings;
|
||||
use Friendica\Util\Temporal;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
|
|
@ -143,17 +143,7 @@ class Subscription
|
|||
{
|
||||
$type = \Friendica\Factory\Api\Mastodon\Notification::getType($Notification);
|
||||
|
||||
$desktop_notification = !in_array($type, [Notification::TYPE_RESHARE, Notification::TYPE_LIKE]);
|
||||
|
||||
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) {
|
||||
if (DI::notify()->NotifyOnDesktop($Notification, $type)) {
|
||||
DI::notify()->createFromNotification($Notification);
|
||||
}
|
||||
|
||||
|
|
|
@ -187,6 +187,9 @@ class Ping extends BaseModule
|
|||
$owner = User::getOwnerDataById(local_user());
|
||||
|
||||
$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])) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ use Friendica\BaseRepository;
|
|||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Content\Text\Plaintext;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\System;
|
||||
|
@ -37,6 +38,7 @@ use Friendica\Navigation\Notifications\Entity;
|
|||
use Friendica\Navigation\Notifications\Exception;
|
||||
use Friendica\Navigation\Notifications\Factory;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Object\Api\Mastodon\Notification;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Emailer;
|
||||
|
@ -59,6 +61,9 @@ class Notify extends BaseRepository
|
|||
/** @var IManageConfigValues */
|
||||
protected $config;
|
||||
|
||||
/** @var IManagePersonalConfigValues */
|
||||
private $pConfig;
|
||||
|
||||
/** @var Emailer */
|
||||
protected $emailer;
|
||||
|
||||
|
@ -67,11 +72,12 @@ class Notify extends BaseRepository
|
|||
|
||||
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->baseUrl = $baseUrl;
|
||||
$this->config = $config;
|
||||
$this->pConfig = $pConfig;
|
||||
$this->emailer = $emailer;
|
||||
$this->notification = $notification;
|
||||
|
||||
|
@ -651,6 +657,27 @@ class Notify extends BaseRepository
|
|||
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)
|
||||
{
|
||||
$this->logger->info('Start', ['uid' => $Notification->uid, 'id' => $Notification->id, 'type' => $Notification->type]);
|
||||
|
|
Loading…
Reference in a new issue