mv-experiment #1
|
@ -31,30 +31,28 @@ final class ClientMartinMAM {
|
||||||
private func handleMessage(_ received: Martin.MessageArchiveManagementModule.ArchivedMessageReceived) async {
|
private func handleMessage(_ received: Martin.MessageArchiveManagementModule.ArchivedMessageReceived) async {
|
||||||
let message = received.message
|
let message = received.message
|
||||||
let date = received.timestamp
|
let date = received.timestamp
|
||||||
#if DEBUG
|
let msgId = received.messageId
|
||||||
print("---")
|
|
||||||
print("Archive message received: \(message)")
|
|
||||||
print("Date: \(date)")
|
|
||||||
print("---")
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Skip archived message if such message already exists in the database
|
try? await Database.shared.dbQueue.write { db in
|
||||||
if let archiveId = message.id {
|
if try Message.fetchOne(db, key: msgId) != nil {
|
||||||
try? await Database.shared.dbQueue.read { db in
|
#if DEBUG
|
||||||
if try Message.fetchOne(db, key: archiveId) != nil {
|
print("---")
|
||||||
return
|
print("Skipping archived message with id \(message.id ?? "???") (message exists)")
|
||||||
|
print("---")
|
||||||
|
#endif
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
#if DEBUG
|
||||||
|
print("---")
|
||||||
|
print("Archive message received: \(message)")
|
||||||
|
print("Date: \(date)")
|
||||||
|
print("---")
|
||||||
|
#endif
|
||||||
|
if var msg = Message.map(message) {
|
||||||
|
msg.date = received.timestamp
|
||||||
|
try msg.insert(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let msg = Message.map(message) {
|
|
||||||
do {
|
|
||||||
var msg = msg
|
|
||||||
msg.date = received.timestamp
|
|
||||||
try await msg.save()
|
|
||||||
} catch {
|
|
||||||
logIt(.error, "Error saving message: \(error)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ private extension MessagesStore {
|
||||||
// MARK: - Archived messages
|
// MARK: - Archived messages
|
||||||
extension MessagesStore {
|
extension MessagesStore {
|
||||||
func requestEarliestArchivedMessages() {
|
func requestEarliestArchivedMessages() {
|
||||||
guard let beforeId = messages.first?.id else { return }
|
guard let beforeId = messages.last?.id else { return }
|
||||||
Task {
|
Task {
|
||||||
await archiveMessageFetcher.fetchBeforeMessages(roster, client, beforeId: beforeId)
|
await archiveMessageFetcher.fetchBeforeMessages(roster, client, beforeId: beforeId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,5 +44,5 @@ enum Const {
|
||||||
static let attachmentPreviewSize = UIScreen.main.bounds.width * 0.5
|
static let attachmentPreviewSize = UIScreen.main.bounds.width * 0.5
|
||||||
|
|
||||||
// MAM request page size
|
// MAM request page size
|
||||||
static let mamRequestLimit = 30
|
static let mamRequestLimit = 10
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue