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
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-12-08 16:46:54 +0300
committerJoas Schilling <coding@schilljs.com>2020-12-10 13:47:04 +0300
commitbc716c7199a1ed315e63d84e3f5f4501800af68b (patch)
treee4669f0343be5b4e0972717cf5726c4d0e17a63d /lib/Controller
parent6eefd9c3fae1d66d3a277f0b1e3d2a8e3a02418c (diff)
Add the last common read message id as header on chat requests and to the conversation list
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Controller')
-rw-r--r--lib/Controller/ChatController.php28
-rw-r--r--lib/Controller/RoomController.php20
2 files changed, 43 insertions, 5 deletions
diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php
index 6e97a747b..fd3cd0458 100644
--- a/lib/Controller/ChatController.php
+++ b/lib/Controller/ChatController.php
@@ -218,7 +218,11 @@ class ChatController extends AEnvironmentAwareController {
$this->messageParser->parseMessage($chatMessage);
if (!$chatMessage->getVisibility()) {
- return new DataResponse([], Http::STATUS_CREATED);
+ $response = new DataResponse([], Http::STATUS_CREATED);
+ if ($this->participant->getAttendee()->getReadPrivacy() === Participant::PRIVACY_PUBLIC) {
+ $response->addHeader('X-Chat-Last-Common-Read', $this->chatManager->getLastCommonReadMessage($this->room));
+ }
+ return $response;
}
$this->participantService->updateLastReadMessage($this->participant, (int) $comment->getId());
@@ -227,7 +231,12 @@ class ChatController extends AEnvironmentAwareController {
if ($parentMessage instanceof Message) {
$data['parent'] = $parentMessage->toArray();
}
- return new DataResponse($data, Http::STATUS_CREATED);
+
+ $response = new DataResponse($data, Http::STATUS_CREATED);
+ if ($this->participant->getAttendee()->getReadPrivacy() === Participant::PRIVACY_PUBLIC) {
+ $response->addHeader('X-Chat-Last-Common-Read', $this->chatManager->getLastCommonReadMessage($this->room));
+ }
+ return $response;
}
/**
@@ -333,7 +342,11 @@ class ChatController extends AEnvironmentAwareController {
}
if (empty($comments)) {
- return new DataResponse([], Http::STATUS_NOT_MODIFIED);
+ $response = new DataResponse([], Http::STATUS_NOT_MODIFIED);
+ if ($this->participant->getAttendee()->getReadPrivacy() === Participant::PRIVACY_PUBLIC) {
+ $response->addHeader('X-Chat-Last-Common-Read', $this->chatManager->getLastCommonReadMessage($this->room));
+ }
+ return $response;
}
$i = 0;
@@ -424,6 +437,9 @@ class ChatController extends AEnvironmentAwareController {
* $this->participantService->updateLastReadMessage($this->participant, (int) $newLastKnown->getId());
* }
*/
+ if ($this->participant->getAttendee()->getReadPrivacy() === Participant::PRIVACY_PUBLIC) {
+ $response->addHeader('X-Chat-Last-Common-Read', $this->chatManager->getLastCommonReadMessage($this->room));
+ }
}
return $response;
@@ -438,7 +454,11 @@ class ChatController extends AEnvironmentAwareController {
*/
public function setReadMarker(int $lastReadMessage): DataResponse {
$this->participantService->updateLastReadMessage($this->participant, $lastReadMessage);
- return new DataResponse();
+ $response = new DataResponse();
+ if ($this->participant->getAttendee()->getReadPrivacy() === Participant::PRIVACY_PUBLIC) {
+ $response->addHeader('X-Chat-Last-Common-Read', $this->chatManager->getLastCommonReadMessage($this->room));
+ }
+ return $response;
}
/**
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index 6b4e1b3af..2d7a050e3 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -106,6 +106,9 @@ class RoomController extends AEnvironmentAwareController {
/** @var Config */
protected $talkConfig;
+ /** @var array */
+ protected $commonReadMessages = [];
+
public function __construct(string $appName,
?string $UserId,
IRequest $request,
@@ -195,8 +198,14 @@ class RoomController extends AEnvironmentAwareController {
}
}
-
$rooms = $this->manager->getRoomsForUser($this->userId, true);
+ $readPrivacy = (int) $this->config->getUserValue($this->userId, 'spreed', 'read_status_privacy', (string) Participant::PRIVACY_PUBLIC);
+ if ($readPrivacy === Participant::PRIVACY_PUBLIC) {
+ $roomIds = array_map(static function (Room $room) {
+ return $room->getId();
+ }, $rooms);
+ $this->commonReadMessages = $this->participantService->getLastCommonReadChatMessageForMultipleRooms($roomIds);
+ }
$return = [];
foreach ($rooms as $room) {
@@ -549,6 +558,7 @@ class RoomController extends AEnvironmentAwareController {
'canEnableSIP' => false,
'attendeePin' => '',
'description' => '',
+ 'lastCommonReadMessage' => 0,
]);
}
@@ -619,6 +629,14 @@ class RoomController extends AEnvironmentAwareController {
'attendeeId' => $attendee->getId(),
'description' => $room->getDescription(),
]);
+
+ if ($currentParticipant->getAttendee()->getReadPrivacy() === Participant::PRIVACY_PUBLIC) {
+ if (isset($this->commonReadMessages[$room->getId()])) {
+ $roomData['lastCommonReadMessage'] = $this->commonReadMessages[$room->getId()];
+ } else {
+ $roomData['lastCommonReadMessage'] = $this->chatManager->getLastCommonReadMessage($room);
+ }
+ }
}
$session = $currentParticipant->getSession();