-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40564 from nextcloud/fix/userstatus/message-times…
…tamp fix(userstatus): Track message timestamp too
- Loading branch information
Showing
10 changed files
with
221 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
<name>User status</name> | ||
<summary>User status</summary> | ||
<description><![CDATA[User status]]></description> | ||
<version>1.8.0</version> | ||
<version>1.8.1</version> | ||
<licence>agpl</licence> | ||
<author mail="[email protected]" >Georg Ehrke</author> | ||
<namespace>UserStatus</namespace> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
apps/user_status/lib/Migration/Version1008Date20230921144701.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @author Christoph Wurst <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\UserStatus\Migration; | ||
|
||
use Closure; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\DB\Types; | ||
use OCP\IDBConnection; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
class Version1008Date20230921144701 extends SimpleMigrationStep { | ||
|
||
public function __construct(private IDBConnection $connection) { | ||
} | ||
|
||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
|
||
$statusTable = $schema->getTable('user_status'); | ||
if (!($statusTable->hasColumn('status_message_timestamp'))) { | ||
$statusTable->addColumn('status_message_timestamp', Types::INTEGER, [ | ||
'notnull' => true, | ||
'length' => 11, | ||
'unsigned' => true, | ||
'default' => 0, | ||
]); | ||
} | ||
if (!$statusTable->hasIndex('user_status_mtstmp_ix')) { | ||
$statusTable->addIndex(['status_message_timestamp'], 'user_status_mtstmp_ix'); | ||
} | ||
|
||
return $schema; | ||
} | ||
|
||
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { | ||
$qb = $this->connection->getQueryBuilder(); | ||
|
||
$update = $qb->update('user_status') | ||
->set('status_message_timestamp', 'status_timestamp'); | ||
|
||
$update->executeStatement(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @copyright 2023 Christoph Wurst <[email protected]> | ||
* | ||
* @author 2023 Christoph Wurst <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace OCA\UserStatus\Tests\Integration\BackgroundJob; | ||
|
||
use OCA\UserStatus\Service\StatusService; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use OCP\IDBConnection; | ||
use OCP\Server; | ||
use OCP\UserStatus\IUserStatus; | ||
use Test\TestCase; | ||
use function sleep; | ||
use function time; | ||
|
||
/** | ||
* @group DB | ||
*/ | ||
class StatusServiceIntegrationTest extends TestCase { | ||
|
||
private StatusService $service; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->service = Server::get(StatusService::class); | ||
|
||
$db = Server::get(IDBConnection::class); | ||
$qb = $db->getQueryBuilder(); | ||
$qb->delete('user_status')->executeStatement(); | ||
} | ||
|
||
public function testNoStatusYet(): void { | ||
$this->expectException(DoesNotExistException::class); | ||
|
||
$this->service->findByUserId('test123'); | ||
} | ||
|
||
public function testCustomStatusMessageTimestamp(): void { | ||
$this->service->setCustomMessage( | ||
'test123', | ||
'🍕', | ||
'Lunch', | ||
null, | ||
); | ||
|
||
$status = $this->service->findByUserId('test123'); | ||
|
||
self::assertSame('Lunch', $status->getCustomMessage()); | ||
self::assertGreaterThanOrEqual(time(), $status->getStatusMessageTimestamp()); | ||
} | ||
|
||
public function testOnlineStatusKeepsMessageTimestamp(): void { | ||
$this->service->setStatus( | ||
'test123', | ||
IUserStatus::OFFLINE, | ||
time() + 1000, | ||
false, | ||
); | ||
$this->service->setCustomMessage( | ||
'test123', | ||
'🍕', | ||
'Lunch', | ||
null, | ||
); | ||
$timeAfterInsert = time(); | ||
sleep(1); | ||
$this->service->setStatus( | ||
'test123', | ||
IUserStatus::ONLINE, | ||
time() + 2000, | ||
false, | ||
); | ||
$status = $this->service->findByUserId('test123'); | ||
|
||
self::assertSame('Lunch', $status->getCustomMessage()); | ||
self::assertLessThanOrEqual($timeAfterInsert, $status->getStatusMessageTimestamp()); | ||
} | ||
|
||
public function testCreateRestoreBackupAutomatically(): void { | ||
$this->service->setStatus( | ||
'test123', | ||
IUserStatus::ONLINE, | ||
null, | ||
false, | ||
); | ||
$this->service->setUserStatus( | ||
'test123', | ||
IUserStatus::DND, | ||
'meeting', | ||
true, | ||
); | ||
self::assertSame( | ||
'meeting', | ||
$this->service->findByUserId('test123')->getMessageId(), | ||
); | ||
|
||
$this->service->revertUserStatus( | ||
'test123', | ||
'meeting', | ||
); | ||
self::assertSame( | ||
IUserStatus::ONLINE, | ||
$this->service->findByUserId('test123')->getStatus(), | ||
); | ||
} | ||
|
||
public function testCi(): void { | ||
// TODO: remove if CI turns red | ||
self::assertTrue(false); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters