diff options
author | Vitor Mattos <vitor@php.rio> | 2021-09-28 18:02:22 +0300 |
---|---|---|
committer | Vitor Mattos <vitor@php.rio> | 2021-09-29 14:42:35 +0300 |
commit | e89466930fff3c543a9b7630750ab8e99a5b5432 (patch) | |
tree | ccea711cfafea6b10c4e41b88630ec76e933872f /lib | |
parent | b9be9ae1b1dba86f7c7dbec927438800cd3636f0 (diff) |
Moved code to specialist method and add fallback to all
Signed-off-by: Vitor Mattos <vitor@php.rio>
Update lib/Chat/ChatManager.php
Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Chat/ChatManager.php | 33 | ||||
-rw-r--r-- | lib/Controller/ChatController.php | 21 |
2 files changed, 34 insertions, 20 deletions
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php index 7cca61fc5..36e8cd4d0 100644 --- a/lib/Chat/ChatManager.php +++ b/lib/Chat/ChatManager.php @@ -531,4 +531,37 @@ class ChatManager { public function searchForObjects(string $search, array $objectIds, string $verb = '', int $offset = 0, int $limit = 50): array { return $this->commentsManager->searchForObjects($search, 'chat', $objectIds, $verb, $offset, $limit); } + + public function addConversationNotify(array $results, string $search, Room $room, Participant $participant): array { + if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + return $results; + } + $attendee = $participant->getAttendee(); + if ($attendee->getActorType() === Attendee::ACTOR_USERS) { + $roomDisplayName = $room->getDisplayName($attendee->getActorId()); + } else { + $roomDisplayName = $room->getDisplayName(''); + } + if ($search === '' || $this->searchIsPartOfConversationNameOrAtAll($search, $roomDisplayName)) { + array_unshift($results, [ + 'id' => 'all', + 'label' => $roomDisplayName, + 'source' => 'calls', + ]); + } + return $results; + } + + private function searchIsPartOfConversationNameOrAtAll(string $search, string $roomDisplayName): bool { + if (stripos($roomDisplayName, $search) === 0) { + return true; + } + if (strpos('all', $search) === 0) { + return true; + } + if (strpos('here', $search) === 0) { + return true; + } + return false; + } } diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 0084240b7..920e6dd57 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -706,26 +706,7 @@ class ChatController extends AEnvironmentAwareController { $results = $this->prepareResultArray($results, $statuses); - $attendee = $this->participant->getAttendee(); - $userId = $attendee->getActorType() === Attendee::ACTOR_USERS ? $attendee->getActorId() : ''; - $roomDisplayName = $this->room->getDisplayName($userId); - if (($search === '' || strpos('all', $search) !== false || stripos($roomDisplayName, $search) !== false) && $this->room->getType() !== Room::ONE_TO_ONE_CALL) { - if ($search === '' || - stripos($roomDisplayName, $search) === 0 || - strpos('all', $search) === 0) { - array_unshift($results, [ - 'id' => 'all', - 'label' => $roomDisplayName, - 'source' => 'calls', - ]); - } else { - $results[] = [ - 'id' => 'all', - 'label' => $roomDisplayName, - 'source' => 'calls', - ]; - } - } + $results = $this->chatManager->addConversationNotify($results, $search, $this->room, $this->participant); return new DataResponse($results); } |