summaryrefslogtreecommitdiffstats
path: root/apps/user_status/lib/Service
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2020-09-02 11:49:14 +0200
committerGeorg Ehrke <developer@georgehrke.com>2020-09-07 09:22:34 +0200
commita352a7c7f38d7b1e34caafbbd53ef1e2c28c1caa (patch)
tree5bbd84d6880b4fde2593fd82cfff5925f8e5ca81 /apps/user_status/lib/Service
parent16e1d1cb12229270d61d89dfda93399d056d456c (diff)
downloadnextcloud-server-a352a7c7f38d7b1e34caafbbd53ef1e2c28c1caa.tar.gz
nextcloud-server-a352a7c7f38d7b1e34caafbbd53ef1e2c28c1caa.zip
Introduce consts for statuses
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/user_status/lib/Service')
-rw-r--r--apps/user_status/lib/Service/JSDataService.php2
-rw-r--r--apps/user_status/lib/Service/StatusService.php53
2 files changed, 38 insertions, 17 deletions
diff --git a/apps/user_status/lib/Service/JSDataService.php b/apps/user_status/lib/Service/JSDataService.php
index ebe801cd57a..334ae248d4c 100644
--- a/apps/user_status/lib/Service/JSDataService.php
+++ b/apps/user_status/lib/Service/JSDataService.php
@@ -65,7 +65,7 @@ class JSDataService implements \JsonSerializable {
'messageIsPredefined' => false,
'icon' => null,
'clearAt' => null,
- 'status' => 'offline',
+ 'status' => StatusService::OFFLINE,
'statusIsUserDefined' => false,
];
}
diff --git a/apps/user_status/lib/Service/StatusService.php b/apps/user_status/lib/Service/StatusService.php
index e36d605cee4..06441f60059 100644
--- a/apps/user_status/lib/Service/StatusService.php
+++ b/apps/user_status/lib/Service/StatusService.php
@@ -54,17 +54,38 @@ class StatusService {
/** @var EmojiService */
private $emojiService;
- /** @var string[] */
- private $allowedStatusTypes = [
- 'online',
- 'away',
- 'dnd',
- 'invisible',
- 'offline'
+ public const ONLINE = 'online';
+ public const AWAY = 'away';
+ public const DND = 'dnd';
+ public const INVISIBLE = 'invisible';
+ public const OFFLINE = 'offline';
+
+ /**
+ * List of priorities ordered by their priority
+ */
+ public const PRIORITY_ORDERED_STATUSES = [
+ self::ONLINE,
+ self::AWAY,
+ self::DND,
+ self::INVISIBLE,
+ self::OFFLINE
];
+ /**
+ * List of statuses that persist the clear-up
+ * or UserLiveStatusEvents
+ */
+ public const PERSISTENT_STATUSES = [
+ self::AWAY,
+ self::DND,
+ self::INVISIBLE,
+ ];
+
+ /** @var int */
+ public const INVALIDATE_STATUS_THRESHOLD = 5 /* minutes */ * 60 /* seconds */;
+
/** @var int */
- private $maximumMessageLength = 80;
+ public const MAXIMUM_MESSAGE_LENGTH = 80;
/**
* StatusService constructor.
@@ -145,7 +166,7 @@ class StatusService {
}
// Check if status-type is valid
- if (!\in_array($status, $this->allowedStatusTypes, true)) {
+ if (!\in_array($status, self::PRIORITY_ORDERED_STATUSES, true)) {
throw new InvalidStatusTypeException('Status-type "' . $status . '" is not supported');
}
if ($statusTimestamp === null) {
@@ -179,7 +200,7 @@ class StatusService {
} catch (DoesNotExistException $ex) {
$userStatus = new UserStatus();
$userStatus->setUserId($userId);
- $userStatus->setStatus('offline');
+ $userStatus->setStatus(self::OFFLINE);
$userStatus->setStatusTimestamp(0);
$userStatus->setIsUserDefined(false);
}
@@ -224,7 +245,7 @@ class StatusService {
} catch (DoesNotExistException $ex) {
$userStatus = new UserStatus();
$userStatus->setUserId($userId);
- $userStatus->setStatus('offline');
+ $userStatus->setStatus(self::OFFLINE);
$userStatus->setStatusTimestamp(0);
$userStatus->setIsUserDefined(false);
}
@@ -234,8 +255,8 @@ class StatusService {
throw new InvalidStatusIconException('Status-Icon is longer than one character');
}
// Check for maximum length of custom message
- if (\mb_strlen($message) > $this->maximumMessageLength) {
- throw new StatusMessageTooLongException('Message is longer than supported length of ' . $this->maximumMessageLength . ' characters');
+ if (\mb_strlen($message) > self::MAXIMUM_MESSAGE_LENGTH) {
+ throw new StatusMessageTooLongException('Message is longer than supported length of ' . self::MAXIMUM_MESSAGE_LENGTH . ' characters');
}
// Check that clearAt is in the future
if ($clearAt !== null && $clearAt < $this->timeFactory->getTime()) {
@@ -266,7 +287,7 @@ class StatusService {
return false;
}
- $userStatus->setStatus('offline');
+ $userStatus->setStatus(self::OFFLINE);
$userStatus->setStatusTimestamp(0);
$userStatus->setIsUserDefined(false);
@@ -321,7 +342,7 @@ class StatusService {
private function processStatus(UserStatus $status): UserStatus {
$clearAt = $status->getClearAt();
if ($clearAt !== null && $clearAt < $this->timeFactory->getTime()) {
- $this->cleanStatus($status);
+ $this->cleanStatusMessage($status);
}
if ($status->getMessageId() !== null) {
$this->addDefaultMessage($status);
@@ -333,7 +354,7 @@ class StatusService {
/**
* @param UserStatus $status
*/
- private function cleanStatus(UserStatus $status): void {
+ private function cleanStatusMessage(UserStatus $status): void {
$status->setMessageId(null);
$status->setCustomIcon(null);
$status->setCustomMessage(null);