Skip to content

Commit ff12362

Browse files
Merge pull request #12786 from nextcloud/propagate-lobby-state-to-federated-servers
Propagate lobby state to federated servers
2 parents bdbc05b + 5654e8b commit ff12362

File tree

5 files changed

+124
-11
lines changed

5 files changed

+124
-11
lines changed

lib/AppInfo/Application.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ public function register(IRegistrationContext $context): void {
263263

264264
// Federation listeners
265265
$context->registerEventListener(BeforeRoomDeletedEvent::class, TalkV1BeforeRoomDeletedListener::class);
266+
$context->registerEventListener(LobbyModifiedEvent::class, TalkV1RoomModifiedListener::class);
266267
$context->registerEventListener(RoomModifiedEvent::class, TalkV1RoomModifiedListener::class);
267268
$context->registerEventListener(ChatMessageSentEvent::class, TalkV1MessageSentListener::class);
268269
$context->registerEventListener(SystemMessageSentEvent::class, TalkV1MessageSentListener::class);

lib/Federation/BackendNotifier.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,44 @@ public function sendRoomModifiedUpdate(
240240
return $this->sendUpdateToRemote($remote, $notification);
241241
}
242242

243+
/**
244+
* Send information to remote participants that the lobby was updated
245+
* Sent from Host server to Remote participant server
246+
*/
247+
public function sendRoomModifiedLobbyUpdate(
248+
string $remoteServer,
249+
int $localAttendeeId,
250+
#[SensitiveParameter]
251+
string $accessToken,
252+
string $localToken,
253+
string $changedProperty,
254+
int $newValue,
255+
int $oldValue,
256+
?\DateTime $dateTime,
257+
bool $timerReached,
258+
): ?bool {
259+
$remote = $this->prepareRemoteUrl($remoteServer);
260+
261+
$notification = $this->cloudFederationFactory->getCloudFederationNotification();
262+
$notification->setMessage(
263+
FederationManager::NOTIFICATION_ROOM_MODIFIED,
264+
FederationManager::TALK_ROOM_RESOURCE,
265+
(string) $localAttendeeId,
266+
[
267+
'remoteServerUrl' => $this->getServerRemoteUrl(),
268+
'sharedSecret' => $accessToken,
269+
'remoteToken' => $localToken,
270+
'changedProperty' => $changedProperty,
271+
'newValue' => $newValue,
272+
'oldValue' => $oldValue,
273+
'dateTime' => $dateTime ? (string) $dateTime->getTimestamp() : '',
274+
'timerReached' => $timerReached,
275+
],
276+
);
277+
278+
return $this->sendUpdateToRemote($remote, $notification);
279+
}
280+
243281
/**
244282
* Send information to remote participants that a message was posted
245283
* Sent from Host server to Remote participant server

lib/Federation/CloudFederationProviderTalk.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ private function shareUnshared(int $remoteAttendeeId, array $notification): arra
288288

289289
/**
290290
* @param int $remoteAttendeeId
291-
* @param array{remoteServerUrl: string, sharedSecret: string, remoteToken: string, changedProperty: string, newValue: string|int|bool|null, oldValue: string|int|bool|null} $notification
291+
* @param array{remoteServerUrl: string, sharedSecret: string, remoteToken: string, changedProperty: string, newValue: string|int|bool|null, oldValue: string|int|bool|null, dateTime?: string, timerReached?: bool} $notification
292292
* @return array
293293
* @throws ActionNotSupportedException
294294
* @throws AuthenticationFailedException
@@ -311,6 +311,9 @@ private function roomModified(int $remoteAttendeeId, array $notification): array
311311
$this->roomService->setAvatar($room, $notification['newValue']);
312312
} elseif ($notification['changedProperty'] === ARoomModifiedEvent::PROPERTY_DESCRIPTION) {
313313
$this->roomService->setDescription($room, $notification['newValue']);
314+
} elseif ($notification['changedProperty'] === ARoomModifiedEvent::PROPERTY_LOBBY) {
315+
$dateTime = !empty($notification['dateTime']) ? \DateTime::createFromFormat('U', $notification['dateTime']) : null;
316+
$this->roomService->setLobby($room, $notification['newValue'], $dateTime, $notification['timerReached'] ?? false);
314317
} elseif ($notification['changedProperty'] === ARoomModifiedEvent::PROPERTY_NAME) {
315318
$this->roomService->setName($room, $notification['newValue'], $notification['oldValue']);
316319
} elseif ($notification['changedProperty'] === ARoomModifiedEvent::PROPERTY_READ_ONLY) {

lib/Federation/Proxy/TalkV1/Notifier/RoomModifiedListener.php

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
namespace OCA\Talk\Federation\Proxy\TalkV1\Notifier;
1010

1111
use OCA\Talk\Events\AAttendeeRemovedEvent;
12+
use OCA\Talk\Events\ALobbyModifiedEvent;
1213
use OCA\Talk\Events\ARoomModifiedEvent;
14+
use OCA\Talk\Events\LobbyModifiedEvent;
1315
use OCA\Talk\Events\RoomModifiedEvent;
1416
use OCA\Talk\Federation\BackendNotifier;
1517
use OCA\Talk\Model\Attendee;
18+
use OCA\Talk\Participant;
1619
use OCA\Talk\Service\ParticipantService;
1720
use OCP\EventDispatcher\Event;
1821
use OCP\EventDispatcher\IEventListener;
22+
use OCP\Federation\ICloudId;
1923
use OCP\Federation\ICloudIdManager;
2024

2125
/**
@@ -30,13 +34,15 @@ public function __construct(
3034
}
3135

3236
public function handle(Event $event): void {
33-
if (!$event instanceof RoomModifiedEvent) {
37+
if (!$event instanceof LobbyModifiedEvent
38+
&& !$event instanceof RoomModifiedEvent) {
3439
return;
3540
}
3641

3742
if (!in_array($event->getProperty(), [
3843
ARoomModifiedEvent::PROPERTY_AVATAR,
3944
ARoomModifiedEvent::PROPERTY_DESCRIPTION,
45+
ARoomModifiedEvent::PROPERTY_LOBBY,
4046
ARoomModifiedEvent::PROPERTY_NAME,
4147
ARoomModifiedEvent::PROPERTY_READ_ONLY,
4248
ARoomModifiedEvent::PROPERTY_TYPE,
@@ -48,19 +54,41 @@ public function handle(Event $event): void {
4854
foreach ($participants as $participant) {
4955
$cloudId = $this->cloudIdManager->resolveCloudId($participant->getAttendee()->getActorId());
5056

51-
$success = $this->backendNotifier->sendRoomModifiedUpdate(
52-
$cloudId->getRemote(),
53-
$participant->getAttendee()->getId(),
54-
$participant->getAttendee()->getAccessToken(),
55-
$event->getRoom()->getToken(),
56-
$event->getProperty(),
57-
$event->getNewValue(),
58-
$event->getOldValue(),
59-
);
57+
if ($event instanceof ALobbyModifiedEvent) {
58+
$success = $this->notifyLobbyModified($cloudId, $participant, $event);
59+
} else {
60+
$success = $this->notifyRoomModified($cloudId, $participant, $event);
61+
}
6062

6163
if ($success === null) {
6264
$this->participantService->removeAttendee($event->getRoom(), $participant, AAttendeeRemovedEvent::REASON_LEFT);
6365
}
6466
}
6567
}
68+
69+
private function notifyLobbyModified(ICloudId $cloudId, Participant $participant, ALobbyModifiedEvent $event) {
70+
return $this->backendNotifier->sendRoomModifiedLobbyUpdate(
71+
$cloudId->getRemote(),
72+
$participant->getAttendee()->getId(),
73+
$participant->getAttendee()->getAccessToken(),
74+
$event->getRoom()->getToken(),
75+
$event->getProperty(),
76+
$event->getNewValue(),
77+
$event->getOldValue(),
78+
$event->getLobbyTimer(),
79+
$event->isTimerReached(),
80+
);
81+
}
82+
83+
private function notifyRoomModified(ICloudId $cloudId, Participant $participant, ARoomModifiedEvent $event) {
84+
return $this->backendNotifier->sendRoomModifiedUpdate(
85+
$cloudId->getRemote(),
86+
$participant->getAttendee()->getId(),
87+
$participant->getAttendee()->getAccessToken(),
88+
$event->getRoom()->getToken(),
89+
$event->getProperty(),
90+
$event->getNewValue(),
91+
$event->getOldValue(),
92+
);
93+
}
6694
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Feature: federation/lobby
2+
3+
Background:
4+
Given user "participant1" exists
5+
And user "participant2" exists
6+
And the following "spreed" app config is set
7+
| federation_enabled | yes |
8+
9+
Scenario: set lobby state
10+
Given user "participant1" creates room "room" (v4)
11+
| roomType | 2 |
12+
| roomName | room name |
13+
And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4)
14+
And user "participant2" has the following invitations (v1)
15+
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
16+
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
17+
And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1)
18+
| id | name | type | remoteServer | remoteToken |
19+
| LOCAL::room | room name | 2 | LOCAL | room |
20+
When user "participant1" sets lobby state for room "room" to "non moderators" with 200 (v4)
21+
Then user "participant2" is participant of room "LOCAL::room" (v4)
22+
| lobbyState |
23+
| 1 |
24+
25+
Scenario: reset lobby state
26+
Given user "participant1" creates room "room" (v4)
27+
| roomType | 2 |
28+
| roomName | room |
29+
And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4)
30+
And user "participant2" has the following invitations (v1)
31+
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
32+
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
33+
And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1)
34+
| id | name | type | remoteServer | remoteToken |
35+
| LOCAL::room | room | 2 | LOCAL | room |
36+
When user "participant1" sets lobby state for room "room" to "non moderators" for 5 seconds with 200 (v4)
37+
And user "participant2" is participant of room "LOCAL::room" (v4)
38+
| lobbyState |
39+
| 1 |
40+
And wait for 10 second
41+
Then user "participant2" is participant of room "LOCAL::room" (v4)
42+
| lobbyState |
43+
| 0 |

0 commit comments

Comments
 (0)