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:
authorGary Kim <gary@garykim.dev>2021-08-28 00:20:37 +0300
committerGary Kim <gary@garykim.dev>2021-09-21 19:00:11 +0300
commitabbe54696315d1f5b778d4cf3176a23f3a162986 (patch)
treedc5c1eeef5f227e60a227fc4ea080d4b6c1d60f2 /lib/Service
parenta3cd8312a28942cda4260892f442834d41d66e54 (diff)
Review fixes
Signed-off-by: Gary Kim <gary@garykim.dev>
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/ParticipantService.php37
1 files changed, 29 insertions, 8 deletions
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php
index a4d9a0535..7a8d84c25 100644
--- a/lib/Service/ParticipantService.php
+++ b/lib/Service/ParticipantService.php
@@ -311,6 +311,7 @@ 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, ?IUser $addedBy = null): void {
if (empty($participants)) {
@@ -331,7 +332,7 @@ class ParticipantService {
$readPrivacy = $this->talkConfig->getUserReadPrivacy($participant['actorId']);
} elseif ($participant['actorType'] === Attendee::ACTOR_FEDERATED_USERS) {
if ($addedBy === null) {
- continue;
+ throw new \Exception('$addedBy must be set to add a federated user');
}
$participant['accessToken'] = $this->secureRandom->generate(
FederationManager::TOKEN_LENGTH,
@@ -356,17 +357,17 @@ 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;
}
}
-
- if ($attendee->getActorType() === Attendee::ACTOR_FEDERATED_USERS) {
- $this->sendRemoteShare($room, $addedBy, $participant['actorId'], $participant['accessToken'], $entity->getId());
- }
}
if (!empty($attendees)) {
@@ -377,8 +378,28 @@ class ParticipantService {
}
}
- private function sendRemoteShare(Room $room, IUser $addedBy, string $addingUserId, string $token, int $attendeeId) {
- $this->notifications->sendRemoteShare((string) $attendeeId, $token, $addingUserId, $addedBy->getDisplayName(), $addedBy->getCloudId(), 'user', $room);
+ 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;
}
/**