29
29
use OCA \FederatedFileSharing \AddressHandler ;
30
30
use OCA \Talk \AppInfo \Application ;
31
31
use OCA \Talk \Config ;
32
+ use OCA \Talk \Events \ARoomModifiedEvent ;
32
33
use OCA \Talk \Events \AttendeesAddedEvent ;
33
34
use OCA \Talk \Manager ;
34
35
use OCA \Talk \Model \Attendee ;
35
36
use OCA \Talk \Model \AttendeeMapper ;
37
+ use OCA \Talk \Model \Invitation ;
38
+ use OCA \Talk \Model \InvitationMapper ;
36
39
use OCA \Talk \Participant ;
37
40
use OCA \Talk \Room ;
38
41
use OCA \Talk \Service \ParticipantService ;
42
+ use OCA \Talk \Service \RoomService ;
43
+ use OCP \AppFramework \Db \DoesNotExistException ;
39
44
use OCP \AppFramework \Http ;
40
45
use OCP \DB \Exception as DBException ;
41
46
use OCP \EventDispatcher \IEventDispatcher ;
@@ -64,7 +69,9 @@ public function __construct(
64
69
private INotificationManager $ notificationManager ,
65
70
private IURLGenerator $ urlGenerator ,
66
71
private ParticipantService $ participantService ,
72
+ private RoomService $ roomService ,
67
73
private AttendeeMapper $ attendeeMapper ,
74
+ private InvitationMapper $ invitationMapper ,
68
75
private Manager $ manager ,
69
76
private ISession $ session ,
70
77
private IEventDispatcher $ dispatcher ,
@@ -151,6 +158,8 @@ public function notificationReceived($notificationType, $providerId, array $noti
151
158
return $ this ->shareDeclined ((int ) $ providerId , $ notification );
152
159
case FederationManager::NOTIFICATION_SHARE_UNSHARED :
153
160
return $ this ->shareUnshared ((int ) $ providerId , $ notification );
161
+ case FederationManager::NOTIFICATION_ROOM_MODIFIED :
162
+ return $ this ->roomModified ((int ) $ providerId , $ notification );
154
163
}
155
164
156
165
throw new BadRequestException ([$ notificationType ]);
@@ -221,6 +230,42 @@ private function shareUnshared(int $id, array $notification): array {
221
230
return [];
222
231
}
223
232
233
+ /**
234
+ * @param int $remoteAttendeeId
235
+ * @param array{sharedSecret: string, remoteToken: string, changedProperty: string, newValue: string|int|bool|null, oldValue: string|int|bool|null} $notification
236
+ * @return array
237
+ * @throws ActionNotSupportedException
238
+ * @throws AuthenticationFailedException
239
+ * @throws ShareNotFound
240
+ * @throws \OCA\Talk\Exceptions\RoomNotFoundException
241
+ */
242
+ private function roomModified (int $ remoteAttendeeId , array $ notification ): array {
243
+ $ attendee = $ this ->getRemoteAttendeeAndValidate ($ remoteAttendeeId , $ notification ['sharedSecret ' ]);
244
+
245
+ $ room = $ this ->manager ->getRoomById ($ attendee ->getRoomId ());
246
+
247
+ // Sanity check to make sure the room is a remote room
248
+ if (!$ room ->isFederatedRemoteRoom ()) {
249
+ throw new ShareNotFound ();
250
+ }
251
+
252
+ if ($ notification ['changedProperty ' ] === ARoomModifiedEvent::PROPERTY_AVATAR ) {
253
+ $ this ->roomService ->setAvatar ($ room , $ notification ['newValue ' ]);
254
+ } elseif ($ notification ['changedProperty ' ] === ARoomModifiedEvent::PROPERTY_DESCRIPTION ) {
255
+ $ this ->roomService ->setDescription ($ room , $ notification ['newValue ' ]);
256
+ } elseif ($ notification ['changedProperty ' ] === ARoomModifiedEvent::PROPERTY_NAME ) {
257
+ $ this ->roomService ->setName ($ room , $ notification ['newValue ' ], $ notification ['oldValue ' ]);
258
+ } elseif ($ notification ['changedProperty ' ] === ARoomModifiedEvent::PROPERTY_READ_ONLY ) {
259
+ $ this ->roomService ->setReadOnly ($ room , $ notification ['newValue ' ]);
260
+ } elseif ($ notification ['changedProperty ' ] === ARoomModifiedEvent::PROPERTY_TYPE ) {
261
+ $ this ->roomService ->setType ($ room , $ notification ['newValue ' ]);
262
+ } else {
263
+ $ this ->logger ->debug ('Update of room property " ' . $ notification ['changedProperty ' ] . '" is not handled and should not be send via federation ' );
264
+ }
265
+
266
+ return [];
267
+ }
268
+
224
269
/**
225
270
* @throws AuthenticationFailedException
226
271
* @throws ActionNotSupportedException
@@ -248,12 +293,12 @@ private function getAttendeeAndValidate(int $id, string $sharedSecret): Attendee
248
293
/**
249
294
* @param int $id
250
295
* @param string $sharedSecret
251
- * @return Attendee
296
+ * @return Attendee|Invitation
252
297
* @throws ActionNotSupportedException
253
298
* @throws ShareNotFound
254
299
* @throws AuthenticationFailedException
255
300
*/
256
- private function getRemoteAttendeeAndValidate (int $ id , string $ sharedSecret ): Attendee {
301
+ private function getRemoteAttendeeAndValidate (int $ id , string $ sharedSecret ): Attendee | Invitation {
257
302
if (!$ this ->federationManager ->isEnabled ()) {
258
303
throw new ActionNotSupportedException ('Server does not support Talk federation ' );
259
304
}
@@ -263,11 +308,16 @@ private function getRemoteAttendeeAndValidate(int $id, string $sharedSecret): At
263
308
}
264
309
265
310
try {
266
- $ attendee = $ this ->attendeeMapper ->getByRemoteIdAndToken ($ id , $ sharedSecret );
267
- } catch (Exception $ ex ) {
311
+ return $ this ->attendeeMapper ->getByRemoteIdAndToken ($ id , $ sharedSecret );
312
+ } catch (DoesNotExistException ) {
313
+ try {
314
+ return $ this ->invitationMapper ->getByRemoteIdAndToken ($ id , $ sharedSecret );
315
+ } catch (DoesNotExistException $ e ) {
316
+ throw new ShareNotFound ();
317
+ }
318
+ } catch (Exception ) {
268
319
throw new ShareNotFound ();
269
320
}
270
- return $ attendee ;
271
321
}
272
322
273
323
private function notifyAboutNewShare (IUser $ shareWith , string $ shareId , string $ sharedByFederatedId , string $ sharedByName , string $ roomName , string $ roomToken , string $ serverUrl ): void {
0 commit comments