diff options
author | Joas Schilling <coding@schilljs.com> | 2023-07-19 10:52:09 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-08-08 10:46:51 +0200 |
commit | fac8f13a7c381d62966f47754a58e89413a251ca (patch) | |
tree | b83a985187c8a5208140d1070c52e49402939169 | |
parent | 7ae69c840bb600098961ee3760e68b55dd79982f (diff) |
feat(Message): Allow parsing messages without a current participant
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/Chat/MessageParser.php | 2 | ||||
-rw-r--r-- | lib/Chat/Parser/Command.php | 1 | ||||
-rw-r--r-- | lib/Chat/Parser/SystemMessage.php | 11 | ||||
-rw-r--r-- | lib/Chat/Parser/UserMention.php | 4 | ||||
-rw-r--r-- | lib/Model/Message.php | 6 |
5 files changed, 15 insertions, 9 deletions
diff --git a/lib/Chat/MessageParser.php b/lib/Chat/MessageParser.php index e4e1b6c46..74441cced 100644 --- a/lib/Chat/MessageParser.php +++ b/lib/Chat/MessageParser.php @@ -63,7 +63,7 @@ class MessageParser { $this->userManager = $userManager; } - public function createMessage(Room $room, Participant $participant, IComment $comment, IL10N $l): Message { + public function createMessage(Room $room, ?Participant $participant, IComment $comment, IL10N $l): Message { return new Message($room, $participant, $comment, $l); } diff --git a/lib/Chat/Parser/Command.php b/lib/Chat/Parser/Command.php index 6a69f2c82..e0fa1b2f7 100644 --- a/lib/Chat/Parser/Command.php +++ b/lib/Chat/Parser/Command.php @@ -45,6 +45,7 @@ class Command { $participant = $message->getParticipant(); if ($data['visibility'] !== \OCA\Talk\Model\Command::RESPONSE_ALL && + $participant !== null && ($participant->getAttendee()->getActorType() !== Attendee::ACTOR_USERS || $data['user'] !== $participant->getAttendee()->getActorId())) { $message->setVisibility(false); diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index 335ecf4c8..0b2dc2847 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -118,7 +118,10 @@ class SystemMessage { $parsedParameters = ['actor' => $this->getActorFromComment($room, $comment)]; $participant = $chatMessage->getParticipant(); - if (!$participant->isGuest()) { + if ($participant === null) { + $currentActorId = null; + $currentUserIsActor = false; + } elseif (!$participant->isGuest()) { $currentActorId = $participant->getAttendee()->getActorId(); $currentUserIsActor = $parsedParameters['actor']['type'] === 'user' && $participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS && @@ -583,12 +586,14 @@ class SystemMessage { $parsedParameters = ['actor' => $this->getActor($room, $data['deleted_by_type'], $data['deleted_by_id'])]; $participant = $chatMessage->getParticipant(); - $currentActorId = $participant->getAttendee()->getActorId(); + $currentActorId = $participant?->getAttendee()->getActorId(); $authorIsActor = $data['deleted_by_type'] === $chatMessage->getComment()->getActorType() && $data['deleted_by_id'] === $chatMessage->getComment()->getActorId(); - if (!$participant->isGuest()) { + if ($participant === null) { + $currentUserIsActor = false; + } elseif (!$participant->isGuest()) { $currentUserIsActor = $parsedParameters['actor']['type'] === 'user' && $participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS && $currentActorId === $parsedParameters['actor']['id']; diff --git a/lib/Chat/Parser/UserMention.php b/lib/Chat/Parser/UserMention.php index 47495e46e..0274f7e8f 100644 --- a/lib/Chat/Parser/UserMention.php +++ b/lib/Chat/Parser/UserMention.php @@ -135,8 +135,8 @@ class UserMention { if ($mention['type'] === 'call') { $userId = ''; - if ($chatMessage->getParticipant()->getAttendee()->getActorType() === Attendee::ACTOR_USERS) { - $userId = $chatMessage->getParticipant()->getAttendee()->getActorId(); + if ($chatMessage->getParticipant()?->getAttendee()->getActorType() === Attendee::ACTOR_USERS) { + $userId = $chatMessage->getParticipant()?->getAttendee()->getActorId(); } $messageParameters[$mentionParameterId] = [ diff --git a/lib/Model/Message.php b/lib/Model/Message.php index 78d614a4e..669b73cbc 100644 --- a/lib/Model/Message.php +++ b/lib/Model/Message.php @@ -39,7 +39,7 @@ class Message { /** @var IL10N */ protected $l; - /** @var Participant */ + /** @var null|Participant */ protected $participant; /** @var bool */ @@ -67,7 +67,7 @@ class Message { protected $actorDisplayName = ''; public function __construct(Room $room, - Participant $participant, + ?Participant $participant, IComment $comment, IL10N $l) { $this->room = $room; @@ -92,7 +92,7 @@ class Message { return $this->l; } - public function getParticipant(): Participant { + public function getParticipant(): ?Participant { return $this->participant; } |