]> BookStack Code Mirror - bookstack/commitdiff
Notifications: Started activity->notification core framework
authorDan Brown <redacted>
Wed, 19 Jul 2023 10:03:05 +0000 (11:03 +0100)
committerDan Brown <redacted>
Wed, 19 Jul 2023 10:03:05 +0000 (11:03 +0100)
app/Activity/Notifications/Handlers/CommentCreationNotificationHandler.php [new file with mode: 0644]
app/Activity/Notifications/Handlers/NotificationHandler.php [new file with mode: 0644]
app/Activity/Notifications/Handlers/PageCreationNotificationHandler.php [new file with mode: 0644]
app/Activity/Notifications/Handlers/PageUpdateNotificationHandler.php [new file with mode: 0644]
app/Activity/Tools/ActivityLogger.php

diff --git a/app/Activity/Notifications/Handlers/CommentCreationNotificationHandler.php b/app/Activity/Notifications/Handlers/CommentCreationNotificationHandler.php
new file mode 100644 (file)
index 0000000..5f2e1c7
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+namespace BookStack\Activity\Notifications\Handlers;
+
+use BookStack\Activity\Models\Loggable;
+
+class CommentCreationNotificationHandler implements NotificationHandler
+{
+    public function handle(string $activityType, Loggable|string $detail): void
+    {
+        // TODO
+    }
+}
diff --git a/app/Activity/Notifications/Handlers/NotificationHandler.php b/app/Activity/Notifications/Handlers/NotificationHandler.php
new file mode 100644 (file)
index 0000000..fdf97eb
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+namespace BookStack\Activity\Notifications\Handlers;
+
+use BookStack\Activity\Models\Loggable;
+
+interface NotificationHandler
+{
+    /**
+     * Run this handler.
+     */
+    public function handle(string $activityType, string|Loggable $detail): void;
+}
diff --git a/app/Activity/Notifications/Handlers/PageCreationNotificationHandler.php b/app/Activity/Notifications/Handlers/PageCreationNotificationHandler.php
new file mode 100644 (file)
index 0000000..20189fc
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+namespace BookStack\Activity\Notifications\Handlers;
+
+use BookStack\Activity\Models\Loggable;
+
+class PageCreationNotificationHandler implements NotificationHandler
+{
+    public function handle(string $activityType, Loggable|string $detail): void
+    {
+        // TODO
+    }
+}
diff --git a/app/Activity/Notifications/Handlers/PageUpdateNotificationHandler.php b/app/Activity/Notifications/Handlers/PageUpdateNotificationHandler.php
new file mode 100644 (file)
index 0000000..ef71dcc
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+namespace BookStack\Activity\Notifications\Handlers;
+
+use BookStack\Activity\Models\Loggable;
+
+class PageUpdateNotificationHandler implements NotificationHandler
+{
+    public function handle(string $activityType, Loggable|string $detail): void
+    {
+        // TODO
+    }
+}
index 315e8bfdf389dd8f52d494b9d1c2448161f7af7e..3135f57a72d3300a05ab4c30c890ec9fe289f76e 100644 (file)
@@ -6,7 +6,7 @@ use BookStack\Activity\DispatchWebhookJob;
 use BookStack\Activity\Models\Activity;
 use BookStack\Activity\Models\Loggable;
 use BookStack\Activity\Models\Webhook;
-use BookStack\App\Model;
+use BookStack\Activity\Notifications\NotificationManager;
 use BookStack\Entities\Models\Entity;
 use BookStack\Facades\Theme;
 use BookStack\Theming\ThemeEvents;
@@ -15,10 +15,16 @@ use Illuminate\Support\Facades\Log;
 
 class ActivityLogger
 {
+    public function __construct(
+        protected NotificationManager $notifications
+    ) {
+        $this->notifications->loadDefaultHandlers();
+    }
+
     /**
      * Add a generic activity event to the database.
      */
-    public function add(string $type, $detail = '')
+    public function add(string $type, string|Loggable $detail = ''): void
     {
         $detailToStore = ($detail instanceof Loggable) ? $detail->logDescriptor() : $detail;
 
@@ -34,6 +40,7 @@ class ActivityLogger
 
         $this->setNotification($type);
         $this->dispatchWebhooks($type, $detail);
+        $this->notifications->handle($type, $detail);
         Theme::dispatch(ThemeEvents::ACTIVITY_LOGGED, $type, $detail);
     }