Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ban): Encode room token #1930

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions NextcloudTalk/NCAPIControllerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}

apiSessionManager.getOcs(urlString, account: account, parameters: parameters) { ocsResponse, ocsError in
// TODO: Move away from generic dictionary return type

Check warning on line 31 in NextcloudTalk/NCAPIControllerExtensions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (Move away from generic diction...) (todo)
// let rooms = ocs?.dataArrayDict.compactMap { NCRoom(dictionary: $0, andAccountId: account.accountId) }
completionBlock(ocsResponse?.dataArrayDict, ocsError?.error)
}
Expand Down Expand Up @@ -352,16 +352,17 @@

// MARK: - Ban

public func banActor(for accountId: String, in roomToken: String, with actorType: String, with actorId: String, with internalNote: String?, completionBlock: @escaping (_ success: Bool) -> Void) {

Check warning on line 355 in NextcloudTalk/NCAPIControllerExtensions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Function Parameter Count Violation: Function should have 5 parameters or less: it currently has 6 (function_parameter_count)
guard let account = NCDatabaseManager.sharedInstance().talkAccount(forAccountId: accountId),
let encodedToken = roomToken.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed),
let apiSessionManager = self.apiSessionManagers.object(forKey: account.accountId) as? NCAPISessionManager
else {
completionBlock(false)
return
}

let apiVersion = self.banAPIVersion(for: account)
let urlString = self.getRequestURL(forEndpoint: "ban/\(roomToken)", withAPIVersion: apiVersion, for: account)
let urlString = self.getRequestURL(forEndpoint: "ban/\(encodedToken)", withAPIVersion: apiVersion, for: account)

var parameters: [String: Any] = [
"actorType": actorType,
Expand All @@ -381,14 +382,15 @@

public func listBans(for accountId: String, in roomToken: String, completionBlock: @escaping (_ bannedActors: [BannedActor]?) -> Void) {
guard let account = NCDatabaseManager.sharedInstance().talkAccount(forAccountId: accountId),
let encodedToken = roomToken.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed),
let apiSessionManager = self.apiSessionManagers.object(forKey: account.accountId) as? NCAPISessionManager
else {
completionBlock(nil)
return
}

let apiVersion = self.banAPIVersion(for: account)
let urlString = self.getRequestURL(forEndpoint: "ban/\(roomToken)", withAPIVersion: apiVersion, for: account)
let urlString = self.getRequestURL(forEndpoint: "ban/\(encodedToken)", withAPIVersion: apiVersion, for: account)

apiSessionManager.getOcs(urlString, account: account) { ocs, _ in
let actorBans = ocs?.dataArrayDict?.map { BannedActor(dictionary: $0) }
Expand All @@ -398,14 +400,15 @@

public func unbanActor(for accountId: String, in roomToken: String, with banId: Int, completionBlock: @escaping (_ success: Bool) -> Void) {
guard let account = NCDatabaseManager.sharedInstance().talkAccount(forAccountId: accountId),
let encodedToken = roomToken.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed),
let apiSessionManager = self.apiSessionManagers.object(forKey: account.accountId) as? NCAPISessionManager
else {
completionBlock(false)
return
}

let apiVersion = self.banAPIVersion(for: account)
let urlString = self.getRequestURL(forEndpoint: "ban/\(roomToken)/\(banId)", withAPIVersion: apiVersion, for: account)
let urlString = self.getRequestURL(forEndpoint: "ban/\(encodedToken)/\(banId)", withAPIVersion: apiVersion, for: account)

apiSessionManager.delete(urlString, parameters: nil) { _, _ in
completionBlock(true)
Expand Down Expand Up @@ -605,7 +608,7 @@

let urlString = "\(account.server)/ocs/v2.php/apps/notifications/api/v3/test/self"

apiSessionManager.postOcs(urlString, account: account) { ocsResponse, ocsError in

Check warning on line 611 in NextcloudTalk/NCAPIControllerExtensions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Unused Closure Parameter Violation: Unused parameter in a closure should be replaced with _ (unused_closure_parameter)
let message = ocsResponse?.dataDict?["message"] as? String
completionBlock(message)
}
Expand Down
Loading