Skip to content

Commit a9c23e1

Browse files
Merge pull request #33315 from nextcloud/bugfix/33314/allow-reseting-status-only-with-message-id
Reset user status based on message ID only
2 parents 623d533 + 9a9db28 commit a9c23e1

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

apps/user_status/lib/Connector/UserStatusProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public function setUserStatus(string $userId, string $messageId, string $status,
6262
}
6363

6464
public function revertUserStatus(string $userId, string $messageId, string $status): void {
65-
$this->service->revertUserStatus($userId, $messageId, $status);
65+
$this->service->revertUserStatus($userId, $messageId);
6666
}
6767

6868
public function revertMultipleUserStatus(array $userIds, string $messageId, string $status): void {
69-
$this->service->revertMultipleUserStatus($userIds, $messageId, $status);
69+
$this->service->revertMultipleUserStatus($userIds, $messageId);
7070
}
7171
}

apps/user_status/lib/Db/UserStatusMapper.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,13 @@ public function clearOlderThanClearAt(int $timestamp): void {
160160
*
161161
* @param string $userId
162162
* @param string $messageId
163-
* @param string $status
164163
* @return bool True if an entry was deleted
165164
*/
166-
public function deleteCurrentStatusToRestoreBackup(string $userId, string $messageId, string $status): bool {
165+
public function deleteCurrentStatusToRestoreBackup(string $userId, string $messageId): bool {
167166
$qb = $this->db->getQueryBuilder();
168167
$qb->delete($this->tableName)
169168
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)))
170169
->andWhere($qb->expr()->eq('message_id', $qb->createNamedParameter($messageId)))
171-
->andWhere($qb->expr()->eq('status', $qb->createNamedParameter($status)))
172170
->andWhere($qb->expr()->eq('is_backup', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)));
173171
return $qb->executeStatement() > 0;
174172
}

apps/user_status/lib/Service/StatusService.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ public function backupCurrentStatus(string $userId): bool {
496496
}
497497
}
498498

499-
public function revertUserStatus(string $userId, string $messageId, string $status): void {
499+
public function revertUserStatus(string $userId, string $messageId): void {
500500
try {
501501
/** @var UserStatus $userStatus */
502502
$backupUserStatus = $this->mapper->findByUserId($userId, true);
@@ -505,7 +505,7 @@ public function revertUserStatus(string $userId, string $messageId, string $stat
505505
return;
506506
}
507507

508-
$deleted = $this->mapper->deleteCurrentStatusToRestoreBackup($userId, $messageId, $status);
508+
$deleted = $this->mapper->deleteCurrentStatusToRestoreBackup($userId, $messageId);
509509
if (!$deleted) {
510510
// Another status is set automatically or no status, do nothing
511511
return;
@@ -517,7 +517,7 @@ public function revertUserStatus(string $userId, string $messageId, string $stat
517517
$this->mapper->update($backupUserStatus);
518518
}
519519

520-
public function revertMultipleUserStatus(array $userIds, string $messageId, string $status): void {
520+
public function revertMultipleUserStatus(array $userIds, string $messageId): void {
521521
// Get all user statuses and the backups
522522
$findById = $userIds;
523523
foreach ($userIds as $userId) {
@@ -528,8 +528,7 @@ public function revertMultipleUserStatus(array $userIds, string $messageId, stri
528528
$backups = $restoreIds = $statuesToDelete = [];
529529
foreach ($userStatuses as $userStatus) {
530530
if (!$userStatus->getIsBackup()
531-
&& $userStatus->getMessageId() === $messageId
532-
&& $userStatus->getStatus() === $status) {
531+
&& $userStatus->getMessageId() === $messageId) {
533532
$statuesToDelete[$userStatus->getUserId()] = $userStatus->getId();
534533
} else if ($userStatus->getIsBackup()) {
535534
$backups[$userStatus->getUserId()] = $userStatus->getId();

apps/user_status/tests/Unit/Service/StatusServiceTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,24 +795,34 @@ public function testRevertMultipleUserStatus(): void {
795795
$backupOnly->setUserId('_backuponly');
796796
$backupOnly->setIsBackup(true);
797797

798+
$noBackupDND = new UserStatus();
799+
$noBackupDND->setId(5);
800+
$noBackupDND->setStatus(IUserStatus::DND);
801+
$noBackupDND->setStatusTimestamp(1337);
802+
$noBackupDND->setIsUserDefined(false);
803+
$noBackupDND->setMessageId('call');
804+
$noBackupDND->setUserId('nobackupanddnd');
805+
$noBackupDND->setIsBackup(false);
806+
798807
$this->mapper->expects($this->once())
799808
->method('findByUserIds')
800-
->with(['john', 'nobackup', 'backuponly', '_john', '_nobackup', '_backuponly'])
809+
->with(['john', 'nobackup', 'backuponly', 'nobackupanddnd', '_john', '_nobackup', '_backuponly', '_nobackupanddnd'])
801810
->willReturn([
802811
$john,
803812
$johnBackup,
804813
$noBackup,
805814
$backupOnly,
815+
$noBackupDND,
806816
]);
807817

808818
$this->mapper->expects($this->once())
809819
->method('deleteByIds')
810-
->with([1, 3]);
820+
->with([1, 3, 5]);
811821

812822
$this->mapper->expects($this->once())
813823
->method('restoreBackupStatuses')
814824
->with([2]);
815825

816-
$this->service->revertMultipleUserStatus(['john', 'nobackup', 'backuponly'], 'call', IUserStatus::AWAY);
826+
$this->service->revertMultipleUserStatus(['john', 'nobackup', 'backuponly', 'nobackupanddnd'], 'call');
817827
}
818828
}

0 commit comments

Comments
 (0)