summaryrefslogtreecommitdiffstats
path: root/lib/Federation/CloudFederationProviderTalk.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-10-24 17:44:39 +0200
committerJoas Schilling <coding@schilljs.com>2023-10-30 17:27:05 +0100
commitfc8734a59350e58d840b112b9948bb44c6afdacc (patch)
tree83e777d902f6357c4a496ca24a98b86d4c994c54 /lib/Federation/CloudFederationProviderTalk.php
parentec8eb42fe3ef5d0f0247a3fd078099e49d0140c3 (diff)
fix(federation): Make invitations force unique based on remote server and attendee id
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Federation/CloudFederationProviderTalk.php')
-rw-r--r--lib/Federation/CloudFederationProviderTalk.php33
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/Federation/CloudFederationProviderTalk.php b/lib/Federation/CloudFederationProviderTalk.php
index 877ae3f47..bb53ca76f 100644
--- a/lib/Federation/CloudFederationProviderTalk.php
+++ b/lib/Federation/CloudFederationProviderTalk.php
@@ -29,6 +29,7 @@ use Exception;
use OCA\FederatedFileSharing\AddressHandler;
use OCA\Talk\AppInfo\Application;
use OCA\Talk\Config;
+use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Events\ARoomModifiedEvent;
use OCA\Talk\Events\AttendeesAddedEvent;
use OCA\Talk\Manager;
@@ -134,10 +135,10 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
throw new ProviderCouldNotAddShareException('User does not exist', '', Http::STATUS_BAD_REQUEST);
}
- $shareId = (string) $this->federationManager->addRemoteRoom($shareWith, $remoteId, $roomType, $roomName, $roomToken, $remote, $shareSecret);
+ $invite = $this->federationManager->addRemoteRoom($shareWith, (int) $remoteId, $roomType, $roomName, $roomToken, $remote, $shareSecret);
- $this->notifyAboutNewShare($shareWith, $shareId, $sharedByFederatedId, $sharedBy, $roomName, $roomToken, $remote);
- return $shareId;
+ $this->notifyAboutNewShare($shareWith, (string) $invite->getId(), $sharedByFederatedId, $sharedBy, $roomName, $roomToken, $remote);
+ return (string) $invite->getId();
}
$this->logger->debug('Received a federation invite with missing request data');
@@ -202,7 +203,7 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
$room = $this->manager->getRoomById($attendee->getRoomId());
$participant = new Participant($room, $attendee, null);
- $this->participantService->removeAttendee($room, $participant, Room::PARTICIPANT_LEFT);
+ $this->participantService->removeAttendee($room, $participant, AAttendeeRemovedEvent::REASON_LEFT);
$this->session->remove('talk-overwrite-actor-type');
$this->session->remove('talk-overwrite-actor-id');
@@ -218,7 +219,11 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
private function shareUnshared(int $id, array $notification): array {
$attendee = $this->getRemoteAttendeeAndValidate($id, $notification['sharedSecret']);
- $room = $this->manager->getRoomById($attendee->getRoomId());
+ if ($attendee instanceof Attendee) {
+ $room = $this->manager->getRoomById($attendee->getRoomId());
+ } else {
+ $room = $this->manager->getRoomById($attendee->getLocalRoomId());
+ }
// Sanity check to make sure the room is a remote room
if (!$room->isFederatedRemoteRoom()) {
@@ -226,7 +231,7 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
}
$participant = new Participant($room, $attendee, null);
- $this->participantService->removeAttendee($room, $participant, Room::PARTICIPANT_REMOVED);
+ $this->participantService->removeAttendee($room, $participant, AAttendeeRemovedEvent::REASON_REMOVED);
return [];
}
@@ -242,7 +247,11 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
private function roomModified(int $remoteAttendeeId, array $notification): array {
$attendee = $this->getRemoteAttendeeAndValidate($remoteAttendeeId, $notification['sharedSecret']);
- $room = $this->manager->getRoomById($attendee->getRoomId());
+ if ($attendee instanceof Attendee) {
+ $room = $this->manager->getRoomById($attendee->getRoomId());
+ } else {
+ $room = $this->manager->getRoomById($attendee->getLocalRoomId());
+ }
// Sanity check to make sure the room is a remote room
if (!$room->isFederatedRemoteRoom()) {
@@ -299,7 +308,7 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
* @throws AuthenticationFailedException
*/
private function getRemoteAttendeeAndValidate(int $id, string $sharedSecret): Attendee|Invitation {
- if (!$this->federationManager->isEnabled()) {
+ if (!$this->config->isFederationEnabled()) {
throw new ActionNotSupportedException('Server does not support Talk federation');
}
@@ -320,18 +329,18 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
}
}
- private function notifyAboutNewShare(IUser $shareWith, string $shareId, string $sharedByFederatedId, string $sharedByName, string $roomName, string $roomToken, string $serverUrl): void {
+ private function notifyAboutNewShare(IUser $shareWith, string $inviteId, string $sharedByFederatedId, string $sharedByName, string $roomName, string $remoteRoomToken, string $remoteServerUrl): void {
$notification = $this->notificationManager->createNotification();
$notification->setApp(Application::APP_ID)
->setUser($shareWith->getUID())
->setDateTime(new \DateTime())
- ->setObject('remote_talk_share', $shareId)
+ ->setObject('remote_talk_share', $inviteId)
->setSubject('remote_talk_share', [
'sharedByDisplayName' => $sharedByName,
'sharedByFederatedId' => $sharedByFederatedId,
'roomName' => $roomName,
- 'serverUrl' => $serverUrl,
- 'roomToken' => $roomToken,
+ 'serverUrl' => $remoteServerUrl,
+ 'roomToken' => $remoteRoomToken,
]);
$this->notificationManager->notify($notification);