Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable24] Reset user status based on message ID only #33350

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/user_status/lib/Connector/UserStatusProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public function setUserStatus(string $userId, string $messageId, string $status,
}

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);
}
}
4 changes: 1 addition & 3 deletions apps/user_status/lib/Db/UserStatusMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,13 @@ public function clearMessagesOlderThan(int $timestamp): void {
*
* @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;
}
Expand Down
9 changes: 4 additions & 5 deletions apps/user_status/lib/Service/StatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public function backupCurrentStatus(string $userId): bool {
}
}

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);
Expand All @@ -514,7 +514,7 @@ public function revertUserStatus(string $userId, string $messageId, string $stat
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;
Expand All @@ -526,7 +526,7 @@ public function revertUserStatus(string $userId, string $messageId, string $stat
$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) {
Expand All @@ -537,8 +537,7 @@ public function revertMultipleUserStatus(array $userIds, string $messageId, stri
$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();
Expand Down
16 changes: 13 additions & 3 deletions apps/user_status/tests/Unit/Service/StatusServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,24 +795,34 @@ public function testRevertMultipleUserStatus(): void {
$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');
}
}