Merge pull request #29858 from nextcloud/backport/29791/stable23

This commit is contained in:
Pytal 2021-11-23 16:19:19 -08:00 committed by GitHub
commit 21a1b0cace
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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

View file

@ -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();

View file

@ -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 . '"');

View file

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

View file

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