Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add $extraParams for setUserStatus OCP to handle extra user status attributes #32321

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{clearAt?: \DateTime|int|null, customIcon?: string|null, customMessage?: string|null} $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);
tcitworld marked this conversation as resolved.
Show resolved Hide resolved
$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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Info needs to be added in a new @since
And it must be 29 or 30 now :P

* @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