diff --git a/Monal/another.im/Views/Conversation/ConversationScreen.swift b/Monal/another.im/Views/Conversation/ConversationScreen.swift index 8d9e69b..50d1be6 100644 --- a/Monal/another.im/Views/Conversation/ConversationScreen.swift +++ b/Monal/another.im/Views/Conversation/ConversationScreen.swift @@ -25,18 +25,17 @@ struct ConversationScreen: View { router.dismissScreen() } ), - centerText: .init(text: centerText()), - rightButton: nil - // rightButton: .init( - // image: Image(systemName: "gear"), - // action: { - // router.showScreen(.push) { _ in - // ConversationSettingsScreen() - // // .environmentObject(settings) - // .navigationBarHidden(true) - // } - // } - // ) + centerText: .init(text: chatWrapper.chatTitle), + rightButton: .init( + image: Image(systemName: "gear"), + action: { + router.showScreen(.push) { _ in + ConversationSettingsScreen() + .environmentObject(chatWrapper) + .navigationBarHidden(true) + } + } + ) ) // Msg list @@ -114,8 +113,4 @@ struct ConversationScreen: View { .environmentObject(chatWrapper) } } - - private func centerText() -> String { - chatWrapper.contact.name ?? chatWrapper.contact.contactJid - } } diff --git a/Monal/another.im/Views/Conversation/ConversationSettingsScreen.swift b/Monal/another.im/Views/Conversation/ConversationSettingsScreen.swift index 4c1837c..8c95591 100644 --- a/Monal/another.im/Views/Conversation/ConversationSettingsScreen.swift +++ b/Monal/another.im/Views/Conversation/ConversationSettingsScreen.swift @@ -3,8 +3,8 @@ import Foundation import SwiftUI struct ConversationSettingsScreen: View { + @EnvironmentObject var chatWrapper: MonalChatWrapper @Environment(\.router) var router - // @EnvironmentObject var settingsStore: ChatSettingsStore var body: some View { ZStack { @@ -22,30 +22,20 @@ struct ConversationSettingsScreen: View { router.dismissScreen() } ), - centerText: .init(text: centerText()) + centerText: .init(text: chatWrapper.chatTitle) ) // Settings list - // ScrollView { - // LazyVStack(spacing: 0) { - // SharedListRow( - // iconType: .none, - // text: L10n.Conversation.Settings.enableOmemo, - // controlType: .switcher(isOn: Binding( - // get: { settingsStore.chat?.encrypted ?? false }, - // set: { new in - // settingsStore.setSecured(new) - // } - // )) - // ) - // } - // } + ScrollView { + LazyVStack(spacing: 0) { + SharedListRow( + iconType: .none, + text: L10n.Conversation.Settings.enableOmemo, + controlType: .switcher(isOn: $chatWrapper.isOmemoEnabled) + ) + } + } } } } - - private func centerText() -> String { - // TODO: make center text depend on conversation type in future (chat, group chat, channel, etc.) - L10n.Conversation.Settings.Title.chat - } } diff --git a/Monal/another.im/XMPP/MonalXmppWrapper.swift b/Monal/another.im/XMPP/MonalXmppWrapper.swift index 66fd257..f6dd3de 100644 --- a/Monal/another.im/XMPP/MonalXmppWrapper.swift +++ b/Monal/another.im/XMPP/MonalXmppWrapper.swift @@ -181,6 +181,11 @@ private extension MonalXmppWrapper { final class MonalChatWrapper: ObservableObject { @Published private(set) var messages: [Message] = [] @Published var replyText: String = "" + @Published var isOmemoEnabled: Bool { + didSet { + toggleOmemo(isOmemoEnabled) + } + } let contact: Contact @@ -199,15 +204,22 @@ final class MonalChatWrapper: ObservableObject { // swiftlint:disable:next force_unwrapping monalContact = db.contactList().first { $0.accountID.intValue == contact.ownerId && $0.contactJid == contact.contactJid }! + isOmemoEnabled = monalContact.isEncrypted subscribe() NotificationCenter.default.post(name: Notification.Name(kMonalNewMessageNotice), object: nil) + + // } deinit { notificationObservers.forEach { NotificationCenter.default.removeObserver($0) } } + var chatTitle: String { + contact.name ?? contact.contactJid + } + func sendText(_ text: String) { let newMessageId = UUID().uuidString _ = db.addMessageHistory( @@ -265,4 +277,10 @@ private extension MonalChatWrapper { .sorted { $0.timestamp > $1.timestamp } self.messages = messages } + + func toggleOmemo(_ new: Bool) { + if monalContact.isEncrypted != new { + monalContact.toggleEncryption(new) + } + } }