Merge pull request #11352 from MrPetovan/task/4639-soapbox-intro-notification

Add support for notification visibility settings
This commit is contained in:
Michael Vogel 2022-03-17 06:33:10 +01:00 committed by GitHub
commit 5c3226d88e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 4 deletions

View file

@ -35,8 +35,10 @@ use Friendica\Model\Item;
use Friendica\Model\Notification; use Friendica\Model\Notification;
use Friendica\Model\Profile; 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\Util\Temporal;
use Friendica\Worker\Delivery; use Friendica\Worker\Delivery;
@ -352,7 +354,18 @@ function settings_post(App $a)
DI::pConfig()->set(local_user(), 'expire', 'photos', $expire_photos); DI::pConfig()->set(local_user(), 'expire', 'photos', $expire_photos);
DI::pConfig()->set(local_user(), 'expire', 'network_only', $expire_network_only); DI::pConfig()->set(local_user(), 'expire', 'network_only', $expire_network_only);
// Reset like notifications when they are going to be shown again
if (!DI::pConfig()->get(local_user(), 'system', 'notify_like') && $notify_like) {
DI::notification()->setAllSeenForUser(local_user(), ['vid' => Verb::getID(Activity::LIKE)]);
}
DI::pConfig()->set(local_user(), 'system', 'notify_like', $notify_like); DI::pConfig()->set(local_user(), 'system', 'notify_like', $notify_like);
// Reset share notifications when they are going to be shown again
if (!DI::pConfig()->get(local_user(), 'system', 'notify_announce') && $notify_announce) {
DI::notification()->setAllSeenForUser(local_user(), ['vid' => Verb::getID(Activity::ANNOUNCE)]);
}
DI::pConfig()->set(local_user(), 'system', 'notify_announce', $notify_announce); DI::pConfig()->set(local_user(), 'system', 'notify_announce', $notify_announce);
DI::pConfig()->set(local_user(), 'system', 'email_textonly', $email_textonly); DI::pConfig()->set(local_user(), 'system', 'email_textonly', $email_textonly);

View file

@ -87,7 +87,7 @@ class Ping extends BaseModule
if (local_user()) { if (local_user()) {
if (DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) { if (DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) {
$notifications = $this->notificationRepo->selectForUser(local_user(), ['`vid` != ?', Verb::getID(\Friendica\Protocol\Activity::LIKE)], ['limit' => 50, 'order' => ['id' => true]]); $notifications = $this->notificationRepo->selectDetailedForUser(local_user());
} else { } else {
$notifications = $this->notificationRepo->selectDigestForUser(local_user()); $notifications = $this->notificationRepo->selectDigestForUser(local_user());
} }

View file

@ -24,6 +24,7 @@ namespace Friendica\Navigation\Notifications\Repository;
use Exception; use Exception;
use Friendica\BaseCollection; use Friendica\BaseCollection;
use Friendica\BaseRepository; use Friendica\BaseRepository;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Verb; use Friendica\Model\Verb;
@ -41,9 +42,14 @@ class Notification extends BaseRepository
protected static $table_name = 'notification'; protected static $table_name = 'notification';
public function __construct(Database $database, LoggerInterface $logger, Factory\Notification $factory) /** @var IManagePersonalConfigValues */
private $pconfig;
public function __construct(IManagePersonalConfigValues $pconfig, Database $database, LoggerInterface $logger, Factory\Notification $factory)
{ {
parent::__construct($database, $logger, $factory); parent::__construct($database, $logger, $factory);
$this->pconfig = $pconfig;
} }
/** /**
@ -100,6 +106,28 @@ class Notification extends BaseRepository
return $this->select($condition, $params); return $this->select($condition, $params);
} }
/**
* Returns only the most recent notifications for the same conversation or contact
*
* @param int $uid
* @return Collection\Notifications
* @throws Exception
*/
public function selectDetailedForUser(int $uid): Collection\Notifications
{
$condition = [];
if (!$this->pconfig->get($uid, 'system', 'notify_like')) {
$condition = DBA::mergeConditions($condition, ['`vid` != ?', Verb::getID(\Friendica\Protocol\Activity::LIKE)]);
}
if (!$this->pconfig->get($uid, 'system', 'notify_announce')) {
$condition = DBA::mergeConditions($condition, ['`vid` != ?', Verb::getID(\Friendica\Protocol\Activity::ANNOUNCE)]);
}
return $this->selectForUser(local_user(), $condition, ['limit' => 50, 'order' => ['id' => true]]);
}
/** /**
* Returns only the most recent notifications for the same conversation or contact * Returns only the most recent notifications for the same conversation or contact
* *
@ -109,6 +137,20 @@ class Notification extends BaseRepository
*/ */
public function selectDigestForUser(int $uid): Collection\Notifications public function selectDigestForUser(int $uid): Collection\Notifications
{ {
$values = [$uid];
$like_condition = '';
if (!$this->pconfig->get($uid, 'system', 'notify_like')) {
$like_condition = 'AND vid != ?';
$values[] = Verb::getID(\Friendica\Protocol\Activity::LIKE);
}
$announce_condition = '';
if (!$this->pconfig->get($uid, 'system', 'notify_announce')) {
$announce_condition = 'AND vid != ?';
$values[] = Verb::getID(\Friendica\Protocol\Activity::ANNOUNCE);
}
$rows = $this->db->p(" $rows = $this->db->p("
SELECT notification.* SELECT notification.*
FROM notification FROM notification
@ -116,12 +158,13 @@ class Notification extends BaseRepository
SELECT MAX(`id`) SELECT MAX(`id`)
FROM notification FROM notification
WHERE uid = ? WHERE uid = ?
AND vid != ? $like_condition
$announce_condition
GROUP BY IFNULL(`parent-uri-id`, `actor-id`) GROUP BY IFNULL(`parent-uri-id`, `actor-id`)
) )
ORDER BY `seen`, `id` DESC ORDER BY `seen`, `id` DESC
LIMIT 50 LIMIT 50
", $uid, Verb::getID(\Friendica\Protocol\Activity::LIKE)); ", ...$values);
$Entities = new Collection\Notifications(); $Entities = new Collection\Notifications();
foreach ($rows as $fields) { foreach ($rows as $fields) {