diff --git a/extend.php b/extend.php index dd8cf36..b2c6df2 100644 --- a/extend.php +++ b/extend.php @@ -1,37 +1,29 @@ js(__DIR__ . '/js/dist/admin.js'), - - // Forum UI (User notification settings – Teams checkbox) - (new Extend\Frontend('forum')) - ->js(__DIR__ . '/js/dist/forum.js'), - - // CLI test command - (new Extend\Console()) - ->command(TestTeamsUserCommand::class), - - // Notification hooks - (new Extend\Notification()) - ->beforeSending(MirrorAlertsToTeams::class) - ->driver('teams', TeamsNotificationDriver::class, []), - - // Deine bisherigen Preferences (SettingsPage-Toggles) - (new Extend\User()) - ->registerPreference('sbp-jm-msteams.enabled', 'boolval', false) - ->registerPreference('sbp-jm-msteams.types.newPost', 'boolval', false) - ->registerPreference('sbp-jm-msteams.types.postMentioned', 'boolval', false) - ->registerPreference('sbp-jm-msteams.types.userMentioned', 'boolval', false), -]; +class SendTeamsActivityNotificationJob implements ShouldQueue +{ + use InteractsWithQueue; + use SerializesModels; + public function __construct( + protected User $user, + protected BlueprintInterface $blueprint + ) { + } + public function handle(TeamsActivityNotifier $notifier): void + { + $notifier->notify($this->user, $this->blueprint); + } +} \ No newline at end of file diff --git a/js/src/forum/extendNotificationGridWithTeams.js b/js/src/forum/extendNotificationGridWithTeams.js index b6b21db..eb256a9 100644 --- a/js/src/forum/extendNotificationGridWithTeams.js +++ b/js/src/forum/extendNotificationGridWithTeams.js @@ -7,9 +7,7 @@ export default function extendNotificationGridWithTeams() { items.add('teams', { name: 'teams', icon: 'fab fa-microsoft', - label: app.translator.trans( - 'sbp-jm-flarum-msteams-webhook.forum.notification_method.teams' - ), + label: app.translator.trans('sbp-jm-flarum-msteams-webhook.forum.notification_method.teams'), }); }); } \ No newline at end of file diff --git a/locale/de.yml b/locale/de.yml new file mode 100644 index 0000000..abf1b7e --- /dev/null +++ b/locale/de.yml @@ -0,0 +1,4 @@ +sbp-jm-flarum-msteams-webhook: + forum: + notification_method: + teams: Teams \ No newline at end of file diff --git a/locale/en.yml b/locale/en.yml index 01d4589..abf1b7e 100644 --- a/locale/en.yml +++ b/locale/en.yml @@ -1,23 +1,4 @@ -sbp-jm-msteams-webhook: - admin: - title: MS Teams Activity Feed - description: Mirror Flarum web notifications to Microsoft Teams. -notification: - drivers: - teams: Microsoft Teams - - - -sbp-jm-msteams: - forum: - teams: - header: Microsoft Teams - newPost: Someone replies to a discussion I am following - postMentioned: Someone mentions me in a post - userMentioned: Someone mentions me - - sbp-jm-flarum-msteams-webhook: forum: notification_method: - teams: Teams + teams: Teams \ No newline at end of file diff --git a/src/Listener/MirrorAlertsToTeams.php b/src/Listener/MirrorAlertsToTeams.php deleted file mode 100644 index 011aab0..0000000 --- a/src/Listener/MirrorAlertsToTeams.php +++ /dev/null @@ -1,70 +0,0 @@ -isEnabled()) { - return $newRecipients; - } - - foreach ($newRecipients as $user) { - if (!$user instanceof User) { - continue; - } - - if (!$this->shouldMirrorForUser($user, $blueprint)) { - continue; - } - - if ($this->targetResolver->resolve($user) === null) { - continue; - } - - $this->queue->push(new SendTeamsActivityNotificationJob($blueprint, $user)); - } - - return $newRecipients; - } - - protected function isEnabled(): bool - { - return filter_var($this->settings->get('sbp-jm-msteams-webhook.enabled', '0'), FILTER_VALIDATE_BOOLEAN); - } - - protected function shouldMirrorForUser(User $user, BlueprintInterface $blueprint): bool - { - $webPreferenceKey = User::getNotificationPreferenceKey($blueprint::getType(), 'alert'); - $webEnabled = (bool) $user->getPreference($webPreferenceKey, false); - - if (!$webEnabled) { - return false; - } - - $globalOptOutKey = 'sbp-jm-msteams-webhook.user_disabled'; - - return !(bool) $user->getPreference($globalOptOutKey, false); - } -} diff --git a/src/Notification/TeamsNotificationDriver.php b/src/Notification/TeamsNotificationDriver.php index 4c6c694..8d1e04a 100644 --- a/src/Notification/TeamsNotificationDriver.php +++ b/src/Notification/TeamsNotificationDriver.php @@ -5,26 +5,47 @@ namespace SbpJm\FlarumMSTeamsWebhook\Notification; use Flarum\Notification\Blueprint\BlueprintInterface; use Flarum\Notification\Driver\NotificationDriverInterface; use Flarum\User\User; +use Illuminate\Contracts\Queue\Queue; +use SbpJm\FlarumMSTeamsWebhook\Jobs\SendTeamsNotificationJob; class TeamsNotificationDriver implements NotificationDriverInterface { + public function __construct( + protected Queue $queue + ) {} + + /** + * Wird vom Core aufgerufen, wenn eine Notification dispatched wird + */ public function send(BlueprintInterface $blueprint, array $users): void { foreach ($users as $user) { - $prefKey = User::getNotificationPreferenceKey($blueprint::getType(), 'teams'); + $prefKey = User::getNotificationPreferenceKey( + $blueprint::getType(), + 'teams' + ); if (! $user->getPreference($prefKey)) { continue; } - // TODO: Hier dein bestehendes "echtes Teams senden" aufrufen. + // ✅ Versand immer über Queue + $this->queue->push( + new SendTeamsNotificationJob($blueprint, $user) + ); } } + /** + * Registriert die notify_*_teams Preferences für ALLE Notification-Typen + */ public function registerType(string $blueprintClass, array $driversEnabledByDefault): void { User::registerPreference( - User::getNotificationPreferenceKey($blueprintClass::getType(), 'teams'), + User::getNotificationPreferenceKey( + $blueprintClass::getType(), + 'teams' + ), 'boolval', in_array('teams', $driversEnabledByDefault) );