Skip to content

Commit

Permalink
Add $extraParams for setUserStatus OCP to handle extra user status at…
Browse files Browse the repository at this point in the history
…tributes

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
  • Loading branch information
tcitworld committed May 10, 2022
1 parent 8f989bb commit 22b4a6e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
18 changes: 16 additions & 2 deletions apps/user_status/lib/Connector/UserStatusProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,22 @@ public function getUserStatuses(array $userIds): array {
return $userStatuses;
}

public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup): void {
$this->service->setUserStatus($userId, $status, $messageId, $createBackup);
/**
* Set a new status for the selected user.
*
* The following $extraParams keys are supported:
* - clearAt When to clear this user status
* - customIcon A custom icon for the user status
* - customMessage A custom message for the user status
*
* @param string $userId The user for which we want to update the status.
* @param string $messageId The new message id.
* @param string $status The new status.
* @param bool $createBackup If true, this will store the old status so that it is possible to revert it later (e.g. after a call).
* @param array{clearAt: \DateTime|int|null, customIcon: string|null, customMessage: string|null} $extraParams Pass extra parameters to the user status implementation provider. Added in 25.0.0
*/
public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup, array $extraParams = []): void {
$this->service->setUserStatus($userId, $status, $messageId, $createBackup, $extraParams);
}

public function revertUserStatus(string $userId, string $messageId, string $status): void {
Expand Down
22 changes: 17 additions & 5 deletions apps/user_status/lib/Service/StatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,15 @@ public function setPredefinedMessage(string $userId,
* @param string $status
* @param string $messageId
* @param bool $createBackup
* @param array $extraParams
* @throws InvalidStatusTypeException
* @throws InvalidMessageIdException
*/
public function setUserStatus(string $userId,
string $status,
string $messageId,
bool $createBackup): void {
bool $createBackup,
array $extraParams): void {
// Check if status-type is valid
if (!\in_array($status, self::PRIORITY_ORDERED_STATUSES, true)) {
throw new InvalidStatusTypeException('Status-type "' . $status . '" is not supported');
Expand All @@ -284,14 +286,24 @@ public function setUserStatus(string $userId,
}
}

$now = $this->timeFactory->getTime();

$clearAt = $extraParams['clearAt'] ?? null;
if ($clearAt instanceof \DateTime) {
$clearAt = $clearAt->getTimestamp();
}
if (!is_int($clearAt) || $clearAt < $now) {
$clearAt = null;
}

$userStatus->setStatus($status);
$userStatus->setStatusTimestamp($this->timeFactory->getTime());
$userStatus->setStatusTimestamp($now);
$userStatus->setIsUserDefined(true);
$userStatus->setIsBackup(false);
$userStatus->setMessageId($messageId);
$userStatus->setCustomIcon(null);
$userStatus->setCustomMessage(null);
$userStatus->setClearAt(null);
$userStatus->setCustomIcon($extraParams['customIcon'] ?? null);
$userStatus->setCustomMessage($extraParams['customMessage'] ?? null);
$userStatus->setClearAt($clearAt);

if ($userStatus->getId() !== null) {
$this->mapper->update($userStatus);
Expand Down
3 changes: 2 additions & 1 deletion lib/private/UserStatus/ISettableProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ interface ISettableProvider extends IProvider {
* @param string $messageId The new message id.
* @param string $status The new status.
* @param bool $createBackup If true, this will store the old status so that it is possible to revert it later (e.g. after a call).
* @param array $extraParams Pass extra parameters to the user status implementation provider. Refer to the provider implementation to determine which keys are supported. Added in 25.0.0
*/
public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup): void;
public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup, array $extraParams = []): void;

/**
* Revert an automatically set user status. For example after leaving a call,
Expand Down
4 changes: 2 additions & 2 deletions lib/private/UserStatus/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ private function setupProvider(): void {
$this->provider = $provider;
}

public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false): void {
public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false, array $extraParams = []): void {
$this->setupProvider();
if (!$this->provider || !($this->provider instanceof ISettableProvider)) {
return;
}

$this->provider->setUserStatus($userId, $messageId, $status, $createBackup);
$this->provider->setUserStatus($userId, $messageId, $status, $createBackup, $extraParams);
}

public function revertUserStatus(string $userId, string $messageId, string $status): void {
Expand Down
3 changes: 2 additions & 1 deletion lib/public/UserStatus/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public function getUserStatuses(array $userIds): array;
* @param string $messageId The id of the predefined message.
* @param string $status The status to assign
* @param bool $createBackup If true, this will store the old status so that it is possible to revert it later (e.g. after a call).
* @param array $extraParams Pass extra parameters to the user status implementation provider. Refer to the provider implementation to determine which keys are supported. Added in 25.0.0
* @since 23.0.0
*/
public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false): void;
public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false, array $extraParams = []): void;

/**
* Revert an automatically set user status. For example after leaving a call,
Expand Down

0 comments on commit 22b4a6e

Please # to comment.