From 73c7b88fb2b25ddc1a5b4c04f2d70b86fefe2019 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 14 Mar 2022 21:53:33 -0400 Subject: [PATCH 1/4] Add exception when message is empty in FormatteNavNotification::createFromNotification - Filter out message less notifications in Ping --- src/Module/Notifications/Ping.php | 16 +++++++++--- .../Exception/NoMessageException.php | 26 +++++++++++++++++++ .../Factory/FormattedNavNotification.php | 13 ++++++++++ .../ValueObject/FormattedNavNotification.php | 4 +-- 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 src/Navigation/Notifications/Exception/NoMessageException.php diff --git a/src/Module/Notifications/Ping.php b/src/Module/Notifications/Ping.php index 50c8232032..c2c0c2c674 100644 --- a/src/Module/Notifications/Ping.php +++ b/src/Module/Notifications/Ping.php @@ -37,6 +37,7 @@ use Friendica\Model\Verb; use Friendica\Module\Register; use Friendica\Module\Response; use Friendica\Navigation\Notifications\Entity; +use Friendica\Navigation\Notifications\Exception\NoMessageException; use Friendica\Navigation\Notifications\Factory; use Friendica\Navigation\Notifications\Repository; use Friendica\Navigation\Notifications\ValueObject; @@ -182,11 +183,20 @@ class Ping extends BaseModule } } - $sysnotify_count = $notifications->countUnseen(); - + // Temporary workaround for notifications without messages like with the following verb: + // - \Friendica\Protocol\Activity::ANNOUNCE $navNotifications = array_map(function (Entity\Notification $notification) { - return $this->formattedNavNotification->createFromNotification($notification); + try { + return $this->formattedNavNotification->createFromNotification($notification); + } catch (NoMessageException $e) { + return null; + } }, $notifications->getArrayCopy()); + $navNotifications = array_filter($navNotifications); + + $sysnotify_count = array_reduce($navNotifications, function (int $carry, ValueObject\FormattedNavNotification $navNotification) { + return $carry + ($navNotification->seen ? 0 : 1); + }, 0); // merge all notification types in one array foreach ($intros as $intro) { diff --git a/src/Navigation/Notifications/Exception/NoMessageException.php b/src/Navigation/Notifications/Exception/NoMessageException.php new file mode 100644 index 0000000000..710f25fa33 --- /dev/null +++ b/src/Navigation/Notifications/Exception/NoMessageException.php @@ -0,0 +1,26 @@ +. + * + */ + +namespace Friendica\Navigation\Notifications\Exception; + +class NoMessageException extends \Exception +{ +} diff --git a/src/Navigation/Notifications/Factory/FormattedNavNotification.php b/src/Navigation/Notifications/Factory/FormattedNavNotification.php index a9498eaa58..2577f53337 100644 --- a/src/Navigation/Notifications/Factory/FormattedNavNotification.php +++ b/src/Navigation/Notifications/Factory/FormattedNavNotification.php @@ -25,6 +25,7 @@ use Friendica\BaseFactory; use Friendica\Core\Renderer; use Friendica\Model\Contact; use Friendica\Navigation\Notifications\Entity; +use Friendica\Navigation\Notifications\Exception\NoMessageException; use Friendica\Navigation\Notifications\ValueObject; use Friendica\Util\DateTimeFormat; use Friendica\Util\Proxy; @@ -94,10 +95,22 @@ class FormattedNavNotification extends BaseFactory ); } + /** + * @param Entity\Notification $notification + * @return ValueObject\FormattedNavNotification + * @throws NoMessageException + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \Friendica\Network\HTTPException\NotFoundException + * @throws \Friendica\Network\HTTPException\ServiceUnavailableException + */ public function createFromNotification(Entity\Notification $notification): ValueObject\FormattedNavNotification { $message = $this->notification->getMessageFromNotification($notification); + if (empty($message)) { + throw new NoMessageException(); + } + if (!isset(self::$contacts[$notification->actorId])) { self::$contacts[$notification->actorId] = Contact::getById($notification->actorId, ['name', 'url']); } diff --git a/src/Navigation/Notifications/ValueObject/FormattedNavNotification.php b/src/Navigation/Notifications/ValueObject/FormattedNavNotification.php index 4a11fa616f..d2fae060aa 100644 --- a/src/Navigation/Notifications/ValueObject/FormattedNavNotification.php +++ b/src/Navigation/Notifications/ValueObject/FormattedNavNotification.php @@ -21,12 +21,12 @@ namespace Friendica\Navigation\Notifications\ValueObject; -use Friendica\BaseDataTransferObject; +use Friendica\BaseEntity; /** * A view-only object for printing item notifications to the frontend */ -class FormattedNavNotification extends BaseDataTransferObject +class FormattedNavNotification extends BaseEntity { /** @var array */ protected $contact; From 36e85b01c6429580e0caca78f7fa41573992fe6d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 14 Mar 2022 22:25:10 -0400 Subject: [PATCH 2/4] Hide like notifications from menu again --- src/Module/Notifications/Ping.php | 2 +- src/Navigation/Notifications/Repository/Notification.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Module/Notifications/Ping.php b/src/Module/Notifications/Ping.php index c2c0c2c674..d97fb27fdf 100644 --- a/src/Module/Notifications/Ping.php +++ b/src/Module/Notifications/Ping.php @@ -87,7 +87,7 @@ class Ping extends BaseModule if (local_user()) { if (DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) { - $notifications = $this->notificationRepo->selectForUser(local_user(), [], ['limit' => 50]); + $notifications = $this->notificationRepo->selectForUser(local_user(), ['`vid` != ?', Verb::getID(\Friendica\Protocol\Activity::LIKE)], ['limit' => 50]); } else { $notifications = $this->notificationRepo->selectDigestForUser(local_user()); } diff --git a/src/Navigation/Notifications/Repository/Notification.php b/src/Navigation/Notifications/Repository/Notification.php index 290845645a..60ac82ae31 100644 --- a/src/Navigation/Notifications/Repository/Notification.php +++ b/src/Navigation/Notifications/Repository/Notification.php @@ -116,11 +116,12 @@ class Notification extends BaseRepository SELECT MAX(`id`) FROM notification WHERE uid = ? + AND vid != ? GROUP BY IFNULL(`parent-uri-id`, `actor-id`) ) ORDER BY `seen`, `id` DESC LIMIT 50 - ", $uid); + ", $uid, Verb::getID(\Friendica\Protocol\Activity::LIKE)); $Entities = new Collection\Notifications(); foreach ($rows as $fields) { From 07d4cdbdde9fad20cdc0323995e5209ef2f98942 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 14 Mar 2022 22:25:57 -0400 Subject: [PATCH 3/4] Fix misleading notification message strings - The mentioned title is from the top-level post, not the liked post --- src/Navigation/Notifications/Factory/Notification.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Navigation/Notifications/Factory/Notification.php b/src/Navigation/Notifications/Factory/Notification.php index b404ad8671..d64ae3f8d7 100644 --- a/src/Navigation/Notifications/Factory/Notification.php +++ b/src/Navigation/Notifications/Factory/Notification.php @@ -175,7 +175,7 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow case Activity::LIKE: switch ($Notification->type) { case Post\UserNotification::TYPE_DIRECT_COMMENT: - $msg = $this->l10n->t('%1$s liked your comment %2$s'); + $msg = $this->l10n->t('%1$s liked your comment on %2$s'); break; case Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT: $msg = $this->l10n->t('%1$s liked your post %2$s'); @@ -185,7 +185,7 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow case Activity::DISLIKE: switch ($Notification->type) { case Post\UserNotification::TYPE_DIRECT_COMMENT: - $msg = $this->l10n->t('%1$s disliked your comment %2$s'); + $msg = $this->l10n->t('%1$s disliked your comment on %2$s'); break; case Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT: $msg = $this->l10n->t('%1$s disliked your post %2$s'); From 634c785d4b849137e2a45e52a5ff37233098e582 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 14 Mar 2022 22:29:38 -0400 Subject: [PATCH 4/4] Update main translation file after string changes --- view/lang/C/messages.po | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index bdd6c1efaf..3dd8725a04 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2022.05-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-03-14 08:01-0400\n" +"POT-Creation-Date: 2022-03-14 22:29-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -8513,11 +8513,11 @@ msgstr "" msgid "Show unread" msgstr "" -#: src/Module/Notifications/Ping.php:204 +#: src/Module/Notifications/Ping.php:211 msgid "{0} requested registration" msgstr "" -#: src/Module/Notifications/Ping.php:215 +#: src/Module/Notifications/Ping.php:222 #, php-format msgid "{0} and %d others requested registration" msgstr "" @@ -9963,7 +9963,7 @@ msgid "" "features and resources." msgstr "" -#: src/Navigation/Notifications/Factory/FormattedNavNotification.php:122 +#: src/Navigation/Notifications/Factory/FormattedNavNotification.php:135 msgid "{0}} wants to follow you" msgstr "" @@ -10032,7 +10032,7 @@ msgstr "" #: src/Navigation/Notifications/Factory/Notification.php:178 #, php-format -msgid "%1$s liked your comment %2$s" +msgid "%1$s liked your comment on %2$s" msgstr "" #: src/Navigation/Notifications/Factory/Notification.php:181 @@ -10042,7 +10042,7 @@ msgstr "" #: src/Navigation/Notifications/Factory/Notification.php:188 #, php-format -msgid "%1$s disliked your comment %2$s" +msgid "%1$s disliked your comment on %2$s" msgstr "" #: src/Navigation/Notifications/Factory/Notification.php:191