Skip to content
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
1 change: 1 addition & 0 deletions apps/user_status/lib/Db/UserStatusMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function clearStatusesOlderThan(int $olderThan, int $now): void {
->set('is_user_defined', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))
->set('status_timestamp', $qb->createNamedParameter($now, IQueryBuilder::PARAM_INT))
->where($qb->expr()->lte('status_timestamp', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->neq('status', $qb->createNamedParameter(IUserStatus::OFFLINE)))
->andWhere($qb->expr()->orX(
$qb->expr()->eq('is_user_defined', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL), IQueryBuilder::PARAM_BOOL),
$qb->expr()->eq('status', $qb->createNamedParameter(IUserStatus::ONLINE))
Expand Down
4 changes: 4 additions & 0 deletions apps/user_status/lib/Service/StatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ private function processStatus(UserStatus $status): UserStatus {
* @param UserStatus $status
*/
private function cleanStatus(UserStatus $status): void {
if ($status->getStatus() === IUserStatus::OFFLINE && !$status->getIsUserDefined()) {
return;
}

$status->setStatus(IUserStatus::OFFLINE);
$status->setStatusTimestamp($this->timeFactory->getTime());
$status->setIsUserDefined(false);
Expand Down
1 change: 1 addition & 0 deletions apps/user_status/tests/Unit/Db/UserStatusMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function testClearStatusesOlderThan(string $status, bool $isUserDefined,

public function clearStatusesOlderThanDataProvider(): array {
return [
['offline', false, 6000, false],
['online', true, 6000, false],
['online', true, 4000, true],
['online', false, 6000, false],
Expand Down
41 changes: 41 additions & 0 deletions apps/user_status/tests/Unit/Service/StatusServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCA\UserStatus\Service\StatusService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\UserStatus\IUserStatus;
use Test\TestCase;

class StatusServiceTest extends TestCase {
Expand Down Expand Up @@ -623,4 +624,44 @@ public function testRemoveUserStatusDoesNotExist(): void {
$actual = $this->service->removeUserStatus('john.doe');
$this->assertFalse($actual);
}

public function testCleanStatusAutomaticOnline(): void {
$status = new UserStatus();
$status->setStatus(IUserStatus::ONLINE);
$status->setStatusTimestamp(1337);
$status->setIsUserDefined(false);

$this->mapper->expects(self::once())
->method('update')
->with($status);

parent::invokePrivate($this->service, 'cleanStatus', [$status]);
}

public function testCleanStatusCustomOffline(): void {
$status = new UserStatus();
$status->setStatus(IUserStatus::OFFLINE);
$status->setStatusTimestamp(1337);
$status->setIsUserDefined(true);

$this->mapper->expects(self::once())
->method('update')
->with($status);

parent::invokePrivate($this->service, 'cleanStatus', [$status]);
}

public function testCleanStatusCleanedAlready(): void {
$status = new UserStatus();
$status->setStatus(IUserStatus::OFFLINE);
$status->setStatusTimestamp(1337);
$status->setIsUserDefined(false);

// Don't update the status again and again when no value changed
$this->mapper->expects(self::never())
->method('update')
->with($status);

parent::invokePrivate($this->service, 'cleanStatus', [$status]);
}
}