lass uns raten!

This commit is contained in:
JM 2026-05-06 14:22:33 +02:00
parent 65a332178c
commit f4aa28df8a
6 changed files with 79 additions and 6 deletions

View File

@ -24,7 +24,14 @@ return [
// ✅ EINZIGER Notification-Hook (richtig für Flarum 1.8.x) // ✅ EINZIGER Notification-Hook (richtig für Flarum 1.8.x)
(new Extend\Notification()) (new Extend\Notification())
->beforeSending(MirrorAlertsToTeams::class), ->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()) (new Extend\User())
@ -33,4 +40,5 @@ return [
->registerPreference('sbp-jm-msteams.types.postMentioned', 'boolval', false) ->registerPreference('sbp-jm-msteams.types.postMentioned', 'boolval', false)
->registerPreference('sbp-jm-msteams.types.userMentioned', 'boolval', false), ->registerPreference('sbp-jm-msteams.types.userMentioned', 'boolval', false),
]; ];

View File

@ -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'),
});
});
}

View File

@ -1,6 +1,6 @@
import app from 'flarum/forum/app'; 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();
});

Binary file not shown.

View File

@ -15,3 +15,9 @@ sbp-jm-msteams:
newPost: Someone replies to a discussion I am following newPost: Someone replies to a discussion I am following
postMentioned: Someone mentions me in a post postMentioned: Someone mentions me in a post
userMentioned: Someone mentions me userMentioned: Someone mentions me
sbp-jm-flarum-msteams-webhook:
forum:
notification_method:
teams: Teams

View File

@ -0,0 +1,46 @@
<?php
namespace SbpJm\FlarumMSTeamsWebhook\Notification;
use Flarum\Notification\Blueprint\BlueprintInterface;
use Flarum\Notification\Driver\NotificationDriverInterface;
use Flarum\User\User;
class TeamsNotificationDriver implements NotificationDriverInterface
{
/**
* Sendet Benachrichtigungen über "teams".
*
* Wichtig: Für reine UI+Preference-Integration kannst du hier erstmal NO-OP lassen,
* oder du hängst deine bestehende Teams-Sende-Logik an die Preference an.
*/
public function send(BlueprintInterface $blueprint, array $users): void
{
foreach ($users as $user) {
// notify_<type>_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)
);
}
}