diff --git a/src/Module/Notifications/Ping.php b/src/Module/Notifications/Ping.php index 50c8232032..d97fb27fdf 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; @@ -86,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()); } @@ -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/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'); 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) { 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; 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