Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove room information for users which are not a participant #1502

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/Controller/CallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
use OCP\IUserManager;

class CallController extends OCSController {
/** @var string */
Expand All @@ -48,14 +47,12 @@ class CallController extends OCSController {
* @param string $appName
* @param string $UserId
* @param IRequest $request
* @param IUserManager $userManager
* @param TalkSession $session
* @param Manager $manager
*/
public function __construct($appName,
$UserId,
IRequest $request,
IUserManager $userManager,
TalkSession $session,
Manager $manager) {
parent::__construct($appName, $request);
Expand Down
103 changes: 46 additions & 57 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,9 @@ class RoomController extends OCSController {
private $chatManager;
/** @var MessageParser */
private $messageParser;
/** @var IMailer */
private $mailer;
/** @var IL10N */
private $l10n;

/**
* @param string $appName
* @param string $UserId
* @param IRequest $request
* @param TalkSession $session
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param ILogger $logger
* @param Manager $manager
* @param GuestManager $guestManager
* @param ChatManager $chatManager
* @param MessageParser $messageParser
* @param IMailer $mailer
* @param IL10N $l10n
*/
public function __construct($appName,
$UserId,
IRequest $request,
Expand All @@ -100,7 +83,6 @@ public function __construct($appName,
GuestManager $guestManager,
ChatManager $chatManager,
MessageParser $messageParser,
IMailer $mailer,
IL10N $l10n) {
parent::__construct($appName, $request);
$this->session = $session;
Expand All @@ -112,7 +94,6 @@ public function __construct($appName,
$this->guestManager = $guestManager;
$this->chatManager = $chatManager;
$this->messageParser = $messageParser;
$this->mailer = $mailer;
$this->l10n = $l10n;
}

Expand Down Expand Up @@ -171,45 +152,26 @@ public function getRoom($token): DataResponse {
* @throws RoomNotFoundException
*/
protected function formatRoom(Room $room, Participant $currentParticipant = null): array {

if ($currentParticipant instanceof Participant) {
$participantType = $currentParticipant->getParticipantType();
$participantFlags = $currentParticipant->getInCallFlags();
$favorite = $currentParticipant->isFavorite();
} else {
$participantType = Participant::GUEST;
$participantFlags = Participant::FLAG_DISCONNECTED;
$favorite = false;
}
$participantInCall = ($participantFlags & Participant::FLAG_IN_CALL) !== 0;

$lastActivity = $room->getLastActivity();
if ($lastActivity instanceof \DateTimeInterface) {
$lastActivity = $lastActivity->getTimestamp();
} else {
$lastActivity = 0;
}

$roomData = [
'id' => $room->getId(),
'token' => $room->getToken(),
'type' => $room->getType(),
'name' => $room->getName(),
'displayName' => $room->getName(),
'objectType' => $room->getObjectType(),
'objectId' => $room->getObjectId(),
'participantType' => $participantType,
'name' => '',
'displayName' => '',
'objectType' => '',
'objectId' => '',
'participantType' => Participant::GUEST,
// Deprecated, use participantFlags instead.
'participantInCall' => $participantInCall,
'participantFlags' => $participantFlags,
'count' => $room->getNumberOfParticipants(false, time() - 30),
'participantInCall' => false,
'participantFlags' => Participant::FLAG_DISCONNECTED,
'count' => 0,
'hasPassword' => $room->hasPassword(),
'hasCall' => $room->getActiveSince() instanceof \DateTimeInterface,
'lastActivity' => $lastActivity,
'hasCall' => false,
'lastActivity' => 0,
'unreadMessages' => 0,
'unreadMention' => false,
'isFavorite' => $favorite,
'notificationLevel' => $room->getType() === Room::ONE_TO_ONE_CALL ? Participant::NOTIFY_ALWAYS : Participant::NOTIFY_MENTION,
'isFavorite' => false,
'notificationLevel' => Participant::NOTIFY_NEVER,
'lastPing' => 0,
'sessionId' => '0',
'participants' => [],
Expand All @@ -222,16 +184,43 @@ protected function formatRoom(Room $room, Participant $currentParticipant = null
return $roomData;
}

if ($currentParticipant->getNotificationLevel() !== Participant::NOTIFY_DEFAULT) {
$roomData['notificationLevel'] = $currentParticipant->getNotificationLevel();
$lastActivity = $room->getLastActivity();
if ($lastActivity instanceof \DateTimeInterface) {
$lastActivity = $lastActivity->getTimestamp();
} else {
$lastActivity = 0;
}

$roomData = array_merge($roomData, [
'name' => $room->getName(),
'displayName' => $room->getName(),
'objectType' => $room->getObjectType(),
'objectId' => $room->getObjectId(),
'participantType' => $currentParticipant->getParticipantType(),
// Deprecated, use participantFlags instead.
'participantInCall' => ($currentParticipant->getInCallFlags() & Participant::FLAG_IN_CALL) !== 0,
'participantFlags' => $currentParticipant->getInCallFlags(),
'count' => $room->getNumberOfParticipants(false, time() - 30),
'hasCall' => $room->getActiveSince() instanceof \DateTimeInterface,
'lastActivity' => $lastActivity,
'isFavorite' => $currentParticipant->isFavorite(),
'notificationLevel' => $currentParticipant->getNotificationLevel(),
]);

if ($roomData['notificationLevel'] === Participant::NOTIFY_DEFAULT) {
if ($currentParticipant->isGuest()) {
$roomData['notificationLevel'] = Participant::NOTIFY_NEVER;
} else {
$roomData['notificationLevel'] = $room->getType() === Room::ONE_TO_ONE_CALL ? Participant::NOTIFY_ALWAYS : Participant::NOTIFY_MENTION;
}
}

if ($room->getObjectType() === 'share:password') {
// FIXME use an event
$roomData['displayName'] = $this->l10n->t('Password request: %s', [$room->getName()]);
}

$currentUser = $this->userManager->get($this->userId);
$currentUser = $this->userManager->get($currentParticipant->getUser());
if ($currentUser instanceof IUser) {
$unreadSince = $this->chatManager->getUnreadMarker($room, $currentUser);
if ($currentParticipant instanceof Participant) {
Expand Down Expand Up @@ -292,8 +281,8 @@ protected function formatRoom(Room $room, Participant $currentParticipant = null
'lastMessage' => $lastMessage,
]);

if ($this->userId !== null) {
unset($participantList[$this->userId]);
if (!$currentParticipant->isGuest()) {
unset($participantList[$currentParticipant->getUser()]);
$numOtherParticipants = \count($participantList);
$numGuestParticipants = $numActiveGuests;
} else {
Expand Down Expand Up @@ -321,7 +310,7 @@ protected function formatRoom(Room $room, Participant $currentParticipant = null

/** @noinspection PhpMissingBreakStatementInspection */
case Room::PUBLIC_CALL:
if ($this->userId === null && $numGuestParticipants) {
if ($currentParticipant->isGuest() && $numGuestParticipants) {
$guestString = $this->l10n->n('%n other guest', '%n other guests', $numGuestParticipants);
} else if ($numGuestParticipants) {
$guestString = $this->l10n->n('%n guest', '%n guests', $numGuestParticipants);
Expand All @@ -335,7 +324,7 @@ protected function formatRoom(Room $room, Participant $currentParticipant = null
$participantList = array_map(function($participant) {
return $participant['name'];
}, $participantList);
if ($this->userId === null) {
if ($currentParticipant->isGuest()) {
$participantList[] = $this->l10n->t('You');
} else if ($numOtherParticipants === 0) {
$participantList = [$this->l10n->t('You')];
Expand Down
5 changes: 0 additions & 5 deletions tests/php/Controller/RoomControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\Mail\IMailer;

class RoomControllerTest extends \Test\TestCase {

Expand All @@ -62,8 +61,6 @@ class RoomControllerTest extends \Test\TestCase {
protected $guestManager;
/** @var MessageParser|\PHPUnit_Framework_MockObject_MockObject */
protected $messageParser;
/** @var IMailer|\PHPUnit_Framework_MockObject_MockObject */
protected $mailer;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l;

Expand All @@ -80,7 +77,6 @@ public function setUp() {
$this->guestManager = $this->createMock(GuestManager::class);
$this->chatManager = $this->createMock(ChatManager::class);
$this->messageParser = $this->createMock(MessageParser::class);
$this->mailer = $this->createMock(IMailer::class);
$this->l = $this->createMock(IL10N::class);
}

Expand All @@ -97,7 +93,6 @@ private function getController() {
$this->guestManager,
$this->chatManager,
$this->messageParser,
$this->mailer,
$this->l
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Signaling/BackendNotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function clearRequests() {
$this->requests = [];
}

protected function doRequest($url, $params) {
protected function doRequest(string $url, array $params) {
$this->requests[] = [
'url' => $url,
'params' => $params,
Expand Down