Move getSignalingSettings to swift

Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
This commit is contained in:
Marcel Müller 2024-07-24 22:55:28 +02:00
Родитель 58ca31897b
Коммит d94699a020
3 изменённых файлов: 30 добавлений и 33 удалений

Просмотреть файл

@ -67,7 +67,6 @@ typedef void (^PollCompletionBlock)(NCPoll *poll, NSError *error, NSInteger stat
typedef void (^SendSignalingMessagesCompletionBlock)(NSError *error);
typedef void (^PullSignalingMessagesCompletionBlock)(NSDictionary *messages, NSError *error);
typedef void (^GetSignalingSettingsCompletionBlock)(NSDictionary *settings, NSError *error);
typedef void (^SetReadStatusPrivacySettingCompletionBlock)(NSError *error);
typedef void (^SetTypingPrivacySettingCompletionBlock)(NSError *error);
@ -226,7 +225,6 @@ extern NSInteger const kReceivedChatMessagesLimit;
// Signaling Controller
- (NSURLSessionDataTask *)sendSignalingMessages:(NSString *)messages toRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(SendSignalingMessagesCompletionBlock)block;
- (NSURLSessionDataTask *)pullSignalingMessagesFromRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PullSignalingMessagesCompletionBlock)block;
- (NSURLSessionDataTask *)getSignalingSettingsForAccount:(TalkAccount *)account forRoom:(NSString * _Nullable)token withCompletionBlock:(GetSignalingSettingsCompletionBlock)block;
- (NSString *)authenticationBackendUrlForAccount:(TalkAccount *)account;
// Settings Controller

Просмотреть файл

@ -1810,37 +1810,6 @@ NSInteger const kReceivedChatMessagesLimit = 100;
return task;
}
- (NSURLSessionDataTask *)getSignalingSettingsForAccount:(TalkAccount *)account forRoom:(NSString *)token withCompletionBlock:(GetSignalingSettingsCompletionBlock)block
{
NSString *endpoint = @"signaling/settings";
NSInteger signalingAPIVersion = [self signalingAPIVersionForAccount:account];
NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:signalingAPIVersion forAccount:account];
NSDictionary *parameters = nil;
if (token) {
parameters = @{
@"token" : token,
};
}
NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
NSURLSessionDataTask *task = [apiSessionManager GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSDictionary *responseDict = responseObject;
if (block) {
block(responseDict, nil);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSInteger statusCode = [self getResponseStatusCode:task.response];
[self checkResponseStatusCode:statusCode forAccount:account];
if (block) {
block(nil, error);
}
}];
return task;
}
- (NSString *)authenticationBackendUrlForAccount:(TalkAccount *)account
{
NSString *endpoint = @"signaling/backend";

Просмотреть файл

@ -213,6 +213,36 @@ import Foundation
}
}
// MARK: - Signaling
@discardableResult
public func getSignalingSettings(for account: TalkAccount, forRoom roomToken: String?, completionBlock: @escaping (_ signalingSettings: SignalingSettings?, _ error: (any Error)?) -> Void) -> URLSessionDataTask? {
guard let apiSessionManager = self.apiSessionManagers.object(forKey: account.accountId) as? NCAPISessionManager
else {
completionBlock(nil, nil)
return nil
}
let apiVersion = self.signalingAPIVersion(for: account)
let urlString = self.getRequestURL(forEndpoint: "signaling/settings", withAPIVersion: apiVersion, for: account)
var parameters: [String: Any]?
if let roomToken, let encodedToken = roomToken.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) {
parameters = [
"token": encodedToken
]
}
return apiSessionManager.getOcs(urlString, account: account, parameters: parameters) { ocs, error in
if let dataDict = ocs?.dataDict {
completionBlock(SignalingSettings(dictionary: dataDict), nil)
} else {
completionBlock(nil, error)
}
}
}
// MARK: - Mentions
public func getMentionSuggestions(for accountId: String, in roomToken: String, with searchString: String, completionBlock: @escaping (_ mentions: [MentionSuggestion]?) -> Void) {