mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 15:09:31 +02:00
MESSENGER-5383 Check alias on acl update
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
30
bwi/Extentions/MXTools+Alias.swift
Normal file
30
bwi/Extentions/MXTools+Alias.swift
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user