mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Improve how alias settings are handled, add unit tests (#3686)
This commit is contained in:
@@ -67,6 +67,37 @@ struct RoomInfoProxy: BaseRoomInfoProxyProtocol {
|
||||
var pinnedEventIDs: Set<String> { Set(roomInfo.pinnedEventIds) }
|
||||
var joinRule: JoinRule? { roomInfo.joinRule }
|
||||
var historyVisibility: RoomHistoryVisibility { roomInfo.historyVisibility }
|
||||
|
||||
/// Find the first alias that matches the given homeserver
|
||||
/// - Parameters:
|
||||
/// - serverName: the homserver in question
|
||||
/// - useFallback: whether to return any alias if none match
|
||||
func firstAliasMatching(serverName: String?, useFallback: Bool) -> String? {
|
||||
guard let serverName else { return nil }
|
||||
|
||||
// Check if the canonical alias matches the homeserver
|
||||
if let canonicalAlias = roomInfo.canonicalAlias,
|
||||
canonicalAlias.range(of: serverName) != nil {
|
||||
return canonicalAlias
|
||||
}
|
||||
|
||||
// Otherwise check the alternative aliases and return the first one that matches
|
||||
if let matchingAlternativeAlias = roomInfo.alternativeAliases.filter({ $0.range(of: serverName) != nil }).first {
|
||||
return matchingAlternativeAlias
|
||||
}
|
||||
|
||||
guard useFallback else {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Or just return the canonical alias if any
|
||||
if let canonicalAlias = roomInfo.canonicalAlias {
|
||||
return canonicalAlias
|
||||
}
|
||||
|
||||
// And finally return whatever the first alternative alias is
|
||||
return roomInfo.alternativeAliases.first
|
||||
}
|
||||
}
|
||||
|
||||
struct RoomPreviewInfoProxy: BaseRoomInfoProxyProtocol {
|
||||
|
||||
Reference in New Issue
Block a user