From 0a207413cf9507f59e80d30e3ef8611d5baeb1e6 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Fri, 19 Jan 2024 18:03:25 +0100 Subject: [PATCH] Fix email subject on invite/add users --- controllers/EntryController.php | 4 +- docs/CHANGELOG.md | 4 + jobs/ForceParticipation.php | 4 +- .../forms/CalendarEntryParticipationForm.php | 4 +- module.json | 2 +- notifications/Invited.php | 85 ------------------- .../{ForceAdd.php => ParticipantAdded.php} | 36 +++++--- 7 files changed, 37 insertions(+), 102 deletions(-) delete mode 100644 notifications/Invited.php rename notifications/{ForceAdd.php => ParticipantAdded.php} (57%) diff --git a/controllers/EntryController.php b/controllers/EntryController.php index 57b8f1ec..fdd8e244 100644 --- a/controllers/EntryController.php +++ b/controllers/EntryController.php @@ -10,7 +10,7 @@ use humhub\modules\calendar\models\forms\CalendarEntryForm; use humhub\modules\calendar\models\forms\CalendarEntryParticipationForm; use humhub\modules\calendar\models\participation\CalendarEntryParticipation; -use humhub\modules\calendar\notifications\Invited; +use humhub\modules\calendar\notifications\ParticipantAdded; use humhub\modules\calendar\widgets\ParticipantItem; use humhub\modules\content\components\ContentContainerController; use humhub\modules\content\widgets\richtext\converter\RichTextToPlainTextConverter; @@ -418,7 +418,7 @@ private function addParticipants(CalendarEntry $entry, $status): Response } if ($isInvitation && count($users)) { - Invited::instance()->from(Yii::$app->user->getIdentity())->about($entry)->sendBulk($users); + ParticipantAdded::instance()->from(Yii::$app->user->getIdentity())->about($entry)->sendBulk($users); } $successMessageParams = ['users' => implode(', ', $addedUserNames)]; diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6e415f6b..b80221c2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +1.5.9 (Unreleased) +------------------------ +- Fix #443: Fix email subject on invite/add users + 1.5.8 (January 19, 2024) ------------------------ - Fix #437: Hide the profile calendar if the module is not available for users diff --git a/jobs/ForceParticipation.php b/jobs/ForceParticipation.php index a6a268d9..636a066c 100644 --- a/jobs/ForceParticipation.php +++ b/jobs/ForceParticipation.php @@ -11,7 +11,7 @@ use humhub\modules\calendar\models\CalendarEntry; use humhub\modules\calendar\models\CalendarEntryParticipant; use humhub\modules\calendar\models\participation\CalendarEntryParticipation; -use humhub\modules\calendar\notifications\ForceAdd; +use humhub\modules\calendar\notifications\ParticipantAdded; use humhub\modules\queue\ActiveJob; use humhub\modules\space\models\Membership; use humhub\modules\space\models\Space; @@ -62,7 +62,7 @@ public function run() } if (count($users)) { - ForceAdd::instance()->from($originator)->about($entry)->sendBulk($users); + ParticipantAdded::instance()->from($originator)->about($entry)->sendBulk($users); } } } diff --git a/models/forms/CalendarEntryParticipationForm.php b/models/forms/CalendarEntryParticipationForm.php index cfb3b582..6b6c3fe1 100644 --- a/models/forms/CalendarEntryParticipationForm.php +++ b/models/forms/CalendarEntryParticipationForm.php @@ -9,7 +9,7 @@ use humhub\modules\calendar\models\CalendarEntryParticipant; use humhub\modules\calendar\models\participation\CalendarEntryParticipation; -use humhub\modules\calendar\notifications\Invited; +use humhub\modules\calendar\notifications\ParticipantAdded; use humhub\modules\calendar\widgets\ParticipantItem; use humhub\modules\user\models\User; use humhub\modules\content\widgets\richtext\RichText; @@ -172,7 +172,7 @@ private function addParticipants(): void } if ($this->newParticipantStatus == CalendarEntryParticipant::PARTICIPATION_STATE_INVITED && count($users)) { - Invited::instance()->from(Yii::$app->user->getIdentity())->about($this->entry)->sendBulk($users); + ParticipantAdded::instance()->from(Yii::$app->user->getIdentity())->about($this->entry)->sendBulk($users); } } } diff --git a/module.json b/module.json index 0544232f..3afb0af7 100644 --- a/module.json +++ b/module.json @@ -3,7 +3,7 @@ "name": "Calendar", "description": "Calendar for spaces or user profiles.", "keywords": ["calendar"], - "version": "1.5.8", + "version": "1.5.9", "humhub": { "minVersion": "1.14" }, diff --git a/notifications/Invited.php b/notifications/Invited.php deleted file mode 100644 index 7a524639..00000000 --- a/notifications/Invited.php +++ /dev/null @@ -1,85 +0,0 @@ - Html::tag('strong', Html::encode($this->originator->displayName)), - 'contentTitle' => $this->getContentInfo($this->source, false), - 'spaceName' => Html::encode($this->source->content->container->displayName), - 'time' => $this->source->getFormattedTime() - ]); - } - - /** - * @inheritdoc - */ - public function getMailSubject() - { - return Yii::t('CalendarModule.notifications_views_CanceledEvent', '{displayName} just invited you to event "{contentTitle}".', [ - 'displayName' => Html::encode($this->originator->displayName), - 'contentTitle' => $this->getContentInfo($this->source, false) - ]); - } - - /** - * @inheritdoc - */ - public function beforeMailSend(MessageInterface $message) - { - $ics = $this->source->generateIcs(); - - if (!empty($ics)) { - $message->attachContent($ics, [ - 'fileName' => $this->source->getUid() . '.ics', - 'contentType' => 'text/calendar' - ]); - } - - return true; - } -} diff --git a/notifications/ForceAdd.php b/notifications/ParticipantAdded.php similarity index 57% rename from notifications/ForceAdd.php rename to notifications/ParticipantAdded.php index 573f9c04..1aa03c26 100644 --- a/notifications/ForceAdd.php +++ b/notifications/ParticipantAdded.php @@ -1,23 +1,20 @@ Html::tag('strong', Html::encode($this->originator->displayName)), 'contentTitle' => $this->getContentInfo($this->source, false), 'spaceName' => Html::encode($this->source->content->container->displayName), 'time' => $this->source->getFormattedTime() - ]); + ]; + + return $this->isInvited() + ? Yii::t('CalendarModule.base', '{displayName} just invited you to event "{contentTitle}" in space {spaceName} starting at {time}.', $params) + : Yii::t('CalendarModule.base', '{displayName} just added you to event "{contentTitle}" in space {spaceName} starting at {time}.', $params); } /** @@ -61,10 +64,14 @@ public function html() */ public function getMailSubject() { - return Yii::t('CalendarModule.notifications_views_CanceledEvent', '{displayName} just added you to event "{contentTitle}".', [ + $params = [ 'displayName' => Html::encode($this->originator->displayName), 'contentTitle' => $this->getContentInfo($this->source, false) - ]); + ]; + + return $this->isInvited() + ? Yii::t('CalendarModule.base', '{displayName} just invited you to event "{contentTitle}".', $params) + : Yii::t('CalendarModule.base', '{displayName} just added you to event "{contentTitle}".', $params); } /** @@ -83,4 +90,13 @@ public function beforeMailSend(MessageInterface $message) return true; } + + private function isInvited(): bool + { + if ($this->participationStatus === null) { + $this->participationStatus = (int) $this->source->participation->getParticipationStatus($this->record->user); + } + + return $this->participationStatus === CalendarEventParticipationIF::PARTICIPATION_STATUS_INVITED; + } }