From 8bb2c9fc1391e9cec514d9ca61380484798e9555 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Jan 2022 19:37:52 +0000 Subject: [PATCH] Support for desktop notifications for reshared posts --- src/Model/Post/UserNotification.php | 8 ++++++-- .../Notifications/Factory/Notification.php | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Model/Post/UserNotification.php b/src/Model/Post/UserNotification.php index d7c72d899..77aecee29 100644 --- a/src/Model/Post/UserNotification.php +++ b/src/Model/Post/UserNotification.php @@ -257,8 +257,12 @@ class UserNotification } } + if (empty($notification_type)) { + return; + } + // Only create notifications for posts and comments, not for activities - if (empty($notification_type) || !in_array($item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT])) { + if (($item['gravity'] == GRAVITY_ACTIVITY) && ($item['verb'] != Activity::ANNOUNCE)) { return; } @@ -280,7 +284,7 @@ class UserNotification */ private static function insertNotificationByItem(int $type, int $uid, array $item): void { - if (($item['gravity'] == GRAVITY_ACTIVITY) && + if (($item['verb'] != Activity::ANNOUNCE) && ($item['gravity'] == GRAVITY_ACTIVITY) && !in_array($type, [self::TYPE_DIRECT_COMMENT, self::TYPE_DIRECT_THREAD_COMMENT])) { // Activities are only stored when performed on the user's post or comment return; diff --git a/src/Navigation/Notifications/Factory/Notification.php b/src/Navigation/Notifications/Factory/Notification.php index 68b2e8a70..b0f57f0e4 100644 --- a/src/Navigation/Notifications/Factory/Notification.php +++ b/src/Navigation/Notifications/Factory/Notification.php @@ -153,6 +153,8 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow $title = ''; } + $this->logger->debug('Got verb and type', ['verb' => $Notification->verb, 'type' => $Notification->type]); + switch ($Notification->verb) { case Activity::LIKE: switch ($Notification->type) { @@ -182,6 +184,17 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow case Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT: $msg = $userL10n->t('%1$s shared your post %2$s'); break; + case Post\UserNotification::TYPE_SHARED: + if (($causer['id'] != $author['id']) && ($title != '')) { + $msg = $userL10n->t('%1$s shared the post %2$s from %3$s'); + } elseif ($causer['id'] != $author['id']) { + $msg = $userL10n->t('%1$s shared a post from %3$s'); + } elseif ($title != '') { + $msg = $userL10n->t('%1$s shared the post %2$s'); + } else { + $msg = $userL10n->t('%1$s shared a post'); + } + break; } break; case Activity::POST: