wip
This commit is contained in:
parent
c8cf403d15
commit
406b2fde1d
|
@ -127,7 +127,16 @@ private struct ContactsScreenRow: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func startChat() {
|
private func startChat() {
|
||||||
let model = wrapper.chat(with: contact)
|
guard let model = wrapper.chat(with: contact) else {
|
||||||
|
router.showAlert(
|
||||||
|
.alert,
|
||||||
|
title: L10n.Global.Error.title,
|
||||||
|
subtitle: L10n.Conversation.startError
|
||||||
|
) {
|
||||||
|
Button(L10n.Global.ok, role: .cancel) {}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
router.showScreen(.push) { _ in
|
router.showScreen(.push) { _ in
|
||||||
ConversationScreen()
|
ConversationScreen()
|
||||||
.navigationBarHidden(true)
|
.navigationBarHidden(true)
|
||||||
|
|
|
@ -16,7 +16,6 @@ final class WrapperChat: ObservableObject {
|
||||||
private let xmpp: MLXMPPManager
|
private let xmpp: MLXMPPManager
|
||||||
private let db: DataLayer
|
private let db: DataLayer
|
||||||
private let monalContact: MLContact
|
private let monalContact: MLContact
|
||||||
// private let account: Account
|
|
||||||
private var notificationObservers: [AnyObject] = []
|
private var notificationObservers: [AnyObject] = []
|
||||||
|
|
||||||
init?(with: Contact) {
|
init?(with: Contact) {
|
||||||
|
@ -32,9 +31,30 @@ final class WrapperChat: ObservableObject {
|
||||||
else { return nil }
|
else { return nil }
|
||||||
self.monalContact = monalContact
|
self.monalContact = monalContact
|
||||||
isOmemoEnabled = monalContact.isEncrypted
|
isOmemoEnabled = monalContact.isEncrypted
|
||||||
|
|
||||||
|
subscribe()
|
||||||
|
NotificationCenter.default.post(name: Notification.Name(kMonalNewMessageNotice), object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
init?(with _: Chat) {
|
init?(with: Chat) {
|
||||||
|
xmpp = MLXMPPManager.sharedInstance()
|
||||||
|
db = DataLayer.sharedInstance()
|
||||||
|
|
||||||
|
guard
|
||||||
|
let monalContact = db.contactList()
|
||||||
|
.first(where: {
|
||||||
|
$0.accountID.intValue == with.accountId
|
||||||
|
})
|
||||||
|
else { return nil }
|
||||||
|
self.monalContact = monalContact
|
||||||
|
isOmemoEnabled = monalContact.isEncrypted
|
||||||
|
|
||||||
|
guard let contact = Contact(monalContact) else { return nil }
|
||||||
|
self.contact = contact
|
||||||
|
|
||||||
|
subscribe()
|
||||||
|
NotificationCenter.default.post(name: Notification.Name(kMonalNewMessageNotice), object: nil)
|
||||||
|
|
||||||
// guard let account = accounts.first(where: { $0.id == with.accountId }) else { return nil }
|
// guard let account = accounts.first(where: { $0.id == with.accountId }) else { return nil }
|
||||||
//
|
//
|
||||||
// var contact = contacts.first(where: { $0.ownerId == with.accountId && $0.contactJid == with.participantJid })
|
// var contact = contacts.first(where: { $0.ownerId == with.accountId && $0.contactJid == with.participantJid })
|
||||||
|
@ -51,7 +71,6 @@ final class WrapperChat: ObservableObject {
|
||||||
// guard let contact else { return nil }
|
// guard let contact else { return nil }
|
||||||
// let chatModel = WrapperChat(account: account, contact: contact, db: db, xmpp: xmpp)
|
// let chatModel = WrapperChat(account: account, contact: contact, db: db, xmpp: xmpp)
|
||||||
// return chatModel
|
// return chatModel
|
||||||
nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// init(account: Account, contact: Contact, db: DataLayer, xmpp: MLXMPPManager) {
|
// init(account: Account, contact: Contact, db: DataLayer, xmpp: MLXMPPManager) {
|
||||||
|
@ -83,7 +102,9 @@ final class WrapperChat: ObservableObject {
|
||||||
to: contact.contactJid,
|
to: contact.contactJid,
|
||||||
forAccount: monalContact.accountID,
|
forAccount: monalContact.accountID,
|
||||||
withMessage: text,
|
withMessage: text,
|
||||||
actuallyFrom: account.jid,
|
|
||||||
|
// MARK: WARNING!
|
||||||
|
actuallyFrom: "testmon3@test.anal.company",
|
||||||
withId: newMessageId,
|
withId: newMessageId,
|
||||||
encrypted: monalContact.isEncrypted,
|
encrypted: monalContact.isEncrypted,
|
||||||
messageType: kMessageTypeText,
|
messageType: kMessageTypeText,
|
||||||
|
@ -95,13 +116,12 @@ final class WrapperChat: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func requestMAM() {
|
func requestMAM() {
|
||||||
|
guard let acc = monalContact.account else { return }
|
||||||
if mamRequestInProgress { return }
|
if mamRequestInProgress { return }
|
||||||
mamRequestInProgress = true
|
mamRequestInProgress = true
|
||||||
|
|
||||||
guard let acc = xmpp.getEnabledAccount(forID: NSNumber(value: account.id)) else { return }
|
|
||||||
|
|
||||||
let lastStanzaId = messages.last?.stanzaId // last here because list is reversed
|
let lastStanzaId = messages.last?.stanzaId // last here because list is reversed
|
||||||
?? db.lastStanzaId(forAccount: NSNumber(value: account.id))
|
?? db.lastStanzaId(forAccount: NSNumber(value: contact.ownerId))
|
||||||
|
|
||||||
acc.setMAMQueryMostRecentFor(monalContact, before: lastStanzaId) { [weak self] msgs, _ in
|
acc.setMAMQueryMostRecentFor(monalContact, before: lastStanzaId) { [weak self] msgs, _ in
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
|
||||||
|
|
Loading…
Reference in a new issue