69 lines
1.5 KiB
PHP
69 lines
1.5 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace SbpJm\FlarumMSTeamsWebhook\Notification;
|
||
|
||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||
use Flarum\Notification\Channel\ChannelInterface;
|
||
use Flarum\User\User;
|
||
use SbpJm\FlarumMSTeamsWebhook\Support\TeamsNotifier;
|
||
|
||
class TeamsChannel implements ChannelInterface
|
||
{
|
||
public function __construct(
|
||
protected TeamsNotifier $notifier
|
||
) {}
|
||
|
||
/**
|
||
* Called by Flarum when the user has enabled this channel.
|
||
*/
|
||
public function send(User $recipient, BlueprintInterface $blueprint): void
|
||
{
|
||
// Defensive: only send if supported
|
||
if (!$this->supports($blueprint)) {
|
||
return;
|
||
}
|
||
|
||
$this->notifier->sendToUser($recipient, $blueprint);
|
||
}
|
||
|
||
/**
|
||
* Decide which notification types are allowed for Teams.
|
||
*/
|
||
public function supports(BlueprintInterface $blueprint): bool
|
||
{
|
||
return in_array($blueprint::getType(), [
|
||
'newPost',
|
||
'postMentioned',
|
||
'userMentioned',
|
||
'discussionRenamed',
|
||
'postLiked',
|
||
], true);
|
||
}
|
||
|
||
/**
|
||
* Channel identifier used internally by Flarum.
|
||
*/
|
||
public function getName(): string
|
||
{
|
||
return 'teams';
|
||
}
|
||
|
||
/**
|
||
* Label shown in the user notification settings UI.
|
||
*/
|
||
public function getLabel(): string
|
||
{
|
||
return 'Microsoft Teams';
|
||
}
|
||
|
||
/**
|
||
* Teams is opt‑in by default.
|
||
*/
|
||
public function isEnabledByDefault(): bool
|
||
{
|
||
return false;
|
||
}
|
||
}
|