aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_status/lib
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2023-09-21 17:05:06 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2023-09-29 09:55:19 +0200
commitfbdf733be0df1bf00f8903a98ccabdf519db55d2 (patch)
treed0e4fdeaa14319452d1d24938fb5c355dd30e82e /apps/user_status/lib
parentf8f437072ac13a4556dea18219d55f11466497e5 (diff)
downloadnextcloud-server-fbdf733be0df1bf00f8903a98ccabdf519db55d2.tar.gz
nextcloud-server-fbdf733be0df1bf00f8903a98ccabdf519db55d2.zip
fix(userstatus): Track message timestamp too
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/user_status/lib')
-rw-r--r--apps/user_status/lib/Dashboard/UserStatusWidget.php2
-rw-r--r--apps/user_status/lib/Db/UserStatus.php6
-rw-r--r--apps/user_status/lib/Db/UserStatusMapper.php3
-rw-r--r--apps/user_status/lib/Migration/Version1008Date20230921144701.php67
-rw-r--r--apps/user_status/lib/Service/StatusService.php6
5 files changed, 82 insertions, 2 deletions
diff --git a/apps/user_status/lib/Dashboard/UserStatusWidget.php b/apps/user_status/lib/Dashboard/UserStatusWidget.php
index 89b9c05f805..6c0dd356730 100644
--- a/apps/user_status/lib/Dashboard/UserStatusWidget.php
+++ b/apps/user_status/lib/Dashboard/UserStatusWidget.php
@@ -165,7 +165,7 @@ class UserStatusWidget implements IAPIWidget, IAPIWidgetV2, IIconWidget, IOption
: $status->getStatus(),
'icon' => $status->getCustomIcon(),
'message' => $status->getCustomMessage(),
- 'timestamp' => $status->getStatusTimestamp(),
+ 'timestamp' => $status->getStatusMessageTimestamp(),
];
}, $recentStatusUpdates);
}
diff --git a/apps/user_status/lib/Db/UserStatus.php b/apps/user_status/lib/Db/UserStatus.php
index d4e24e75597..92b3df740c2 100644
--- a/apps/user_status/lib/Db/UserStatus.php
+++ b/apps/user_status/lib/Db/UserStatus.php
@@ -52,6 +52,8 @@ use OCP\AppFramework\Db\Entity;
* @method void setClearAt(int|null $clearAt)
* @method setIsBackup(bool $true): void
* @method getIsBackup(): bool
+ * @method int getStatusMessageTimestamp()
+ * @method void setStatusMessageTimestamp(int $statusTimestamp)
*/
class UserStatus extends Entity {
@@ -82,6 +84,9 @@ class UserStatus extends Entity {
/** @var bool $isBackup */
public $isBackup;
+ /** @var int */
+ protected $statusMessageTimestamp = 0;
+
public function __construct() {
$this->addType('userId', 'string');
$this->addType('status', 'string');
@@ -92,5 +97,6 @@ class UserStatus extends Entity {
$this->addType('customMessage', 'string');
$this->addType('clearAt', 'int');
$this->addType('isBackup', 'boolean');
+ $this->addType('statusMessageTimestamp', 'int');
}
}
diff --git a/apps/user_status/lib/Db/UserStatusMapper.php b/apps/user_status/lib/Db/UserStatusMapper.php
index d40c6a29860..3621c1bfa96 100644
--- a/apps/user_status/lib/Db/UserStatusMapper.php
+++ b/apps/user_status/lib/Db/UserStatusMapper.php
@@ -75,8 +75,9 @@ class UserStatusMapper extends QBMapper {
$qb
->select('*')
->from($this->tableName)
- ->orderBy('status_timestamp', 'DESC')
+ ->orderBy('status_message_timestamp', 'DESC')
->where($qb->expr()->andX(
+ $qb->expr()->neq('status_message_timestamp', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT),
$qb->expr()->orX(
$qb->expr()->notIn('status', $qb->createNamedParameter([IUserStatus::ONLINE, IUserStatus::AWAY, IUserStatus::OFFLINE], IQueryBuilder::PARAM_STR_ARRAY)),
$qb->expr()->isNotNull('message_id'),
diff --git a/apps/user_status/lib/Migration/Version1008Date20230921144701.php b/apps/user_status/lib/Migration/Version1008Date20230921144701.php
new file mode 100644
index 00000000000..3b653f68eeb
--- /dev/null
+++ b/apps/user_status/lib/Migration/Version1008Date20230921144701.php
@@ -0,0 +1,67 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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();
+ }
+}
diff --git a/apps/user_status/lib/Service/StatusService.php b/apps/user_status/lib/Service/StatusService.php
index b5dd3cd361a..f9ae769a5a9 100644
--- a/apps/user_status/lib/Service/StatusService.php
+++ b/apps/user_status/lib/Service/StatusService.php
@@ -237,6 +237,7 @@ class StatusService {
$userStatus->setCustomIcon(null);
$userStatus->setCustomMessage(null);
$userStatus->setClearAt($clearAt);
+ $userStatus->setStatusMessageTimestamp($this->timeFactory->now()->getTimestamp());
if ($userStatus->getId() === null) {
return $this->mapper->insert($userStatus);
@@ -291,6 +292,7 @@ class StatusService {
$userStatus->setCustomIcon(null);
$userStatus->setCustomMessage(null);
$userStatus->setClearAt(null);
+ $userStatus->setStatusMessageTimestamp($this->timeFactory->now()->getTimestamp());
if ($userStatus->getId() !== null) {
$this->mapper->update($userStatus);
@@ -340,6 +342,7 @@ class StatusService {
$userStatus->setCustomIcon($statusIcon);
$userStatus->setCustomMessage($message);
$userStatus->setClearAt($clearAt);
+ $userStatus->setStatusMessageTimestamp($this->timeFactory->now()->getTimestamp());
if ($userStatus->getId() === null) {
return $this->mapper->insert($userStatus);
@@ -384,6 +387,7 @@ class StatusService {
$userStatus->setCustomMessage(null);
$userStatus->setCustomIcon(null);
$userStatus->setClearAt(null);
+ $userStatus->setStatusMessageTimestamp(0);
$this->mapper->update($userStatus);
return true;
@@ -465,6 +469,7 @@ class StatusService {
$status->setCustomIcon(null);
$status->setCustomMessage(null);
$status->setClearAt(null);
+ $status->setStatusMessageTimestamp(0);
$this->mapper->update($status);
}
@@ -478,6 +483,7 @@ class StatusService {
if ($predefinedMessage !== null) {
$status->setCustomMessage($predefinedMessage['message']);
$status->setCustomIcon($predefinedMessage['icon']);
+ $status->setStatusMessageTimestamp($this->timeFactory->now()->getTimestamp());
}
}