Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-09-01 18:28:19 +0300
committerJoas Schilling <coding@schilljs.com>2021-09-20 13:51:19 +0300
commitbf6150be9549813459f26a92cfafaa114331cebe (patch)
tree68ec559bba93f0198cfc79fdb19111ab435f268d /lib
parent9aff2302dfc1f94c607e0296ca14a620c2758cdb (diff)
Add a counter for the direct mentions
This allows the UI can show the user bubble depending on user vs. all mentions Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Capabilities.php1
-rw-r--r--lib/Chat/ChatManager.php6
-rw-r--r--lib/Chat/Notifier.php2
-rw-r--r--lib/Controller/RoomController.php3
-rw-r--r--lib/Migration/Version13000Date20210901164235.php55
-rw-r--r--lib/Model/Attendee.php7
-rw-r--r--lib/Model/AttendeeMapper.php1
-rw-r--r--lib/Model/SelectHelper.php1
-rw-r--r--lib/Service/ParticipantService.php13
9 files changed, 86 insertions, 3 deletions
diff --git a/lib/Capabilities.php b/lib/Capabilities.php
index 0af64cee3..769dcd004 100644
--- a/lib/Capabilities.php
+++ b/lib/Capabilities.php
@@ -95,6 +95,7 @@ class Capabilities implements IPublicCapability {
'signaling-v3',
'publishing-permissions',
'clear-history',
+ 'direct-mention-flag',
],
'config' => [
'attachments' => [
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php
index 627af40fa..7cca61fc5 100644
--- a/lib/Chat/ChatManager.php
+++ b/lib/Chat/ChatManager.php
@@ -239,13 +239,17 @@ class ChatManager {
}
$alreadyNotifiedUsers = [];
+ $usersDirectlyMentioned = $this->notifier->getMentionedUserIds($comment);
if ($replyTo instanceof IComment) {
$alreadyNotifiedUsers = $this->notifier->notifyReplyToAuthor($chat, $comment, $replyTo);
+ if ($replyTo->getActorType() === Attendee::ACTOR_USERS) {
+ $usersDirectlyMentioned[] = $replyTo->getActorId();
+ }
}
$alreadyNotifiedUsers = $this->notifier->notifyMentionedUsers($chat, $comment, $alreadyNotifiedUsers);
if (!empty($alreadyNotifiedUsers)) {
- $this->participantService->markUsersAsMentioned($chat, $alreadyNotifiedUsers, (int) $comment->getId());
+ $this->participantService->markUsersAsMentioned($chat, $alreadyNotifiedUsers, (int) $comment->getId(), $usersDirectlyMentioned);
}
// User was not mentioned, send a normal notification
diff --git a/lib/Chat/Notifier.php b/lib/Chat/Notifier.php
index c881d5b88..b5e5ddd35 100644
--- a/lib/Chat/Notifier.php
+++ b/lib/Chat/Notifier.php
@@ -251,7 +251,7 @@ class Notifier {
* @param IComment $comment
* @return string[] the mentioned user IDs
*/
- private function getMentionedUserIds(IComment $comment): array {
+ public function getMentionedUserIds(IComment $comment): array {
$mentions = $comment->getMentions();
if (empty($mentions)) {
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index 0a8d8487a..b63c0b7c2 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -383,6 +383,7 @@ class RoomController extends AEnvironmentAwareController {
'lastReadMessage' => 0,
'unreadMessages' => 0,
'unreadMention' => false,
+ 'unreadMentionDirect' => false,
'isFavorite' => false,
'canLeaveConversation' => false,
'canDeleteConversation' => false,
@@ -540,7 +541,9 @@ class RoomController extends AEnvironmentAwareController {
}
$lastMention = $attendee->getLastMentionMessage();
+ $lastMentionDirect = $attendee->getLastMentionDirect();
$roomData['unreadMention'] = $lastMention !== 0 && $lastReadMessage < $lastMention;
+ $roomData['unreadMentionDirect'] = $lastMentionDirect !== 0 && $lastReadMessage < $lastMentionDirect;
$roomData['lastReadMessage'] = $lastReadMessage;
$roomData['canDeleteConversation'] = $room->getType() !== Room::ONE_TO_ONE_CALL
diff --git a/lib/Migration/Version13000Date20210901164235.php b/lib/Migration/Version13000Date20210901164235.php
new file mode 100644
index 000000000..ad2121273
--- /dev/null
+++ b/lib/Migration/Version13000Date20210901164235.php
@@ -0,0 +1,55 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2021, Joas Schilling <coding@schilljs.com>
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ *
+ * @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\Talk\Migration;
+
+use Closure;
+use Doctrine\DBAL\Types\Types;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+class Version13000Date20210901164235 extends SimpleMigrationStep {
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ * @return null|ISchemaWrapper
+ */
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ $table = $schema->getTable('talk_attendees');
+ if (!$table->hasColumn('last_mention_direct')) {
+ $table->addColumn('last_mention_direct', Types::BIGINT, [
+ 'default' => 0,
+ ]);
+ return $schema;
+ }
+
+ return null;
+ }
+}
diff --git a/lib/Model/Attendee.php b/lib/Model/Attendee.php
index e0de04da1..c98f36ae2 100644
--- a/lib/Model/Attendee.php
+++ b/lib/Model/Attendee.php
@@ -47,6 +47,8 @@ use OCP\AppFramework\Db\Entity;
* @method int getLastReadMessage()
* @method void setLastMentionMessage(int $lastMentionMessage)
* @method int getLastMentionMessage()
+ * @method void setLastMentionDirect(int $lastMentionDirect)
+ * @method int getLastMentionDirect()
* @method void setReadPrivacy(int $readPrivacy)
* @method int getReadPrivacy()
* @method void setPublishingPermissions(int $publishingPermissions)
@@ -105,6 +107,9 @@ class Attendee extends Entity {
protected $lastMentionMessage;
/** @var int */
+ protected $lastMentionDirect;
+
+ /** @var int */
protected $readPrivacy;
/** @var int */
@@ -128,6 +133,7 @@ class Attendee extends Entity {
$this->addType('lastJoinedCall', 'int');
$this->addType('lastReadMessage', 'int');
$this->addType('lastMentionMessage', 'int');
+ $this->addType('lastMentionDirect', 'int');
$this->addType('readPrivacy', 'int');
$this->addType('publishingPermissions', 'int');
$this->addType('accessToken', 'string');
@@ -155,6 +161,7 @@ class Attendee extends Entity {
'last_joined_call' => $this->getLastJoinedCall(),
'last_read_message' => $this->getLastReadMessage(),
'last_mention_message' => $this->getLastMentionMessage(),
+ 'last_mention_direct' => $this->getLastMentionDirect(),
'read_privacy' => $this->getReadPrivacy(),
'publishing_permissions' => $this->getPublishingPermissions(),
'access_token' => $this->getAccessToken(),
diff --git a/lib/Model/AttendeeMapper.php b/lib/Model/AttendeeMapper.php
index 1c689805b..261b949b0 100644
--- a/lib/Model/AttendeeMapper.php
+++ b/lib/Model/AttendeeMapper.php
@@ -174,6 +174,7 @@ class AttendeeMapper extends QBMapper {
'last_joined_call' => (int) $row['last_joined_call'],
'last_read_message' => (int) $row['last_read_message'],
'last_mention_message' => (int) $row['last_mention_message'],
+ 'last_mention_direct' => (int) $row['last_mention_direct'],
'read_privacy' => (int) $row['read_privacy'],
'publishing_permissions' => (int) $row['publishing_permissions'],
'access_token' => (string) $row['access_token'],
diff --git a/lib/Model/SelectHelper.php b/lib/Model/SelectHelper.php
index 0ba06d2ad..a42097f6e 100644
--- a/lib/Model/SelectHelper.php
+++ b/lib/Model/SelectHelper.php
@@ -69,6 +69,7 @@ class SelectHelper {
->addSelect($alias . 'last_joined_call')
->addSelect($alias . 'last_read_message')
->addSelect($alias . 'last_mention_message')
+ ->addSelect($alias . 'last_mention_direct')
->addSelect($alias . 'read_privacy')
->addSelect($alias . 'publishing_permissions')
->addSelect($alias . 'access_token')
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php
index 03d7f927a..16d29f2cf 100644
--- a/lib/Service/ParticipantService.php
+++ b/lib/Service/ParticipantService.php
@@ -870,7 +870,7 @@ class ParticipantService {
$this->dispatcher->dispatch(Room::EVENT_AFTER_SESSION_UPDATE_CALL_FLAGS, $event);
}
- public function markUsersAsMentioned(Room $room, array $userIds, int $messageId): void {
+ public function markUsersAsMentioned(Room $room, array $userIds, int $messageId, array $usersDirectlyMentioned): void {
$query = $this->connection->getQueryBuilder();
$query->update('talk_attendees')
->set('last_mention_message', $query->createNamedParameter($messageId, IQueryBuilder::PARAM_INT))
@@ -878,6 +878,16 @@ class ParticipantService {
->andWhere($query->expr()->eq('actor_type', $query->createNamedParameter(Attendee::ACTOR_USERS)))
->andWhere($query->expr()->in('actor_id', $query->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY)));
$query->execute();
+
+ if (!empty($usersDirectlyMentioned)) {
+ $query = $this->connection->getQueryBuilder();
+ $query->update('talk_attendees')
+ ->set('last_mention_direct', $query->createNamedParameter($messageId, IQueryBuilder::PARAM_INT))
+ ->where($query->expr()->eq('room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)))
+ ->andWhere($query->expr()->eq('actor_type', $query->createNamedParameter(Attendee::ACTOR_USERS)))
+ ->andWhere($query->expr()->in('actor_id', $query->createNamedParameter($usersDirectlyMentioned, IQueryBuilder::PARAM_STR_ARRAY)));
+ $query->execute();
+ }
}
public function resetChatDetails(Room $room): void {
@@ -885,6 +895,7 @@ class ParticipantService {
$query->update('talk_attendees')
->set('last_read_message', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
->set('last_mention_message', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
+ ->set('last_mention_direct', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)));
$query->executeStatement();
}