From f55a9adbedaaa8ec309ccd7dd7bd05e3e73d12f1 Mon Sep 17 00:00:00 2001 From: Bruno Muniz Azevedo Filho <bruno@elixxir.io> Date: Tue, 28 Jun 2022 21:59:28 -0300 Subject: [PATCH] Fixed incoming FT --- .../Integration/Session/Session+Chat.swift | 35 ++++++++++--------- Sources/Integration/Session/Session.swift | 21 ++--------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/Sources/Integration/Session/Session+Chat.swift b/Sources/Integration/Session/Session+Chat.swift index 3e3eb63a..97c2b8ed 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 d2ab638a..5508d58b 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) } -- GitLab