wip
This commit is contained in:
parent
66262f2f75
commit
51cd7f82f6
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue