X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/9779c1a357d49654856ceb1b1f30d91cde8fa2fd..refs/pull/5725/head:/app/Activity/Notifications/Handlers/PageCreationNotificationHandler.php diff --git a/app/Activity/Notifications/Handlers/PageCreationNotificationHandler.php b/app/Activity/Notifications/Handlers/PageCreationNotificationHandler.php index a61df48ae..2492021e2 100644 --- a/app/Activity/Notifications/Handlers/PageCreationNotificationHandler.php +++ b/app/Activity/Notifications/Handlers/PageCreationNotificationHandler.php @@ -2,33 +2,23 @@ namespace BookStack\Activity\Notifications\Handlers; +use BookStack\Activity\Models\Activity; use BookStack\Activity\Models\Loggable; -use BookStack\Activity\Models\Watch; +use BookStack\Activity\Notifications\Messages\PageCreationNotification; use BookStack\Activity\Tools\EntityWatchers; use BookStack\Activity\WatchLevels; +use BookStack\Entities\Models\Page; use BookStack\Users\Models\User; -class PageCreationNotificationHandler implements NotificationHandler +class PageCreationNotificationHandler extends BaseNotificationHandler { - public function handle(string $activityType, Loggable|string $detail, User $user): void + public function handle(Activity $activity, Loggable|string $detail, User $user): void { - // TODO + if (!($detail instanceof Page)) { + throw new \InvalidArgumentException("Detail for page create notifications must be a page"); + } - // No user-level preferences to care about here. - // Possible Scenarios: - // ✅ User watching parent chapter - // ✅ User watching parent book - // ❌ User ignoring parent book - // ❌ User ignoring parent chapter - // ❌ User watching parent book, ignoring chapter - // ✅ User watching parent book, watching chapter - // ❌ User ignoring parent book, ignoring chapter - // ✅ User ignoring parent book, watching chapter - - // Get all relevant watchers $watchers = new EntityWatchers($detail, WatchLevels::NEW); - - // TODO - need to check entity visibility and receive-notifications permissions. - // Maybe abstract this to a generic late-stage filter? + $this->sendNotificationToUserIds(PageCreationNotification::class, $watchers->getWatcherUserIds(), $user, $detail, $detail); } }