46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
<?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)
|
|
);
|
|
}
|
|
} |