Browse Source

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>
pull/29791/head
Carl Schwan 4 years ago
parent
commit
92fe694b7f
No known key found for this signature in database GPG Key ID: 6B35D38387B67BE
  1. 4
      apps/user_status/js/user-status-menu.js
  2. 2
      apps/user_status/js/user-status-menu.js.map
  3. 4
      apps/user_status/js/user-status-modal.js
  4. 2
      apps/user_status/js/user-status-modal.js.map
  5. 4
      apps/user_status/lib/Controller/StatusesController.php
  6. 4
      apps/user_status/lib/Controller/UserStatusController.php
  7. 28
      apps/user_status/lib/Service/StatusService.php
  8. 3
      apps/user_status/src/components/SetStatusModal.vue

4
apps/user_status/js/user-status-menu.js
File diff suppressed because it is too large
View File

2
apps/user_status/js/user-status-menu.js.map
File diff suppressed because it is too large
View File

4
apps/user_status/js/user-status-modal.js
File diff suppressed because it is too large
View File

2
apps/user_status/js/user-status-modal.js.map
File diff suppressed because it is too large
View File

4
apps/user_status/lib/Controller/StatusesController.php

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

4
apps/user_status/lib/Controller/UserStatusController.php

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

28
apps/user_status/lib/Service/StatusService.php

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

3
apps/user_status/src/components/SetStatusModal.vue

@ -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…
Cancel
Save