Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(userstatus): Only track message timestamp for values #41512

Merged
Merged
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
2 changes: 1 addition & 1 deletion apps/user_status/lib/Db/UserStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @method void setCustomMessage(string|null $customMessage)
* @method int|null getClearAt()
* @method void setClearAt(int|null $clearAt)
* @method setIsBackup(bool $true): void
* @method setIsBackup(bool $isBackup): void
nickvergessen marked this conversation as resolved.
Show resolved Hide resolved
* @method getIsBackup(): bool
* @method int getStatusMessageTimestamp()
* @method void setStatusMessageTimestamp(int $statusTimestamp)
Expand Down
8 changes: 7 additions & 1 deletion apps/user_status/lib/Service/StatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,13 @@ public function setUserStatus(string $userId,
$userStatus->setCustomIcon(null);
$userStatus->setCustomMessage($customMessage);
$userStatus->setClearAt(null);
$userStatus->setStatusMessageTimestamp($this->timeFactory->now()->getTimestamp());
if ($this->predefinedStatusService->getTranslatedStatusForId($messageId) !== null
|| ($customMessage !== null && $customMessage !== '')) {
// Only track status message ID if there is one
$userStatus->setStatusMessageTimestamp($this->timeFactory->now()->getTimestamp());
} else {
$userStatus->setStatusMessageTimestamp(0);
}

if ($userStatus->getId() !== null) {
return $this->mapper->update($userStatus);
Expand Down
30 changes: 30 additions & 0 deletions apps/user_status/tests/Unit/Service/StatusServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1130,4 +1130,34 @@ public function testFindByUserIdSystemDefined(): void {

$this->assertEquals($status, $this->service->findByUserId('admin'));
}

public function testSetStatusWithoutMessage(): void {
$this->predefinedStatusService->expects(self::once())
->method('isValidId')
->with(IUserStatus::MESSAGE_AVAILABILITY)
->willReturn(true);
$this->timeFactory
->method('getTime')
->willReturn(1234);
$status = new UserStatus();
$status->setUserId('admin');
$status->setStatusTimestamp(1234);
$status->setIsUserDefined(true);
$status->setStatus(IUserStatus::DND);
$status->setIsBackup(false);
$status->setMessageId(IUserStatus::MESSAGE_AVAILABILITY);
$this->mapper->expects(self::once())
->method('insert')
->with($this->equalTo($status))
->willReturnArgument(0);

$result = $this->service->setUserStatus(
'admin',
IUserStatus::DND,
IUserStatus::MESSAGE_AVAILABILITY,
true,
);

self::assertNotNull($result);
}
}
Loading