Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
--------------------------
Expand Down
26 changes: 13 additions & 13 deletions widgets/InboxMessagePreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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 = '';
Expand All @@ -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.')
Expand All @@ -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')) {
Expand All @@ -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
Expand All @@ -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());
Expand Down