MESSENGER-5383 Check alias on acl update

This commit is contained in:
JanNiklas Grabowski
2024-01-30 12:45:05 +01:00
parent 80170b0c4f
commit ba4e145039
5 changed files with 70 additions and 11 deletions

View File

@@ -123,7 +123,7 @@ final class EnterNewRoomDetailsViewModel: EnterNewRoomDetailsViewModelType, Obse
return alias
} else if BWIBuildSettings.shared.bwiAutoCreateAliasOnRoomCreation {
if let roomName = roomCreationParameters.name {
return self.createAlias(from: roomName)
return MXTools.createAlias(from: roomName) // here?
}
}
@@ -248,14 +248,4 @@ final class EnterNewRoomDetailsViewModel: EnterNewRoomDetailsViewModelType, Obse
self.currentOperation?.cancel()
}
// MARK bwi Alias creation
private func createAlias(from roomName: String) -> String {
var alias = roomName.trimmingCharacters(in: .whitespacesAndNewlines).filter { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".contains($0) }
let timeInterval = String(Int(NSDate().timeIntervalSince1970))
alias.append(timeInterval)
return alias
}
}

View File

@@ -1709,6 +1709,9 @@ BOOL reloadToggleCell = false;
if (serverACLRule)
{
// bwi: #5383 set alias
[mxRoom setAliasIfNeeded];
NSDictionary *content = [mxRoom createServerACLContentWithServerACL:serverACLRule];
pendingOperation = [mxRoom sendStateEventOfType:kMXEventTypeStringRoomServerACL content:content stateKey:nil success:^(NSString *eventId) {

View File

@@ -0,0 +1,30 @@
//
/*
* Copyright (c) 2024 BWI GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Foundation
extension MXTools {
static func createAlias(from roomName: String) -> String {
var alias = roomName.trimmingCharacters(in: .whitespacesAndNewlines).filter { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".contains($0) }
let timeInterval = String(Int(NSDate().timeIntervalSince1970))
alias.append(timeInterval)
return alias
}
}

View File

@@ -145,4 +145,38 @@ import MatrixSDK
return content
}
// #5383 Check if no alias exists, create alias from name and timestamp and add as canonical alias
func setAliasIfNeeded() {
var needsAlias: Bool = true
if let summary = summary {
if let aliases = summary.aliases {
for alias in aliases {
if !alias.isEmpty {
needsAlias = false
return
}
}
}
}
if needsAlias {
if let displayName = displayName {
// Create new alias
var newAlias = MXTools.createAlias(from: displayName)
// Generate local alias
newAlias = MXTools.fullLocalAlias(from: newAlias, with: mxSession)
// Add local alias
addAlias(newAlias) { [self] response in
if response.isSuccess {
// Set new alias as canonical alias
setCanonicalAlias(newAlias) { response in
return
}
}
return
}
}
}
}
}

View File

@@ -163,6 +163,8 @@ struct RoomFederationDecisionView: View {
func setServerACL(isFederated: Bool) {
let content: [String:Any] = room.createServerACL(isFederated: isFederated)
isUpdatingServerACLs = true
// #5383 set alias
room.setAliasIfNeeded()
pendingRequest = room.sendStateEvent(MXEventType.roomServerACL, content: content, stateKey: "") { response in
isUpdatingServerACLs = false
if response.isSuccess {