3 namespace BookStack\Activity\Notifications\Handlers;
5 use BookStack\Activity\Models\Loggable;
6 use BookStack\Activity\Notifications\Messages\PageUpdateNotification;
7 use BookStack\Activity\Tools\EntityWatchers;
8 use BookStack\Activity\WatchLevels;
9 use BookStack\Entities\Models\Page;
10 use BookStack\Settings\UserNotificationPreferences;
11 use BookStack\Users\Models\User;
13 class PageUpdateNotificationHandler extends BaseNotificationHandler
15 public function handle(string $activityType, Loggable|string $detail, User $user): void
17 if (!($detail instanceof Page)) {
18 throw new \InvalidArgumentException("Detail for page update notifications must be a page");
21 $watchers = new EntityWatchers($detail, WatchLevels::UPDATES);
22 $watcherIds = $watchers->getWatcherUserIds();
24 if (!$watchers->isUserIgnoring($detail->owned_by) && $detail->ownedBy) {
25 $userNotificationPrefs = new UserNotificationPreferences($detail->ownedBy);
26 if ($userNotificationPrefs->notifyOnOwnPageChanges()) {
27 $watcherIds[] = $detail->owned_by;
31 $this->sendNotificationToUserIds(PageUpdateNotification::class, $watcherIds, $user, $detail);