diff --git a/extend.php b/extend.php index a55dcfe..1ee7569 100644 --- a/extend.php +++ b/extend.php @@ -24,7 +24,14 @@ return [ // ✅ EINZIGER Notification-Hook (richtig für Flarum 1.8.x) (new Extend\Notification()) ->beforeSending(MirrorAlertsToTeams::class), - + + + (new Extend\Notification()) + ->driver('teams', TeamsNotificationDriver::class, [ + // Absichtlich leer: Teams ist nicht default-on, + // kann aber im Notification-Grid pro Zeile aktiviert werden. + ]), + (new Extend\User()) @@ -33,4 +40,5 @@ return [ ->registerPreference('sbp-jm-msteams.types.postMentioned', 'boolval', false) ->registerPreference('sbp-jm-msteams.types.userMentioned', 'boolval', false), -]; \ No newline at end of file +]; + diff --git a/js/src/forum/extendNotificationGridWithTeams.js b/js/src/forum/extendNotificationGridWithTeams.js new file mode 100644 index 0000000..eb256a9 --- /dev/null +++ b/js/src/forum/extendNotificationGridWithTeams.js @@ -0,0 +1,13 @@ +import { extend } from 'flarum/common/extend'; +import NotificationGrid from 'flarum/forum/components/NotificationGrid'; +import app from 'flarum/forum/app'; + +export default function extendNotificationGridWithTeams() { + extend(NotificationGrid.prototype, 'notificationMethods', function (items) { + items.add('teams', { + name: 'teams', + icon: 'fab fa-microsoft', + label: app.translator.trans('sbp-jm-flarum-msteams-webhook.forum.notification_method.teams'), + }); + }); +} \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index 2dc6dfc..2f9e9e9 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -1,6 +1,6 @@ import app from 'flarum/forum/app'; -import addTeamsSettings from './addTeamsSettings'; +import extendNotificationGridWithTeams from './extendNotificationGridWithTeams('sbp-jm/flarum-msteams-webhook', () => {import extendNotificationGridWithTeams from './extendNotificationGridWithTeams'; + extendNotificationGridWithTeams(); +}); + -app.initializers.add('sbp-jm-msteams-webhook-forum', () => { - addTeamsSettings(); -}); \ No newline at end of file diff --git a/js/src/forum/src - Verknüpfung.lnk b/js/src/forum/src - Verknüpfung.lnk new file mode 100644 index 0000000..bc19ddb Binary files /dev/null and b/js/src/forum/src - Verknüpfung.lnk differ diff --git a/locale/en.yml b/locale/en.yml index e6c6262..01d4589 100644 --- a/locale/en.yml +++ b/locale/en.yml @@ -15,3 +15,9 @@ sbp-jm-msteams: 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 diff --git a/src/Notification/TeamsNotificationDriver.php b/src/Notification/TeamsNotificationDriver.php new file mode 100644 index 0000000..6dafa8b --- /dev/null +++ b/src/Notification/TeamsNotificationDriver.php @@ -0,0 +1,46 @@ +_teams + $prefKey = User::getNotificationPreferenceKey($blueprint::getType(), 'teams'); + + // Wenn User "Teams" in dieser Zeile nicht aktiviert hat, nichts senden. + if (! $user->getPreference($prefKey)) { + continue; + } + + // TODO: Hier deine bestehende Teams-Sende-Logik aufrufen. + // Beispiel: + // $this->mirrorToTeams($blueprint, $user); + } + } + + /** + * Wird vom Core für jeden bekannten Notification-Type aufgerufen. + * Hier registrieren wir den Preference-Key, damit er im Grid angezeigt + gespeichert wird. + */ + public function registerType(string $blueprintClass, array $driversEnabledByDefault): void + { + User::registerPreference( + User::getNotificationPreferenceKey($blueprintClass::getType(), 'teams'), + 'boolval', + in_array('teams', $driversEnabledByDefault) + ); + } +} \ No newline at end of file