wip
This commit is contained in:
parent
2b876e5ae6
commit
515ed2197e
|
@ -25,18 +25,17 @@ struct ConversationScreen: View {
|
||||||
router.dismissScreen()
|
router.dismissScreen()
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
centerText: .init(text: centerText()),
|
centerText: .init(text: chatWrapper.chatTitle),
|
||||||
rightButton: nil
|
rightButton: .init(
|
||||||
// rightButton: .init(
|
image: Image(systemName: "gear"),
|
||||||
// image: Image(systemName: "gear"),
|
action: {
|
||||||
// action: {
|
router.showScreen(.push) { _ in
|
||||||
// router.showScreen(.push) { _ in
|
ConversationSettingsScreen()
|
||||||
// ConversationSettingsScreen()
|
.environmentObject(chatWrapper)
|
||||||
// // .environmentObject(settings)
|
.navigationBarHidden(true)
|
||||||
// .navigationBarHidden(true)
|
}
|
||||||
// }
|
}
|
||||||
// }
|
)
|
||||||
// )
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Msg list
|
// Msg list
|
||||||
|
@ -114,8 +113,4 @@ struct ConversationScreen: View {
|
||||||
.environmentObject(chatWrapper)
|
.environmentObject(chatWrapper)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func centerText() -> String {
|
|
||||||
chatWrapper.contact.name ?? chatWrapper.contact.contactJid
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ import Foundation
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ConversationSettingsScreen: View {
|
struct ConversationSettingsScreen: View {
|
||||||
|
@EnvironmentObject var chatWrapper: MonalChatWrapper
|
||||||
@Environment(\.router) var router
|
@Environment(\.router) var router
|
||||||
// @EnvironmentObject var settingsStore: ChatSettingsStore
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
|
@ -22,30 +22,20 @@ struct ConversationSettingsScreen: View {
|
||||||
router.dismissScreen()
|
router.dismissScreen()
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
centerText: .init(text: centerText())
|
centerText: .init(text: chatWrapper.chatTitle)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Settings list
|
// Settings list
|
||||||
// ScrollView {
|
ScrollView {
|
||||||
// LazyVStack(spacing: 0) {
|
LazyVStack(spacing: 0) {
|
||||||
// SharedListRow(
|
SharedListRow(
|
||||||
// iconType: .none,
|
iconType: .none,
|
||||||
// text: L10n.Conversation.Settings.enableOmemo,
|
text: L10n.Conversation.Settings.enableOmemo,
|
||||||
// controlType: .switcher(isOn: Binding(
|
controlType: .switcher(isOn: $chatWrapper.isOmemoEnabled)
|
||||||
// get: { settingsStore.chat?.encrypted ?? false },
|
)
|
||||||
// set: { new in
|
}
|
||||||
// settingsStore.setSecured(new)
|
}
|
||||||
// }
|
|
||||||
// ))
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
final class MonalChatWrapper: ObservableObject {
|
||||||
@Published private(set) var messages: [Message] = []
|
@Published private(set) var messages: [Message] = []
|
||||||
@Published var replyText: String = ""
|
@Published var replyText: String = ""
|
||||||
|
@Published var isOmemoEnabled: Bool {
|
||||||
|
didSet {
|
||||||
|
toggleOmemo(isOmemoEnabled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let contact: Contact
|
let contact: Contact
|
||||||
|
|
||||||
|
@ -199,15 +204,22 @@ final class MonalChatWrapper: ObservableObject {
|
||||||
|
|
||||||
// swiftlint:disable:next force_unwrapping
|
// swiftlint:disable:next force_unwrapping
|
||||||
monalContact = db.contactList().first { $0.accountID.intValue == contact.ownerId && $0.contactJid == contact.contactJid }!
|
monalContact = db.contactList().first { $0.accountID.intValue == contact.ownerId && $0.contactJid == contact.contactJid }!
|
||||||
|
isOmemoEnabled = monalContact.isEncrypted
|
||||||
|
|
||||||
subscribe()
|
subscribe()
|
||||||
NotificationCenter.default.post(name: Notification.Name(kMonalNewMessageNotice), object: nil)
|
NotificationCenter.default.post(name: Notification.Name(kMonalNewMessageNotice), object: nil)
|
||||||
|
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
notificationObservers.forEach { NotificationCenter.default.removeObserver($0) }
|
notificationObservers.forEach { NotificationCenter.default.removeObserver($0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var chatTitle: String {
|
||||||
|
contact.name ?? contact.contactJid
|
||||||
|
}
|
||||||
|
|
||||||
func sendText(_ text: String) {
|
func sendText(_ text: String) {
|
||||||
let newMessageId = UUID().uuidString
|
let newMessageId = UUID().uuidString
|
||||||
_ = db.addMessageHistory(
|
_ = db.addMessageHistory(
|
||||||
|
@ -265,4 +277,10 @@ private extension MonalChatWrapper {
|
||||||
.sorted { $0.timestamp > $1.timestamp }
|
.sorted { $0.timestamp > $1.timestamp }
|
||||||
self.messages = messages
|
self.messages = messages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toggleOmemo(_ new: Bool) {
|
||||||
|
if monalContact.isEncrypted != new {
|
||||||
|
monalContact.toggleEncryption(new)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue