From 0ad1b499d9eb520fff9cec0cc270570bebc29284 Mon Sep 17 00:00:00 2001 From: sualko Date: Fri, 18 Sep 2020 14:36:31 +0200 Subject: [PATCH] feat: render activities with markup --- img/actions/room-created.png | Bin 0 -> 554 bytes img/actions/room-created.svg | 72 ++++++++++++++++++++++++ img/actions/room-deleted.png | Bin 0 -> 666 bytes img/actions/room-deleted.svg | 67 ++++++++++++++++++++++ lib/Activity/Provider.php | 106 ++++++++++++++++++++++++++++++++--- lib/AppInfo/Application.php | 1 + lib/Service/RoomService.php | 1 + 7 files changed, 239 insertions(+), 8 deletions(-) create mode 100644 img/actions/room-created.png create mode 100644 img/actions/room-created.svg create mode 100644 img/actions/room-deleted.png create mode 100644 img/actions/room-deleted.svg diff --git a/img/actions/room-created.png b/img/actions/room-created.png new file mode 100644 index 0000000000000000000000000000000000000000..08339a8fa9518243f59d65ad7638f4c834ab6efc GIT binary patch literal 554 zcmV+_0@eMAP)Un22^KLJW#OJgKz ztgZYn2rU@3vQk4N_$Np~)EI4zkwPPZXsI+pv9q||4Y+&mP~DSkW^aDa%=5jO?Cl&q z{jDQ-jCE|*e65GMTRVlfu#zCS{aV3r9@;1XJizU6{|s-!fI8H`d0Y*j=Ww^(v>F1R z*AyDle8~8gck~sCL!o__5a4ZS561xV?Wk+nW6I~=-uk{BjC-aYz`p+&JA`rBzAnpt zXez6l6=-4xU$BUm_=;)tSDmbz6_~}%w!VJc!vWl?GFjCX7>k4#HH9-N0Ve-ZZ(t%N zz(5Jl{*(Y8N_gI<1X#eQUFsiYPew9;4cRO8N2K;0*McV*z-c_e!AR{;sGUj$Fost+ zv5V&%Tm#YGFoK^}t-UYyDq_5-D zRRmZI?b*n{-(3L2bS|{3c}MYW_yTuuNp>uM?GNb&epU?oh5O;YfeW};$m-CDz4>GE sS>aUNt`;82wxjOgH9QPow5M%t0ZG7_mrI6K?*IS*07*qoM6N<$f{r}&2mk;8 literal 0 HcmV?d00001 diff --git a/img/actions/room-created.svg b/img/actions/room-created.svg new file mode 100644 index 0000000..76906cc --- /dev/null +++ b/img/actions/room-created.svg @@ -0,0 +1,72 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/img/actions/room-deleted.png b/img/actions/room-deleted.png new file mode 100644 index 0000000000000000000000000000000000000000..07ac1a965462d79d3228ba96a7524e672c006d92 GIT binary patch literal 666 zcmV;L0%iS)P)1_)9z&E^Dm>wg`8jh~qd^cCoSqwqq2V6SiJl!;ZQLtQB&+312(- z^x;+=1XiLcoB-i9j0t&vmLR&TY68R9Z{hj87k0WAC$*l)R^gJywMJLyqyww*GqN{v zsu19;c1^gDi1AlC@J-PDQOx2U?rK%DtGE+=&sj*H74l5 zLrhdjAjkJbY;%GXmqMI^wrZsYv{hX(f$6N@StEh`c~0d6aSEC^jUz%?{z|oF`ECnE zN;Bou=l}dMnGjXQMf3{-GhIXAY23^ + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/lib/Activity/Provider.php b/lib/Activity/Provider.php index 9e4a2e4..1f6aa84 100644 --- a/lib/Activity/Provider.php +++ b/lib/Activity/Provider.php @@ -6,6 +6,11 @@ use OCA\BigBlueButton\AppInfo\Application; use OCP\Activity\IProvider; use OCP\Activity\IEvent; use OCP\Activity\IManager; +use OCP\IL10N; +use OCP\IUserManager; +use OCP\IURLGenerator; +use OCP\L10N\IFactory; +use OCP\IUser; class Provider implements IProvider { @@ -15,13 +20,31 @@ class Provider implements IProvider { /** @var string */ public const ROOM_DELETED = 'room_deleted'; + /** @var IL10N */ + protected $l; + /** @var IManager */ protected $activityManager; + /** @var IUserManager */ + protected $userManager; + + /** @var IURLGenerator */ + protected $url; + + /** @var IFactory */ + protected $languageFactory; + public function __construct( - IManager $manager + IManager $manager, + IUserManager $userManager, + IURLGenerator $url, + IFactory $languageFactory ) { $this->activityManager = $manager; + $this->userManager = $userManager; + $this->url = $url; + $this->languageFactory = $languageFactory; } public function parse($language, IEvent $event, IEvent $previousEvent = null) { @@ -29,19 +52,86 @@ class Provider implements IProvider { throw new \InvalidArgumentException(); } + $this->l = $this->languageFactory->get(Application::ID, $language); + $subject = $event->getSubject(); - $params = $event->getSubjectParameters(); if ($subject === self::ROOM_CREATED) { - $event->setParsedSubject('You created the room ' . $params['name']); + $this->parseRoomCreated($event); } elseif ($subject === self::ROOM_DELETED) { - if ($this->activityManager->getCurrentUserId() === $event->getAffectedUser()) { - $event->setParsedSubject('You deleted the room ' . $params['name']); - } else { - $event->setParsedSubject($event->getAffectedUser() . ' deleted the room ' . $params['name']); - } + $this->parseRoomDeleted($event); + } else { + $event->setParsedSubject('Unknown subject: ' . $subject); } return $event; } + + private function parseRoomCreated(IEvent $event) { + $params = $event->getSubjectParameters(); + + $event->setParsedSubject($this->l->t('You created the room %s.', [$params['name']])); + + $this->setIcon($event, 'room-created'); + } + + private function parseRoomDeleted(IEvent $event) { + $params = $event->getSubjectParameters(); + + if ($this->activityManager->getCurrentUserId() === $event->getAuthor()) { + $event->setParsedSubject($this->l->t('You deleted the room %s.', [$params['name']])); + } else { + $subject = $this->l->t('{user} deleted the room %s', [$params['name']]); + + $this->setSubjects($event, $subject, [ + 'user' => $this->getUser($event->getAuthor()), + ]); + } + + $this->setIcon($event, 'room-deleted'); + } + + private function setIcon(IEvent $event, string $baseName) { + if ($this->activityManager->getRequirePNG()) { + $imagePath = $this->url->imagePath(Application::ID, 'actions/'.$baseName.'.png'); + } else { + $imagePath = $this->url->imagePath(Application::ID, 'actions/'.$baseName.'.svg'); + } + + $event->setIcon($this->url->getAbsoluteURL($imagePath)); + } + + private function setSubjects(IEvent $event, $subject, array $parameters) { + $placeholders = $replacements = []; + + foreach ($parameters as $placeholder => $parameter) { + $placeholders[] = '{' . $placeholder . '}'; + if ($parameter['type'] === 'file') { + $replacements[] = $parameter['path']; + } else { + $replacements[] = $parameter['name']; + } + } + + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) + ->setRichSubject($subject, $parameters); + } + + protected function getUser($uid) { + $user = $this->userManager->get($uid); + + if ($user instanceof IUser) { + return [ + 'type' => 'user', + 'id' => $user->getUID(), + 'name' => $user->getDisplayName(), + ]; + } + + return [ + 'type' => 'user', + 'id' => $uid, + 'name' => $uid, + ]; + } } diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 4c8d31c..47f1a69 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -8,6 +8,7 @@ use \OCP\AppFramework\App; use \OCP\EventDispatcher\IEventDispatcher; use \OCA\BigBlueButton\Middleware\JoinMiddleware; use \OCA\BigBlueButton\Event\RoomCreatedEvent; +use \OCA\BigBlueButton\Event\RoomDeletedEvent; use \OCA\BigBlueButton\Activity\RoomListener; if ((@include_once __DIR__ . '/../../vendor/autoload.php') === false) { diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index ae8c5f3..ceda7b2 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -111,6 +111,7 @@ class RoomService { public function delete($id) { try { $room = $this->mapper->find($id); + $this->mapper->delete($room); $this->eventDispatcher->dispatch(RoomDeletedEvent::class, new RoomDeletedEvent($room));