diff --git a/appinfo/info.xml b/appinfo/info.xml
index 102f0a528a..0872908f46 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -18,7 +18,7 @@
* 🌉 **Sync with other chat solutions** With [Matterbridge](https://github.com/42wim/matterbridge/) being integrated in Talk, you can easily sync a lot of other chat solutions to Nextcloud Talk and vice-versa.
]]>
- 22.0.0-dev.9
+ 22.0.0-dev.10
agpl
Anna Larch
diff --git a/lib/Migration/Version22000Date20250710124258.php b/lib/Migration/Version22000Date20250710124258.php
new file mode 100644
index 0000000000..c86b924f73
--- /dev/null
+++ b/lib/Migration/Version22000Date20250710124258.php
@@ -0,0 +1,50 @@
+getTable('talk_threads');
+ if (!$table->hasColumn('last_activity')) {
+ $table->addColumn('last_activity', Types::DATETIME, [
+ 'notnull' => false,
+ ]);
+ $table->addColumn('name', Types::STRING, [
+ 'notnull' => false,
+ 'length' => 255,
+ 'default' => '',
+ ]);
+
+ $table->addIndex(['last_activity'], 'talkthread_lastactive');
+ }
+
+ return $schema;
+ }
+}
diff --git a/lib/Model/Thread.php b/lib/Model/Thread.php
index 38b216d526..6795d2a3a8 100644
--- a/lib/Model/Thread.php
+++ b/lib/Model/Thread.php
@@ -20,6 +20,10 @@ use OCP\DB\Types;
* @method int getLastMessageId()
* @method void setNumReplies(int $numReplies)
* @method int getNumReplies()
+ * @method void setLastActivity(\DateTime $lastActivity)
+ * @method \DateTime|null getLastActivity()
+ * @method void setName(string $name)
+ * @method string getName()
*
* @psalm-import-type TalkThread from ResponseDefinitions
*/
@@ -27,11 +31,15 @@ class Thread extends Entity implements \JsonSerializable {
protected int $roomId = 0;
protected int $lastMessageId = 0;
protected int $numReplies = 0;
+ protected ?\DateTime $lastActivity = null;
+ protected string $name = '';
public function __construct() {
$this->addType('roomId', Types::BIGINT);
$this->addType('lastMessageId', Types::BIGINT);
$this->addType('numReplies', Types::BIGINT);
+ $this->addType('lastActivity', Types::DATETIME);
+ $this->addType('name', Types::STRING);
}
/**
@@ -41,9 +49,11 @@ class Thread extends Entity implements \JsonSerializable {
public function jsonSerialize(): array {
return [
'id' => max(1, $this->getId()),
- 'roomId' => max(1, $this->getRoomId()),
+ // 'roomId' => max(1, $this->getRoomId()),
'lastMessageId' => max(0, $this->getLastMessageId()),
'numReplies' => max(0, $this->getNumReplies()),
+ 'lastActivity' => max(0, $this->getLastActivity()?->getTimestamp() ?? 0),
+ // 'name' => $this->getName(),
];
}
}
diff --git a/lib/ResponseDefinitions.php b/lib/ResponseDefinitions.php
index cbb84530a6..200d1ee51d 100644
--- a/lib/ResponseDefinitions.php
+++ b/lib/ResponseDefinitions.php
@@ -449,8 +449,8 @@ namespace OCA\Talk;
*
* @psalm-type TalkThread = array{
* id: positive-int,
- * roomId: positive-int,
* lastMessageId: non-negative-int,
+ * lastActivity: non-negative-int,
* numReplies: non-negative-int,
* }
*
diff --git a/lib/Service/ThreadService.php b/lib/Service/ThreadService.php
index f385538685..e6b89dc933 100644
--- a/lib/Service/ThreadService.php
+++ b/lib/Service/ThreadService.php
@@ -16,6 +16,7 @@ use OCA\Talk\Model\ThreadAttendeeMapper;
use OCA\Talk\Model\ThreadMapper;
use OCA\Talk\Room;
use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
@@ -26,6 +27,7 @@ class ThreadService {
protected IDBConnection $connection,
protected ThreadMapper $threadMapper,
protected ThreadAttendeeMapper $threadAttendeeMapper,
+ protected ITimeFactory $timeFactory,
) {
}
@@ -37,6 +39,7 @@ class ThreadService {
$thread->setNumReplies($info['num_replies']);
$thread->setLastMessageId($info['last_message_id']);
$thread->setRoomId($room->getId());
+ $thread->setLastActivity($this->timeFactory->getDateTime());
try {
$this->threadMapper->insert($thread);
@@ -125,15 +128,19 @@ class ThreadService {
}
public function updateLastMessageInfoAfterReply(Thread $thread, int $lastMessageId): void {
+ $dateTime = $this->timeFactory->getDateTime();
+
$query = $this->connection->getQueryBuilder();
$query->update('talk_threads')
->set('num_replies', $query->func()->add('num_replies', $query->expr()->literal(1)))
->set('last_message_id', $query->createNamedParameter($lastMessageId))
+ ->set('last_activity', $query->createNamedParameter($dateTime, IQueryBuilder::PARAM_DATETIME_MUTABLE))
->where($query->expr()->eq('id', $query->createNamedParameter($thread->getId())));
$query->executeStatement();
$thread->setNumReplies($thread->getNumReplies() + 1);
$thread->setLastMessageId($lastMessageId);
+ $thread->setLastActivity($dateTime);
}
/**