Skip to content

Commit bf5f69c

Browse files
committed
Provide information for incoming call screens
Signed-off-by: Joas Schilling <[email protected]>
1 parent dd0e81c commit bf5f69c

File tree

10 files changed

+107
-8
lines changed

10 files changed

+107
-8
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
1616
1717
]]></description>
1818

19-
<version>12.0.0-dev.2</version>
19+
<version>12.0.0-dev.3</version>
2020
<licence>agpl</licence>
2121

2222
<author>Daniel Calviño Sánchez</author>

lib/Activity/Listener.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use OCA\Talk\Events\ModifyParticipantEvent;
2929
use OCA\Talk\Events\RoomEvent;
3030
use OCA\Talk\Model\Attendee;
31+
use OCA\Talk\Participant;
3132
use OCA\Talk\Room;
3233
use OCA\Talk\Service\ParticipantService;
3334
use OCP\Activity\IManager;
@@ -75,7 +76,7 @@ public static function register(IEventDispatcher $dispatcher): void {
7576
$listener = static function (ModifyParticipantEvent $event) {
7677
/** @var self $listener */
7778
$listener = \OC::$server->query(self::class);
78-
$listener->setActive($event->getRoom());
79+
$listener->setActive($event->getRoom(), $event->getParticipant());
7980
};
8081
$dispatcher->addListener(Room::EVENT_AFTER_SESSION_JOIN_CALL, $listener);
8182

@@ -97,8 +98,12 @@ public static function register(IEventDispatcher $dispatcher): void {
9798
$dispatcher->addListener(Room::EVENT_AFTER_USERS_ADD, $listener);
9899
}
99100

100-
public function setActive(Room $room): void {
101-
$room->setActiveSince($this->timeFactory->getDateTime(), !$this->userSession->isLoggedIn());
101+
public function setActive(Room $room, Participant $participant): void {
102+
$room->setActiveSince(
103+
$this->timeFactory->getDateTime(),
104+
$participant->getSession() ? $participant->getSession()->getInCall() : Participant::FLAG_DISCONNECTED,
105+
$participant->getAttendee()->getActorType() !== Attendee::ACTOR_USERS
106+
);
102107
}
103108

104109
/**

lib/Controller/RoomController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ protected function formatRoomV2andV3(Room $room, ?Participant $currentParticipan
586586
'description' => '',
587587
'lastCommonReadMessage' => 0,
588588
'listable' => Room::LISTABLE_NONE,
589+
'callFlag' => Participant::FLAG_DISCONNECTED,
589590
]);
590591
}
591592

@@ -614,6 +615,7 @@ protected function formatRoomV2andV3(Room $room, ?Participant $currentParticipan
614615
'readOnly' => $room->getReadOnly(),
615616
'hasCall' => $room->getActiveSince() instanceof \DateTimeInterface,
616617
'lastActivity' => $lastActivity,
618+
'callFlag' => $room->getCallFlag(),
617619
'lobbyState' => $room->getLobbyState(),
618620
'lobbyTimer' => $lobbyTimer,
619621
'sipEnabled' => $room->getSIPEnabled(),
@@ -637,6 +639,7 @@ protected function formatRoomV2andV3(Room $room, ?Participant $currentParticipan
637639
'readOnly' => $room->getReadOnly(),
638640
'hasCall' => $room->getActiveSince() instanceof \DateTimeInterface,
639641
'lastActivity' => $lastActivity,
642+
'callFlag' => $room->getCallFlag(),
640643
'isFavorite' => $attendee->isFavorite(),
641644
'notificationLevel' => $attendee->getNotificationLevel(),
642645
'lobbyState' => $room->getLobbyState(),

lib/Manager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public function createRoomObject(array $row): Room {
187187
(string) $row['description'],
188188
(string) $row['password'],
189189
(int) $row['active_guests'],
190+
(int) $row['call_flag'],
190191
$activeSince,
191192
$lastActivity,
192193
(int) $row['last_message'],
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2021, Joas Schilling <[email protected]>
6+
*
7+
* @author Joas Schilling <[email protected]>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
namespace OCA\Talk\Migration;
27+
28+
use Closure;
29+
use Doctrine\DBAL\Types\Types;
30+
use OCP\DB\ISchemaWrapper;
31+
use OCP\Migration\IOutput;
32+
use OCP\Migration\SimpleMigrationStep;
33+
34+
class Version11001Date20210211111527 extends SimpleMigrationStep {
35+
/**
36+
* @param IOutput $output
37+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
38+
* @param array $options
39+
* @return null|ISchemaWrapper
40+
*/
41+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
42+
/** @var ISchemaWrapper $schema */
43+
$schema = $schemaClosure();
44+
45+
$table = $schema->getTable('talk_rooms');
46+
if (!$table->hasColumn('call_flag')) {
47+
$table->addColumn('call_flag', Types::INTEGER, [
48+
'default' => 0,
49+
]);
50+
return $schema;
51+
}
52+
return null;
53+
}
54+
}

lib/Model/SelectHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function selectRoomsTable(IQueryBuilder $query, string $alias = 'r'): voi
4242
->addSelect($alias . 'password')
4343
->addSelect($alias . 'active_guests')
4444
->addSelect($alias . 'active_since')
45+
->addSelect($alias . 'call_flag')
4546
->addSelect($alias . 'last_activity')
4647
->addSelect($alias . 'last_message')
4748
->addSelect($alias . 'lobby_timer')

lib/Room.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ class Room {
168168
private $password;
169169
/** @var int */
170170
private $activeGuests;
171+
/** @var int */
172+
private $callFlag;
171173
/** @var \DateTime|null */
172174
private $activeSince;
173175
/** @var \DateTime|null */
@@ -204,6 +206,7 @@ public function __construct(Manager $manager,
204206
string $description,
205207
string $password,
206208
int $activeGuests,
209+
int $callFlag,
207210
\DateTime $activeSince = null,
208211
\DateTime $lastActivity = null,
209212
int $lastMessageId,
@@ -229,6 +232,7 @@ public function __construct(Manager $manager,
229232
$this->description = $description;
230233
$this->password = $password;
231234
$this->activeGuests = $activeGuests;
235+
$this->callFlag = $callFlag;
232236
$this->activeSince = $activeSince;
233237
$this->lastActivity = $lastActivity;
234238
$this->lastMessageId = $lastMessageId;
@@ -318,6 +322,10 @@ public function getActiveGuests(): int {
318322
return $this->activeGuests;
319323
}
320324

325+
public function getCallFlag(): int {
326+
return $this->callFlag;
327+
}
328+
321329
public function getActiveSince(): ?\DateTime {
322330
return $this->activeSince;
323331
}
@@ -662,18 +670,32 @@ public function setLastActivity(\DateTime $now): bool {
662670

663671
/**
664672
* @param \DateTime $since
673+
* @param int $callFlag
665674
* @param bool $isGuest
666675
* @return bool
667676
*/
668-
public function setActiveSince(\DateTime $since, bool $isGuest): bool {
677+
public function setActiveSince(\DateTime $since, int $callFlag, bool $isGuest): bool {
669678
if ($isGuest && $this->getType() === self::PUBLIC_CALL) {
670679
$query = $this->db->getQueryBuilder();
671680
$query->update('talk_rooms')
672681
->set('active_guests', $query->createFunction($query->getColumnName('active_guests') . ' + 1'))
682+
->set(
683+
'call_flag',
684+
$query->expr()->bitwiseOr('call_flag', $callFlag)
685+
)
673686
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
674687
$query->execute();
675688

676689
$this->activeGuests++;
690+
} elseif (!$isGuest) {
691+
$query = $this->db->getQueryBuilder();
692+
$query->update('talk_rooms')
693+
->set(
694+
'call_flag',
695+
$query->expr()->bitwiseOr('call_flag', $callFlag)
696+
)
697+
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
698+
$query->execute();
677699
}
678700

679701
if ($this->activeSince instanceof \DateTime) {
@@ -682,7 +704,7 @@ public function setActiveSince(\DateTime $since, bool $isGuest): bool {
682704

683705
$query = $this->db->getQueryBuilder();
684706
$query->update('talk_rooms')
685-
->set('active_since', $query->createNamedParameter($since, 'datetime'))
707+
->set('active_since', $query->createNamedParameter($since, IQueryBuilder::PARAM_DATE))
686708
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
687709
->andWhere($query->expr()->isNull('active_since'));
688710
$query->execute();
@@ -703,8 +725,9 @@ public function setLastMessage(IComment $message): void {
703725
public function resetActiveSince(): bool {
704726
$query = $this->db->getQueryBuilder();
705727
$query->update('talk_rooms')
706-
->set('active_guests', $query->createNamedParameter(0))
707-
->set('active_since', $query->createNamedParameter(null, 'datetime'))
728+
->set('active_guests', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
729+
->set('active_since', $query->createNamedParameter(null, IQueryBuilder::PARAM_DATE))
730+
->set('call_flag', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
708731
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
709732
->andWhere($query->expr()->isNotNull('active_since'));
710733

tests/integration/features/bootstrap/FeatureContext.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ private function assertRooms($rooms, TableNode $formData) {
270270
if (isset($expectedRoom['sipEnabled'])) {
271271
$data['sipEnabled'] = (string) $room['sipEnabled'];
272272
}
273+
if (isset($expectedRoom['callFlag'])) {
274+
$data['callFlag'] = (int) $room['callFlag'];
275+
}
273276
if (isset($expectedRoom['attendeePin'])) {
274277
$data['attendeePin'] = $room['attendeePin'] ? '**PIN**' : '';
275278
}

tests/integration/features/callapi/group.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@ Feature: callapi/group
2323
Then user "participant1" sees 0 peers in call "room" with 200
2424
And user "participant2" sees 0 peers in call "room" with 200
2525
Then user "participant1" joins call "room" with 200
26+
| flags | 1 |
2627
Then user "participant1" sees 1 peers in call "room" with 200
2728
And user "participant2" sees 1 peers in call "room" with 200
29+
Then user "participant1" is participant of the following rooms (v3)
30+
| id | type | callFlag |
31+
| room | 2 | 1 |
2832
Then user "participant2" joins room "room" with 200
2933
Then user "participant1" sees 1 peers in call "room" with 200
3034
And user "participant2" sees 1 peers in call "room" with 200
3135
And user "participant2" joins call "room" with 200
3236
Then user "participant1" sees 2 peers in call "room" with 200
3337
And user "participant2" sees 2 peers in call "room" with 200
38+
Then user "participant1" is participant of the following rooms (v3)
39+
| id | type | callFlag |
40+
| room | 2 | 7 |
3441
Then user "participant1" leaves call "room" with 200
3542
Then user "participant1" sees 1 peers in call "room" with 200
3643
And user "participant2" sees 1 peers in call "room" with 200

tests/php/RoomTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use OC\EventDispatcher\EventDispatcher;
2626
use OCA\Talk\Events\VerifyRoomPasswordEvent;
2727
use OCA\Talk\Manager;
28+
use OCA\Talk\Participant;
2829
use OCA\Talk\Room;
2930
use OCA\Talk\Webinary;
3031
use OCP\AppFramework\Utility\ITimeFactory;
@@ -72,6 +73,7 @@ public function testVerifyPassword() {
7273
'description',
7374
'passy',
7475
0,
76+
Participant::FLAG_DISCONNECTED,
7577
null,
7678
null,
7779
0

0 commit comments

Comments
 (0)