diff options
author | Joas Schilling <coding@schilljs.com> | 2017-10-11 15:13:08 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-10-11 15:13:08 +0300 |
commit | bf979d31a066f4ed99b32bdc928554b7acdcca8d (patch) | |
tree | 5fa35a27b8d8a06e09b5d158cbcd8b57d1336ec3 /lib/Activity | |
parent | 5c1eac208023b186de176e551c400563d910b330 (diff) |
Simplify activity and fix handling of deleted rooms
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Activity')
-rw-r--r-- | lib/Activity/Provider/Base.php | 20 | ||||
-rw-r--r-- | lib/Activity/Provider/Call.php | 64 | ||||
-rw-r--r-- | lib/Activity/Provider/Invitation.php | 55 |
3 files changed, 52 insertions, 87 deletions
diff --git a/lib/Activity/Provider/Base.php b/lib/Activity/Provider/Base.php index b6e086ff2..346ebe815 100644 --- a/lib/Activity/Provider/Base.php +++ b/lib/Activity/Provider/Base.php @@ -27,6 +27,7 @@ use OCA\Spreed\Room; use OCP\Activity\IEvent; use OCP\Activity\IManager; use OCP\Activity\IProvider; +use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; @@ -104,10 +105,11 @@ abstract class Base implements IProvider { } /** + * @param IL10N $l * @param Room $room * @return array */ - protected function getRoom(Room $room) { + protected function getRoom(IL10N $l, Room $room) { switch ($room->getType()) { case Room::ONE_TO_ONE_CALL: $stringType = 'one2one'; @@ -124,12 +126,26 @@ abstract class Base implements IProvider { return [ 'type' => 'call', 'id' => $room->getId(), - 'name' => $room->getName(), + 'name' => $room->getName() ?: $l->t('a call'), 'call-type' => $stringType, ]; } /** + * @param IL10N $l + * @param int $roomId + * @return array + */ + protected function getFormerRoom(IL10N $l, $roomId) { + return [ + 'type' => 'call', + 'id' => $roomId, + 'name' => $l->t('a call'), + 'call-type' => Room::UNKNOWN_CALL, + ]; + } + + /** * @param string $uid * @return array */ diff --git a/lib/Activity/Provider/Call.php b/lib/Activity/Provider/Call.php index 47526d948..81134bfff 100644 --- a/lib/Activity/Provider/Call.php +++ b/lib/Activity/Provider/Call.php @@ -38,20 +38,23 @@ class Call extends Base { */ public function parse($language, IEvent $event, IEvent $previousEvent = null) { $event = parent::preParse($event); - $l = $this->languageFactory->get('spreed', $language); - try { + if ($event->getSubject() === 'call') { + $l = $this->languageFactory->get('spreed', $language); $parameters = $event->getSubjectParameters(); - $room = $this->manager->getRoomById((int) $parameters['room']); - - if ($event->getSubject() === 'call') { - $result = $this->parseCall($event, $l, $room); - $result['subject'] .= ' ' . $this->getDuration($l, $parameters['duration']); - $this->setSubjects($event, $result['subject'], $result['params']); - } else { - throw new \InvalidArgumentException(); - } - } catch (RoomNotFoundException $e) { + +// $roomParameter = $this->getFormerRoom($l, (int) $parameters['room']); +// try { +// $room = $this->manager->getRoomById((int) $parameters['room']); +// $roomParameter = $this->getRoom($l, $room); +// } catch (RoomNotFoundException $e) { +// } + + $result = $this->parseCall($event, $l); + $result['subject'] .= ' ' . $this->getDuration($l, $parameters['duration']); +// $result['params']['call'] = $roomParameter; + $this->setSubjects($event, $result['subject'], $result['params']); + } else { throw new \InvalidArgumentException(); } @@ -73,7 +76,7 @@ class Call extends Base { return $l->t('(Duration %s)', $duration); } - protected function parseCall(IEvent $event, IL10N $l, Room $room) { + protected function parseCall(IEvent $event, IL10N $l) { $parameters = $event->getSubjectParameters(); $currentUser = array_search($this->activityManager->getCurrentUserId(), $parameters['users'], true); @@ -83,63 +86,48 @@ class Call extends Base { unset($parameters['users'][$currentUser]); sort($parameters['users']); - if ($room->getType() === Room::ONE_TO_ONE_CALL) { - $otherUser = array_pop($parameters['users']); - - if ($otherUser === '') { - throw new \InvalidArgumentException('Unknown case'); - } - - return [ - 'subject' => $l->t('You had a private call with {user}'), - 'params' => [ - 'user' => $this->getUser($otherUser), - ], - ]; - } - $numUsers = count($parameters['users']); $displayedUsers = $numUsers; switch ($numUsers) { case 0: - $subject = $l->t('You had a call with {user1}'); + $subject = $l->t('You attended a call with {user1}'); $subject = str_replace('{user1}', $l->n('%n guest', '%n guests', $parameters['guests']), $subject); break; case 1: if ($parameters['guests'] === 0) { - $subject = $l->t('You had a call with {user1}'); + $subject = $l->t('You attended a call with {user1}'); } else { - $subject = $l->t('You had a call with {user1} and {user2}'); + $subject = $l->t('You attended a call with {user1} and {user2}'); $subject = str_replace('{user2}', $l->n('%n guest', '%n guests', $parameters['guests']), $subject); } break; case 2: if ($parameters['guests'] === 0) { - $subject = $l->t('You had a call with {user1} and {user2}'); + $subject = $l->t('You attended a call with {user1} and {user2}'); } else { - $subject = $l->t('You had a call with {user1}, {user2} and {user3}'); + $subject = $l->t('You attended a call with {user1}, {user2} and {user3}'); $subject = str_replace('{user3}', $l->n('%n guest', '%n guests', $parameters['guests']), $subject); } break; case 3: if ($parameters['guests'] === 0) { - $subject = $l->t('You had a call with {user1}, {user2} and {user3}'); + $subject = $l->t('You attended a call with {user1}, {user2} and {user3}'); } else { - $subject = $l->t('You had a call with {user1}, {user2}, {user3} and {user4}'); + $subject = $l->t('You attended a call with {user1}, {user2}, {user3} and {user4}'); $subject = str_replace('{user4}', $l->n('%n guest', '%n guests', $parameters['guests']), $subject); } break; case 4: if ($parameters['guests'] === 0) { - $subject = $l->t('You had a call with {user1}, {user2}, {user3} and {user4}'); + $subject = $l->t('You attended a call with {user1}, {user2}, {user3} and {user4}'); } else { - $subject = $l->t('You had a call with {user1}, {user2}, {user3}, {user4} and {user5}'); + $subject = $l->t('You attended a call with {user1}, {user2}, {user3}, {user4} and {user5}'); $subject = str_replace('{user5}', $l->n('%n guest', '%n guests', $parameters['guests']), $subject); } break; case 5: default: - $subject = $l->t('You had a call with {user1}, {user2}, {user3}, {user4} and {user5}'); + $subject = $l->t('You attended a call with {user1}, {user2}, {user3}, {user4} and {user5}'); if ($numUsers === 5 && $parameters['guests'] === 0) { $displayedUsers = 5; } else { diff --git a/lib/Activity/Provider/Invitation.php b/lib/Activity/Provider/Invitation.php index 73b6dba66..3f045496e 100644 --- a/lib/Activity/Provider/Invitation.php +++ b/lib/Activity/Provider/Invitation.php @@ -22,9 +22,7 @@ namespace OCA\Spreed\Activity\Provider; use OCA\Spreed\Exceptions\RoomNotFoundException; -use OCA\Spreed\Room; use OCP\Activity\IEvent; -use OCP\IL10N; class Invitation extends Base { @@ -40,17 +38,20 @@ class Invitation extends Base { $event = parent::preParse($event); if ($event->getSubject() === 'invitation') { + $l = $this->languageFactory->get('spreed', $language); $parameters = $event->getSubjectParameters(); + + $roomParameter = $this->getFormerRoom($l, (int) $parameters['room']); try { $room = $this->manager->getRoomById((int) $parameters['room']); + $roomParameter = $this->getRoom($l, $room); } catch (RoomNotFoundException $e) { - throw new \InvalidArgumentException(); } - $l = $this->languageFactory->get('spreed', $language); - - $result = $this->parseInvitation($event, $l, $room); - $this->setSubjects($event, $result['subject'], $result['params']); + $this->setSubjects($event, $l->t('{actor} invited you to {call}'), [ + 'actor' => $this->getUser($parameters['user']), + 'call' => $roomParameter, + ]); } else { throw new \InvalidArgumentException(); } @@ -58,44 +59,4 @@ class Invitation extends Base { return $event; } - protected function parseInvitation(IEvent $event, IL10N $l, Room $room) { - $parameters = $event->getSubjectParameters(); - - if ($room->getName() === '') { - if ($room->getType() === Room::ONE_TO_ONE_CALL) { - $subject = $l->t('{actor} invited you to a private call'); - } else { - $subject = $l->t('{actor} invited you to a group call'); - } - - return [ - 'subject' => $subject, - 'params' => $this->getParameters($parameters), - ]; - } - - return [ - 'subject' => $l->t('{actor} invited you to the call {call}'), - 'params' => $this->getParameters($parameters, $room), - ]; - } - - /** - * @param array $parameters - * @param Room $room - * @return array - */ - protected function getParameters(array $parameters, Room $room = null) { - if ($room === null) { - return [ - 'actor' => $this->getUser($parameters['user']), - ]; - } - - return [ - 'actor' => $this->getUser($parameters['user']), - 'call' => $this->getRoom($room), - ]; - } - } |