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:
authorVitor Mattos <vitor@php.rio>2021-10-07 17:03:41 +0300
committerVitor Mattos <vitor@php.rio>2021-10-07 17:03:41 +0300
commit4ffd4820b6ea5a94eb5c302d2f7203f267ff56da (patch)
tree2eec1e87a9024566c167fb2e2b48ba8af1402fcd /lib/Service
parenta2e57ab980a419d0f40cf4540b5387d40e65f51a (diff)
parent8431ecd288c04884a9c06920c6c2e094f063658e (diff)
Merge remote-tracking branch 'origin/master' into reduce-psalm-infos
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/ParticipantService.php58
-rw-r--r--lib/Service/RoomService.php4
2 files changed, 54 insertions, 8 deletions
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php
index 89dd94106..90b5712c3 100644
--- a/lib/Service/ParticipantService.php
+++ b/lib/Service/ParticipantService.php
@@ -40,6 +40,8 @@ use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Exceptions\InvalidPasswordException;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\UnauthorizedException;
+use OCA\Talk\Federation\FederationManager;
+use OCA\Talk\Federation\Notifications;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\AttendeeMapper;
use OCA\Talk\Model\SelectHelper;
@@ -57,9 +59,9 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroup;
+use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
-use OCP\IGroupManager;
use OCP\Security\ISecureRandom;
class ParticipantService {
@@ -85,6 +87,8 @@ class ParticipantService {
private $groupManager;
/** @var MembershipService */
private $membershipService;
+ /** @var Notifications */
+ private $notifications;
/** @var ITimeFactory */
private $timeFactory;
@@ -99,6 +103,7 @@ class ParticipantService {
IUserManager $userManager,
IGroupManager $groupManager,
MembershipService $membershipService,
+ Notifications $notifications,
ITimeFactory $timeFactory) {
$this->serverConfig = $serverConfig;
$this->talkConfig = $talkConfig;
@@ -112,6 +117,7 @@ class ParticipantService {
$this->groupManager = $groupManager;
$this->membershipService = $membershipService;
$this->timeFactory = $timeFactory;
+ $this->notifications = $notifications;
}
public function updateParticipantType(Room $room, Participant $participant, int $participantType): void {
@@ -221,7 +227,7 @@ class ParticipantService {
'displayName' => $user->getDisplayName(),
// need to use "USER" here, because "USER_SELF_JOINED" only works for public calls
'participantType' => Participant::USER,
- ]]);
+ ]], $user);
} elseif ($room->getType() === Room::PUBLIC_CALL) {
// User joining a public room, without being invited
$this->addUsers($room, [[
@@ -229,7 +235,7 @@ class ParticipantService {
'actorId' => $user->getUID(),
'displayName' => $user->getDisplayName(),
'participantType' => Participant::USER_SELF_JOINED,
- ]]);
+ ]], $user);
} else {
// shouldn't happen unless some code called joinRoom without previous checks
throw new UnauthorizedException('Participant is not allowed to join');
@@ -304,8 +310,10 @@ class ParticipantService {
/**
* @param Room $room
* @param array $participants
+ * @param IUser|null $addedBy User that is attempting to add these users (must be set for federated users to be added)
+ * @throws \Exception thrown if $addedBy is not set when adding a federated user
*/
- public function addUsers(Room $room, array $participants): void {
+ public function addUsers(Room $room, array $participants, ?IUser $addedBy = null): void {
if (empty($participants)) {
return;
}
@@ -322,6 +330,14 @@ class ParticipantService {
$readPrivacy = Participant::PRIVACY_PUBLIC;
if ($participant['actorType'] === Attendee::ACTOR_USERS) {
$readPrivacy = $this->talkConfig->getUserReadPrivacy($participant['actorId']);
+ } elseif ($participant['actorType'] === Attendee::ACTOR_FEDERATED_USERS) {
+ if ($addedBy === null) {
+ throw new \Exception('$addedBy must be set to add a federated user');
+ }
+ $participant['accessToken'] = $this->secureRandom->generate(
+ FederationManager::TOKEN_LENGTH,
+ ISecureRandom::CHAR_HUMAN_READABLE
+ );
}
$attendee = new Attendee();
@@ -341,8 +357,12 @@ class ParticipantService {
$attendee->setLastReadMessage($lastMessage);
$attendee->setReadPrivacy($readPrivacy);
try {
- $this->attendeeMapper->insert($attendee);
+ $entity = $this->attendeeMapper->insert($attendee);
$attendees[] = $attendee;
+
+ if ($attendee->getActorType() === Attendee::ACTOR_FEDERATED_USERS) {
+ $this->notifications->sendRemoteShare((string) $entity->getId(), $participant['accessToken'], $participant['actorId'], $addedBy->getDisplayName(), $addedBy->getCloudId(), 'user', $room, $this->getHighestPermissionAttendee($room));
+ }
} catch (Exception $e) {
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
throw $e;
@@ -358,6 +378,30 @@ class ParticipantService {
}
}
+ public function getHighestPermissionAttendee(Room $room): ?Attendee {
+ try {
+ $roomOwners = $this->attendeeMapper->getActorsByParticipantTypes($room->getId(), [Participant::OWNER]);
+
+ if (!empty($roomOwners)) {
+ foreach ($roomOwners as $owner) {
+ if ($owner->getActorType() === Attendee::ACTOR_USERS) {
+ return $owner;
+ }
+ }
+ }
+ $roomModerators = $this->attendeeMapper->getActorsByParticipantTypes($room->getId(), [Participant::MODERATOR]);
+ if (!empty($roomOwners)) {
+ foreach ($roomModerators as $moderator) {
+ if ($moderator->getActorType() === Attendee::ACTOR_USERS) {
+ return $moderator;
+ }
+ }
+ }
+ } catch (Exception $e) {
+ }
+ return null;
+ }
+
/**
* @param Room $room
* @param IGroup $group
@@ -773,7 +817,7 @@ class ParticipantService {
->leftJoin('s', 'talk_attendees', 'a', $query->expr()->eq('s.attendee_id', 'a.id'))
->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('a.actor_type', $query->createNamedParameter(Attendee::ACTOR_GUESTS)))
- ->andWhere($query->expr()->lte('s.last_ping', $query->createNamedParameter($this->timeFactory->getTime() - 100, IQueryBuilder::PARAM_INT)));
+ ->andWhere($query->expr()->lte('s.last_ping', $query->createNamedParameter($this->timeFactory->getTime() - Session::SESSION_TIMEOUT_KILL, IQueryBuilder::PARAM_INT)));
$sessionTableIds = [];
$result = $query->execute();
@@ -1149,6 +1193,7 @@ class ParticipantService {
$query->expr()->andX(
$query->expr()->eq('s.attendee_id', 'a.id'),
$query->expr()->neq('s.in_call', $query->createNamedParameter(Participant::FLAG_DISCONNECTED)),
+ $query->expr()->gte('s.last_ping', $query->createNamedParameter($this->timeFactory->getTime() - Session::SESSION_TIMEOUT, IQueryBuilder::PARAM_INT)),
)
)
->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)))
@@ -1236,6 +1281,7 @@ class ParticipantService {
->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->isNotNull('s.in_call'))
->andWhere($query->expr()->neq('s.in_call', $query->createNamedParameter(Participant::FLAG_DISCONNECTED)))
+ ->andWhere($query->expr()->gte('s.last_ping', $query->createNamedParameter($this->timeFactory->getTime() - Session::SESSION_TIMEOUT, IQueryBuilder::PARAM_INT)))
->setMaxResults(1);
$result = $query->execute();
$row = $result->fetch();
diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php
index 5e1000af7..9667f7193 100644
--- a/lib/Service/RoomService.php
+++ b/lib/Service/RoomService.php
@@ -77,7 +77,7 @@ class RoomService {
'displayName' => $targetUser->getDisplayName(),
'participantType' => Participant::OWNER,
],
- ]);
+ ], $actor);
}
return $room;
@@ -130,7 +130,7 @@ class RoomService {
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $owner->getUID(),
'participantType' => Participant::OWNER,
- ]]);
+ ]], null);
}
return $room;