Skip to content

Commit

Permalink
Merge pull request #2945 from nextcloud/backport/2942/stable18
Browse files Browse the repository at this point in the history
[stable18] Send the notifications after joining the call
  • Loading branch information
nickvergessen authored Feb 14, 2020
2 parents 9a16455 + 9fe2d46 commit 7c8cb1f
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions lib/Notification/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class Listener {
/** @var ILogger */
protected $logger;

/** @var bool */
protected $shouldSendCallNotification = false;

public function __construct(IManager $notificationManager,
IUserSession $userSession,
ITimeFactory $timeFactory,
Expand Down Expand Up @@ -78,10 +81,17 @@ public static function register(IEventDispatcher $dispatcher): void {
$listener = static function(RoomEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
$listener->generateCallNotifications($event->getRoom());
$listener->checkCallNotifications($event->getRoom());
};
$dispatcher->addListener(Room::EVENT_BEFORE_SESSION_JOIN_CALL, $listener);

$listener = static function(RoomEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
$listener->sendCallNotifications($event->getRoom());
};
$dispatcher->addListener(Room::EVENT_AFTER_SESSION_JOIN_CALL, $listener);

$listener = static function(RoomEvent $event) {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
Expand Down Expand Up @@ -161,13 +171,28 @@ public function markInvitationRead(Room $room): void {
*
* @param Room $room
*/
public function generateCallNotifications(Room $room): void {
public function checkCallNotifications(Room $room): void {
if ($room->getActiveSince() instanceof \DateTime) {
// Call already active => No new notifications
$this->shouldSendCallNotification = false;
return;
}

if ($room->getObjectType() === 'file') {
$this->shouldSendCallNotification = false;
return;
}

$this->shouldSendCallNotification = true;
}

/**
* Call notification: "{user} wants to talk with you"
*
* @param Room $room
*/
public function sendCallNotifications(Room $room): void {
if (!$this->shouldSendCallNotification) {
return;
}

Expand Down

0 comments on commit 7c8cb1f

Please sign in to comment.