mv-experiment #1
|
@ -69,12 +69,6 @@ final class ClientMartinMessagesManager {
|
||||||
)
|
)
|
||||||
|
|
||||||
// Save message
|
// Save message
|
||||||
Task {
|
|
||||||
await updateMsgInDB(msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func updateMsgInDB(_ msg: Message) async {
|
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
try await msg.save()
|
try await msg.save()
|
||||||
|
|
|
@ -87,7 +87,7 @@ extension Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Client {
|
extension Client {
|
||||||
func sendMessage(_ message: Message) async {
|
func sendMessage(_ message: Message) async throws {
|
||||||
guard let to = message.to else {
|
guard let to = message.to else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -96,20 +96,9 @@ extension Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
let msg = chat.createMessage(text: message.body ?? "??", id: message.id)
|
let msg = chat.createMessage(text: message.body ?? "??", id: message.id)
|
||||||
do {
|
|
||||||
try await chat.send(message: msg)
|
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 {
|
extension Client {
|
||||||
static func tryLogin(with credentials: Credentials) async throws -> Client {
|
static func tryLogin(with credentials: Credentials) async throws -> Client {
|
||||||
|
|
|
@ -26,7 +26,7 @@ struct Message: DBStorable, Equatable {
|
||||||
let type: MessageType
|
let type: MessageType
|
||||||
let date: Date
|
let date: Date
|
||||||
let contentType: MessageContentType
|
let contentType: MessageContentType
|
||||||
let status: MessageStatus
|
var status: MessageStatus
|
||||||
|
|
||||||
let from: String
|
let from: String
|
||||||
let to: String?
|
let to: String?
|
||||||
|
@ -43,4 +43,12 @@ extension Message {
|
||||||
try self.insert(db)
|
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
|
// store as pending on db, and send
|
||||||
do {
|
do {
|
||||||
try await message.save()
|
try await message.save()
|
||||||
await client.sendMessage(message)
|
try await client.sendMessage(message)
|
||||||
} catch {}
|
try await message.setStatus(.sent)
|
||||||
|
} catch {
|
||||||
|
try? await message.setStatus(.error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue