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>2022-04-11 16:08:50 +0300
committerJoas Schilling <coding@schilljs.com>2022-04-12 09:48:41 +0300
commit7cde6b2cb1a970d2bbd61c7ca9b534bdc381e33f (patch)
tree82e5f2f57e72626956648b985f1d2912591b4585 /lib
parent1d6a805c17876336b702e2c8b968773dfec876fd (diff)
Move to a dedicated method
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Chat/ReactionManager.php2
-rw-r--r--lib/Controller/ChatController.php61
2 files changed, 35 insertions, 28 deletions
diff --git a/lib/Chat/ReactionManager.php b/lib/Chat/ReactionManager.php
index bf33b259f..de346fa7b 100644
--- a/lib/Chat/ReactionManager.php
+++ b/lib/Chat/ReactionManager.php
@@ -175,7 +175,7 @@ class ReactionManager {
* @return array[]
* @psalm-return array<int, string[]>
*/
- public function getReactionsForMessages(Participant $participant, array $messageIds): array {
+ public function getReactionsByActorForMessages(Participant $participant, array $messageIds): array {
return $this->commentsManager->retrieveReactionsByActor(
$participant->getAttendee()->getActorType(),
$participant->getAttendee()->getActorId(),
diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php
index 5c53d635a..c60885bc5 100644
--- a/lib/Controller/ChatController.php
+++ b/lib/Controller/ChatController.php
@@ -501,30 +501,58 @@ class ChatController extends AEnvironmentAwareController {
];
}
- /**
- * Gather information to expose $message['reactions']['self']
- */
+ $messages = $this->loadSelfReactions($messages, $commentIdToIndex);
+
+ $response = new DataResponse($messages, Http::STATUS_OK);
+
+ $newLastKnown = end($comments);
+ if ($newLastKnown instanceof IComment) {
+ $response->addHeader('X-Chat-Last-Given', $newLastKnown->getId());
+ /**
+ * This falsely set the read marker on new messages although you
+ * navigated away to a different chat already. So we removed this
+ * and instead update the read marker before your next waiting.
+ * So when you are still there, it will just have a wrong read
+ * marker for the time until your next request starts, while it will
+ * not update the value, when you actually left the chat already.
+ * if ($setReadMarker === 1 && $lookIntoFuture) {
+ * $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;
+ }
+
+ protected function loadSelfReactions(array $messages, array $commentIdToIndex): array {
+ // Get message ids with reactions
$messageIdsWithReactions = array_map(
static fn (array $message) => $message['id'],
array_filter($messages, static fn (array $message) => !empty($message['reactions']))
);
+ // Get parents with reactions
$parentsWithReactions = array_map(
static fn (array $message) => ['parent' => $message['parent']['id'], 'message' => $message['id']],
array_filter($messages, static fn (array $message) => !empty($message['parent']['reactions']))
);
+ // Create a map, so we can translate the parent's $messageId to the correct child entries
$parentMap = $parentIdsWithReactions = [];
foreach ($parentsWithReactions as $entry) {
- // Create a map, so we can translate the parent's $messageId to the correct child entries
$parentMap[(int) $entry['parent']] ??= [];
$parentMap[(int) $entry['parent']][] = (int) $entry['message'];
$parentIdsWithReactions[] = (int) $entry['parent'];
}
+ // Unique list for the query
$idsWithReactions = array_unique(array_merge($messageIdsWithReactions, $parentIdsWithReactions));
+ $reactionsById = $this->reactionManager->getReactionsByActorForMessages($this->participant, $idsWithReactions);
- $reactionsById = $this->reactionManager->getReactionsForMessages($this->participant, $idsWithReactions);
+ // Inject the reactions self into the $messages array
foreach ($reactionsById as $messageId => $reactions) {
if (isset($messages[$commentIdToIndex[$messageId]])) {
$messages[$commentIdToIndex[$messageId]]['reactions']['self'] = $reactions;
@@ -540,28 +568,7 @@ class ChatController extends AEnvironmentAwareController {
}
}
- $response = new DataResponse($messages, Http::STATUS_OK);
-
- $newLastKnown = end($comments);
- if ($newLastKnown instanceof IComment) {
- $response->addHeader('X-Chat-Last-Given', $newLastKnown->getId());
- /**
- * This falsely set the read marker on new messages although you
- * navigated away to a different chat already. So we removed this
- * and instead update the read marker before your next waiting.
- * So when you are still there, it will just have a wrong read
- * marker for the time until your next request starts, while it will
- * not update the value, when you actually left the chat already.
- * if ($setReadMarker === 1 && $lookIntoFuture) {
- * $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;
+ return $messages;
}
/**