]> source.dussan.org Git - nextcloud-server.git/commitdiff
Always use IUserStatus consts 22548/head
authorGeorg Ehrke <developer@georgehrke.com>
Thu, 3 Sep 2020 14:23:35 +0000 (16:23 +0200)
committerGeorg Ehrke <developer@georgehrke.com>
Mon, 7 Sep 2020 09:30:18 +0000 (11:30 +0200)
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
apps/user_status/lib/Connector/UserStatus.php
apps/user_status/lib/Controller/HeartbeatController.php
apps/user_status/lib/Controller/StatusesController.php
apps/user_status/lib/Dashboard/UserStatusWidget.php
apps/user_status/lib/Db/UserStatusMapper.php
apps/user_status/lib/Listener/UserLiveStatusListener.php
apps/user_status/lib/Service/JSDataService.php
apps/user_status/lib/Service/StatusService.php
lib/public/UserStatus/IUserStatus.php

index e8ab31bb10365c3287442d98f9f372c1eca98482..d6b075dcd8ee4879209ce0d7093acb7363bf24fe 100644 (file)
@@ -25,7 +25,6 @@ declare(strict_types=1);
 namespace OCA\UserStatus\Connector;
 
 use DateTimeImmutable;
-use OCA\UserStatus\Service\StatusService;
 use OCP\UserStatus\IUserStatus;
 use OCA\UserStatus\Db;
 
@@ -57,8 +56,8 @@ class UserStatus implements IUserStatus {
                $this->message = $status->getCustomMessage();
                $this->icon = $status->getCustomIcon();
 
-               if ($status->getStatus() === StatusService::INVISIBLE) {
-                       $this->status = StatusService::OFFLINE;
+               if ($status->getStatus() === IUserStatus::INVISIBLE) {
+                       $this->status = IUserStatus::OFFLINE;
                }
                if ($status->getClearAt() !== null) {
                        $this->clearAt = DateTimeImmutable::createFromFormat('U', (string)$status->getClearAt());
index cc45b0502cc41a91baeffd746d7f1ebb35f52b42..02a0fd082cff9bc3403e49f1bab22abeab1d4f50 100644 (file)
@@ -25,7 +25,6 @@ declare(strict_types=1);
 
 namespace OCA\UserStatus\Controller;
 
-use OCA\UserStatus\Service\StatusService;
 use OCP\AppFramework\Controller;
 use OCP\AppFramework\Http;
 use OCP\AppFramework\Http\JSONResponse;
@@ -34,6 +33,7 @@ use OCP\EventDispatcher\IEventDispatcher;
 use OCP\IRequest;
 use OCP\IUserSession;
 use OCP\User\Events\UserLiveStatusEvent;
+use OCP\UserStatus\IUserStatus;
 
 class HeartbeatController extends Controller {
 
@@ -73,7 +73,7 @@ class HeartbeatController extends Controller {
         * @return JSONResponse
         */
        public function heartbeat(string $status): JSONResponse {
-               if (!\in_array($status, [StatusService::ONLINE, StatusService::AWAY], true)) {
+               if (!\in_array($status, [IUserStatus::ONLINE, IUserStatus::AWAY], true)) {
                        return new JSONResponse([], Http::STATUS_BAD_REQUEST);
                }
 
index 0391ea1492845726da04dc13f832dd13621c8ba6..4295fb769493ae90e0689b0b3d8139172ecce040 100644 (file)
@@ -32,6 +32,7 @@ use OCP\AppFramework\Http\DataResponse;
 use OCP\AppFramework\OCS\OCSNotFoundException;
 use OCP\AppFramework\OCSController;
 use OCP\IRequest;
+use OCP\UserStatus\IUserStatus;
 
 class StatusesController extends OCSController {
 
@@ -92,8 +93,8 @@ class StatusesController extends OCSController {
         */
        private function formatStatus(UserStatus $status): array {
                $visibleStatus = $status->getStatus();
-               if ($visibleStatus === StatusService::INVISIBLE) {
-                       $visibleStatus = StatusService::OFFLINE;
+               if ($visibleStatus === IUserStatus::INVISIBLE) {
+                       $visibleStatus = IUserStatus::OFFLINE;
                }
 
                return [
index 9cd29e3ddba87996465a1f72a0dee8e07dd6979f..6ccea95acdc16169ab01c44ab0587641767f3eb9 100644 (file)
@@ -32,6 +32,7 @@ use OCP\IInitialStateService;
 use OCP\IL10N;
 use OCP\IUserManager;
 use OCP\IUserSession;
+use OCP\UserStatus\IUserStatus;
 
 /**
  * Class UserStatusWidget
@@ -146,8 +147,8 @@ class UserStatusWidget implements IWidget {
                        return [
                                'userId' => $status->getUserId(),
                                'displayName' => $displayName,
-                               'status' => $status->getStatus() === StatusService::INVISIBLE
-                                       ? StatusService::OFFLINE
+                               'status' => $status->getStatus() === IUserStatus::INVISIBLE
+                                       ? IUserStatus::OFFLINE
                                        : $status->getStatus(),
                                'icon' => $status->getCustomIcon(),
                                'message' => $status->getCustomMessage(),
index 31156345b4ec73dd1acdc6d6db7a74f3dfaaf763..dc54789d3432f38aa9e858884c4202c08dd47296 100644 (file)
@@ -25,10 +25,10 @@ declare(strict_types=1);
 
 namespace OCA\UserStatus\Db;
 
-use OCA\UserStatus\Service\StatusService;
 use OCP\AppFramework\Db\QBMapper;
 use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCP\IDBConnection;
+use OCP\UserStatus\IUserStatus;
 
 /**
  * Class UserStatusMapper
@@ -82,7 +82,7 @@ class UserStatusMapper extends QBMapper {
                        ->select('*')
                        ->from($this->tableName)
                        ->orderBy('status_timestamp', 'DESC')
-                       ->where($qb->expr()->notIn('status', $qb->createNamedParameter([StatusService::ONLINE, StatusService::AWAY, StatusService::OFFLINE], IQueryBuilder::PARAM_STR_ARRAY)))
+                       ->where($qb->expr()->notIn('status', $qb->createNamedParameter([IUserStatus::ONLINE, IUserStatus::AWAY, IUserStatus::OFFLINE], IQueryBuilder::PARAM_STR_ARRAY)))
                        ->orWhere($qb->expr()->isNotNull('message_id'))
                        ->orWhere($qb->expr()->isNotNull('custom_icon'))
                        ->orWhere($qb->expr()->isNotNull('custom_message'));
@@ -133,13 +133,13 @@ class UserStatusMapper extends QBMapper {
        public function clearStatusesOlderThan(int $olderThan, int $now): void {
                $qb = $this->db->getQueryBuilder();
                $qb->update($this->tableName)
-                       ->set('status', $qb->createNamedParameter(StatusService::OFFLINE))
+                       ->set('status', $qb->createNamedParameter(IUserStatus::OFFLINE))
                        ->set('is_user_defined', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))
                        ->set('status_timestamp', $qb->createNamedParameter($now, IQueryBuilder::PARAM_INT))
                        ->where($qb->expr()->lte('status_timestamp', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT)))
                        ->andWhere($qb->expr()->orX(
                                $qb->expr()->eq('is_user_defined', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL), IQueryBuilder::PARAM_BOOL),
-                               $qb->expr()->eq('status', $qb->createNamedParameter(StatusService::ONLINE))
+                               $qb->expr()->eq('status', $qb->createNamedParameter(IUserStatus::ONLINE))
                        ));
 
                $qb->execute();
index 52e73017d4b8cb89e3568284c63e56ce72d3f450..967810367eb625f2085cc76464772a3292a55ca8 100644 (file)
@@ -33,6 +33,7 @@ use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\EventDispatcher\IEventListener;
 use OCP\EventDispatcher\Event;
 use OCP\User\Events\UserLiveStatusEvent;
+use OCP\UserStatus\IUserStatus;
 
 /**
  * Class UserDeletedListener
@@ -74,7 +75,7 @@ class UserLiveStatusListener implements IEventListener {
                } catch (DoesNotExistException $ex) {
                        $userStatus = new UserStatus();
                        $userStatus->setUserId($user->getUID());
-                       $userStatus->setStatus(StatusService::OFFLINE);
+                       $userStatus->setStatus(IUserStatus::OFFLINE);
                        $userStatus->setStatusTimestamp(0);
                        $userStatus->setIsUserDefined(false);
                }
index 334ae248d4c6c0d172206f61e66cc8e15e54e830..ca78943fafe0cd478def345a8f86a64ea0b8ac11 100644 (file)
@@ -27,6 +27,7 @@ namespace OCA\UserStatus\Service;
 
 use OCP\AppFramework\Db\DoesNotExistException;
 use OCP\IUserSession;
+use OCP\UserStatus\IUserStatus;
 
 class JSDataService implements \JsonSerializable {
 
@@ -65,7 +66,7 @@ class JSDataService implements \JsonSerializable {
                                'messageIsPredefined' => false,
                                'icon' => null,
                                'clearAt' => null,
-                               'status' => StatusService::OFFLINE,
+                               'status' => IUserStatus::OFFLINE,
                                'statusIsUserDefined' => false,
                        ];
                }
index 1e1e5b1fcc57af70114dd7145a28a7e7a9ca21b5..85368342b2596b1b1cb28cc7fe5a63c55e071904 100644 (file)
@@ -34,6 +34,7 @@ use OCA\UserStatus\Exception\InvalidStatusTypeException;
 use OCA\UserStatus\Exception\StatusMessageTooLongException;
 use OCP\AppFramework\Db\DoesNotExistException;
 use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\UserStatus\IUserStatus;
 
 /**
  * Class StatusService
@@ -54,21 +55,15 @@ class StatusService {
        /** @var EmojiService */
        private $emojiService;
 
-       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
+               IUserStatus::ONLINE,
+               IUserStatus::AWAY,
+               IUserStatus::DND,
+               IUserStatus::INVISIBLE,
+               IUserStatus::OFFLINE
        ];
 
        /**
@@ -76,9 +71,9 @@ class StatusService {
         * or UserLiveStatusEvents
         */
        public const PERSISTENT_STATUSES = [
-               self::AWAY,
-               self::DND,
-               self::INVISIBLE,
+               IUserStatus::AWAY,
+               IUserStatus::DND,
+               IUserStatus::INVISIBLE,
        ];
 
        /** @var int */
@@ -200,7 +195,7 @@ class StatusService {
                } catch (DoesNotExistException $ex) {
                        $userStatus = new UserStatus();
                        $userStatus->setUserId($userId);
-                       $userStatus->setStatus(self::OFFLINE);
+                       $userStatus->setStatus(IUserStatus::OFFLINE);
                        $userStatus->setStatusTimestamp(0);
                        $userStatus->setIsUserDefined(false);
                }
@@ -245,7 +240,7 @@ class StatusService {
                } catch (DoesNotExistException $ex) {
                        $userStatus = new UserStatus();
                        $userStatus->setUserId($userId);
-                       $userStatus->setStatus(self::OFFLINE);
+                       $userStatus->setStatus(IUserStatus::OFFLINE);
                        $userStatus->setStatusTimestamp(0);
                        $userStatus->setIsUserDefined(false);
                }
@@ -287,7 +282,7 @@ class StatusService {
                        return false;
                }
 
-               $userStatus->setStatus(self::OFFLINE);
+               $userStatus->setStatus(IUserStatus::OFFLINE);
                $userStatus->setStatusTimestamp(0);
                $userStatus->setIsUserDefined(false);
 
@@ -343,7 +338,7 @@ class StatusService {
                $clearAt = $status->getClearAt();
 
                if ($status->getStatusTimestamp() < $this->timeFactory->getTime() - self::INVALIDATE_STATUS_THRESHOLD
-                       && (!$status->getIsUserDefined() || $status->getStatus() === self::ONLINE)) {
+                       && (!$status->getIsUserDefined() || $status->getStatus() === IUserStatus::ONLINE)) {
                        $this->cleanStatus($status);
                }
                if ($clearAt !== null && $clearAt < $this->timeFactory->getTime()) {
@@ -360,7 +355,7 @@ class StatusService {
         * @param UserStatus $status
         */
        private function cleanStatus(UserStatus $status): void {
-               $status->setStatus(self::OFFLINE);
+               $status->setStatus(IUserStatus::OFFLINE);
                $status->setStatusTimestamp($this->timeFactory->getTime());
                $status->setIsUserDefined(false);
 
index b721ee67a781e0002bac773d0a0f8e1cc2ba30cb..3e606e3871212503bded4eb7b4f52912d74167cb 100644 (file)
@@ -59,6 +59,12 @@ interface IUserStatus {
         */
        public const OFFLINE = 'offline';
 
+       /**
+        * @var string
+        * @since 20.0.0
+        */
+       public const INVISIBLE = 'invisible';
+
        /**
         * Get the user this status is connected to
         *