flarum-msteams-webhook/src/Notification/TeamsChannel.php

69 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 optin by default.
*/
public function isEnabledByDefault(): bool
{
return false;
}
}