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-06-29 15:34:53 +0300
committerJoas Schilling <coding@schilljs.com>2021-07-07 16:37:17 +0300
commit81922eef896b9a3b34e7ea68ac99f554760a6d93 (patch)
tree9a90c7b0131e7cebde7b87c2829f90f078ab385b /lib
parentd76631499a5764178d1fdad81d296fe3c967962a (diff)
Remove shares and fix the message markers
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Chat/ChatManager.php13
-rw-r--r--lib/Chat/Notifier.php12
-rw-r--r--lib/Chat/Parser/SystemMessage.php5
-rw-r--r--lib/Service/ParticipantService.php9
4 files changed, 33 insertions, 6 deletions
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php
index f0ff88fea..2b12079e3 100644
--- a/lib/Chat/ChatManager.php
+++ b/lib/Chat/ChatManager.php
@@ -32,6 +32,7 @@ use OCA\Talk\Model\Attendee;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
+use OCA\Talk\Share\RoomShareProvider;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
@@ -69,6 +70,8 @@ class ChatManager {
private $connection;
/** @var INotificationManager */
private $notificationManager;
+ /** @var RoomShareProvider */
+ private $shareProvider;
/** @var ParticipantService */
private $participantService;
/** @var Notifier */
@@ -84,6 +87,7 @@ class ChatManager {
IEventDispatcher $dispatcher,
IDBConnection $connection,
INotificationManager $notificationManager,
+ RoomShareProvider $shareProvider,
ParticipantService $participantService,
Notifier $notifier,
ICacheFactory $cacheFactory,
@@ -92,6 +96,7 @@ class ChatManager {
$this->dispatcher = $dispatcher;
$this->connection = $connection;
$this->notificationManager = $notificationManager;
+ $this->shareProvider = $shareProvider;
$this->participantService = $participantService;
$this->notifier = $notifier;
$this->cache = $cacheFactory->createDistributed('talk/lastmsgid');
@@ -282,7 +287,11 @@ class ChatManager {
public function clearHistory(Room $chat, string $actorType, string $actorId): IComment {
$this->commentsManager->deleteCommentsAtObject('chat', (string) $chat->getId());
- // TODO reset read markers so they don't error when being used as offset
+ $this->shareProvider->deleteInRoom($chat->getToken());
+
+ $this->notifier->removePendingNotificationsForRoom($chat, true);
+
+ $this->participantService->resetChatDetails($chat);
return $this->addSystemMessage(
$chat,
@@ -498,6 +507,8 @@ class ChatManager {
public function deleteMessages(Room $chat): void {
$this->commentsManager->deleteCommentsAtObject('chat', (string) $chat->getId());
+ $this->shareProvider->deleteInRoom($chat->getToken());
+
$this->notifier->removePendingNotificationsForRoom($chat);
}
diff --git a/lib/Chat/Notifier.php b/lib/Chat/Notifier.php
index 235ffe128..e3aa088be 100644
--- a/lib/Chat/Notifier.php
+++ b/lib/Chat/Notifier.php
@@ -197,7 +197,7 @@ class Notifier {
*
* @param Room $chat
*/
- public function removePendingNotificationsForRoom(Room $chat): void {
+ public function removePendingNotificationsForRoom(Room $chat, bool $chatOnly = false): void {
$notification = $this->notificationManager->createNotification();
$shouldFlush = $this->notificationManager->defer();
@@ -207,11 +207,13 @@ class Notifier {
$notification->setObject('chat', $chat->getToken());
$this->notificationManager->markProcessed($notification);
- $notification->setObject('room', $chat->getToken());
- $this->notificationManager->markProcessed($notification);
+ if ($chatOnly) {
+ $notification->setObject('room', $chat->getToken());
+ $this->notificationManager->markProcessed($notification);
- $notification->setObject('call', $chat->getToken());
- $this->notificationManager->markProcessed($notification);
+ $notification->setObject('call', $chat->getToken());
+ $this->notificationManager->markProcessed($notification);
+ }
if ($shouldFlush) {
$this->notificationManager->flush();
diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php
index 03cf8929f..031a4b943 100644
--- a/lib/Chat/Parser/SystemMessage.php
+++ b/lib/Chat/Parser/SystemMessage.php
@@ -402,6 +402,11 @@ class SystemMessage {
if ($currentUserIsActor) {
$parsedMessage = $this->l->t('You deleted a message');
}
+ } elseif ($message === 'cleared_history') {
+ $parsedMessage = $this->l->t('{actor} cleared the history of the conversation');
+ if ($currentUserIsActor) {
+ $parsedMessage = $this->l->t('You cleared the history of the conversation');
+ }
} else {
throw new \OutOfBoundsException('Unknown subject');
}
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php
index b5c18054d..0b69ab3ae 100644
--- a/lib/Service/ParticipantService.php
+++ b/lib/Service/ParticipantService.php
@@ -787,6 +787,15 @@ class ParticipantService {
$query->execute();
}
+ public function resetChatDetails(Room $room): void {
+ $query = $this->connection->getQueryBuilder();
+ $query->update('talk_attendees')
+ ->set('last_read_message', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
+ ->set('last_mention_message', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
+ ->where($query->expr()->eq('room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)));
+ $query->executeStatement();
+ }
+
public function updateReadPrivacyForActor(string $actorType, string $actorId, int $readPrivacy): void {
$query = $this->connection->getQueryBuilder();
$query->update('talk_attendees')