aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_status
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2024-01-17 16:15:15 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2024-01-25 10:10:41 +0000
commita3095303d58eac0bc6782922699116a2a31cbf15 (patch)
tree4fc4491c75a18ed1f6092beff805b2f38ceaa5a0 /apps/user_status
parent4d43b6e3d5bf9ab6e4a26bbd3a20c0669a2c4d1f (diff)
downloadnextcloud-server-a3095303d58eac0bc6782922699116a2a31cbf15.tar.gz
nextcloud-server-a3095303d58eac0bc6782922699116a2a31cbf15.zip
fix(userstatus): CALL status should overwrite MEETING status
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'apps/user_status')
-rw-r--r--apps/user_status/lib/Service/StatusService.php33
-rw-r--r--apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php67
2 files changed, 91 insertions, 9 deletions
diff --git a/apps/user_status/lib/Service/StatusService.php b/apps/user_status/lib/Service/StatusService.php
index c623262eec6..813f6b9d4e1 100644
--- a/apps/user_status/lib/Service/StatusService.php
+++ b/apps/user_status/lib/Service/StatusService.php
@@ -172,8 +172,6 @@ class StatusService {
throw new InvalidStatusTypeException('Status-type "' . $status . '" is not supported');
}
-
-
if ($statusTimestamp === null) {
$statusTimestamp = $this->timeFactory->getTime();
}
@@ -257,21 +255,38 @@ class StatusService {
throw new InvalidMessageIdException('Message-Id "' . $messageId . '" is not supported');
}
+ try {
+ $userStatus = $this->mapper->findByUserId($userId);
+ } catch (DoesNotExistException $e) {
+ // We don't need to do anything
+ $userStatus = new UserStatus();
+ $userStatus->setUserId($userId);
+ }
+
+ // CALL trumps CALENDAR status, but we don't need to do anything but overwrite the message
+ if ($userStatus->getMessageId() === IUserStatus::MESSAGE_CALENDAR_BUSY && $messageId === IUserStatus::MESSAGE_CALL) {
+ $userStatus->setStatus($status);
+ $userStatus->setStatusTimestamp($this->timeFactory->getTime());
+ $userStatus->setIsUserDefined(true);
+ $userStatus->setIsBackup(false);
+ $userStatus->setMessageId($messageId);
+ $userStatus->setCustomIcon(null);
+ $userStatus->setCustomMessage($customMessage);
+ $userStatus->setClearAt(null);
+ $userStatus->setStatusMessageTimestamp($this->timeFactory->now()->getTimestamp());
+ return $this->mapper->update($userStatus);
+ }
+
if ($createBackup) {
if ($this->backupCurrentStatus($userId) === false) {
return null; // Already a status set automatically => abort.
}
// If we just created the backup
+ // we need to create a new status to insert
+ // Unfortunatley there's no way to unset the DB ID on an Entity
$userStatus = new UserStatus();
$userStatus->setUserId($userId);
- } else {
- try {
- $userStatus = $this->mapper->findByUserId($userId);
- } catch (DoesNotExistException $ex) {
- $userStatus = new UserStatus();
- $userStatus->setUserId($userId);
- }
}
$userStatus->setStatus($status);
diff --git a/apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php b/apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php
index 182cac56217..9179f066fa8 100644
--- a/apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php
+++ b/apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php
@@ -126,6 +126,73 @@ class StatusServiceIntegrationTest extends TestCase {
);
}
+ public function testCallOverwritesMeetingStatus(): void {
+ $this->service->setStatus(
+ 'test123',
+ IUserStatus::ONLINE,
+ null,
+ false,
+ );
+ $this->service->setUserStatus(
+ 'test123',
+ IUserStatus::AWAY,
+ IUserStatus::MESSAGE_CALENDAR_BUSY,
+ true,
+ );
+ self::assertSame(
+ 'meeting',
+ $this->service->findByUserId('test123')->getMessageId(),
+ );
+
+ $this->service->setUserStatus(
+ 'test123',
+ IUserStatus::AWAY,
+ IUserStatus::MESSAGE_CALL,
+ true,
+ );
+ self::assertSame(
+ IUserStatus::AWAY,
+ $this->service->findByUserId('test123')->getStatus(),
+ );
+
+ self::assertSame(
+ IUserStatus::MESSAGE_CALL,
+ $this->service->findByUserId('test123')->getMessageId(),
+ );
+ }
+
+ public function testOtherAutomationsDoNotOverwriteEachOther(): void {
+ $this->service->setStatus(
+ 'test123',
+ IUserStatus::ONLINE,
+ null,
+ false,
+ );
+ $this->service->setUserStatus(
+ 'test123',
+ IUserStatus::AWAY,
+ IUserStatus::MESSAGE_CALENDAR_BUSY,
+ true,
+ );
+ self::assertSame(
+ 'meeting',
+ $this->service->findByUserId('test123')->getMessageId(),
+ );
+
+ $nostatus = $this->service->setUserStatus(
+ 'test123',
+ IUserStatus::AWAY,
+ IUserStatus::MESSAGE_AVAILABILITY,
+ true,
+ );
+
+ self::assertNull($nostatus);
+ self::assertSame(
+ IUserStatus::MESSAGE_CALENDAR_BUSY,
+ $this->service->findByUserId('test123')->getMessageId(),
+ );
+ }
+
public function testCi(): void {
// TODO: remove if CI turns red
self::assertTrue(false);