diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4998c0e8..fd2b9b1e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -11,6 +11,7 @@ Changelog - Enh #466: Convert swagger docs to OpenAPI 3.0 - Fix #469: In mail notifications, use core button for "Reply now", to allow auto-contrast - Fix #470: Email inline style from Sass variables, e.g. when overwriting `$mail-font-family` in the Custom SCSS field +- Fix #404: Fix wrong user messages 3.3.5 (September 30, 2025) -------------------------- diff --git a/widgets/InboxMessagePreview.php b/widgets/InboxMessagePreview.php index 1fa87c26..12c47a38 100644 --- a/widgets/InboxMessagePreview.php +++ b/widgets/InboxMessagePreview.php @@ -27,7 +27,7 @@ public function run() } return $this->render('inboxMessagePreview', [ - 'message' => $this->userMessage->message, + 'message' => $this->userMessage?->message, 'messageTitle' => $this->getMessageTitle(), 'messageText' => $this->getMessagePreview(), 'messageTime' => $this->getMessageTime(), @@ -41,16 +41,16 @@ private function getOptions(): array $message = $this->getMessage(); return [ - 'class' => 'messagePreviewEntry entry' . ($this->userMessage->isUnread() ? ' unread' : ''), + 'class' => 'messagePreviewEntry entry' . ($this->userMessage?->isUnread() ? ' unread' : ''), 'data' => [ - 'message-id' => $message->id, + 'message-id' => $message?->id, 'action-click' => 'mail.notification.loadMessage', 'action-url' => Url::toMessenger($message), ], ]; } - public function getMessage(): Message + public function getMessage(): ?Message { if ($this->_message === null) { $this->_message = $this->userMessage->message; @@ -62,8 +62,8 @@ public function getMessage(): Message public function lastParticipant(): ?User { return $this->isGroupChat() - ? $this->getLastEntry()->user - : $this->getMessage()->getLastActiveParticipant(); + ? $this->getLastEntry()?->user + : $this->getMessage()?->getLastActiveParticipant(); } private function getUsername(): string @@ -86,7 +86,7 @@ private function getMessageTitle(): string { if ($this->isGroupChat()) { $suffix = ', ' . Yii::t('MailModule.base', '{n,plural,=1{# other} other{# others}}', [ - 'n' => $this->getMessage()->getUsersCount() - 2, + 'n' => $this->getMessage()?->getUsersCount() - 2, ]); } else { $suffix = ''; @@ -97,7 +97,7 @@ private function getMessageTitle(): string public function getMessagePreview(): string { - switch ($this->getLastEntry()->type) { + switch ($this->getLastEntry()?->type) { case AbstractMessageEntry::TYPE_USER_JOINED: return $this->isOwnLastEntry() ? Yii::t('MailModule.base', 'You joined the conversation.') @@ -118,12 +118,12 @@ public function getMessagePreview(): string $prefix = ''; } - return $prefix . RichText::preview($this->getLastEntry()->content, 70); + return $prefix . RichText::preview($this->getLastEntry()?->content ?? '', 70); } private function getMessageTime(): string { - $datetime = $this->getMessage()->updated_at ?? $this->getMessage()->created_at; + $datetime = $this->getMessage()?->updated_at ?? $this->getMessage()?->created_at; $datetime = new DateTime($datetime, new DateTimeZone(Yii::$app->timeZone)); if ($datetime->format('Y-m-d') === date('Y-m-d')) { @@ -148,12 +148,12 @@ private function getMessageTime(): string public function getLastEntry(): ?MessageEntry { - return $this->getMessage()->getLastEntry(); + return $this->getMessage()?->getLastEntry(); } private function isGroupChat(): bool { - return $this->getMessage()->getUsersCount() > 2; + return $this->getMessage()?->getUsersCount() > 2; } private function isOwnLastEntry(): bool @@ -162,7 +162,7 @@ private function isOwnLastEntry(): bool return false; } - $lastEntryUser = $this->getLastEntry()->user; + $lastEntryUser = $this->getLastEntry()?->user; return $lastEntryUser instanceof User && $lastEntryUser->is(Yii::$app->user->getIdentity());