mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 15:09:31 +02:00
Merge branch 'feature/3288_automatic_room_alias' into 'develop'
MESSENGER-3288 auto create room alias on room creation See merge request bwmessenger/bundesmessenger/bundesmessenger-ios!19
This commit is contained in:
@@ -94,20 +94,26 @@ final class EnterNewRoomDetailsViewModel: EnterNewRoomDetailsViewModelType {
|
||||
}
|
||||
|
||||
private func fixRoomAlias(alias: String?) -> String? {
|
||||
guard var alias = alias else { return nil }
|
||||
|
||||
// drop prefix # from room alias
|
||||
while alias.hasPrefix("#") {
|
||||
alias = String(alias.dropFirst())
|
||||
if var alias = alias {
|
||||
// drop prefix # from room alias
|
||||
while alias.hasPrefix("#") {
|
||||
alias = String(alias.dropFirst())
|
||||
}
|
||||
|
||||
// TODO: Fix below somehow
|
||||
alias = alias.replacingOccurrences(of: ":matrix.org", with: "")
|
||||
if let homeserver = session.credentials.homeServer {
|
||||
alias = alias.replacingOccurrences(of: ":" + homeserver, with: "")
|
||||
}
|
||||
|
||||
return alias
|
||||
} else if BwiBuildSettings.bwiAutoCreateAliasOnRoomCreation {
|
||||
if let roomName = roomCreationParameters.name {
|
||||
return self.createAlias(from: roomName)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Fix below somehow
|
||||
alias = alias.replacingOccurrences(of: ":matrix.org", with: "")
|
||||
if let homeserver = session.credentials.homeServer {
|
||||
alias = alias.replacingOccurrences(of: ":" + homeserver, with: "")
|
||||
}
|
||||
|
||||
return alias
|
||||
return nil
|
||||
}
|
||||
|
||||
private func createRoom() {
|
||||
@@ -195,4 +201,15 @@ final class EnterNewRoomDetailsViewModel: EnterNewRoomDetailsViewModelType {
|
||||
private func cancelOperations() {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,4 +69,6 @@ final class BwiBuildSettings: NSObject {
|
||||
static let bwiShowThreads = false
|
||||
|
||||
static let bwiShowRoomCreationSectionFooter = false
|
||||
|
||||
static let bwiAutoCreateAliasOnRoomCreation = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user