mirror of https://github.com/sualko/cloud_bbb
feat: add activity for room events
parent
916cd3bd92
commit
3fbd815d3f
|
@ -40,4 +40,12 @@ Developer wanted! If you have time it would be awesome if you could help to enha
|
||||||
<admin>OCA\BigBlueButton\Settings\Admin</admin>
|
<admin>OCA\BigBlueButton\Settings\Admin</admin>
|
||||||
<personal-section>OCA\BigBlueButton\Settings\Section</personal-section>
|
<personal-section>OCA\BigBlueButton\Settings\Section</personal-section>
|
||||||
</settings>
|
</settings>
|
||||||
|
<activity>
|
||||||
|
<settings>
|
||||||
|
<setting>OCA\BigBlueButton\Activity\Setting</setting>
|
||||||
|
</settings>
|
||||||
|
<providers>
|
||||||
|
<provider>OCA\BigBlueButton\Activity\Provider</provider>
|
||||||
|
</providers>
|
||||||
|
</activity>
|
||||||
</info>
|
</info>
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\BigBlueButton\Activity;
|
||||||
|
|
||||||
|
use OCA\BigBlueButton\AppInfo\Application;
|
||||||
|
use OCP\Activity\IProvider;
|
||||||
|
use OCP\Activity\IEvent;
|
||||||
|
use OCP\Activity\IManager;
|
||||||
|
|
||||||
|
class Provider implements IProvider {
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
public const ROOM_CREATED = 'room_created';
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
public const ROOM_DELETED = 'room_deleted';
|
||||||
|
|
||||||
|
/** @var IManager */
|
||||||
|
protected $activityManager;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
IManager $manager
|
||||||
|
) {
|
||||||
|
$this->activityManager = $manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parse($language, IEvent $event, IEvent $previousEvent = null) {
|
||||||
|
if ($event->getApp() !== Application::ID) {
|
||||||
|
throw new \InvalidArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$subject = $event->getSubject();
|
||||||
|
$params = $event->getSubjectParameters();
|
||||||
|
|
||||||
|
if ($subject === self::ROOM_CREATED) {
|
||||||
|
$event->setParsedSubject('You created the room ' . $params['name']);
|
||||||
|
} 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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $event;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\BigBlueButton\Activity;
|
||||||
|
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
|
use OCP\EventDispatcher\IEventListener;
|
||||||
|
use OCP\Activity\IManager as IActivityManager;
|
||||||
|
use OCA\BigBlueButton\Event\RoomCreatedEvent;
|
||||||
|
use OCA\BigBlueButton\Event\RoomDeletedEvent;
|
||||||
|
use OCA\BigBlueButton\AppInfo\Application;
|
||||||
|
|
||||||
|
class RoomListener implements IEventListener {
|
||||||
|
|
||||||
|
/** @var IActivityManager */
|
||||||
|
private $activityManager;
|
||||||
|
|
||||||
|
public function __construct(IActivityManager $activityManager) {
|
||||||
|
$this->activityManager = $activityManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(Event $event): void {
|
||||||
|
if ($event instanceof RoomCreatedEvent) {
|
||||||
|
$subject = Provider::ROOM_CREATED;
|
||||||
|
} elseif ($event instanceof RoomDeletedEvent) {
|
||||||
|
$subject = Provider::ROOM_DELETED;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$room = $event->getRoom();
|
||||||
|
$activityEvent = $this->activityManager->generateEvent();
|
||||||
|
|
||||||
|
$activityEvent->setApp(Application::ID);
|
||||||
|
$activityEvent->setType(Setting::Identifier);
|
||||||
|
$activityEvent->setAffectedUser($room->getUserId());
|
||||||
|
$activityEvent->setSubject($subject, [
|
||||||
|
'id' => $room->getId(),
|
||||||
|
'name' => $room->getName(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->activityManager->publish($activityEvent);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\BigBlueButton\Activity;
|
||||||
|
|
||||||
|
use OCP\Activity\ISetting;
|
||||||
|
|
||||||
|
class Setting implements ISetting {
|
||||||
|
public const Identifier = 'bbb';
|
||||||
|
|
||||||
|
public function getIdentifier() {
|
||||||
|
return self::Identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName() {
|
||||||
|
return 'BigBlueButton';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPriority() {
|
||||||
|
return 70;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canChangeStream() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDefaultEnabledStream() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canChangeMail() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDefaultEnabledMail() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,23 +5,33 @@ namespace OCA\BigBlueButton\AppInfo;
|
||||||
use \OCP\IConfig;
|
use \OCP\IConfig;
|
||||||
use \OCP\Settings\IManager as ISettingsManager;
|
use \OCP\Settings\IManager as ISettingsManager;
|
||||||
use \OCP\AppFramework\App;
|
use \OCP\AppFramework\App;
|
||||||
|
use \OCP\EventDispatcher\IEventDispatcher;
|
||||||
use \OCA\BigBlueButton\Middleware\JoinMiddleware;
|
use \OCA\BigBlueButton\Middleware\JoinMiddleware;
|
||||||
|
use \OCA\BigBlueButton\Event\RoomCreatedEvent;
|
||||||
|
use \OCA\BigBlueButton\Activity\RoomListener;
|
||||||
|
|
||||||
if ((@include_once __DIR__ . '/../../vendor/autoload.php') === false) {
|
if ((@include_once __DIR__ . '/../../vendor/autoload.php') === false) {
|
||||||
throw new \Exception('Cannot include autoload. Did you run install dependencies using composer?');
|
throw new \Exception('Cannot include autoload. Did you run install dependencies using composer?');
|
||||||
}
|
}
|
||||||
|
|
||||||
class Application extends App {
|
class Application extends App {
|
||||||
|
public const ID = 'bbb';
|
||||||
|
|
||||||
public function __construct(array $urlParams = []) {
|
public function __construct(array $urlParams = []) {
|
||||||
parent::__construct('bbb', $urlParams);
|
parent::__construct(self::ID, $urlParams);
|
||||||
|
|
||||||
$container = $this->getContainer();
|
$container = $this->getContainer();
|
||||||
|
|
||||||
|
/* @var IEventDispatcher $eventDispatcher */
|
||||||
|
$dispatcher = $container->query(IEventDispatcher::class);
|
||||||
|
$dispatcher->addServiceListener(RoomCreatedEvent::class, RoomListener::class);
|
||||||
|
$dispatcher->addServiceListener(RoomDeletedEvent::class, RoomListener::class);
|
||||||
|
|
||||||
$container->registerMiddleWare(JoinMiddleware::class);
|
$container->registerMiddleWare(JoinMiddleware::class);
|
||||||
|
|
||||||
$config = $container->query(IConfig::class);
|
$config = $container->query(IConfig::class);
|
||||||
|
|
||||||
if ($config->getAppValue('bbb', 'app.navigation') === 'true') {
|
if ($config->getAppValue(self::ID, 'app.navigation') === 'true') {
|
||||||
$this->registerAsNavigationEntry();
|
$this->registerAsNavigationEntry();
|
||||||
} else {
|
} else {
|
||||||
$this->registerAsPersonalSetting();
|
$this->registerAsPersonalSetting();
|
||||||
|
@ -39,7 +49,7 @@ class Application extends App {
|
||||||
|
|
||||||
$server->getNavigationManager()->add(function () use ($server) {
|
$server->getNavigationManager()->add(function () use ($server) {
|
||||||
return [
|
return [
|
||||||
'id' => 'bbb',
|
'id' => self::ID,
|
||||||
'order' => 80,
|
'order' => 80,
|
||||||
'href' => $server->getURLGenerator()->linkToRoute('bbb.page.index'),
|
'href' => $server->getURLGenerator()->linkToRoute('bbb.page.index'),
|
||||||
'icon' => $server->getURLGenerator()->imagePath('bbb', 'app.svg'),
|
'icon' => $server->getURLGenerator()->imagePath('bbb', 'app.svg'),
|
||||||
|
|
Loading…
Reference in New Issue