diff --git a/Sources/Integration/Session/Session+Chat.swift b/Sources/Integration/Session/Session+Chat.swift index 3e3eb63a7df4c8d2dcc1ab315335f8fb046b6d69..97c2b8ed51d8993df873ddd624c1d04672d4d093 100644 --- a/Sources/Integration/Session/Session+Chat.swift +++ b/Sources/Integration/Session/Session+Chat.swift @@ -124,7 +124,7 @@ extension Session { message.date = Date() if let message = try? dbManager.saveMessage(message) { - if let recipientId = message.recipientId { + if let _ = message.recipientId { send(message: message) } else { send(groupMessage: message) @@ -229,24 +229,27 @@ extension Session { let content = transfer.type == "m4a" ? "a voice message" : "an image" - var message = Message( - networkId: nil, - senderId: transfer.contactId, - recipientId: myId, - groupId: nil, - date: transfer.createdAt, - status: .receiving, - isUnread: true, - text: "Sent you \(content)", - replyMessageId: nil, - roundURL: nil, - fileTransferId: transfer.id + var message = try! dbManager.saveMessage( + Message( + networkId: nil, + senderId: transfer.contactId, + recipientId: myId, + groupId: nil, + date: transfer.createdAt, + status: .receiving, + isUnread: true, + text: "Sent you \(content)", + replyMessageId: nil, + roundURL: nil, + fileTransferId: transfer.id + ) ) - message = try! self.dbManager.saveMessage(message) - try! manager.listenDownloadFromTransfer(with: transfer.id) { completed, arrived, total, error in - if let error = error { fatalError(error.localizedDescription) } + if let error = error { + print(error.localizedDescription) + return + } if completed { guard let rawFile = try? manager.downloadFileFromTransfer(with: transfer.id) else { return } diff --git a/Sources/Integration/Session/Session.swift b/Sources/Integration/Session/Session.swift index d2ab638a5a6aefd6e7a69d917e55deaa0cbca53e..5508d58bdb443b2775fe3134c533c165c259e89b 100644 --- a/Sources/Integration/Session/Session.swift +++ b/Sources/Integration/Session/Session.swift @@ -410,25 +410,8 @@ public final class Session: SessionType { client.transfers .sink { [unowned self] in - _ = try? dbManager.saveFileTransfer($0) - - let content = $0.type == "m4a" ? "a voice message" : "an image" - - let message = Message( - networkId: $0.id, - senderId: $0.contactId, - recipientId: myId, - groupId: nil, - date: $0.createdAt, - status: .receiving, - isUnread: true, - text: "Sent you \(content)", - replyMessageId: nil, - roundURL: nil, - fileTransferId: $0.id - ) - - _ = try? dbManager.saveMessage(message) + guard let transfer = try? dbManager.saveFileTransfer($0) else { return } + handle(incomingTransfer: transfer) } .store(in: &cancellables) }