mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-30 21:26:57 +02:00
Release 2.0.0
This commit is contained in:
+14
-3
@@ -14,12 +14,14 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import CommonKit
|
||||
import SwiftUI
|
||||
|
||||
struct UserSessionOverviewCoordinatorParameters {
|
||||
let session: MXSession
|
||||
let sessionInfo: UserSessionInfo
|
||||
let sessionsOverviewDataPublisher: CurrentValueSubject<UserSessionsOverviewData, Never>
|
||||
}
|
||||
|
||||
final class UserSessionOverviewCoordinator: Coordinator, Presentable {
|
||||
@@ -42,9 +44,13 @@ final class UserSessionOverviewCoordinator: Coordinator, Presentable {
|
||||
self.parameters = parameters
|
||||
|
||||
let service = UserSessionOverviewService(session: parameters.session, sessionInfo: parameters.sessionInfo)
|
||||
viewModel = UserSessionOverviewViewModel(sessionInfo: parameters.sessionInfo, service: service)
|
||||
viewModel = UserSessionOverviewViewModel(sessionInfo: parameters.sessionInfo,
|
||||
service: service,
|
||||
sessionsOverviewDataPublisher: parameters.sessionsOverviewDataPublisher)
|
||||
|
||||
hostingController = VectorHostingController(rootView: UserSessionOverview(viewModel: viewModel.context))
|
||||
hostingController.vc_setLargeTitleDisplayMode(.never)
|
||||
hostingController.vc_removeBackTitle()
|
||||
|
||||
indicatorPresenter = UserIndicatorTypePresenter(presentingViewController: hostingController)
|
||||
}
|
||||
@@ -55,12 +61,17 @@ final class UserSessionOverviewCoordinator: Coordinator, Presentable {
|
||||
MXLog.debug("[UserSessionOverviewCoordinator] did start.")
|
||||
viewModel.completion = { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
|
||||
MXLog.debug("[UserSessionOverviewCoordinator] UserSessionOverviewViewModel did complete with result: \(result).")
|
||||
switch result {
|
||||
case .verifyCurrentSession:
|
||||
break // TODO:
|
||||
case let .verifySession(sessionInfo):
|
||||
self.completion?(.verifySession(sessionInfo))
|
||||
case let .showSessionDetails(sessionInfo: sessionInfo):
|
||||
self.completion?(.openSessionDetails(sessionInfo: sessionInfo))
|
||||
case let .renameSession(sessionInfo):
|
||||
self.completion?(.renameSession(sessionInfo))
|
||||
case let .logoutOfSession(sessionInfo):
|
||||
self.completion?(.logoutOfSession(sessionInfo))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -51,7 +51,7 @@ enum MockUserSessionOverviewScreenState: MockScreenState, CaseIterable {
|
||||
session = UserSessionInfo(id: "alice",
|
||||
name: "iOS",
|
||||
deviceType: .mobile,
|
||||
isVerified: false,
|
||||
verificationState: .unverified,
|
||||
lastSeenIP: "10.0.0.10",
|
||||
lastSeenTimestamp: nil,
|
||||
applicationName: "Element iOS",
|
||||
@@ -69,14 +69,14 @@ enum MockUserSessionOverviewScreenState: MockScreenState, CaseIterable {
|
||||
session = UserSessionInfo(id: "1",
|
||||
name: "macOS",
|
||||
deviceType: .desktop,
|
||||
isVerified: true,
|
||||
verificationState: .verified,
|
||||
lastSeenIP: "1.0.0.1",
|
||||
lastSeenTimestamp: Date().timeIntervalSince1970 - 130_000,
|
||||
applicationName: "Element MacOS",
|
||||
applicationVersion: "1.0.0",
|
||||
applicationURL: nil,
|
||||
deviceModel: nil,
|
||||
deviceOS: "macOS 12.5.1",
|
||||
deviceOS: "macOS",
|
||||
lastSeenIPLocation: nil,
|
||||
clientName: "Electron",
|
||||
clientVersion: "20.1.1",
|
||||
@@ -87,14 +87,14 @@ enum MockUserSessionOverviewScreenState: MockScreenState, CaseIterable {
|
||||
session = UserSessionInfo(id: "1",
|
||||
name: "macOS",
|
||||
deviceType: .desktop,
|
||||
isVerified: true,
|
||||
verificationState: .verified,
|
||||
lastSeenIP: "1.0.0.1",
|
||||
lastSeenTimestamp: Date().timeIntervalSince1970 - 130_000,
|
||||
applicationName: "Element MacOS",
|
||||
applicationVersion: "1.0.0",
|
||||
applicationURL: nil,
|
||||
deviceModel: nil,
|
||||
deviceOS: "macOS 12.5.1",
|
||||
deviceOS: "macOS",
|
||||
lastSeenIPLocation: nil,
|
||||
clientName: "My Mac",
|
||||
clientVersion: "1.0.0",
|
||||
@@ -105,14 +105,14 @@ enum MockUserSessionOverviewScreenState: MockScreenState, CaseIterable {
|
||||
session = UserSessionInfo(id: "1",
|
||||
name: "macOS",
|
||||
deviceType: .desktop,
|
||||
isVerified: true,
|
||||
verificationState: .verified,
|
||||
lastSeenIP: "1.0.0.1",
|
||||
lastSeenTimestamp: Date().timeIntervalSince1970 - 130_000,
|
||||
applicationName: "Element MacOS",
|
||||
applicationVersion: "1.0.0",
|
||||
applicationURL: nil,
|
||||
deviceModel: nil,
|
||||
deviceOS: "macOS 12.5.1",
|
||||
deviceOS: "macOS",
|
||||
lastSeenIPLocation: nil,
|
||||
clientName: "My Mac",
|
||||
clientVersion: "1.0.0",
|
||||
|
||||
+75
-33
@@ -18,7 +18,6 @@ import Combine
|
||||
import MatrixSDK
|
||||
|
||||
class UserSessionOverviewService: UserSessionOverviewServiceProtocol {
|
||||
|
||||
// MARK: - Members
|
||||
|
||||
private(set) var pusherEnabledSubject: CurrentValueSubject<Bool?, Never>
|
||||
@@ -29,54 +28,97 @@ class UserSessionOverviewService: UserSessionOverviewServiceProtocol {
|
||||
private let session: MXSession
|
||||
private let sessionInfo: UserSessionInfo
|
||||
private var pusher: MXPusher?
|
||||
private var localNotificationSettings: [String: Any]?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(session: MXSession, sessionInfo: UserSessionInfo) {
|
||||
self.session = session
|
||||
self.sessionInfo = sessionInfo
|
||||
self.pusherEnabledSubject = CurrentValueSubject(nil)
|
||||
self.remotelyTogglingPushersAvailableSubject = CurrentValueSubject(false)
|
||||
|
||||
checkServerVersions { [weak self] in
|
||||
self?.checkPusher()
|
||||
pusherEnabledSubject = CurrentValueSubject(nil)
|
||||
remotelyTogglingPushersAvailableSubject = CurrentValueSubject(false)
|
||||
|
||||
localNotificationSettings = session.accountData.localNotificationSettingsForDevice(withId: sessionInfo.id)
|
||||
|
||||
if let localNotificationSettings = localNotificationSettings, let isSilenced = localNotificationSettings[kMXAccountDataIsSilencedKey] as? Bool {
|
||||
remotelyTogglingPushersAvailableSubject.send(true)
|
||||
pusherEnabledSubject.send(!isSilenced)
|
||||
}
|
||||
|
||||
checkPusher { [weak self] in
|
||||
guard self?.pusher != nil else {
|
||||
return
|
||||
}
|
||||
|
||||
self?.checkServerVersions()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UserSessionOverviewServiceProtocol
|
||||
|
||||
func togglePushNotifications() {
|
||||
guard let pusher = pusher, let enabled = pusher.enabled?.boolValue, self.remotelyTogglingPushersAvailableSubject.value else {
|
||||
guard let pusher = pusher, let enabled = pusher.enabled?.boolValue else {
|
||||
updateLocalNotification()
|
||||
return
|
||||
}
|
||||
|
||||
let data = pusher.data.jsonDictionary() as? [String: Any] ?? [:]
|
||||
|
||||
self.session.matrixRestClient.setPusher(pushKey: pusher.pushkey,
|
||||
kind: MXPusherKind(value: pusher.kind),
|
||||
appId: pusher.appId,
|
||||
appDisplayName:pusher.appDisplayName,
|
||||
deviceDisplayName: pusher.deviceDisplayName,
|
||||
profileTag: pusher.profileTag ?? "",
|
||||
lang: pusher.lang,
|
||||
data: data,
|
||||
append: false,
|
||||
enabled: !enabled) { [weak self] response in
|
||||
guard let self = self else { return }
|
||||
|
||||
switch response {
|
||||
case .success:
|
||||
self.checkPusher()
|
||||
case .failure(let error):
|
||||
MXLog.warning("[UserSessionOverviewService] togglePushNotifications failed due to error: \(error)")
|
||||
self.pusherEnabledSubject.send(enabled)
|
||||
}
|
||||
}
|
||||
|
||||
toggle(pusher, enabled: !enabled)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func checkServerVersions(_ completion: @escaping () -> Void) {
|
||||
private func toggle(_ pusher: MXPusher, enabled: Bool) {
|
||||
guard remotelyTogglingPushersAvailableSubject.value else {
|
||||
MXLog.warning("[UserSessionOverviewService] toggle pusher canceled: remotely toggling pushers not available")
|
||||
return
|
||||
}
|
||||
|
||||
MXLog.debug("[UserSessionOverviewService] remotely toggling pusher")
|
||||
let data = pusher.data.jsonDictionary() as? [String: Any] ?? [:]
|
||||
|
||||
session.matrixRestClient.setPusher(pushKey: pusher.pushkey,
|
||||
kind: MXPusherKind(value: pusher.kind),
|
||||
appId: pusher.appId,
|
||||
appDisplayName: pusher.appDisplayName,
|
||||
deviceDisplayName: pusher.deviceDisplayName,
|
||||
profileTag: pusher.profileTag ?? "",
|
||||
lang: pusher.lang,
|
||||
data: data,
|
||||
append: false,
|
||||
enabled: enabled) { [weak self] response in
|
||||
guard let self = self else { return }
|
||||
|
||||
switch response {
|
||||
case .success:
|
||||
if let account = MXKAccountManager.shared().activeAccounts.first, account.device?.deviceId == pusher.deviceId {
|
||||
account.loadCurrentPusher(nil)
|
||||
}
|
||||
|
||||
self.checkPusher()
|
||||
case .failure(let error):
|
||||
MXLog.warning("[UserSessionOverviewService] togglePusher failed due to error: \(error)")
|
||||
self.pusherEnabledSubject.send(!enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func updateLocalNotification() {
|
||||
guard var localNotificationSettings = localNotificationSettings, let isSilenced = localNotificationSettings[kMXAccountDataIsSilencedKey] as? Bool else {
|
||||
MXLog.warning("[UserSessionOverviewService] updateLocalNotification canceled: \"\(kMXAccountDataIsSilencedKey)\" notification property not found")
|
||||
return
|
||||
}
|
||||
|
||||
localNotificationSettings[kMXAccountDataIsSilencedKey] = !isSilenced
|
||||
session.setAccountData(localNotificationSettings, forType: MXAccountData.localNotificationSettingsKeyForDevice(withId: sessionInfo.id)) { [weak self] in
|
||||
self?.localNotificationSettings = localNotificationSettings
|
||||
self?.pusherEnabledSubject.send(isSilenced)
|
||||
} failure: { [weak self] error in
|
||||
MXLog.warning("[UserSessionOverviewService] updateLocalNotification failed due to error: \(String(describing: error))")
|
||||
self?.pusherEnabledSubject.send(!isSilenced)
|
||||
}
|
||||
}
|
||||
|
||||
private func checkServerVersions() {
|
||||
session.supportedMatrixVersions { [weak self] response in
|
||||
switch response {
|
||||
case .success(let versions):
|
||||
@@ -84,11 +126,10 @@ class UserSessionOverviewService: UserSessionOverviewServiceProtocol {
|
||||
case .failure(let error):
|
||||
MXLog.warning("[UserSessionOverviewService] checkServerVersions failed due to error: \(error)")
|
||||
}
|
||||
completion()
|
||||
}
|
||||
}
|
||||
|
||||
private func checkPusher() {
|
||||
private func checkPusher(_ completion: (() -> Void)? = nil) {
|
||||
session.matrixRestClient.pushers { [weak self] response in
|
||||
switch response {
|
||||
case .success(let pushers):
|
||||
@@ -96,6 +137,7 @@ class UserSessionOverviewService: UserSessionOverviewServiceProtocol {
|
||||
case .failure(let error):
|
||||
MXLog.warning("[UserSessionOverviewService] checkPusher failed due to error: \(error)")
|
||||
}
|
||||
completion?()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -18,18 +18,16 @@ import Combine
|
||||
import Foundation
|
||||
|
||||
class MockUserSessionOverviewService: UserSessionOverviewServiceProtocol {
|
||||
|
||||
|
||||
var pusherEnabledSubject: CurrentValueSubject<Bool?, Never>
|
||||
var remotelyTogglingPushersAvailableSubject: CurrentValueSubject<Bool, Never>
|
||||
|
||||
init(pusherEnabled: Bool? = nil, remotelyTogglingPushersAvailable: Bool = true) {
|
||||
self.pusherEnabledSubject = CurrentValueSubject(pusherEnabled)
|
||||
self.remotelyTogglingPushersAvailableSubject = CurrentValueSubject(remotelyTogglingPushersAvailable)
|
||||
pusherEnabledSubject = CurrentValueSubject(pusherEnabled)
|
||||
remotelyTogglingPushersAvailableSubject = CurrentValueSubject(remotelyTogglingPushersAvailable)
|
||||
}
|
||||
|
||||
func togglePushNotifications() {
|
||||
guard let enabled = pusherEnabledSubject.value, self.remotelyTogglingPushersAvailableSubject.value else {
|
||||
guard let enabled = pusherEnabledSubject.value, remotelyTogglingPushersAvailableSubject.value else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+10
-11
@@ -20,23 +20,22 @@ import XCTest
|
||||
@testable import RiotSwiftUI
|
||||
|
||||
class UserSessionOverviewViewModelTests: XCTestCase {
|
||||
var sut: UserSessionOverviewViewModel!
|
||||
|
||||
func test_whenVerifyCurrentSessionProcessed_completionWithVerifyCurrentSessionCalled() {
|
||||
sut = UserSessionOverviewViewModel(sessionInfo: createUserSessionInfo(), service: MockUserSessionOverviewService())
|
||||
let sessionInfo = createUserSessionInfo()
|
||||
let sut = UserSessionOverviewViewModel(sessionInfo: sessionInfo, service: MockUserSessionOverviewService())
|
||||
|
||||
XCTAssertEqual(sut.state.isPusherEnabled, nil)
|
||||
var modelResult: UserSessionOverviewViewModelResult?
|
||||
sut.completion = { result in
|
||||
modelResult = result
|
||||
}
|
||||
sut.process(viewAction: .verifyCurrentSession)
|
||||
XCTAssertEqual(modelResult, .verifyCurrentSession)
|
||||
sut.process(viewAction: .verifySession)
|
||||
XCTAssertEqual(modelResult, .verifySession(sessionInfo))
|
||||
}
|
||||
|
||||
func test_whenViewSessionDetailsProcessed_completionWithShowSessionDetailsCalled() {
|
||||
let sessionInfo = createUserSessionInfo()
|
||||
sut = UserSessionOverviewViewModel(sessionInfo: sessionInfo, service: MockUserSessionOverviewService())
|
||||
let sut = UserSessionOverviewViewModel(sessionInfo: sessionInfo, service: MockUserSessionOverviewService())
|
||||
|
||||
XCTAssertEqual(sut.state.isPusherEnabled, nil)
|
||||
var modelResult: UserSessionOverviewViewModelResult?
|
||||
@@ -46,11 +45,11 @@ class UserSessionOverviewViewModelTests: XCTestCase {
|
||||
sut.process(viewAction: .viewSessionDetails)
|
||||
XCTAssertEqual(modelResult, .showSessionDetails(sessionInfo: sessionInfo))
|
||||
}
|
||||
|
||||
|
||||
func test_whenViewSessionDetailsProcessed_toggleAvailablePusher() {
|
||||
let sessionInfo = createUserSessionInfo()
|
||||
let service = MockUserSessionOverviewService(pusherEnabled: true)
|
||||
sut = UserSessionOverviewViewModel(sessionInfo: sessionInfo, service: service)
|
||||
let sut = UserSessionOverviewViewModel(sessionInfo: sessionInfo, service: service)
|
||||
|
||||
XCTAssertTrue(sut.state.remotelyTogglingPushersAvailable)
|
||||
XCTAssertEqual(sut.state.isPusherEnabled, true)
|
||||
@@ -63,7 +62,7 @@ class UserSessionOverviewViewModelTests: XCTestCase {
|
||||
func test_whenViewSessionDetailsProcessed_toggleNoPusher() {
|
||||
let sessionInfo = createUserSessionInfo()
|
||||
let service = MockUserSessionOverviewService(pusherEnabled: nil)
|
||||
sut = UserSessionOverviewViewModel(sessionInfo: sessionInfo, service: service)
|
||||
let sut = UserSessionOverviewViewModel(sessionInfo: sessionInfo, service: service)
|
||||
|
||||
XCTAssertTrue(sut.state.remotelyTogglingPushersAvailable)
|
||||
XCTAssertEqual(sut.state.isPusherEnabled, nil)
|
||||
@@ -76,7 +75,7 @@ class UserSessionOverviewViewModelTests: XCTestCase {
|
||||
func test_whenViewSessionDetailsProcessed_remotelyTogglingPushersNotAvailable() {
|
||||
let sessionInfo = createUserSessionInfo()
|
||||
let service = MockUserSessionOverviewService(pusherEnabled: true, remotelyTogglingPushersAvailable: false)
|
||||
sut = UserSessionOverviewViewModel(sessionInfo: sessionInfo, service: service)
|
||||
let sut = UserSessionOverviewViewModel(sessionInfo: sessionInfo, service: service)
|
||||
|
||||
XCTAssertFalse(sut.state.remotelyTogglingPushersAvailable)
|
||||
XCTAssertEqual(sut.state.isPusherEnabled, true)
|
||||
@@ -90,7 +89,7 @@ class UserSessionOverviewViewModelTests: XCTestCase {
|
||||
UserSessionInfo(id: "session",
|
||||
name: "iOS",
|
||||
deviceType: .mobile,
|
||||
isVerified: false,
|
||||
verificationState: .unverified,
|
||||
lastSeenIP: "10.0.0.10",
|
||||
lastSeenTimestamp: Date().timeIntervalSince1970 - 100,
|
||||
applicationName: "Element iOS",
|
||||
|
||||
+10
-3
@@ -20,19 +20,24 @@ import Foundation
|
||||
|
||||
enum UserSessionOverviewCoordinatorResult {
|
||||
case openSessionDetails(sessionInfo: UserSessionInfo)
|
||||
case verifySession(UserSessionInfo)
|
||||
case renameSession(UserSessionInfo)
|
||||
case logoutOfSession(UserSessionInfo)
|
||||
}
|
||||
|
||||
// MARK: View model
|
||||
|
||||
enum UserSessionOverviewViewModelResult: Equatable {
|
||||
case showSessionDetails(sessionInfo: UserSessionInfo)
|
||||
case verifyCurrentSession
|
||||
case verifySession(UserSessionInfo)
|
||||
case renameSession(UserSessionInfo)
|
||||
case logoutOfSession(UserSessionInfo)
|
||||
}
|
||||
|
||||
// MARK: View
|
||||
|
||||
struct UserSessionOverviewViewState: BindableState {
|
||||
let cardViewData: UserSessionCardViewData
|
||||
var cardViewData: UserSessionCardViewData
|
||||
let isCurrentSession: Bool
|
||||
var isPusherEnabled: Bool?
|
||||
var remotelyTogglingPushersAvailable: Bool
|
||||
@@ -40,7 +45,9 @@ struct UserSessionOverviewViewState: BindableState {
|
||||
}
|
||||
|
||||
enum UserSessionOverviewViewAction {
|
||||
case verifyCurrentSession
|
||||
case verifySession
|
||||
case viewSessionDetails
|
||||
case togglePushNotifications
|
||||
case renameSession
|
||||
case logoutOfSession
|
||||
}
|
||||
|
||||
+30
-4
@@ -14,6 +14,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
typealias UserSessionOverviewViewModelType = StateStoreViewModel<UserSessionOverviewViewState, UserSessionOverviewViewAction>
|
||||
@@ -26,7 +27,13 @@ class UserSessionOverviewViewModel: UserSessionOverviewViewModelType, UserSessio
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(sessionInfo: UserSessionInfo, service: UserSessionOverviewServiceProtocol) {
|
||||
init(sessionInfo: UserSessionInfo,
|
||||
service: UserSessionOverviewServiceProtocol,
|
||||
sessionsOverviewDataPublisher: CurrentValueSubject<UserSessionsOverviewData, Never> = .init(.init(currentSession: nil,
|
||||
unverifiedSessions: [],
|
||||
inactiveSessions: [],
|
||||
otherSessions: [],
|
||||
linkDeviceEnabled: false))) {
|
||||
self.sessionInfo = sessionInfo
|
||||
self.service = service
|
||||
|
||||
@@ -39,6 +46,21 @@ class UserSessionOverviewViewModel: UserSessionOverviewViewModelType, UserSessio
|
||||
super.init(initialViewState: state)
|
||||
|
||||
startObservingService()
|
||||
|
||||
sessionsOverviewDataPublisher.sink { [weak self] overviewData in
|
||||
guard let self = self else { return }
|
||||
|
||||
var updatedInfo: UserSessionInfo?
|
||||
if let currentSession = overviewData.currentSession, currentSession.id == sessionInfo.id {
|
||||
updatedInfo = currentSession
|
||||
} else if let otherSession = overviewData.otherSessions.first(where: { $0.id == sessionInfo.id }) {
|
||||
updatedInfo = otherSession
|
||||
}
|
||||
|
||||
guard let updatedInfo = updatedInfo else { return }
|
||||
self.state.cardViewData = UserSessionCardViewData(sessionInfo: updatedInfo)
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private func startObservingService() {
|
||||
@@ -62,13 +84,17 @@ class UserSessionOverviewViewModel: UserSessionOverviewViewModelType, UserSessio
|
||||
|
||||
override func process(viewAction: UserSessionOverviewViewAction) {
|
||||
switch viewAction {
|
||||
case .verifyCurrentSession:
|
||||
completion?(.verifyCurrentSession)
|
||||
case .verifySession:
|
||||
completion?(.verifySession(sessionInfo))
|
||||
case .viewSessionDetails:
|
||||
completion?(.showSessionDetails(sessionInfo: sessionInfo))
|
||||
case .togglePushNotifications:
|
||||
self.state.showLoadingIndicator = true
|
||||
state.showLoadingIndicator = true
|
||||
service.togglePushNotifications()
|
||||
case .renameSession:
|
||||
completion?(.renameSession(sessionInfo))
|
||||
case .logoutOfSession:
|
||||
completion?(.logoutOfSession(sessionInfo))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+29
-3
@@ -24,16 +24,18 @@ struct UserSessionOverview: View {
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
UserSessionCardView(viewData: viewModel.viewState.cardViewData, onVerifyAction: { _ in
|
||||
viewModel.send(viewAction: .verifyCurrentSession)
|
||||
viewModel.send(viewAction: .verifySession)
|
||||
},
|
||||
onViewDetailsAction: { _ in
|
||||
viewModel.send(viewAction: .viewSessionDetails)
|
||||
})
|
||||
.padding(16)
|
||||
SwiftUI.Section {
|
||||
UserSessionOverviewDisclosureCell(title: VectorL10n.userSessionOverviewSessionDetailsButtonTitle, onBackgroundTap: {
|
||||
UserSessionOverviewItem(title: VectorL10n.userSessionOverviewSessionDetailsButtonTitle,
|
||||
showsChevron: true) {
|
||||
viewModel.send(viewAction: .viewSessionDetails)
|
||||
})
|
||||
}
|
||||
|
||||
if let enabled = viewModel.viewState.isPusherEnabled {
|
||||
UserSessionOverviewToggleCell(title: VectorL10n.userSessionPushNotifications,
|
||||
message: VectorL10n.userSessionPushNotificationsMessage,
|
||||
@@ -42,6 +44,14 @@ struct UserSessionOverview: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SwiftUI.Section {
|
||||
UserSessionOverviewItem(title: VectorL10n.manageSessionSignOut,
|
||||
alignment: .center,
|
||||
isDestructive: true) {
|
||||
viewModel.send(viewAction: .logoutOfSession)
|
||||
}
|
||||
}
|
||||
}
|
||||
.background(theme.colors.system.ignoresSafeArea())
|
||||
.frame(maxHeight: .infinity)
|
||||
@@ -49,6 +59,22 @@ struct UserSessionOverview: View {
|
||||
.navigationTitle(viewModel.viewState.isCurrentSession ?
|
||||
VectorL10n.userSessionOverviewCurrentSessionTitle :
|
||||
VectorL10n.userSessionOverviewSessionTitle)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Menu {
|
||||
Button { viewModel.send(viewAction: .renameSession) } label: {
|
||||
Label(VectorL10n.manageSessionRename, systemImage: "pencil")
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "ellipsis")
|
||||
.padding(.horizontal, 4)
|
||||
.padding(.vertical, 12)
|
||||
}
|
||||
.offset(x: 4) // Re-align the symbol after applying padding.
|
||||
}
|
||||
}
|
||||
.accentColor(theme.colors.accent)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+27
-11
@@ -16,10 +16,13 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct UserSessionOverviewDisclosureCell: View {
|
||||
struct UserSessionOverviewItem: View {
|
||||
@Environment(\.theme) private var theme: ThemeSwiftUI
|
||||
|
||||
let title: String
|
||||
var alignment: Alignment = .leading
|
||||
var showsChevron = false
|
||||
var isDestructive = false
|
||||
var onBackgroundTap: (() -> Void)?
|
||||
|
||||
var body: some View {
|
||||
@@ -29,9 +32,12 @@ struct UserSessionOverviewDisclosureCell: View {
|
||||
HStack {
|
||||
Text(title)
|
||||
.font(theme.fonts.body)
|
||||
.foregroundColor(theme.colors.primaryContent)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Image(Asset.Images.chevron.name)
|
||||
.foregroundColor(textColor)
|
||||
.frame(maxWidth: .infinity, alignment: alignment)
|
||||
|
||||
if showsChevron {
|
||||
Image(Asset.Images.chevron.name)
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 15)
|
||||
.padding(.horizontal, 16)
|
||||
@@ -40,17 +46,27 @@ struct UserSessionOverviewDisclosureCell: View {
|
||||
.background(theme.colors.background)
|
||||
}
|
||||
}
|
||||
|
||||
var textColor: Color {
|
||||
isDestructive ? theme.colors.alert : theme.colors.primaryContent
|
||||
}
|
||||
}
|
||||
|
||||
struct UserSessionOverviewDisclosureCell_Previews: PreviewProvider {
|
||||
struct UserSessionOverviewItem_Previews: PreviewProvider {
|
||||
static var buttons: some View {
|
||||
NavigationView {
|
||||
ScrollView {
|
||||
UserSessionOverviewItem(title: "Nav item", showsChevron: true)
|
||||
UserSessionOverviewItem(title: "Button")
|
||||
UserSessionOverviewItem(title: "Button", isDestructive: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static var previews: some View {
|
||||
Group {
|
||||
UserSessionOverviewDisclosureCell(title: "Title")
|
||||
.theme(.light)
|
||||
.preferredColorScheme(.light)
|
||||
UserSessionOverviewDisclosureCell(title: "Title")
|
||||
.theme(.dark)
|
||||
.preferredColorScheme(.dark)
|
||||
buttons.theme(.light).preferredColorScheme(.light)
|
||||
buttons.theme(.dark).preferredColorScheme(.dark)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user