aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_status/lib
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2023-12-15 14:51:01 +0100
committerAnna Larch <anna@nextcloud.com>2023-12-19 14:59:00 +0100
commit4c6eff975f1ea07e0250d0eff921b5ee54eeab3b (patch)
treeda53d6b2fc6ce2818276d60b176fb18147c11d00 /apps/user_status/lib
parent2f647aacc50f949eccbaaa49a30698776e8205bb (diff)
downloadnextcloud-server-4c6eff975f1ea07e0250d0eff921b5ee54eeab3b.tar.gz
nextcloud-server-4c6eff975f1ea07e0250d0eff921b5ee54eeab3b.zip
fix(userstatus): set user status to 'In a meeting' if calendar is busy
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'apps/user_status/lib')
-rw-r--r--apps/user_status/lib/Controller/UserStatusController.php3
-rw-r--r--apps/user_status/lib/Listener/UserLiveStatusListener.php11
-rw-r--r--apps/user_status/lib/Service/StatusService.php31
3 files changed, 14 insertions, 31 deletions
diff --git a/apps/user_status/lib/Controller/UserStatusController.php b/apps/user_status/lib/Controller/UserStatusController.php
index f2b1537e4f7..3beb8abc3ab 100644
--- a/apps/user_status/lib/Controller/UserStatusController.php
+++ b/apps/user_status/lib/Controller/UserStatusController.php
@@ -28,6 +28,7 @@ declare(strict_types=1);
*/
namespace OCA\UserStatus\Controller;
+use OCA\DAV\CalDAV\Status\StatusService as CalendarStatusService;
use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Exception\InvalidClearAtException;
use OCA\UserStatus\Exception\InvalidMessageIdException;
@@ -55,6 +56,7 @@ class UserStatusController extends OCSController {
private string $userId,
private LoggerInterface $logger,
private StatusService $service,
+ private CalendarStatusService $calendarStatusService,
) {
parent::__construct($appName, $request);
}
@@ -71,6 +73,7 @@ class UserStatusController extends OCSController {
*/
public function getStatus(): DataResponse {
try {
+ $this->calendarStatusService->processCalendarStatus($this->userId);
$userStatus = $this->service->findByUserId($this->userId);
} catch (DoesNotExistException $ex) {
throw new OCSNotFoundException('No status for the current user');
diff --git a/apps/user_status/lib/Listener/UserLiveStatusListener.php b/apps/user_status/lib/Listener/UserLiveStatusListener.php
index 0d0e6e3ebf0..b999c51d72f 100644
--- a/apps/user_status/lib/Listener/UserLiveStatusListener.php
+++ b/apps/user_status/lib/Listener/UserLiveStatusListener.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
*/
namespace OCA\UserStatus\Listener;
+use OCA\DAV\CalDAV\Status\StatusService as CalendarStatusService;
use OCA\UserStatus\Connector\UserStatus as ConnectorUserStatus;
use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Db\UserStatusMapper;
@@ -48,7 +49,8 @@ class UserLiveStatusListener implements IEventListener {
public function __construct(UserStatusMapper $mapper,
StatusService $statusService,
- ITimeFactory $timeFactory) {
+ ITimeFactory $timeFactory,
+ private CalendarStatusService $calendarStatusService) {
$this->mapper = $mapper;
$this->statusService = $statusService;
$this->timeFactory = $timeFactory;
@@ -65,6 +67,7 @@ class UserLiveStatusListener implements IEventListener {
$user = $event->getUser();
try {
+ $this->calendarStatusService->processCalendarStatus($user->getUID());
$userStatus = $this->statusService->findByUserId($user->getUID());
} catch (DoesNotExistException $ex) {
$userStatus = new UserStatus();
@@ -81,6 +84,12 @@ class UserLiveStatusListener implements IEventListener {
return;
}
+ // Don't overwrite the "away" calendar status if it's set
+ if($userStatus->getMessageId() === IUserStatus::MESSAGE_CALENDAR_BUSY) {
+ $event->setUserStatus(new ConnectorUserStatus($userStatus));
+ return;
+ }
+
$needsUpdate = false;
// If the current status is older than 5 minutes,
diff --git a/apps/user_status/lib/Service/StatusService.php b/apps/user_status/lib/Service/StatusService.php
index 9582c403329..c623262eec6 100644
--- a/apps/user_status/lib/Service/StatusService.php
+++ b/apps/user_status/lib/Service/StatusService.php
@@ -27,8 +27,6 @@ declare(strict_types=1);
*/
namespace OCA\UserStatus\Service;
-use OCA\DAV\CalDAV\Status\Status as CalendarStatus;
-use OCA\DAV\CalDAV\Status\StatusService as CalendarStatusService;
use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Db\UserStatusMapper;
use OCA\UserStatus\Exception\InvalidClearAtException;
@@ -89,8 +87,7 @@ class StatusService {
private PredefinedStatusService $predefinedStatusService,
private IEmojiHelper $emojiHelper,
private IConfig $config,
- private IUserManager $userManager,
- private CalendarStatusService $calendarStatusService) {
+ private IUserManager $userManager) {
$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
$this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
$this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
@@ -558,30 +555,4 @@ class StatusService {
// For users that matched restore the previous status
$this->mapper->restoreBackupStatuses($restoreIds);
}
-
- /**
- * Calculate a users' status according to their calendar events
- *
- * There are 4 predefined types of FBTYPE - 'FREE', 'BUSY', 'BUSY-UNAVAILABLE', 'BUSY-TENTATIVE',
- * but 'X-' properties are possible
- *
- * @link https://icalendar.org/iCalendar-RFC-5545/3-2-9-free-busy-time-type.html
- *
- * The status will be changed for types
- * - 'BUSY'
- * - 'BUSY-TENTATIVE' (ex.: an event has been accepted tentatively)
- * and all FREEBUSY components without a type (implicitly a 'BUSY' status)
- *
- * 'X-' properties and BUSY-UNAVAILABLE is not handled
- *
- * @param string $userId
- * @return CalendarStatus|null
- */
- public function getCalendarStatus(string $userId): ?CalendarStatus {
- $user = $this->userManager->get($userId);
- if ($user === null) {
- return null;
- }
- return $this->calendarStatusService->processCalendarAvailability($user);
- }
}