diff --git a/img/actions/room-created.png b/img/actions/room-created.png
new file mode 100644
index 0000000..08339a8
Binary files /dev/null and b/img/actions/room-created.png differ
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 @@
+
+
diff --git a/img/actions/room-deleted.png b/img/actions/room-deleted.png
new file mode 100644
index 0000000..07ac1a9
Binary files /dev/null and b/img/actions/room-deleted.png differ
diff --git a/img/actions/room-deleted.svg b/img/actions/room-deleted.svg
new file mode 100644
index 0000000..0361475
--- /dev/null
+++ b/img/actions/room-deleted.svg
@@ -0,0 +1,67 @@
+
+
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));