mv-experiment #1

Merged
fmodf merged 88 commits from mv-experiment into develop 2024-09-03 15:13:59 +00:00
4 changed files with 16 additions and 22 deletions
Showing only changes of commit 51cd7f82f6 - Show all commits

View file

@ -69,12 +69,6 @@ final class ClientMartinMessagesManager {
)
// Save message
Task {
await updateMsgInDB(msg)
}
}
private func updateMsgInDB(_ msg: Message) async {
Task {
do {
try await msg.save()

View file

@ -87,7 +87,7 @@ extension Client {
}
extension Client {
func sendMessage(_ message: Message) async {
func sendMessage(_ message: Message) async throws {
guard let to = message.to else {
return
}
@ -96,19 +96,8 @@ extension Client {
}
let msg = chat.createMessage(text: message.body ?? "??", id: message.id)
do {
try await chat.send(message: msg)
} catch {
print("Error sending message: \(error)")
}
}
// func sendMessage(_ message: String, to roster: Roster) async {
// guard let chat = chatsManager.chat(for: connection.context, with: BareJID(roster.contactBareJid)) else {
// return
// }
// let message = chat.createMessage(text: message, id: UUID().uuidString)
// try? await chat.send(message: message)
// }
}
extension Client {

View file

@ -26,7 +26,7 @@ struct Message: DBStorable, Equatable {
let type: MessageType
let date: Date
let contentType: MessageContentType
let status: MessageStatus
var status: MessageStatus
let from: String
let to: String?
@ -43,4 +43,12 @@ extension Message {
try self.insert(db)
}
}
func setStatus(_ status: MessageStatus) async throws {
try await Database.shared.dbQueue.write { db in
var updatedMessage = self
updatedMessage.status = status
try updatedMessage.update(db, columns: ["status"])
}
}
}

View file

@ -42,8 +42,11 @@ extension ConversationStore {
// store as pending on db, and send
do {
try await message.save()
await client.sendMessage(message)
} catch {}
try await client.sendMessage(message)
try await message.setStatus(.sent)
} catch {
try? await message.setStatus(.error)
}
}
}