wip
This commit is contained in:
parent
9b8b5d1ae6
commit
2b876e5ae6
|
@ -20,7 +20,10 @@ struct AnotherIMApp: App {
|
|||
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
func applicationWillEnterForeground(_: UIApplication) {
|
||||
// let manager = MLXMPPManager.sharedInstance()
|
||||
// manager.nowForegrounded()
|
||||
MLXMPPManager.sharedInstance().nowForegrounded()
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground(_: UIApplication) {
|
||||
MLXMPPManager.sharedInstance().nowBackgrounded()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,9 @@ struct ConversationScreen: View {
|
|||
firstIsVisible = true
|
||||
autoScroll = true
|
||||
}
|
||||
// messagesStore.scrolledMessage(message.id)
|
||||
if message.id == chatWrapper.messages.last?.id {
|
||||
chatWrapper.requestMAM()
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
if message.id == chatWrapper.messages.first?.id {
|
||||
|
|
|
@ -86,6 +86,7 @@ struct Message: Identifiable {
|
|||
let accountId: Int
|
||||
let participantJid: String
|
||||
let dbId: Int
|
||||
let stanzaId: String
|
||||
let timestamp: Date
|
||||
let body: String
|
||||
let isInbound: Bool
|
||||
|
@ -99,6 +100,7 @@ struct Message: Identifiable {
|
|||
accountId = accId
|
||||
participantJid = obj.participantJid
|
||||
self.dbId = dbId
|
||||
stanzaId = obj.stanzaId
|
||||
timestamp = obj.timestamp
|
||||
body = obj.messageText
|
||||
isInbound = obj.inbound
|
||||
|
|
|
@ -189,6 +189,7 @@ final class MonalChatWrapper: ObservableObject {
|
|||
private let xmpp: MLXMPPManager
|
||||
private let db: DataLayer
|
||||
private var notificationObservers: [AnyObject] = []
|
||||
private var mamRequestInProgress = false
|
||||
|
||||
init(account: Account, contact: Contact, db: DataLayer, xmpp: MLXMPPManager) {
|
||||
self.contact = contact
|
||||
|
@ -223,6 +224,23 @@ final class MonalChatWrapper: ObservableObject {
|
|||
print(newMessageId)
|
||||
xmpp.sendMessage(text, to: monalContact, isEncrypted: monalContact.isEncrypted, isUpload: false, messageId: newMessageId)
|
||||
}
|
||||
|
||||
func requestMAM() {
|
||||
if mamRequestInProgress { return }
|
||||
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
|
||||
?? db.lastStanzaId(forAccount: NSNumber(value: account.id))
|
||||
|
||||
acc.setMAMQueryMostRecentFor(monalContact, before: lastStanzaId) { [weak self] msgs, _ in
|
||||
self?.mamRequestInProgress = false
|
||||
if !(msgs ?? []).isEmpty {
|
||||
self?.refreshMessages()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension MonalChatWrapper {
|
||||
|
|
Loading…
Reference in a new issue