wip
This commit is contained in:
parent
ea333acb1a
commit
477e58f35c
|
@ -49,7 +49,6 @@ private struct ChatsRow: View {
|
||||||
var chat: Chat
|
var chat: Chat
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Text("dump")
|
|
||||||
SharedListRow(iconType: .charCircle(chat.name), text: chat.name, controlType: .none)
|
SharedListRow(iconType: .charCircle(chat.name), text: chat.name, controlType: .none)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
Task {
|
Task {
|
||||||
|
@ -61,12 +60,15 @@ private struct ChatsRow: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// try? await clientsStore.addRosterForNewChatIfNeeded(chat)
|
guard let model = wrapper.chat(with: chat) else {
|
||||||
// let (messages, attachments, settings) = try await clientsStore.conversationStores(for: chat)
|
throw AimErrors.wrongContact
|
||||||
// router.showScreen(.push) { _ in
|
}
|
||||||
// ConversationScreen(messagesStore: messages, attachments: attachments, settings: settings)
|
|
||||||
// .navigationBarHidden(true)
|
router.showScreen(.push) { _ in
|
||||||
// }
|
ConversationScreen()
|
||||||
|
.navigationBarHidden(true)
|
||||||
|
.environmentObject(model)
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
router.showAlert(
|
router.showAlert(
|
||||||
.alert,
|
.alert,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
enum AimErrors: Error {
|
enum AimErrors: Error {
|
||||||
case loginError
|
case loginError
|
||||||
case contactRemoveError
|
case contactRemoveError
|
||||||
|
case wrongContact
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,9 @@ final class MonalXmppWrapper: ObservableObject {
|
||||||
// subscribe to monalxmpp notifications and fire notification for update
|
// subscribe to monalxmpp notifications and fire notification for update
|
||||||
subscribeToUpdates()
|
subscribeToUpdates()
|
||||||
NotificationCenter.default.post(name: Notification.Name(kMonalRefresh), object: nil)
|
NotificationCenter.default.post(name: Notification.Name(kMonalRefresh), object: nil)
|
||||||
|
|
||||||
|
// reconnect
|
||||||
|
xmpp.connectIfNecessary()
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
@ -59,6 +62,12 @@ extension MonalXmppWrapper {
|
||||||
let chatModel = MonalChatWrapper(contact: with, db: db, xmpp: xmpp)
|
let chatModel = MonalChatWrapper(contact: with, db: db, xmpp: xmpp)
|
||||||
return chatModel
|
return chatModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func chat(with: Chat) -> MonalChatWrapper? {
|
||||||
|
guard let contact = contacts.first(where: { $0.ownerId == with.accountId && $0.contactJid == with.participantJid }) else { return nil }
|
||||||
|
let chatModel = MonalChatWrapper(contact: contact, db: db, xmpp: xmpp)
|
||||||
|
return chatModel
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Try login from Login screen
|
// MARK: - Try login from Login screen
|
||||||
|
@ -173,6 +182,7 @@ final class MonalChatWrapper: ObservableObject {
|
||||||
let contact: Contact
|
let contact: Contact
|
||||||
private let xmpp: MLXMPPManager
|
private let xmpp: MLXMPPManager
|
||||||
private let db: DataLayer
|
private let db: DataLayer
|
||||||
|
private var notificationObservers: [AnyObject] = []
|
||||||
|
|
||||||
init(contact: Contact, db: DataLayer, xmpp: MLXMPPManager) {
|
init(contact: Contact, db: DataLayer, xmpp: MLXMPPManager) {
|
||||||
self.contact = contact
|
self.contact = contact
|
||||||
|
@ -180,6 +190,17 @@ final class MonalChatWrapper: ObservableObject {
|
||||||
self.xmpp = xmpp
|
self.xmpp = xmpp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
notificationObservers.forEach { NotificationCenter.default.removeObserver($0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func subscribe() {
|
||||||
|
let newMsg = NotificationCenter.default.addObserver(forName: Notification.Name(kMonalNewMessageNotice), object: nil, queue: .main) { [weak self] _ in
|
||||||
|
self?.refreshMessages()
|
||||||
|
}
|
||||||
|
notificationObservers.append(newMsg)
|
||||||
|
}
|
||||||
|
|
||||||
private func refreshMessages() {
|
private func refreshMessages() {
|
||||||
messages = db.messages(forContact: contact.contactJid, forAccount: NSNumber(value: contact.ownerId))
|
messages = db.messages(forContact: contact.contactJid, forAccount: NSNumber(value: contact.ownerId))
|
||||||
.compactMap {
|
.compactMap {
|
||||||
|
|
Loading…
Reference in a new issue