diff options
author | Joas Schilling <coding@schilljs.com> | 2018-10-01 16:01:57 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2018-10-08 16:26:45 +0300 |
commit | ee894cc5cd93bf14c15904daec212dfeee378ac8 (patch) | |
tree | 3703a1d116a4e2b73313a616bc2cebe81524e08f /lib/Participant.php | |
parent | 0b017630462d42f8261d81611abe8f3b12056b1b (diff) |
Introduce notification levels for participants
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Participant.php')
-rw-r--r-- | lib/Participant.php | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/lib/Participant.php b/lib/Participant.php index 8b424cb44..fef5850ee 100644 --- a/lib/Participant.php +++ b/lib/Participant.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace OCA\Spreed; -use OCA\Spreed\Exceptions\ParticipantNotFoundException; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; @@ -41,6 +40,11 @@ class Participant { const FLAG_WITH_AUDIO = 2; const FLAG_WITH_VIDEO = 4; + const NOTIFY_DEFAULT = 0; + const NOTIFY_ALWAYS = 1; + const NOTIFY_MENTION = 2; + const NOTIFY_NEVER = 3; + /** @var IDBConnection */ protected $db; /** @var Room */ @@ -55,12 +59,14 @@ class Participant { protected $sessionId; /** @var int */ protected $inCall; + /** @var int */ + protected $notificationLevel; /** @var bool */ private $isFavorite; /** @var \DateTime|null */ private $lastMention; - public function __construct(IDBConnection $db, Room $room, string $user, int $participantType, int $lastPing, string $sessionId, int $inCall, bool $isFavorite, \DateTime $lastMention = null) { + public function __construct(IDBConnection $db, Room $room, string $user, int $participantType, int $lastPing, string $sessionId, int $inCall, int $notificationLevel, bool $isFavorite, \DateTime $lastMention = null) { $this->db = $db; $this->room = $room; $this->user = $user; @@ -68,6 +74,7 @@ class Participant { $this->lastPing = $lastPing; $this->sessionId = $sessionId; $this->inCall = $inCall; + $this->notificationLevel = $notificationLevel; $this->isFavorite = $isFavorite; $this->lastMention = $lastMention; } @@ -130,4 +137,32 @@ class Participant { $this->isFavorite = $favor; return true; } + + public function getNotificationLevel(): int { + return $this->notificationLevel; + } + + public function setNotificationLevel(int $notificationLevel): bool { + if (!$this->user) { + return false; + } + + if (!\in_array($notificationLevel, [ + self::NOTIFY_ALWAYS, + self::NOTIFY_MENTION, + self::NOTIFY_NEVER + ], true)) { + return false; + } + + $query = $this->db->getQueryBuilder(); + $query->update('talk_participants') + ->set('notification_level', $query->createNamedParameter($notificationLevel, IQueryBuilder::PARAM_INT)) + ->where($query->expr()->eq('user_id', $query->createNamedParameter($this->user))) + ->andWhere($query->expr()->eq('room_id', $query->createNamedParameter($this->room->getId()))); + $query->execute(); + + $this->notificationLevel = $notificationLevel; + return true; + } } |