]> source.dussan.org Git - nextcloud-server.git/commitdiff
Reset the user status when clearing the custom message 23115/head
authorJoas Schilling <coding@schilljs.com>
Wed, 30 Sep 2020 12:12:02 +0000 (14:12 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Wed, 30 Sep 2020 17:27:14 +0000 (17:27 +0000)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/user_status/lib/Controller/UserStatusController.php
apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php

index ffbe1e753ef40bf9ef42a7211e8f6af1595a0e10..950cafb104d3b42182ee0ebf5119467cdb619e86 100644 (file)
@@ -138,7 +138,12 @@ class UserStatusController extends OCSController {
                                                                         string $message,
                                                                         ?int $clearAt): DataResponse {
                try {
-                       $status = $this->service->setCustomMessage($this->userId, $statusIcon, $message, $clearAt);
+                       if ($message !== '') {
+                               $status = $this->service->setCustomMessage($this->userId, $statusIcon, $message, $clearAt);
+                       } else {
+                               $this->service->clearMessage($this->userId);
+                               $status = $this->service->findByUserId($this->userId);
+                       }
                        return new DataResponse($this->formatStatus($status));
                } catch (InvalidClearAtException $ex) {
                        $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid clearAt value "' . $clearAt . '"');
index 5d1e15b0d3ee22a99d6f9dbddc3a3c219e66db49..fbf86ba92c411228b6044d5694a8ba90173ccfda 100644 (file)
@@ -243,6 +243,7 @@ class UserStatusControllerTest extends TestCase {
         * @param Throwable|null $exception
         * @param bool $expectLogger
         * @param string|null $expectedLogMessage
+        * @param bool $expectSuccessAsReset
         *
         * @dataProvider setCustomMessageDataProvider
         */
@@ -253,7 +254,8 @@ class UserStatusControllerTest extends TestCase {
                                                                                 bool $expectException,
                                                                                 ?Throwable $exception,
                                                                                 bool $expectLogger,
-                                                                                ?string $expectedLogMessage): void {
+                                                                                ?string $expectedLogMessage,
+                                                                                bool $expectSuccessAsReset = false): void {
                $userStatus = $this->getUserStatus();
 
                if ($expectException) {
@@ -262,10 +264,25 @@ class UserStatusControllerTest extends TestCase {
                                ->with('john.doe', $statusIcon, $message, $clearAt)
                                ->willThrowException($exception);
                } else {
-                       $this->service->expects($this->once())
-                               ->method('setCustomMessage')
-                               ->with('john.doe', $statusIcon, $message, $clearAt)
-                               ->willReturn($userStatus);
+                       if ($expectSuccessAsReset) {
+                               $this->service->expects($this->never())
+                                       ->method('setCustomMessage');
+                               $this->service->expects($this->once())
+                                       ->method('clearMessage')
+                                       ->with('john.doe');
+                               $this->service->expects($this->once())
+                                       ->method('findByUserId')
+                                       ->with('john.doe')
+                                       ->willReturn($userStatus);
+                       } else {
+                               $this->service->expects($this->once())
+                                       ->method('setCustomMessage')
+                                       ->with('john.doe', $statusIcon, $message, $clearAt)
+                                       ->willReturn($userStatus);
+
+                               $this->service->expects($this->never())
+                                       ->method('clearMessage');
+                       }
                }
 
                if ($expectLogger) {
@@ -297,6 +314,7 @@ class UserStatusControllerTest extends TestCase {
        public function setCustomMessageDataProvider(): array {
                return [
                        ['👨🏽‍💻', 'Busy developing the status feature', 500, true, false, null, false, null],
+                       ['👨🏽‍💻', '', 500, true, false, null, false, null, true],
                        ['👨🏽‍💻', 'Busy developing the status feature', 500, false, true, new InvalidClearAtException('Original exception message'), true,
                                'New user-status for "john.doe" was rejected due to an invalid clearAt value "500"'],
                        ['👨🏽‍💻', 'Busy developing the status feature', 500, false, true, new InvalidStatusIconException('Original exception message'), true,