mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Fix multiple bugs with user status
* Fix editing the status while on a call, don't send a bogus request * Clean backup user status when setting up a new status manually * A bit more type hinting Signed-off-by: Carl Schwan <carl@carlschwan.eu>
This commit is contained in:
parent
c35ad0c20d
commit
92fe694b7f
8 changed files with 29 additions and 22 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -87,10 +87,8 @@ class StatusesController extends OCSController {
|
|||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param UserStatus $status
|
||||
* @return array
|
||||
* @return array{userId: string, message: string, icon: string, clearAt: int, status: string}
|
||||
*/
|
||||
private function formatStatus(UserStatus $status): array {
|
||||
$visibleStatus = $status->getStatus();
|
||||
|
|
|
|||
|
|
@ -99,6 +99,8 @@ class UserStatusController extends OCSController {
|
|||
public function setStatus(string $statusType): DataResponse {
|
||||
try {
|
||||
$status = $this->service->setStatus($this->userId, $statusType, null, true);
|
||||
|
||||
$this->service->removeBackupUserStatus($this->userId);
|
||||
return new DataResponse($this->formatStatus($status));
|
||||
} catch (InvalidStatusTypeException $ex) {
|
||||
$this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid status type "' . $statusType . '"');
|
||||
|
|
@ -118,6 +120,7 @@ class UserStatusController extends OCSController {
|
|||
?int $clearAt): DataResponse {
|
||||
try {
|
||||
$status = $this->service->setPredefinedMessage($this->userId, $messageId, $clearAt);
|
||||
$this->service->removeBackupUserStatus($this->userId);
|
||||
return new DataResponse($this->formatStatus($status));
|
||||
} catch (InvalidClearAtException $ex) {
|
||||
$this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid clearAt value "' . $clearAt . '"');
|
||||
|
|
@ -147,6 +150,7 @@ class UserStatusController extends OCSController {
|
|||
$this->service->clearMessage($this->userId);
|
||||
$status = $this->service->findByUserId($this->userId);
|
||||
}
|
||||
$this->service->removeBackupUserStatus($this->userId);
|
||||
return new DataResponse($this->formatStatus($status));
|
||||
} catch (InvalidClearAtException $ex) {
|
||||
$this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid clearAt value "' . $clearAt . '"');
|
||||
|
|
|
|||
|
|
@ -346,9 +346,21 @@ class StatusService {
|
|||
* @param string $userId
|
||||
* @return bool
|
||||
*/
|
||||
public function removeUserStatus(string $userId, bool $isBackup = false): bool {
|
||||
public function removeUserStatus(string $userId): bool {
|
||||
try {
|
||||
$userStatus = $this->mapper->findByUserId($userId, $isBackup);
|
||||
$userStatus = $this->mapper->findByUserId($userId, false);
|
||||
} catch (DoesNotExistException $ex) {
|
||||
// if there is no status to remove, just return
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->mapper->delete($userStatus);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function removeBackupUserStatus(string $userId): bool {
|
||||
try {
|
||||
$userStatus = $this->mapper->findByUserId($userId, true);
|
||||
} catch (DoesNotExistException $ex) {
|
||||
// if there is no status to remove, just return
|
||||
return false;
|
||||
|
|
@ -448,20 +460,12 @@ class StatusService {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function revertUserStatus(string $userId, string $messageId, string $status): void {
|
||||
public function revertUserStatus(string $userId, ?string $messageId, string $status): void {
|
||||
try {
|
||||
/** @var UserStatus $userStatus */
|
||||
$backupUserStatus = $this->mapper->findByUserId($userId, true);
|
||||
} catch (DoesNotExistException $ex) {
|
||||
// No backup, just move back to available
|
||||
try {
|
||||
$userStatus = $this->mapper->findByUserId($userId);
|
||||
} catch (DoesNotExistException $ex) {
|
||||
// No backup nor current status => ignore
|
||||
return;
|
||||
}
|
||||
$this->cleanStatus($userStatus);
|
||||
$this->cleanStatusMessage($userStatus);
|
||||
// No user status to revert, do nothing
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ export default {
|
|||
clearAt: null,
|
||||
icon: null,
|
||||
message: '',
|
||||
messageId: '',
|
||||
isSavingStatus: false,
|
||||
statuses: getAllStatusOptions(),
|
||||
}
|
||||
|
|
@ -191,7 +192,7 @@ export default {
|
|||
try {
|
||||
this.isSavingStatus = true
|
||||
|
||||
if (this.messageId !== null) {
|
||||
if (this.messageId !== undefined && this.messageId !== null) {
|
||||
await this.$store.dispatch('setPredefinedMessage', {
|
||||
messageId: this.messageId,
|
||||
clearAt: this.clearAt,
|
||||
|
|
|
|||
Loading…
Reference in a new issue