From 6b1a73e509a606a5e8ea15ed4f82e63665766628 Mon Sep 17 00:00:00 2001 From: Bruno Muniz Azevedo Filho <bruno@elixxir.io> Date: Thu, 23 Jun 2022 09:39:49 -0300 Subject: [PATCH] Avoiding some force unwraps and using assertNoFailure --- .../Controllers/GroupChatController.swift | 16 +++++++++------- .../ViewModels/ContactListViewModel.swift | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Sources/ChatFeature/Controllers/GroupChatController.swift b/Sources/ChatFeature/Controllers/GroupChatController.swift index c4da099e..cbcabb54 100644 --- a/Sources/ChatFeature/Controllers/GroupChatController.swift +++ b/Sources/ChatFeature/Controllers/GroupChatController.swift @@ -326,7 +326,9 @@ extension GroupChatController: UICollectionViewDataSource { ) -> UICollectionViewCell { let item = sections[indexPath.section].elements[indexPath.item] - let canReply: () -> Bool = { item.status == .sent || item.status == .received } + let canReply: () -> Bool = { + (item.status == .sent || item.status == .received) && item.networkId != nil + } let performReply: () -> Void = { [weak self] in self?.viewModel.didRequestReply(item) @@ -337,13 +339,13 @@ extension GroupChatController: UICollectionViewDataSource { let replyContent: (Data) -> (String, String) = viewModel.getReplyContent(for:) if item.status == .received { - if item.replyMessageId != nil { + if let replyMessageId = item.replyMessageId { let cell: IncomingGroupReplyCell = collectionView.dequeueReusableCell(forIndexPath: indexPath) Bubbler.buildReplyGroup( bubble: cell.leftView, with: item, - reply: replyContent(item.replyMessageId!), + reply: replyContent(replyMessageId), sender: name(item.senderId) ) @@ -367,13 +369,13 @@ extension GroupChatController: UICollectionViewDataSource { return cell } } else if item.status == .sendingFailed { - if item.replyMessageId != nil { + if let replyMessageId = item.replyMessageId { let cell: OutgoingFailedGroupReplyCell = collectionView.dequeueReusableCell(forIndexPath: indexPath) Bubbler.buildReplyGroup( bubble: cell.rightView, with: item, - reply: replyContent(item.replyMessageId!), + reply: replyContent(item.replyMessageId), sender: name(item.senderId) ) @@ -396,13 +398,13 @@ extension GroupChatController: UICollectionViewDataSource { return cell } } else { - if item.replyMessageId != nil { + if let replyMessageId = item.replyMessageId { let cell: OutgoingGroupReplyCell = collectionView.dequeueReusableCell(forIndexPath: indexPath) Bubbler.buildReplyGroup( bubble: cell.rightView, with: item, - reply: replyContent(item.replyMessageId!), + reply: replyContent(item.replyMessageId), sender: name(item.senderId) ) diff --git a/Sources/ContactListFeature/ViewModels/ContactListViewModel.swift b/Sources/ContactListFeature/ViewModels/ContactListViewModel.swift index a21ec093..3ef0466b 100644 --- a/Sources/ContactListFeature/ViewModels/ContactListViewModel.swift +++ b/Sources/ContactListFeature/ViewModels/ContactListViewModel.swift @@ -24,8 +24,8 @@ final class ContactListViewModel { ]) return Publishers.CombineLatest( - session.dbManager.fetchContactsPublisher(contactsQuery).catch { _ in Just([]) }, - session.dbManager.fetchGroupsPublisher(groupQuery).catch { _ in Just([]) } + session.dbManager.fetchContactsPublisher(contactsQuery).assertNoFailure(), + session.dbManager.fetchGroupsPublisher(groupQuery).assertNoFailure() ) .map { $0.0.count + $0.1.count } .eraseToAnyPublisher() -- GitLab