Skip to content
Snippets Groups Projects
Unverified Commit 32b577a5 authored by Joas Schilling's avatar Joas Schilling
Browse files

Reset the user status when clearing the custom message

parent aeb7329b
No related branches found
No related tags found
No related merge requests found
...@@ -138,7 +138,12 @@ class UserStatusController extends OCSController { ...@@ -138,7 +138,12 @@ class UserStatusController extends OCSController {
string $message, string $message,
?int $clearAt): DataResponse { ?int $clearAt): DataResponse {
try { 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)); return new DataResponse($this->formatStatus($status));
} catch (InvalidClearAtException $ex) { } catch (InvalidClearAtException $ex) {
$this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid clearAt value "' . $clearAt . '"'); $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid clearAt value "' . $clearAt . '"');
......
...@@ -243,6 +243,7 @@ class UserStatusControllerTest extends TestCase { ...@@ -243,6 +243,7 @@ class UserStatusControllerTest extends TestCase {
* @param Throwable|null $exception * @param Throwable|null $exception
* @param bool $expectLogger * @param bool $expectLogger
* @param string|null $expectedLogMessage * @param string|null $expectedLogMessage
* @param bool $expectSuccessAsReset
* *
* @dataProvider setCustomMessageDataProvider * @dataProvider setCustomMessageDataProvider
*/ */
...@@ -253,7 +254,8 @@ class UserStatusControllerTest extends TestCase { ...@@ -253,7 +254,8 @@ class UserStatusControllerTest extends TestCase {
bool $expectException, bool $expectException,
?Throwable $exception, ?Throwable $exception,
bool $expectLogger, bool $expectLogger,
?string $expectedLogMessage): void { ?string $expectedLogMessage,
bool $expectSuccessAsReset = false): void {
$userStatus = $this->getUserStatus(); $userStatus = $this->getUserStatus();
if ($expectException) { if ($expectException) {
...@@ -262,10 +264,25 @@ class UserStatusControllerTest extends TestCase { ...@@ -262,10 +264,25 @@ class UserStatusControllerTest extends TestCase {
->with('john.doe', $statusIcon, $message, $clearAt) ->with('john.doe', $statusIcon, $message, $clearAt)
->willThrowException($exception); ->willThrowException($exception);
} else { } else {
$this->service->expects($this->once()) if ($expectSuccessAsReset) {
->method('setCustomMessage') $this->service->expects($this->never())
->with('john.doe', $statusIcon, $message, $clearAt) ->method('setCustomMessage');
->willReturn($userStatus); $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) { if ($expectLogger) {
...@@ -297,6 +314,7 @@ class UserStatusControllerTest extends TestCase { ...@@ -297,6 +314,7 @@ class UserStatusControllerTest extends TestCase {
public function setCustomMessageDataProvider(): array { public function setCustomMessageDataProvider(): array {
return [ return [
['👨🏽‍💻', 'Busy developing the status feature', 500, true, false, null, false, null], ['👨🏽‍💻', '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, ['👨🏽‍💻', '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"'], '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, ['👨🏽‍💻', 'Busy developing the status feature', 500, false, true, new InvalidStatusIconException('Original exception message'), true,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment