diff options
author | Joas Schilling <coding@schilljs.com> | 2022-04-07 17:49:03 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-04-07 17:49:03 +0300 |
commit | 55ace3d96773c446623b79750aee101c77eb8f6f (patch) | |
tree | 0f5939191a0cac421882ad3071040872bc22ba52 | |
parent | 06d2432f89e6e08343545b3e19bd814df7ebb478 (diff) |
Message types are defaulting to Verbs so lets reuse the constantstechdebt/7078/const-for-verbs
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/Chat/Parser/Listener.php | 13 | ||||
-rw-r--r-- | lib/Chat/Parser/ReactionParser.php | 2 | ||||
-rw-r--r-- | lib/Chat/Parser/SystemMessage.php | 6 | ||||
-rw-r--r-- | lib/Model/Message.php | 14 | ||||
-rw-r--r-- | lib/Notification/Notifier.php | 3 | ||||
-rw-r--r-- | tests/php/Chat/Parser/SystemMessageTest.php | 3 |
6 files changed, 23 insertions, 18 deletions
diff --git a/lib/Chat/Parser/Listener.php b/lib/Chat/Parser/Listener.php index ebb63fe22..99363b8ec 100644 --- a/lib/Chat/Parser/Listener.php +++ b/lib/Chat/Parser/Listener.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace OCA\Talk\Chat\Parser; +use OCA\Talk\Chat\ChatManager; use OCA\Talk\Chat\MessageParser; use OCA\Talk\Chat\Parser\Command as CommandParser; use OCA\Talk\Events\ChatMessageEvent; @@ -33,7 +34,7 @@ class Listener { $dispatcher->addListener(MessageParser::EVENT_MESSAGE_PARSE, static function (ChatMessageEvent $event) { $message = $event->getMessage(); - if ($message->getMessageType() !== 'comment') { + if ($message->getMessageType() !== ChatManager::VERB_MESSAGE) { return; } @@ -45,7 +46,7 @@ class Listener { $dispatcher->addListener(MessageParser::EVENT_MESSAGE_PARSE, static function (ChatMessageEvent $event) { $message = $event->getMessage(); - if ($message->getMessageType() !== 'comment') { + if ($message->getMessageType() !== ChatManager::VERB_MESSAGE) { return; } @@ -62,7 +63,7 @@ class Listener { $dispatcher->addListener(MessageParser::EVENT_MESSAGE_PARSE, static function (ChatMessageEvent $event) { $message = $event->getMessage(); - if ($message->getMessageType() !== 'system') { + if ($message->getMessageType() !== ChatManager::VERB_SYSTEM) { return; } @@ -80,7 +81,7 @@ class Listener { $dispatcher->addListener(MessageParser::EVENT_MESSAGE_PARSE, static function (ChatMessageEvent $event) { $chatMessage = $event->getMessage(); - if ($chatMessage->getMessageType() !== 'command') { + if ($chatMessage->getMessageType() !== ChatManager::VERB_COMMAND) { return; } @@ -100,7 +101,7 @@ class Listener { $dispatcher->addListener(MessageParser::EVENT_MESSAGE_PARSE, static function (ChatMessageEvent $event) { $chatMessage = $event->getMessage(); - if ($chatMessage->getMessageType() !== 'reaction' && $chatMessage->getMessageType() !== 'reaction_deleted') { + if ($chatMessage->getMessageType() !== ChatManager::VERB_REACTION && $chatMessage->getMessageType() !== ChatManager::VERB_REACTION_DELETED) { return; } @@ -112,7 +113,7 @@ class Listener { $dispatcher->addListener(MessageParser::EVENT_MESSAGE_PARSE, static function (ChatMessageEvent $event) { $chatMessage = $event->getMessage(); - if ($chatMessage->getMessageType() !== 'comment_deleted') { + if ($chatMessage->getMessageType() !== ChatManager::VERB_MESSAGE_DELETED) { return; } diff --git a/lib/Chat/Parser/ReactionParser.php b/lib/Chat/Parser/ReactionParser.php index 89621969c..a7959a9f2 100644 --- a/lib/Chat/Parser/ReactionParser.php +++ b/lib/Chat/Parser/ReactionParser.php @@ -41,7 +41,7 @@ class ReactionParser { throw new \OutOfBoundsException('Not a reaction'); } $this->l = $message->getL10n(); - $message->setMessageType('system'); + $message->setMessageType(ChatManager::VERB_SYSTEM); if ($comment->getVerb() === ChatManager::VERB_REACTION_DELETED) { // This message is necessary to make compatible with old clients $message->setMessage($this->l->t('Reaction deleted by author'), [], $comment->getVerb()); diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index 6a0a7503a..a44eb6346 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -376,7 +376,7 @@ class SystemMessage { if (isset($metaData['messageType']) && $metaData['messageType'] === 'voice-message') { $chatMessage->setMessageType('voice-message'); } else { - $chatMessage->setMessageType('comment'); + $chatMessage->setMessageType(ChatManager::VERB_MESSAGE); } } catch (\Exception $e) { $parsedMessage = $this->l->t('{actor} shared a file which is no longer available'); @@ -395,7 +395,7 @@ class SystemMessage { $parsedMessage = $this->l->t('The shared location is malformed'); } - $chatMessage->setMessageType('comment'); + $chatMessage->setMessageType(ChatManager::VERB_MESSAGE); } elseif ($message === 'matterbridge_config_added') { $parsedMessage = $this->l->t('{actor} set up Matterbridge to synchronize this conversation with other chats'); if ($currentUserIsActor) { @@ -473,7 +473,7 @@ class SystemMessage { $currentActorId === $parsedParameters['actor']['id']; } - if ($chatMessage->getMessageType() === 'comment_deleted') { + if ($chatMessage->getMessageType() === ChatManager::VERB_MESSAGE_DELETED) { $message = 'message_deleted'; $parsedMessage = $this->l->t('Message deleted by author'); diff --git a/lib/Model/Message.php b/lib/Model/Message.php index 118adad72..fd14eaaba 100644 --- a/lib/Model/Message.php +++ b/lib/Model/Message.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace OCA\Talk\Model; +use OCA\Talk\Chat\ChatManager; use OCA\Talk\Participant; use OCA\Talk\Room; use OCP\Comments\IComment; @@ -160,10 +161,11 @@ class Message { return false; } - return $this->getMessageType() !== 'system' && - $this->getMessageType() !== 'command' && - $this->getMessageType() !== 'comment_deleted' && - $this->getMessageType() !== 'reaction' && + return $this->getMessageType() !== ChatManager::VERB_SYSTEM && + $this->getMessageType() !== ChatManager::VERB_COMMAND && + $this->getMessageType() !== ChatManager::VERB_MESSAGE_DELETED && + $this->getMessageType() !== ChatManager::VERB_REACTION && + $this->getMessageType() !== ChatManager::VERB_REACTION_DELETED && \in_array($this->getActorType(), [Attendee::ACTOR_USERS, Attendee::ACTOR_GUESTS]); } @@ -177,14 +179,14 @@ class Message { 'timestamp' => $this->getComment()->getCreationDateTime()->getTimestamp(), 'message' => $this->getMessage(), 'messageParameters' => $this->getMessageParameters(), - 'systemMessage' => $this->getMessageType() === 'system' ? $this->getMessageRaw() : '', + 'systemMessage' => $this->getMessageType() === ChatManager::VERB_SYSTEM ? $this->getMessageRaw() : '', 'messageType' => $this->getMessageType(), 'isReplyable' => $this->isReplyable(), 'referenceId' => (string) $this->getComment()->getReferenceId(), 'reactions' => $this->getComment()->getReactions(), ]; - if ($this->getMessageType() === 'comment_deleted') { + if ($this->getMessageType() === ChatManager::VERB_MESSAGE_DELETED) { $data['deleted'] = true; } diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index ce569d474..fdcf100ca 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace OCA\Talk\Notification; use OCA\FederatedFileSharing\AddressHandler; +use OCA\Talk\Chat\ChatManager; use OCA\Talk\Chat\CommentsManager; use OCA\Talk\Chat\MessageParser; use OCA\Talk\Config; @@ -364,7 +365,7 @@ class Notifier implements INotifier { throw new AlreadyProcessedException(); } - if ($message->getMessageType() === 'comment_deleted') { + if ($message->getMessageType() === ChatManager::VERB_MESSAGE_DELETED) { throw new AlreadyProcessedException(); } diff --git a/tests/php/Chat/Parser/SystemMessageTest.php b/tests/php/Chat/Parser/SystemMessageTest.php index 8e24255df..1fcf409e0 100644 --- a/tests/php/Chat/Parser/SystemMessageTest.php +++ b/tests/php/Chat/Parser/SystemMessageTest.php @@ -22,6 +22,7 @@ namespace OCA\Talk\Tests\php\Chat\Parser; use OCA\DAV\CardDAV\PhotoCache; +use OCA\Talk\Chat\ChatManager; use OCA\Talk\Chat\Parser\SystemMessage; use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\GuestManager; @@ -528,7 +529,7 @@ class SystemMessageTest extends TestCase { $this->assertSame($expectedParameters, $chatMessage->getMessageParameters()); if ($message === 'file_shared' && !is_subclass_of($parameters['share'], \Exception::class)) { - $this->assertSame('comment', $chatMessage->getMessageType()); + $this->assertSame(ChatManager::VERB_MESSAGE, $chatMessage->getMessageType()); } } |