alles mögliche verbessert

This commit is contained in:
JM 2026-05-05 14:49:05 +02:00
parent 2913b64648
commit 9924f19bc3
1 changed files with 52 additions and 43 deletions

View File

@ -16,6 +16,9 @@ class NotificationPayloadFactory
{ {
} }
/**
* @return array<string,mixed>
*/
/** /**
* @return array<string,mixed> * @return array<string,mixed>
*/ */
@ -23,34 +26,32 @@ class NotificationPayloadFactory
{ {
$activityType = trim((string) $this->settings->get('sbp-jm-msteams-webhook.activity_type', 'systemDefault')); $activityType = trim((string) $this->settings->get('sbp-jm-msteams-webhook.activity_type', 'systemDefault'));
$forumName = trim((string) $this->settings->get('forum_title', 'Flarum')) ?: 'Flarum'; $forumName = trim((string) $this->settings->get('forum_title', 'Flarum')) ?: 'Flarum';
$topicUrl = $this->resolveSubjectUrl($blueprint) ?? rtrim((string) $this->settings->get('sbp-jm-msteams-webhook.forum_base_url', ''), '/');
$previewText = $this->buildPreviewText($blueprint);
$teamsAppId = trim((string) $this->settings->get('sbp-jm-msteams-webhook.teams_app_id', ''));
$iconId = trim((string) $this->settings->get('sbp-jm-msteams-webhook.icon_id', '')); $iconId = trim((string) $this->settings->get('sbp-jm-msteams-webhook.icon_id', ''));
$discussionTitle = 'Backup-Strategie für Forum'; // Diskussionstitel + URL dynamisch aus dem Subject ziehen
$discussionUrl = 'https://forum.sbp.de/d/34-which-file-extensions-are-allowed-for-uploads/2'; $discussionTitle = $this->resolveDiscussionTitle($blueprint) ?? $forumName;
$previewSnippet = 'Bitte prüft, ob wir tägliche Snapshots brauchen.'; $discussionUrl = $this->resolveSubjectUrl($blueprint) ?? 'https://forum.sbp.de';
$reasonText = 'Neue Antwort in beobachteter Diskussion'; $previewSnippet = $this->buildPreviewText($blueprint);
// Freie Actor+Reason-Zeile für systemDefault
$discussionTitle = 'Backup-Strategie für Forum'; $reasonText = match ($blueprint::getType()) {
$discussionUrl = 'https://forum.sbp.de/d/34-which-file-extensions-are-allowed-for-uploads/2'; 'newPost' => 'Neue Antwort in beobachteter Diskussion',
$previewSnippet = 'Bitte prüft, ob wir tägliche Snapshots brauchen.'; 'postMentioned' => 'Du wurdest in einem Beitrag erwähnt',
$reasonText = 'Neue Antwort in beobachteter Diskussion'; 'userMentioned' => 'Du wurdest erwähnt',
'postLiked' => 'Dein Beitrag wurde geliked',
default => 'Neue Flarum-Benachrichtigung',
};
// Teams-App-/Tab-Ziel aus deinem aktuellen Manifest // Teams-App-/Tab-Ziel aus deinem aktuellen Manifest
$teamsManifestAppId = 'd92b1be6-ea92-46b1-bcb0-c08ffdd1a61a'; $teamsManifestAppId = 'd92b1be6-ea92-46b1-bcb0-c08ffdd1a61a';
$teamsEntityId = '8ffe419f-ca44-4627-a4b2-f223da2d07aa'; $teamsEntityId = '8ffe419f-ca44-4627-a4b2-f223da2d07aa';
// Kontext für den Tab: die Diskussion wird in subPageId transportiert. // Diskussion in den Tab-Kontext schreiben
// Microsoft dokumentiert page.subPageId als den Kontextwert für eine Unterseite.
$contextJson = json_encode([ $contextJson = json_encode([
'subPageId' => $discussionUrl, 'subPageId' => $discussionUrl,
], JSON_UNESCAPED_SLASHES); ], JSON_UNESCAPED_SLASHES);
// Deep Link auf den Personal Tab. // Teams-Deep-Link auf den Personal Tab
// webUrl ist der Fallback (z. B. Browser-Fallback), context transportiert die Diskussion.
$teamsDeepLink = sprintf( $teamsDeepLink = sprintf(
'https://teams.microsoft.com/l/entity/%s/%s?webUrl=%s&label=%s&context=%s', 'https://teams.microsoft.com/l/entity/%s/%s?webUrl=%s&label=%s&context=%s',
rawurlencode($teamsManifestAppId), rawurlencode($teamsManifestAppId),
@ -66,9 +67,9 @@ class NotificationPayloadFactory
'value' => $discussionTitle, 'value' => $discussionTitle,
'webUrl' => $teamsDeepLink, 'webUrl' => $teamsDeepLink,
], ],
'activityType' => 'systemDefault', 'activityType' => $activityType !== '' ? $activityType : 'systemDefault',
'previewText' => [ 'previewText' => [
'content' => $previewSnippet, 'content' => mb_substr($previewSnippet, 0, 150),
], ],
'templateParameters' => [ 'templateParameters' => [
[ [
@ -78,12 +79,6 @@ class NotificationPayloadFactory
], ],
]; ];
// if ($teamsAppId !== '') {
// $payload['teamsAppId'] = $teamsAppId;
// }
if ($iconId !== '') { if ($iconId !== '') {
$payload['iconId'] = $iconId; $payload['iconId'] = $iconId;
} }
@ -92,14 +87,13 @@ class NotificationPayloadFactory
$payload['templateParameters'] = [ $payload['templateParameters'] = [
[ [
'name' => 'notificationText', 'name' => 'notificationText',
'value' => $previewText, 'value' => mb_substr($previewSnippet, 0, 150),
], ],
]; ];
} }
return $payload; return $payload;
} }
protected function buildPreviewText(BlueprintInterface $blueprint): string protected function buildPreviewText(BlueprintInterface $blueprint): string
{ {
if ($blueprint::getType() === 'teamsTest') { if ($blueprint::getType() === 'teamsTest') {
@ -134,6 +128,21 @@ class NotificationPayloadFactory
return mb_substr($text, 0, 150); return mb_substr($text, 0, 150);
} }
protected function resolveDiscussionTitle(BlueprintInterface $blueprint): ?string
{
$subject = $blueprint->getSubject();
if ($subject instanceof Discussion) {
return (string) $subject->title;
}
if ($subject instanceof Post && $subject->discussion) {
return (string) $subject->discussion->title;
}
return
protected function resolveSubjectUrl(BlueprintInterface $blueprint): ?string protected function resolveSubjectUrl(BlueprintInterface $blueprint): ?string
{ {
$baseUrl = rtrim((string) $this->settings->get('sbp-jm-msteams-webhook.forum_base_url', ''), '/'); $baseUrl = rtrim((string) $this->settings->get('sbp-jm-msteams-webhook.forum_base_url', ''), '/');