From 5cc5a5d013d16beae256d1db90f31a5ff267851b Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Fri, 24 Feb 2023 09:56:15 +0100 Subject: [PATCH] Allow to request assistance in breakout rooms. Signed-off-by: Ivan Sein --- NextcloudTalk/NCAPIController.h | 7 +++++ NextcloudTalk/NCAPIController.m | 53 ++++++++++++++++++++++++++++++++ NextcloudTalk/NCCallController.m | 19 ++++++++++++ NextcloudTalk/NCRoom.h | 2 ++ NextcloudTalk/NCRoom.m | 6 ++++ 5 files changed, 87 insertions(+) diff --git a/NextcloudTalk/NCAPIController.h b/NextcloudTalk/NCAPIController.h index 778531f0..806998f1 100644 --- a/NextcloudTalk/NCAPIController.h +++ b/NextcloudTalk/NCAPIController.h @@ -51,6 +51,8 @@ typedef void (^SetSIPStateCompletionBlock)(NSError *error); typedef void (^ListableCompletionBlock)(NSError *error); typedef void (^MessageExpirationCompletionBlock)(NSError *error); +typedef void (^RequestAssistanceCompletionBlock)(NSError *error); + typedef void (^GetParticipantsFromRoomCompletionBlock)(NSMutableArray *participants, NSError *error); typedef void (^LeaveRoomCompletionBlock)(NSInteger errorCode, NSError *error); typedef void (^ParticipantModificationCompletionBlock)(NSError *error); @@ -132,6 +134,7 @@ extern NSInteger const kReceivedChatMessagesLimit; - (NSInteger)chatAPIVersionForAccount:(TalkAccount *)accounts; - (NSInteger)reactionsAPIVersionForAccount:(TalkAccount *)account; - (NSInteger)pollsAPIVersionForAccount:(TalkAccount *)account; +- (NSInteger)breakoutRoomsAPIVersionForAccount:(TalkAccount *)account; - (NSInteger)signalingAPIVersionForAccount:(TalkAccount *)account; - (NSString *)filesPathForAccount:(TalkAccount *)account; @@ -161,6 +164,10 @@ extern NSInteger const kReceivedChatMessagesLimit; - (NSURLSessionDataTask *)setListableScope:(NCRoomListableScope)scope forRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(ListableCompletionBlock)block; - (NSURLSessionDataTask *)setMessageExpiration:(NCMessageExpiration)messageExpiration forRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(MessageExpirationCompletionBlock)block; +// Breakout Rooms Controller +- (NSURLSessionDataTask *)requestAssistanceInRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(RequestAssistanceCompletionBlock)block; +- (NSURLSessionDataTask *)stopRequestingAssistanceInRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(RequestAssistanceCompletionBlock)block; + // Participants Controller - (NSURLSessionDataTask *)getParticipantsFromRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(GetParticipantsFromRoomCompletionBlock)block; - (NSURLSessionDataTask *)addParticipant:(NSString *)participant ofType:(NSString *)type toRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(ParticipantModificationCompletionBlock)block; diff --git a/NextcloudTalk/NCAPIController.m b/NextcloudTalk/NCAPIController.m index 4cea0c57..625469f7 100644 --- a/NextcloudTalk/NCAPIController.m +++ b/NextcloudTalk/NCAPIController.m @@ -168,6 +168,11 @@ NSInteger const kReceivedChatMessagesLimit = 100; return APIv1; } +- (NSInteger)breakoutRoomsAPIVersionForAccount:(TalkAccount *)account +{ + return APIv1; +} + - (NSInteger)signalingAPIVersionForAccount:(TalkAccount *)account { NSInteger signalingAPIVersion = APIv1; @@ -790,6 +795,54 @@ NSInteger const kReceivedChatMessagesLimit = 100; return task; } +#pragma mark - Breakout Rooms Controller + +- (NSURLSessionDataTask *)requestAssistanceInRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(RequestAssistanceCompletionBlock)block +{ + NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]; + NSString *endpoint = [NSString stringWithFormat:@"breakout-rooms/%@/request-assistance", encodedToken]; + NSInteger breakoutRoomsAPIVersion = [self breakoutRoomsAPIVersionForAccount:account]; + NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:breakoutRoomsAPIVersion forAccount:account]; + + NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId]; + NSURLSessionDataTask *task = [apiSessionManager POST:URLString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + if (block) { + block(nil); + } + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSInteger statusCode = [self getResponseStatusCode:task.response]; + [self checkResponseStatusCode:statusCode forAccount:account]; + if (block) { + block(error); + } + }]; + + return task; +} + +- (NSURLSessionDataTask *)stopRequestingAssistanceInRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(RequestAssistanceCompletionBlock)block +{ + NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]; + NSString *endpoint = [NSString stringWithFormat:@"breakout-rooms/%@/request-assistance", encodedToken]; + NSInteger breakoutRoomsAPIVersion = [self breakoutRoomsAPIVersionForAccount:account]; + NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:breakoutRoomsAPIVersion forAccount:account]; + + NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId]; + NSURLSessionDataTask *task = [apiSessionManager DELETE:URLString parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + if (block) { + block(nil); + } + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSInteger statusCode = [self getResponseStatusCode:task.response]; + [self checkResponseStatusCode:statusCode forAccount:account]; + if (block) { + block(error); + } + }]; + + return task; +} + #pragma mark - Participants Controller - (NSURLSessionDataTask *)getParticipantsFromRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(GetParticipantsFromRoomCompletionBlock)block diff --git a/NextcloudTalk/NCCallController.m b/NextcloudTalk/NCCallController.m index 58927223..11b11301 100644 --- a/NextcloudTalk/NCCallController.m +++ b/NextcloudTalk/NCCallController.m @@ -459,6 +459,25 @@ static NSString * const kNCVideoTrackKind = @"video"; } } }]; + + // Request or stop requesting assistance if we are in a breakout room + if (![_room isBreakoutRoom]) { + return; + } + + if (raised) { + [[NCAPIController sharedInstance] requestAssistanceInRoom:_room.token forAccount:_account withCompletionBlock:^(NSError *error) { + if (error) { + NSLog(@"Error requesting assistance"); + } + }]; + } else { + [[NCAPIController sharedInstance] stopRequestingAssistanceInRoom:_room.token forAccount:_account withCompletionBlock:^(NSError *error) { + if (error) { + NSLog(@"Error on stop requesting assisntance"); + } + }]; + } } - (void)startRecording diff --git a/NextcloudTalk/NCRoom.h b/NextcloudTalk/NCRoom.h index 7b1d171f..db483afd 100644 --- a/NextcloudTalk/NCRoom.h +++ b/NextcloudTalk/NCRoom.h @@ -94,6 +94,7 @@ typedef enum NCCallRecordingState { extern NSString * const NCRoomObjectTypeFile; extern NSString * const NCRoomObjectTypeSharePassword; +extern NSString * const NCRoomObjectTypeRoom; @interface NCRoom : RLMObject @@ -155,6 +156,7 @@ extern NSString * const NCRoomObjectTypeSharePassword; + (void)updateRoom:(NCRoom *)managedRoom withRoom:(NCRoom *)room; - (BOOL)isPublic; +- (BOOL)isBreakoutRoom; - (BOOL)isUserOwnerOrModerator; - (BOOL)canModerate; - (BOOL)isNameEditable; diff --git a/NextcloudTalk/NCRoom.m b/NextcloudTalk/NCRoom.m index b540c44d..1d74430e 100644 --- a/NextcloudTalk/NCRoom.m +++ b/NextcloudTalk/NCRoom.m @@ -26,6 +26,7 @@ NSString * const NCRoomObjectTypeFile = @"file"; NSString * const NCRoomObjectTypeSharePassword = @"share:password"; +NSString * const NCRoomObjectTypeRoom = @"room"; @implementation NCRoom @@ -194,6 +195,11 @@ NSString * const NCRoomObjectTypeSharePassword = @"share:password"; return self.type == kNCRoomTypePublic; } +- (BOOL)isBreakoutRoom +{ + return self.objectType == NCRoomObjectTypeRoom; +} + - (BOOL)isUserOwnerOrModerator { return self.participantType == kNCParticipantTypeOwner || self.participantType == kNCParticipantTypeModerator;