Update history visible settings (#4861)

* Fixes #4852 - Update history visible settings

* Address PR comments and move attributed strings to the view state
This commit is contained in:
Stefan Ceriu
2025-12-17 15:04:02 +02:00
committed by GitHub
parent aa28ef3f19
commit 8164c88437
34 changed files with 150 additions and 112 deletions
@@ -15,20 +15,12 @@ enum SecurityAndPrivacyScreenViewModelAction {
}
struct SecurityAndPrivacyScreenViewState: BindableState {
private static let accessSectionFooterAttributedString = {
let linkPlaceholder = "{link}"
var footer = AttributedString(L10n.screenSecurityAndPrivacyRoomAccessFooter(linkPlaceholder))
var linkString = AttributedString(L10n.screenSecurityAndPrivacyRoomAccessFooterManageSpacesAction)
// Doesn't really matter
linkString.link = .init(stringLiteral: "action://manageSpace")
linkString.bold()
footer.replace(linkPlaceholder, with: linkString)
return footer
}()
let serverName: String
var currentSettings: SecurityAndPrivacySettings
var bindings: SecurityAndPrivacyScreenViewStateBindings
let strings: SecurityAndPrivacyScreenStrings
var canonicalAlias: String?
var isKnockingEnabled: Bool
var isSpaceSettingsEnabled: Bool
@@ -38,6 +30,7 @@ struct SecurityAndPrivacyScreenViewState: BindableState {
var canEditJoinRule = false
var canEnableEncryption = false
var canEditHistoryVisibility = false
/// The union of joined parent spaces and the joined spaces in the current access type
var selectableJoinedSpaces: [SpaceRoomProxyProtocol] = []
@@ -58,13 +51,13 @@ struct SecurityAndPrivacyScreenViewState: BindableState {
}
var availableVisibilityOptions: [SecurityAndPrivacyHistoryVisibility] {
var options = [SecurityAndPrivacyHistoryVisibility.sinceSelection]
var options = [SecurityAndPrivacyHistoryVisibility.shared]
if !bindings.desiredSettings.isEncryptionEnabled, bindings.desiredSettings.accessType == .anyone {
options.append(.anyone)
options.append(.worldReadable)
} else {
options.append(.sinceInvite)
options.append(.invited)
}
return options
return options.sorted()
}
var isSpaceMembersOptionAvailable: Bool {
@@ -113,16 +106,14 @@ struct SecurityAndPrivacyScreenViewState: BindableState {
}
}
var accessSectionFooter: AttributedString? {
if (bindings.desiredSettings.accessType.isSpaceMembers &&
isSpaceMembersOptionSelectable) ||
(bindings.desiredSettings.accessType.isAskToJoinWithSpaceMembers &&
isAskToJoinWithSpaceMembersOptionSelectable),
var shouldShowAccessSectionFooter: Bool {
if (bindings.desiredSettings.accessType.isSpaceMembers && isSpaceMembersOptionSelectable) ||
(bindings.desiredSettings.accessType.isAskToJoinWithSpaceMembers && isAskToJoinWithSpaceMembersOptionSelectable),
case .multiple = spaceSelection {
Self.accessSectionFooterAttributedString
} else {
nil
return true
}
return false
}
enum SpaceSelection {
@@ -169,7 +160,8 @@ struct SecurityAndPrivacyScreenViewState: BindableState {
historyVisibility: SecurityAndPrivacyHistoryVisibility,
isSpace: Bool,
isKnockingEnabled: Bool,
isSpaceSettingsEnabled: Bool) {
isSpaceSettingsEnabled: Bool,
historySharingDetailsURL: URL) {
self.serverName = serverName
self.isKnockingEnabled = isKnockingEnabled
self.isSpace = isSpace
@@ -180,6 +172,7 @@ struct SecurityAndPrivacyScreenViewState: BindableState {
historyVisibility: historyVisibility)
currentSettings = settings
bindings = SecurityAndPrivacyScreenViewStateBindings(desiredSettings: settings)
strings = SecurityAndPrivacyScreenStrings(historySharingDetailsURL: historySharingDetailsURL)
}
}
@@ -254,17 +247,44 @@ enum SecurityAndPrivacyScreenViewAction {
case manageSpaces
}
enum SecurityAndPrivacyHistoryVisibility {
case sinceSelection
case sinceInvite
case anyone
enum SecurityAndPrivacyHistoryVisibility: Int, Comparable {
case invited
case shared
case worldReadable
var fallbackOption: Self {
switch self {
case .sinceInvite, .sinceSelection:
return .sinceSelection
case .anyone:
return .sinceInvite
case .invited, .shared:
return .shared
case .worldReadable:
return .invited
}
}
static func < (lhs: SecurityAndPrivacyHistoryVisibility, rhs: SecurityAndPrivacyHistoryVisibility) -> Bool {
lhs.rawValue < rhs.rawValue
}
}
struct SecurityAndPrivacyScreenStrings {
let accessSectionFooterString: AttributedString
let historySectionFooterString: AttributedString
init(historySharingDetailsURL: URL) {
let linkPlaceholder = "{link}"
var accessFooterString = AttributedString(L10n.screenSecurityAndPrivacyRoomAccessFooter(linkPlaceholder))
var accessLinkString = AttributedString(L10n.screenSecurityAndPrivacyRoomAccessFooterManageSpacesAction)
accessLinkString.link = .init(stringLiteral: "action://manageSpace") // The link address doesn't matter
accessLinkString.bold()
accessFooterString.replace(linkPlaceholder, with: accessLinkString)
accessSectionFooterString = accessFooterString
var historyFooterString = AttributedString(L10n.screenSecurityAndPrivacyRoomHistorySectionFooter(linkPlaceholder))
var historyLinkString = AttributedString(L10n.actionLearnMore)
historyLinkString.link = historySharingDetailsURL
historyLinkString.bold()
historyFooterString.replace(linkPlaceholder, with: historyLinkString)
historySectionFooterString = historyFooterString
}
}