wip
This commit is contained in:
parent
2b876e5ae6
commit
515ed2197e
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue