From b4826e2d6a828ca92073dd17ed52ed66fc0f0cc2 Mon Sep 17 00:00:00 2001 From: Bruno Muniz Azevedo Filho <bruno@elixxir.io> Date: Thu, 23 Jun 2022 22:08:43 -0300 Subject: [PATCH] Fixing mr comments --- .../Controllers/SingleChatController.swift | 6 +++-- .../Helpers/CellConfigurator.swift | 4 +-- .../ViewModels/GroupChatViewModel.swift | 26 ++++--------------- .../Controller/ChatListController.swift | 9 ++----- .../Integration/Session/Session+Chat.swift | 2 +- Sources/Integration/Session/Session.swift | 2 +- 6 files changed, 15 insertions(+), 34 deletions(-) diff --git a/Sources/ChatFeature/Controllers/SingleChatController.swift b/Sources/ChatFeature/Controllers/SingleChatController.swift index 4dac8847..b35d3147 100644 --- a/Sources/ChatFeature/Controllers/SingleChatController.swift +++ b/Sources/ChatFeature/Controllers/SingleChatController.swift @@ -160,9 +160,11 @@ public final class SingleChatController: UIViewController { private func setupNavigationBar(contact: Contact) { screenView.set(name: contact.nickname ?? contact.username!) avatarView.snp.makeConstraints { $0.width.height.equalTo(35) } - avatarView.setupProfile(title: contact.nickname ?? contact.username!, image: contact.photo, size: .small) - nameLabel.text = contact.nickname ?? contact.username + let title = (contact.nickname ?? contact.username) ?? "" + avatarView.setupProfile(title: title, image: contact.photo, size: .small) + + nameLabel.text = title nameLabel.textColor = Asset.neutralActive.color nameLabel.font = Fonts.Mulish.semiBold.font(size: 18.0) diff --git a/Sources/ChatFeature/Helpers/CellConfigurator.swift b/Sources/ChatFeature/Helpers/CellConfigurator.swift index d0eb1671..70923513 100644 --- a/Sources/ChatFeature/Helpers/CellConfigurator.swift +++ b/Sources/ChatFeature/Helpers/CellConfigurator.swift @@ -197,7 +197,7 @@ extension CellFactory { return false } - return transfer(item.fileTransferId!).type == "png" + return transfer(item.fileTransferId!).type == "jpeg" }, build: { item, collectionView, indexPath in let ft = transfer(item.fileTransferId!) @@ -227,7 +227,7 @@ extension CellFactory { return false } - return transfer(item.fileTransferId!).type == "png" + return transfer(item.fileTransferId!).type == "jpeg" }, build: { item, collectionView, indexPath in let ft = transfer(item.fileTransferId!) diff --git a/Sources/ChatFeature/ViewModels/GroupChatViewModel.swift b/Sources/ChatFeature/ViewModels/GroupChatViewModel.swift index 39db1157..a257d9f3 100644 --- a/Sources/ChatFeature/ViewModels/GroupChatViewModel.swift +++ b/Sources/ChatFeature/ViewModels/GroupChatViewModel.swift @@ -93,17 +93,14 @@ final class GroupChatViewModel { return ("[DELETED]", "[DELETED]") } - guard let contact = try? session.dbManager.fetchContacts(.init(id: [message.senderId])).first else { - return ("You", message.text) - } - - let contactTitle = (contact.nickname ?? contact.username) ?? "Fetching username..." - return (contactTitle, message.text) + return (getName(from: message.senderId), message.text) } func getName(from senderId: Data) -> String { + guard senderId != session.myId else { return "You" } + guard let contact = try? session.dbManager.fetchContacts(.init(id: [senderId])).first else { - return "You" + return "[DELETED]" } return (contact.nickname ?? contact.username) ?? "Fetching username..." @@ -111,20 +108,7 @@ final class GroupChatViewModel { func didRequestReply(_ message: Message) { guard let networkId = message.networkId else { return } - - let senderTitle: String = { - if message.senderId == session.myId { - return "You" - } else { - guard let contact = try? session.dbManager.fetchContacts(.init(id: [message.senderId])).first else { - return "Error" - } - - return (contact.nickname ?? contact.username) ?? "Fetching username..." - } - }() - stagedReply = Reply(messageId: networkId, senderId: message.senderId) - replySubject.send((senderTitle, message.text)) + replySubject.send(getReplyContent(for: message.id)) } } diff --git a/Sources/ChatListFeature/Controller/ChatListController.swift b/Sources/ChatListFeature/Controller/ChatListController.swift index 5fbb432a..bddccd28 100644 --- a/Sources/ChatListFeature/Controller/ChatListController.swift +++ b/Sources/ChatListFeature/Controller/ChatListController.swift @@ -7,12 +7,6 @@ import XXModels import MenuFeature import DependencyInjection -extension Contact: Hashable { - public func hash(into hasher: inout Hasher) { - hasher.combine(id) - } -} - public final class ChatListController: UIViewController { @Dependency private var coordinator: ChatListCoordinating @Dependency private var statusBarController: StatusBarStyleControlling @@ -122,7 +116,8 @@ public final class ChatListController: UIViewController { collectionView: screenView.listContainerView.collectionView ) { collectionView, indexPath, contact in let cell: ChatListRecentContactCell = collectionView.dequeueReusableCell(forIndexPath: indexPath) - cell.setup(title: contact.nickname ?? contact.username!, image: contact.photo) + let title = (contact.nickname ?? contact.username) ?? "" + cell.setup(title: title, image: contact.photo) return cell } diff --git a/Sources/Integration/Session/Session+Chat.swift b/Sources/Integration/Session/Session+Chat.swift index b53018f9..ec582ff8 100644 --- a/Sources/Integration/Session/Session+Chat.swift +++ b/Sources/Integration/Session/Session+Chat.swift @@ -18,7 +18,7 @@ extension Session { let url = try FileManager.store( data: compressedImage, name: "image_\(Date.asTimestamp)", - type: "png" + type: "jpeg" ) self.sendFile(url: url, to: contact) diff --git a/Sources/Integration/Session/Session.swift b/Sources/Integration/Session/Session.swift index 7de05d14..6763bed2 100644 --- a/Sources/Integration/Session/Session.swift +++ b/Sources/Integration/Session/Session.swift @@ -184,7 +184,7 @@ public final class Session: SessionType { guard self.hasRunningTasks == false else { throw NSError.create("") } }.finalCatch { _ in fatalError("Couldn't delete account because network is not stopping") } - try? dbManager.drop() + try! dbManager.drop() FileManager.xxCleanup() email = nil -- GitLab