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:
authorCarl Schwan <carl@carlschwan.eu>2021-08-12 19:31:51 +0300
committerCarl Schwan <carl@carlschwan.eu>2021-10-19 00:44:32 +0300
commit0498353a9d121c6c691870f53c56f267103d1f1c (patch)
tree2881cb1b158b23e956dbb395d043419b877302b6 /lib/Status
parent40df0cd7a94ad85730db7e689d2af23541af3a60 (diff)
Add automatic status change feature
The status is of a type "away" with a message that the user is in a call. Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib/Status')
-rw-r--r--lib/Status/Listener.php68
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/Status/Listener.php b/lib/Status/Listener.php
new file mode 100644
index 000000000..fa9346542
--- /dev/null
+++ b/lib/Status/Listener.php
@@ -0,0 +1,68 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Talk\Status;
+
+use OCA\Talk\Events\ModifyParticipantEvent;
+use OCA\Talk\Room;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IUserSession;
+use OCP\UserStatus\IManager;
+use OCP\UserStatus\IUserStatus;
+
+class Listener {
+ /** @var IUserSession */
+ public $userSession;
+
+ /** @var IManager $statusManager */
+ public $statusManager;
+
+ public function __construct(IUserSession $userSession, IManager $statusManager) {
+ $this->userSession = $userSession;
+ $this->statusManager = $statusManager;
+ }
+
+ public static function register(IEventDispatcher $dispatcher): void {
+ $dispatcher->addListener(Room::EVENT_BEFORE_SESSION_JOIN_CALL, static function (ModifyParticipantEvent $event) {
+ // Inject self with $server->get since otherwise we get an error that $this is not available in this context
+
+ /** @var \OCA\Talk\Chat\SystemMessage\Listener $listener */
+ $listener = \OC::$server->get(self::class);
+
+ $user = $listener->userSession->getUser();
+ if ($user !== null) {
+ $listener->statusManager->setUserStatus($listener->userSession->getUser()->getUID(), 'call', IUserStatus::AWAY, true);
+ }
+ });
+
+ $dispatcher->addListener(Room::EVENT_AFTER_SESSION_LEAVE_CALL, static function (ModifyParticipantEvent $event) {
+ /** @var \OCA\Talk\Chat\SystemMessage\Listener $listener */
+ $listener = \OC::$server->get(self::class);
+
+ $user = $listener->userSession->getUser();
+ if ($user !== null) {
+ $listener->statusManager->revertUserStatus($listener->userSession->getUser()->getUID(), 'call', IUserStatus::AWAY);
+ }
+ });
+ }
+}