Skip to content

Commit 22b4a6e

Browse files
committed
Add $extraParams for setUserStatus OCP to handle extra user status attributes
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
1 parent 8f989bb commit 22b4a6e

File tree

5 files changed

+39
-11
lines changed

5 files changed

+39
-11
lines changed

apps/user_status/lib/Connector/UserStatusProvider.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,22 @@ public function getUserStatuses(array $userIds): array {
5757
return $userStatuses;
5858
}
5959

60-
public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup): void {
61-
$this->service->setUserStatus($userId, $status, $messageId, $createBackup);
60+
/**
61+
* Set a new status for the selected user.
62+
*
63+
* The following $extraParams keys are supported:
64+
* - clearAt When to clear this user status
65+
* - customIcon A custom icon for the user status
66+
* - customMessage A custom message for the user status
67+
*
68+
* @param string $userId The user for which we want to update the status.
69+
* @param string $messageId The new message id.
70+
* @param string $status The new status.
71+
* @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).
72+
* @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
73+
*/
74+
public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup, array $extraParams = []): void {
75+
$this->service->setUserStatus($userId, $status, $messageId, $createBackup, $extraParams);
6276
}
6377

6478
public function revertUserStatus(string $userId, string $messageId, string $status): void {

apps/user_status/lib/Service/StatusService.php

+17-5
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,15 @@ public function setPredefinedMessage(string $userId,
251251
* @param string $status
252252
* @param string $messageId
253253
* @param bool $createBackup
254+
* @param array $extraParams
254255
* @throws InvalidStatusTypeException
255256
* @throws InvalidMessageIdException
256257
*/
257258
public function setUserStatus(string $userId,
258259
string $status,
259260
string $messageId,
260-
bool $createBackup): void {
261+
bool $createBackup,
262+
array $extraParams): void {
261263
// Check if status-type is valid
262264
if (!\in_array($status, self::PRIORITY_ORDERED_STATUSES, true)) {
263265
throw new InvalidStatusTypeException('Status-type "' . $status . '" is not supported');
@@ -284,14 +286,24 @@ public function setUserStatus(string $userId,
284286
}
285287
}
286288

289+
$now = $this->timeFactory->getTime();
290+
291+
$clearAt = $extraParams['clearAt'] ?? null;
292+
if ($clearAt instanceof \DateTime) {
293+
$clearAt = $clearAt->getTimestamp();
294+
}
295+
if (!is_int($clearAt) || $clearAt < $now) {
296+
$clearAt = null;
297+
}
298+
287299
$userStatus->setStatus($status);
288-
$userStatus->setStatusTimestamp($this->timeFactory->getTime());
300+
$userStatus->setStatusTimestamp($now);
289301
$userStatus->setIsUserDefined(true);
290302
$userStatus->setIsBackup(false);
291303
$userStatus->setMessageId($messageId);
292-
$userStatus->setCustomIcon(null);
293-
$userStatus->setCustomMessage(null);
294-
$userStatus->setClearAt(null);
304+
$userStatus->setCustomIcon($extraParams['customIcon'] ?? null);
305+
$userStatus->setCustomMessage($extraParams['customMessage'] ?? null);
306+
$userStatus->setClearAt($clearAt);
295307

296308
if ($userStatus->getId() !== null) {
297309
$this->mapper->update($userStatus);

lib/private/UserStatus/ISettableProvider.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ interface ISettableProvider extends IProvider {
3939
* @param string $messageId The new message id.
4040
* @param string $status The new status.
4141
* @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).
42+
* @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
4243
*/
43-
public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup): void;
44+
public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup, array $extraParams = []): void;
4445

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

lib/private/UserStatus/Manager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ private function setupProvider(): void {
105105
$this->provider = $provider;
106106
}
107107

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

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

117117
public function revertUserStatus(string $userId, string $messageId, string $status): void {

lib/public/UserStatus/IManager.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ public function getUserStatuses(array $userIds): array;
5353
* @param string $messageId The id of the predefined message.
5454
* @param string $status The status to assign
5555
* @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).
56+
* @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
5657
* @since 23.0.0
5758
*/
58-
public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false): void;
59+
public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false, array $extraParams = []): void;
5960

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

0 commit comments

Comments
 (0)