Skip to content

Commit

Permalink
fixup! fix(userstatus): set user status to 'In a meeting' if calendar…
Browse files Browse the repository at this point in the history
… is busy
  • Loading branch information
miaulalala committed Dec 18, 2023
1 parent da3c6c9 commit e1056ab
Show file tree
Hide file tree
Showing 2 changed files with 277 additions and 645 deletions.
27 changes: 14 additions & 13 deletions apps/dav/lib/CalDAV/Status/StatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,33 @@ public function processCalendarStatus(string $userId): void {

$availability = $this->availabilityCoordinator->getCurrentOutOfOfficeData($user);
if($availability !== null && $this->availabilityCoordinator->isInEffect($availability)) {
$this->logger->debug('An Absence is in effect, skipping calendar status check', ['user' => $user->getUID()]);
$this->logger->debug('An Absence is in effect, skipping calendar status check', ['user' => $userId]);
return;
}

$calendarEvents = $this->cache->get($user->getUID());
$calendarEvents = $this->cache->get($userId);
if($calendarEvents === null) {
$calendarEvents = $this->getCalendarEvents($user);
$this->cache->set($user->getUID(), $calendarEvents, 300);
$this->cache->set($userId, $calendarEvents, 300);
}

if(empty($calendarEvents)) {
$this->userStatusService->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_CALENDAR_BUSY);
$this->logger->debug('No calendar events found for status check', ['user' => $user->getUID()]);
$this->userStatusService->revertUserStatus($userId, IUserStatus::MESSAGE_CALENDAR_BUSY);
$this->logger->debug('No calendar events found for status check', ['user' => $userId]);
return;
}

$userStatusTimestamp = $currentStatus = null;
$userStatusTimestamp = null;
$currentStatus = null;
try {
$currentStatus = $this->userStatusService->findByUserId($user->getUID());
$currentStatus = $this->userStatusService->findByUserId($userId);
$userStatusTimestamp = $currentStatus->getIsUserDefined() ? $currentStatus->getStatusTimestamp() : null;
} catch (DoesNotExistException) {
}

if($currentStatus !== null && $currentStatus->getMessageId() === IUserStatus::MESSAGE_CALL) {
// We don't overwrite the call status
$this->logger->debug('Call status detected, skipping calendar status change', ['user' => $user->getUID()]);
$this->logger->debug('Call status detected, skipping calendar status change', ['user' => $userId]);
return;
}

Expand All @@ -112,8 +113,8 @@ public function processCalendarStatus(string $userId): void {
});

if(empty($applicableEvents)) {
$this->userStatusService->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_CALENDAR_BUSY);
$this->logger->debug('No status relevant events found, skipping calendar status change', ['user' => $user->getUID()]);
$this->userStatusService->revertUserStatus($userId, IUserStatus::MESSAGE_CALENDAR_BUSY);
$this->logger->debug('No status relevant events found, skipping calendar status change', ['user' => $userId]);
return;
}

Expand All @@ -122,9 +123,9 @@ public function processCalendarStatus(string $userId): void {
// 2. Current user status was not set after the start of this event
// 3. Event is not set to be transparent
$count = count($applicableEvents);
$this->logger->debug("Found $count applicable event(s), changing user status", ['user' => $user->getUID()]);
$this->logger->debug("Found $count applicable event(s), changing user status", ['user' => $userId]);
$this->userStatusService->setUserStatus(
$user->getUID(),
$userId,
IUserStatus::AWAY,
IUserStatus::MESSAGE_CALENDAR_BUSY,
true
Expand Down Expand Up @@ -155,7 +156,7 @@ private function getCalendarEvents(User $user): array {
}

$dtStart = DateTimeImmutable::createFromMutable($this->timeFactory->getDateTime());
$dtEnd = DateTimeImmutable::createFromMutable($this->timeFactory->getDateTime('+10 minutes'));
$dtEnd = DateTimeImmutable::createFromMutable($this->timeFactory->getDateTime('+5 minutes'));

// Only query the calendars when there's any to search
if($query instanceof CalendarQuery && !empty($query->getCalendarUris())) {
Expand Down
Loading

0 comments on commit e1056ab

Please sign in to comment.