mv-experiment #1

Merged
fmodf merged 88 commits from mv-experiment into develop 2024-09-03 15:13:59 +00:00
3 changed files with 21 additions and 23 deletions
Showing only changes of commit 9c4576f1f6 - Show all commits

View file

@ -31,29 +31,27 @@ 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
let msgId = received.messageId
try? await Database.shared.dbQueue.write { db in
if try Message.fetchOne(db, key: msgId) != nil {
#if DEBUG
print("---")
print("Skipping archived message with id \(message.id ?? "???") (message exists)")
print("---")
#endif
return
} else {
#if DEBUG #if DEBUG
print("---") print("---")
print("Archive message received: \(message)") print("Archive message received: \(message)")
print("Date: \(date)") print("Date: \(date)")
print("---") print("---")
#endif #endif
if var msg = Message.map(message) {
// Skip archived message if such message already exists in the database
if let archiveId = message.id {
try? await Database.shared.dbQueue.read { db in
if try Message.fetchOne(db, key: archiveId) != nil {
return
}
}
}
if let msg = Message.map(message) {
do {
var msg = msg
msg.date = received.timestamp msg.date = received.timestamp
try await msg.save() try msg.insert(db)
} catch { }
logIt(.error, "Error saving message: \(error)")
} }
} }
} }

View file

@ -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)
} }

View file

@ -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
} }