mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-01 05:36:57 +02:00
Release 2.0.0
This commit is contained in:
+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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user