Skip to content

Commit

Permalink
Merge pull request #42304 from nextcloud/fix/emoji-ooo-status
Browse files Browse the repository at this point in the history
fix(ooo): add new ooo status with new emoji
  • Loading branch information
nickvergessen authored Dec 18, 2023
2 parents 0ff6746 + fc4ef61 commit f7bead0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
8 changes: 4 additions & 4 deletions apps/dav/lib/BackgroundJob/UserStatusAutomation.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function run($argument) {
$this->logger->info('Removing ' . self::class . ' background job for user "' . $userId . '" because the user has no valid availability rules and no OOO data set');
$this->jobList->remove(self::class, $argument);
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::DND);
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_VACATION, IUserStatus::DND);
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND);
return;
}

Expand Down Expand Up @@ -227,15 +227,15 @@ private function processOutOfOfficeData(IUser $user, ?IOutOfOfficeData $ooo): bo
if(empty($ooo)) {
// Reset the user status if the absence doesn't exist
$this->logger->debug('User has no OOO period in effect, reverting DND status if applicable');
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_VACATION, IUserStatus::DND);
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND);
// We need to also run the availability automation
return true;
}

if(!$this->coordinator->isInEffect($ooo)) {
// Reset the user status if the absence is (no longer) in effect
$this->logger->debug('User has no OOO period in effect, reverting DND status if applicable');
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_VACATION, IUserStatus::DND);
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND);

if($ooo->getStartDate() > $this->time->getTime()) {
// Set the next run to take place at the start of the ooo period if it is in the future
Expand All @@ -250,7 +250,7 @@ private function processOutOfOfficeData(IUser $user, ?IOutOfOfficeData $ooo): bo
// Revert both a possible 'CALL - away' and 'office hours - DND' status
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_CALL, IUserStatus::DND);
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::DND);
$this->manager->setUserStatus($user->getUID(), IUserStatus::MESSAGE_VACATION, IUserStatus::DND, true, $ooo->getShortMessage());
$this->manager->setUserStatus($user->getUID(), IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND, true, $ooo->getShortMessage());
// Run at the end of an ooo period to return to availability / regular user status
// If it's overwritten by a custom status in the meantime, there's nothing we can do about it
$this->setLastRunToNextToggleTime($user->getUID(), $ooo->getEndDate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function testRunNoAvailabilityWithOOO(): void {
->method('revertUserStatus');
$this->statusManager->expects(self::once())
->method('setUserStatus')
->with('user', IUserStatus::MESSAGE_VACATION, IUserStatus::DND, true, $ooo->getShortMessage());
->with('user', IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND, true, $ooo->getShortMessage());
$this->config->expects(self::never())
->method('getUserValue');
$this->time->method('getDateTime')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(private IJobList $jobsList,
*/
public function handle(Event $event): void {
if($event instanceof OutOfOfficeClearedEvent) {
$this->manager->revertUserStatus($event->getData()->getUser()->getUID(), IUserStatus::MESSAGE_VACATION, IUserStatus::DND);
$this->manager->revertUserStatus($event->getData()->getUser()->getUID(), IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND);
$this->jobsList->scheduleAfter(UserStatusAutomation::class, $this->time->getTime(), ['userId' => $event->getData()->getUser()->getUID()]);
return;
}
Expand Down
15 changes: 15 additions & 0 deletions apps/user_status/lib/Service/PredefinedStatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class PredefinedStatusService {
* @deprecated See \OCP\UserStatus\IUserStatus::MESSAGE_CALL
*/
public const CALL = 'call';
public const OUT_OF_OFFICE = 'out-of-office';

/** @var IL10N */
private $l10n;
Expand Down Expand Up @@ -113,6 +114,13 @@ public function getDefaultStatuses(): array {
'clearAt' => null,
'visible' => false,
],
[
'id' => self::OUT_OF_OFFICE,
'icon' => '🛑',
'message' => $this->getTranslatedStatusForId(self::OUT_OF_OFFICE),
'clearAt' => null,
'visible' => false,
],
];
}

Expand Down Expand Up @@ -148,6 +156,9 @@ public function getIconForId(string $id): ?string {
case self::VACATIONING:
return '🌴';

case self::OUT_OF_OFFICE:
return '🛑';

case self::REMOTE_WORK:
return '🏡';

Expand Down Expand Up @@ -178,6 +189,9 @@ public function getTranslatedStatusForId(string $id): ?string {
case self::VACATIONING:
return $this->l10n->t('Vacationing');

case self::OUT_OF_OFFICE:
return $this->l10n->t('Out of office');

case self::REMOTE_WORK:
return $this->l10n->t('Working remotely');

Expand All @@ -199,6 +213,7 @@ public function isValidId(string $id): bool {
self::COMMUTING,
self::SICK_LEAVE,
self::VACATIONING,
self::OUT_OF_OFFICE,
self::REMOTE_WORK,
IUserStatus::MESSAGE_CALL,
IUserStatus::MESSAGE_AVAILABILITY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function setUp(): void {
}

public function testGetDefaultStatuses(): void {
$this->l10n->expects($this->exactly(6))
$this->l10n->expects($this->exactly(7))
->method('t')
->withConsecutive(
['In a meeting'],
Expand Down Expand Up @@ -110,6 +110,13 @@ public function testGetDefaultStatuses(): void {
'clearAt' => null,
'visible' => false,
],
[
'id' => 'out-of-office',
'icon' => '🛑',
'message' => 'Out of office',
'clearAt' => null,
'visible' => false,
],
], $actual);
}

Expand Down Expand Up @@ -195,7 +202,7 @@ public function isValidIdDataProvider(): array {
}

public function testGetDefaultStatusById(): void {
$this->l10n->expects($this->exactly(6))
$this->l10n->expects($this->exactly(7))
->method('t')
->withConsecutive(
['In a meeting'],
Expand Down
6 changes: 6 additions & 0 deletions lib/public/UserStatus/IUserStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ interface IUserStatus {
*/
public const MESSAGE_AVAILABILITY = 'availability';

/**
* @var string
* @since 28.0.1
*/
public const MESSAGE_OUT_OF_OFFICE = 'out-of-office';

/**
* @var string
* @since 28.0.0
Expand Down

0 comments on commit f7bead0

Please sign in to comment.