refactor set serveracl and fix json key

This commit is contained in:
JanNiklas Grabowski
2024-01-26 13:25:27 +01:00
parent 65864cc1ab
commit 56c544797d
3 changed files with 31 additions and 19 deletions

View File

@@ -1708,10 +1708,8 @@ BOOL reloadToggleCell = false;
NSString *serverACLRule = updatedItemsDict[kRoomSettingsFederationKey];
if (serverACLRule)
{
NSMutableDictionary *content = [[NSMutableDictionary alloc] initWithDictionary:@{
@"allow": @[serverACLRule],
@"allowIPLiterals" : @false
}];
NSDictionary *content = [mxRoom createServerACLContentWithServerACL:serverACLRule];
pendingOperation = [mxRoom sendStateEventOfType:kMXEventTypeStringRoomServerACL content:content stateKey:nil success:^(NSString *eventId) {
if (weakSelf)

View File

@@ -117,4 +117,32 @@ import MatrixSDK
}
}
}
// Create map for content json with boolean
func createServerACL(isFederated: Bool) -> [String:Any] {
var serverACL: String = ""
if isFederated {
serverACL = "*"
} else {
if let myUserIDComponents = self.mxSession.myUserId?.components(separatedBy: ":")
{
if myUserIDComponents.count == 2 {
serverACL = myUserIDComponents[1]
}
}
}
return createServerACLContent(serverACL: serverACL)
}
// Create map for content json with serverACL string
func createServerACLContent(serverACL: String) -> [String:Any] {
var content: [String:Any] = [String:Any]()
var serverACLList: [String] = [String]()
serverACLList.append(serverACL)
content.updateValue(serverACLList, forKey: "allow")
content.updateValue(false, forKey: "allow_ip_literals")
return content
}
}

View File

@@ -161,21 +161,7 @@ struct RoomFederationDecisionView: View {
func setServerACL(isFederated: Bool) {
var serverACL: [String] = [String]()
if isFederated {
serverACL.append("*")
} else {
if let myUserIDComponents = room.mxSession.myUserId?.components(separatedBy: ":")
{
if myUserIDComponents.count == 2 {
serverACL.append(myUserIDComponents[1])
}
}
}
var content: [String:Any] = [String:Any]()
content.updateValue(serverACL, forKey: "allow")
content.updateValue(false, forKey: "allowIPLiterals")
let content: [String:Any] = room.createServerACL(isFederated: isFederated)
isUpdatingServerACLs = true
pendingRequest = room.sendStateEvent(MXEventType.roomServerACL, content: content, stateKey: "") { response in
isUpdatingServerACLs = false