Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2022-07-26 23:49:31 +0300
committerGitHub <noreply@github.com>2022-07-26 23:49:31 +0300
commit19a52f45073fdc59b2eef49be6a393d90cc9ee38 (patch)
tree512215f6942ce9c1abe6cb36f77d16ee84d6a101 /apps
parent5f743c3c1d5b01e419db816e87ce72dbc86e9c80 (diff)
parentda14fde621c5e5e2cf4fd150ad65727824cbf32c (diff)
Merge pull request #33350 from nextcloud/backport/33315/stable24
[stable24] Reset user status based on message ID only
Diffstat (limited to 'apps')
-rw-r--r--apps/user_status/lib/Connector/UserStatusProvider.php4
-rw-r--r--apps/user_status/lib/Db/UserStatusMapper.php4
-rw-r--r--apps/user_status/lib/Service/StatusService.php9
-rw-r--r--apps/user_status/tests/Unit/Service/StatusServiceTest.php16
4 files changed, 20 insertions, 13 deletions
diff --git a/apps/user_status/lib/Connector/UserStatusProvider.php b/apps/user_status/lib/Connector/UserStatusProvider.php
index 46b89739f7c..cc674c9967e 100644
--- a/apps/user_status/lib/Connector/UserStatusProvider.php
+++ b/apps/user_status/lib/Connector/UserStatusProvider.php
@@ -62,10 +62,10 @@ class UserStatusProvider implements IProvider, ISettableProvider {
}
public function revertUserStatus(string $userId, string $messageId, string $status): void {
- $this->service->revertUserStatus($userId, $messageId, $status);
+ $this->service->revertUserStatus($userId, $messageId);
}
public function revertMultipleUserStatus(array $userIds, string $messageId, string $status): void {
- $this->service->revertMultipleUserStatus($userIds, $messageId, $status);
+ $this->service->revertMultipleUserStatus($userIds, $messageId);
}
}
diff --git a/apps/user_status/lib/Db/UserStatusMapper.php b/apps/user_status/lib/Db/UserStatusMapper.php
index f67cfcd472d..790179367e5 100644
--- a/apps/user_status/lib/Db/UserStatusMapper.php
+++ b/apps/user_status/lib/Db/UserStatusMapper.php
@@ -164,15 +164,13 @@ class UserStatusMapper extends QBMapper {
*
* @param string $userId
* @param string $messageId
- * @param string $status
* @return bool True if an entry was deleted
*/
- public function deleteCurrentStatusToRestoreBackup(string $userId, string $messageId, string $status): bool {
+ public function deleteCurrentStatusToRestoreBackup(string $userId, string $messageId): bool {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)))
->andWhere($qb->expr()->eq('message_id', $qb->createNamedParameter($messageId)))
- ->andWhere($qb->expr()->eq('status', $qb->createNamedParameter($status)))
->andWhere($qb->expr()->eq('is_backup', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)));
return $qb->executeStatement() > 0;
}
diff --git a/apps/user_status/lib/Service/StatusService.php b/apps/user_status/lib/Service/StatusService.php
index 5dd70e4ea5e..71987227d11 100644
--- a/apps/user_status/lib/Service/StatusService.php
+++ b/apps/user_status/lib/Service/StatusService.php
@@ -505,7 +505,7 @@ class StatusService {
}
}
- public function revertUserStatus(string $userId, string $messageId, string $status): void {
+ public function revertUserStatus(string $userId, string $messageId): void {
try {
/** @var UserStatus $userStatus */
$backupUserStatus = $this->mapper->findByUserId($userId, true);
@@ -514,7 +514,7 @@ class StatusService {
return;
}
- $deleted = $this->mapper->deleteCurrentStatusToRestoreBackup($userId, $messageId, $status);
+ $deleted = $this->mapper->deleteCurrentStatusToRestoreBackup($userId, $messageId);
if (!$deleted) {
// Another status is set automatically or no status, do nothing
return;
@@ -526,7 +526,7 @@ class StatusService {
$this->mapper->update($backupUserStatus);
}
- public function revertMultipleUserStatus(array $userIds, string $messageId, string $status): void {
+ public function revertMultipleUserStatus(array $userIds, string $messageId): void {
// Get all user statuses and the backups
$findById = $userIds;
foreach ($userIds as $userId) {
@@ -537,8 +537,7 @@ class StatusService {
$backups = $restoreIds = $statuesToDelete = [];
foreach ($userStatuses as $userStatus) {
if (!$userStatus->getIsBackup()
- && $userStatus->getMessageId() === $messageId
- && $userStatus->getStatus() === $status) {
+ && $userStatus->getMessageId() === $messageId) {
$statuesToDelete[$userStatus->getUserId()] = $userStatus->getId();
} else if ($userStatus->getIsBackup()) {
$backups[$userStatus->getUserId()] = $userStatus->getId();
diff --git a/apps/user_status/tests/Unit/Service/StatusServiceTest.php b/apps/user_status/tests/Unit/Service/StatusServiceTest.php
index 3dd397e1d36..eba7f9c0819 100644
--- a/apps/user_status/tests/Unit/Service/StatusServiceTest.php
+++ b/apps/user_status/tests/Unit/Service/StatusServiceTest.php
@@ -795,24 +795,34 @@ class StatusServiceTest extends TestCase {
$backupOnly->setUserId('_backuponly');
$backupOnly->setIsBackup(true);
+ $noBackupDND = new UserStatus();
+ $noBackupDND->setId(5);
+ $noBackupDND->setStatus(IUserStatus::DND);
+ $noBackupDND->setStatusTimestamp(1337);
+ $noBackupDND->setIsUserDefined(false);
+ $noBackupDND->setMessageId('call');
+ $noBackupDND->setUserId('nobackupanddnd');
+ $noBackupDND->setIsBackup(false);
+
$this->mapper->expects($this->once())
->method('findByUserIds')
- ->with(['john', 'nobackup', 'backuponly', '_john', '_nobackup', '_backuponly'])
+ ->with(['john', 'nobackup', 'backuponly', 'nobackupanddnd', '_john', '_nobackup', '_backuponly', '_nobackupanddnd'])
->willReturn([
$john,
$johnBackup,
$noBackup,
$backupOnly,
+ $noBackupDND,
]);
$this->mapper->expects($this->once())
->method('deleteByIds')
- ->with([1, 3]);
+ ->with([1, 3, 5]);
$this->mapper->expects($this->once())
->method('restoreBackupStatuses')
->with([2]);
- $this->service->revertMultipleUserStatus(['john', 'nobackup', 'backuponly'], 'call', IUserStatus::AWAY);
+ $this->service->revertMultipleUserStatus(['john', 'nobackup', 'backuponly', 'nobackupanddnd'], 'call');
}
}