Skip to content

Commit 21a1b0c

Browse files
authored
Merge pull request #29858 from nextcloud/backport/29791/stable23
2 parents d038511 + 17db07c commit 21a1b0c

File tree

8 files changed

+29
-22
lines changed

8 files changed

+29
-22
lines changed

apps/user_status/js/user-status-menu.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/user_status/js/user-status-menu.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/user_status/js/user-status-modal.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/user_status/js/user-status-modal.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/user_status/lib/Controller/StatusesController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ public function find(string $userId): DataResponse {
8787
}
8888

8989
/**
90-
* @NoAdminRequired
91-
*
9290
* @param UserStatus $status
93-
* @return array
91+
* @return array{userId: string, message: string, icon: string, clearAt: int, status: string}
9492
*/
9593
private function formatStatus(UserStatus $status): array {
9694
$visibleStatus = $status->getStatus();

apps/user_status/lib/Controller/UserStatusController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public function getStatus(): DataResponse {
9999
public function setStatus(string $statusType): DataResponse {
100100
try {
101101
$status = $this->service->setStatus($this->userId, $statusType, null, true);
102+
103+
$this->service->removeBackupUserStatus($this->userId);
102104
return new DataResponse($this->formatStatus($status));
103105
} catch (InvalidStatusTypeException $ex) {
104106
$this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid status type "' . $statusType . '"');
@@ -118,6 +120,7 @@ public function setPredefinedMessage(string $messageId,
118120
?int $clearAt): DataResponse {
119121
try {
120122
$status = $this->service->setPredefinedMessage($this->userId, $messageId, $clearAt);
123+
$this->service->removeBackupUserStatus($this->userId);
121124
return new DataResponse($this->formatStatus($status));
122125
} catch (InvalidClearAtException $ex) {
123126
$this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid clearAt value "' . $clearAt . '"');
@@ -147,6 +150,7 @@ public function setCustomMessage(?string $statusIcon,
147150
$this->service->clearMessage($this->userId);
148151
$status = $this->service->findByUserId($this->userId);
149152
}
153+
$this->service->removeBackupUserStatus($this->userId);
150154
return new DataResponse($this->formatStatus($status));
151155
} catch (InvalidClearAtException $ex) {
152156
$this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid clearAt value "' . $clearAt . '"');

apps/user_status/lib/Service/StatusService.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,21 @@ public function clearMessage(string $userId): bool {
346346
* @param string $userId
347347
* @return bool
348348
*/
349-
public function removeUserStatus(string $userId, bool $isBackup = false): bool {
349+
public function removeUserStatus(string $userId): bool {
350350
try {
351-
$userStatus = $this->mapper->findByUserId($userId, $isBackup);
351+
$userStatus = $this->mapper->findByUserId($userId, false);
352+
} catch (DoesNotExistException $ex) {
353+
// if there is no status to remove, just return
354+
return false;
355+
}
356+
357+
$this->mapper->delete($userStatus);
358+
return true;
359+
}
360+
361+
public function removeBackupUserStatus(string $userId): bool {
362+
try {
363+
$userStatus = $this->mapper->findByUserId($userId, true);
352364
} catch (DoesNotExistException $ex) {
353365
// if there is no status to remove, just return
354366
return false;
@@ -448,20 +460,12 @@ public function backupCurrentStatus(string $userId): bool {
448460
return true;
449461
}
450462

451-
public function revertUserStatus(string $userId, string $messageId, string $status): void {
463+
public function revertUserStatus(string $userId, ?string $messageId, string $status): void {
452464
try {
453465
/** @var UserStatus $userStatus */
454466
$backupUserStatus = $this->mapper->findByUserId($userId, true);
455467
} catch (DoesNotExistException $ex) {
456-
// No backup, just move back to available
457-
try {
458-
$userStatus = $this->mapper->findByUserId($userId);
459-
} catch (DoesNotExistException $ex) {
460-
// No backup nor current status => ignore
461-
return;
462-
}
463-
$this->cleanStatus($userStatus);
464-
$this->cleanStatusMessage($userStatus);
468+
// No user status to revert, do nothing
465469
return;
466470
}
467471
try {

apps/user_status/src/components/SetStatusModal.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export default {
101101
clearAt: null,
102102
icon: null,
103103
message: '',
104+
messageId: '',
104105
isSavingStatus: false,
105106
statuses: getAllStatusOptions(),
106107
}
@@ -191,7 +192,7 @@ export default {
191192
try {
192193
this.isSavingStatus = true
193194
194-
if (this.messageId !== null) {
195+
if (this.messageId !== undefined && this.messageId !== null) {
195196
await this.$store.dispatch('setPredefinedMessage', {
196197
messageId: this.messageId,
197198
clearAt: this.clearAt,

0 commit comments

Comments
 (0)