feat: render activities with markup

pull/77/head
sualko 2020-09-18 14:36:31 +02:00
parent 3fbd815d3f
commit 0ad1b499d9
7 changed files with 239 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
height="32"
width="32"
version="1.0"
viewBox="0 0 32 32"
id="svg4"
sodipodi:docname="app-dark.svg"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)">
<metadata
id="metadata10">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs8" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1479"
inkscape:window-height="997"
id="namedview6"
showgrid="false"
inkscape:zoom="7.375"
inkscape:cx="13.46269"
inkscape:cy="7.070207"
inkscape:window-x="2110"
inkscape:window-y="585"
inkscape:window-maximized="0"
inkscape:current-layer="svg4" />
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.48244119;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:markers stroke fill;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="M 6.140625,2 C 3.8448872,2 2,3.9362265 2,6.2421875 V 25.757812 C 2,28.063773 3.8448872,30 6.140625,30 h 19.71875 C 28.155113,30 30,28.063773 30,25.757812 V 6.2421875 C 30,3.9362265 28.155113,2 25.859375,2 Z m 0,2.4824219 h 19.71875 c 0.917462,0 1.658203,0.7417266 1.658203,1.7597656 V 25.757812 c 0,1.01804 -0.740741,1.759766 -1.658203,1.759766 H 6.140625 c -0.9174623,0 -1.6582031,-0.741726 -1.6582031,-1.759766 V 6.2421875 c 0,-1.018039 0.7407408,-1.7597656 1.6582031,-1.7597656 z"
id="rect817"
inkscape:connector-curvature="0" />
<g
id="g891"
transform="matrix(0.72859037,0,0,0.72859037,4.3425539,7.2153805)"
style="fill:#000000">
<path
id="path819"
d="m 16,16.40625 a 9.4915257,9.4915257 0 0 0 -9.4921875,9.492188 9.4915257,9.4915257 0 0 0 0.3574219,2.576171 H 25.126953 A 9.4915257,9.4915257 0 0 0 25.492188,25.898438 9.4915257,9.4915257 0 0 0 16,16.40625 Z"
style="opacity:1;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3.37037015;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:markers stroke fill"
inkscape:connector-curvature="0" />
<circle
r="6.2372885"
cy="12.338983"
cx="16"
id="path819-1"
style="opacity:1;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.21481466;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:markers stroke fill" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

@ -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,
];
}
}

View File

@ -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) {

View File

@ -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));