diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2023-11-16 16:53:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-16 16:53:40 +0100 |
commit | 3dc902057e74cc05d176ea51f2b6a4b697be2c92 (patch) | |
tree | e5a13f0e0b35274aa1fdf930aa3ccc77b785ac81 | |
parent | 1b18b976b45b155f005676640e0d49ca7830b8b0 (diff) | |
parent | bdad290d31b9f2696158a0839b2879c7f3f47a02 (diff) | |
download | nextcloud-server-3dc902057e74cc05d176ea51f2b6a4b697be2c92.tar.gz nextcloud-server-3dc902057e74cc05d176ea51f2b6a4b697be2c92.zip |
Merge pull request #41512 from nextcloud/fix/userstatus/no-message-no-message-timestamp
fix(userstatus): Only track message timestamp for values
-rw-r--r-- | apps/user_status/lib/Db/UserStatus.php | 2 | ||||
-rw-r--r-- | apps/user_status/lib/Service/StatusService.php | 8 | ||||
-rw-r--r-- | apps/user_status/tests/Unit/Service/StatusServiceTest.php | 30 |
3 files changed, 38 insertions, 2 deletions
diff --git a/apps/user_status/lib/Db/UserStatus.php b/apps/user_status/lib/Db/UserStatus.php index 92b3df740c2..f7742a4bbe9 100644 --- a/apps/user_status/lib/Db/UserStatus.php +++ b/apps/user_status/lib/Db/UserStatus.php @@ -50,7 +50,7 @@ use OCP\AppFramework\Db\Entity; * @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 * @method getIsBackup(): bool * @method int getStatusMessageTimestamp() * @method void setStatusMessageTimestamp(int $statusTimestamp) diff --git a/apps/user_status/lib/Service/StatusService.php b/apps/user_status/lib/Service/StatusService.php index 508d9287555..99fafaa6426 100644 --- a/apps/user_status/lib/Service/StatusService.php +++ b/apps/user_status/lib/Service/StatusService.php @@ -314,7 +314,13 @@ class StatusService { $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); diff --git a/apps/user_status/tests/Unit/Service/StatusServiceTest.php b/apps/user_status/tests/Unit/Service/StatusServiceTest.php index bd150cd4258..d0742a105a3 100644 --- a/apps/user_status/tests/Unit/Service/StatusServiceTest.php +++ b/apps/user_status/tests/Unit/Service/StatusServiceTest.php @@ -1130,4 +1130,34 @@ EOF; $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); + } } |