Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-11-15 16:38:30 +0300
committerJoas Schilling <coding@schilljs.com>2017-11-15 16:38:30 +0300
commit63eb22b213ecadaf24be69257791c66d3f4e9fea (patch)
tree7297831105321a615234e6cd9d58c9eb8c6f44fd /lib/Activity
parent684522ebc191d48efef009ae6cb3bb6935315be3 (diff)
Create invitation activity "{actor} invited you to {call}" via hook
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Activity')
-rw-r--r--lib/Activity/Hooks.php111
1 files changed, 97 insertions, 14 deletions
diff --git a/lib/Activity/Hooks.php b/lib/Activity/Hooks.php
index 80c486737..b852fdc82 100644
--- a/lib/Activity/Hooks.php
+++ b/lib/Activity/Hooks.php
@@ -24,28 +24,53 @@ namespace OCA\Spreed\Activity;
use OCA\Spreed\Room;
use OCP\Activity\IManager;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\ILogger;
+use OCP\IUser;
+use OCP\IUserSession;
class Hooks {
/** @var IManager */
protected $activityManager;
+ /** @var IUserSession */
+ protected $userSession;
+
+ /** @var ILogger */
+ protected $logger;
+
/** @var ITimeFactory */
protected $timeFactory;
/**
* @param IManager $activityManager
+ * @param IUserSession $userSession
+ * @param ILogger $logger
* @param ITimeFactory $timeFactory
*/
- public function __construct(IManager $activityManager, ITimeFactory $timeFactory) {
+ public function __construct(IManager $activityManager, IUserSession $userSession, ILogger $logger, ITimeFactory $timeFactory) {
$this->activityManager = $activityManager;
+ $this->userSession = $userSession;
+ $this->logger = $logger;
$this->timeFactory = $timeFactory;
}
+ /**
+ * Mark the user as (in)active for a call
+ *
+ * @param Room $room
+ * @param bool $isGuest
+ */
public function setActive(Room $room, $isGuest) {
$room->setActiveSince(new \DateTime(), $isGuest);
}
+ /**
+ * Call activity: "You attended a call with {user1} and {user2}"
+ *
+ * @param Room $room
+ * @return bool True if activity was generated, false otherwise
+ */
public function generateCallActivity(Room $room) {
$activeSince = $room->getActiveSince();
if (!$activeSince instanceof \DateTime || $room->hasActiveSessions()) {
@@ -63,24 +88,82 @@ class Hooks {
}
$event = $this->activityManager->generateEvent();
- $event->setApp('spreed')
- ->setType('spreed')
- ->setAuthor('')
- ->setObject('room', $room->getId(), $room->getName())
- ->setTimestamp(time())
- ->setSubject('call', [
- 'room' => $room->getId(),
- 'users' => $userIds,
- 'guests' => $room->getActiveGuests(),
- 'duration' => $duration,
- ]);
+ try {
+ $event->setApp('spreed')
+ ->setType('spreed')
+ ->setAuthor('')
+ ->setObject('room', $room->getId(), $room->getName())
+ ->setTimestamp($this->timeFactory->getTime())
+ ->setSubject('call', [
+ 'room' => $room->getId(),
+ 'users' => $userIds,
+ 'guests' => $room->getActiveGuests(),
+ 'duration' => $duration,
+ ]);
+ } catch (\InvalidArgumentException $e) {
+ $this->logger->logException($e, ['app' => 'spreed']);
+ return false;
+ }
foreach ($userIds as $userId) {
- $event->setAffectedUser($userId);
- $this->activityManager->publish($event);
+ try {
+ $event->setAffectedUser($userId);
+ $this->activityManager->publish($event);
+ } catch (\BadMethodCallException $e) {
+ $this->logger->logException($e, ['app' => 'spreed']);
+ } catch (\InvalidArgumentException $e) {
+ $this->logger->logException($e, ['app' => 'spreed']);
+ }
}
$room->resetActiveSince();
+ return true;
}
+ /**
+ * Invitation activity: "{actor} invited you to {call}"
+ *
+ * @param Room $room
+ * @param array[] $participants
+ */
+ public function generateInvitationActivity(Room $room, array $participants) {
+ $actor = $this->userSession->getUser();
+ if (!$actor instanceof IUser) {
+ return;
+ }
+ $actorId = $actor->getUID();
+
+ $event = $this->activityManager->generateEvent();
+ try {
+ $event->setApp('spreed')
+ ->setType('spreed')
+ ->setAuthor($actorId)
+ ->setObject('room', $room->getId(), $room->getName())
+ ->setTimestamp($this->timeFactory->getTime())
+ ->setSubject('invitation', [
+ 'user' => $actor->getUID(),
+ 'room' => $room->getId(),
+ 'name' => $room->getName(),
+ ]);
+ } catch (\InvalidArgumentException $e) {
+ $this->logger->logException($e, ['app' => 'spreed']);
+ return;
+ }
+
+ foreach ($participants as $participant) {
+ if ($actorId === $participant['userId']) {
+ // No activity for self-joining and the creator
+ continue;
+ }
+
+ try {
+ $event->setAffectedUser($participant['userId']);
+ $this->activityManager->publish($event);
+ } catch (\InvalidArgumentException $e) {
+ $this->logger->logException($e, ['app' => 'spreed']);
+ } catch (\BadMethodCallException $e) {
+ $this->logger->logException($e, ['app' => 'spreed']);
+ }
+ }
+ }
}