From 1bd8d82654af68ab26ac0bb0c6fc8e0c762adf3a Mon Sep 17 00:00:00 2001 From: Bruno Muniz Azevedo Filho <bruno@elixxir.io> Date: Thu, 23 Jun 2022 09:51:12 -0300 Subject: [PATCH] Avoiding force unwraps --- Sources/ChatFeature/Controllers/GroupChatController.swift | 4 ++-- .../ContactFeature/Controllers/ContactController.swift | 6 +++--- .../Controllers/CreateGroupController.swift | 8 +++++--- .../ViewModels/CreateGroupViewModel.swift | 6 +++++- Sources/PushFeature/PushHandler.swift | 2 +- .../Controllers/RequestsReceivedController.swift | 6 +++--- Sources/RequestsFeature/Views/RequestCell.swift | 6 +++--- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Sources/ChatFeature/Controllers/GroupChatController.swift b/Sources/ChatFeature/Controllers/GroupChatController.swift index cbcabb54..b168e70c 100644 --- a/Sources/ChatFeature/Controllers/GroupChatController.swift +++ b/Sources/ChatFeature/Controllers/GroupChatController.swift @@ -375,7 +375,7 @@ extension GroupChatController: UICollectionViewDataSource { Bubbler.buildReplyGroup( bubble: cell.rightView, with: item, - reply: replyContent(item.replyMessageId), + reply: replyContent(replyMessageId), sender: name(item.senderId) ) @@ -404,7 +404,7 @@ extension GroupChatController: UICollectionViewDataSource { Bubbler.buildReplyGroup( bubble: cell.rightView, with: item, - reply: replyContent(item.replyMessageId), + reply: replyContent(replyMessageId), sender: name(item.senderId) ) diff --git a/Sources/ContactFeature/Controllers/ContactController.swift b/Sources/ContactFeature/Controllers/ContactController.swift index 5dd2b37e..1ef8e96f 100644 --- a/Sources/ContactFeature/Controllers/ContactController.swift +++ b/Sources/ContactFeature/Controllers/ContactController.swift @@ -169,7 +169,7 @@ public final class ContactController: UIViewController { .sink { [unowned self] in coordinator.toNickname( from: self, - prefilled: viewModel.contact.nickname ?? viewModel.contact.username!, + prefilled: (viewModel.contact.nickname ?? viewModel.contact.username) ?? "", viewModel.didTapRequest(with:) ) }.store(in: &cancellables) @@ -181,7 +181,7 @@ public final class ContactController: UIViewController { .sink { [unowned self] in coordinator.toNickname( from: self, - prefilled: viewModel.contact.nickname ?? viewModel.contact.username!, + prefilled: (viewModel.contact.nickname ?? viewModel.contact.username) ?? "", viewModel.didTapAccept(_:) ) }.store(in: &cancellables) @@ -243,7 +243,7 @@ public final class ContactController: UIViewController { .sink { [unowned self] in coordinator.toNickname( from: self, - prefilled: viewModel.contact.nickname ?? viewModel.contact.username!, + prefilled: (viewModel.contact.nickname ?? viewModel.contact.username) ?? "", viewModel.didUpdateNickname(_:) ) } diff --git a/Sources/ContactListFeature/Controllers/CreateGroupController.swift b/Sources/ContactListFeature/Controllers/CreateGroupController.swift index 73c9f8b1..9e9d039d 100644 --- a/Sources/ContactListFeature/Controllers/CreateGroupController.swift +++ b/Sources/ContactListFeature/Controllers/CreateGroupController.swift @@ -74,7 +74,8 @@ public final class CreateGroupController: UIViewController { ) { [weak viewModel] collectionView, indexPath, contact in let cell: CreateGroupCollectionCell = 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) cell.didTapRemove = { viewModel?.didSelect(contact: contact) } return cell @@ -84,8 +85,9 @@ public final class CreateGroupController: UIViewController { tableView: screenView.tableView ) { [weak self] tableView, indexPath, contact in let cell = tableView.dequeueReusableCell(forIndexPath: indexPath, ofType: SmallAvatarAndTitleCell.self) - cell.titleLabel.text = contact.nickname ?? contact.username - cell.avatarView.setupProfile(title: contact.nickname ?? contact.username!, image: contact.photo, size: .medium) + let title = (contact.nickname ?? contact.username) ?? "" + cell.titleLabel.text = title + cell.avatarView.setupProfile(title: title, image: contact.photo, size: .medium) if let selectedElements = self?.selectedElements, selectedElements.contains(contact) { tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none) diff --git a/Sources/ContactListFeature/ViewModels/CreateGroupViewModel.swift b/Sources/ContactListFeature/ViewModels/CreateGroupViewModel.swift index 38717ac2..70485e37 100644 --- a/Sources/ContactListFeature/ViewModels/CreateGroupViewModel.swift +++ b/Sources/ContactListFeature/ViewModels/CreateGroupViewModel.swift @@ -67,7 +67,11 @@ final class CreateGroupViewModel { return } - contactsRelay.send(allContacts.filter { $0.username!.contains(text.lowercased()) }) + contactsRelay.send( + allContacts.filter { + ($0.username ?? "").contains(text.lowercased()) + } + ) } func create(name: String, welcome: String?, members: [Contact]) { diff --git a/Sources/PushFeature/PushHandler.swift b/Sources/PushFeature/PushHandler.swift index 4259476e..adb0feb4 100644 --- a/Sources/PushFeature/PushHandler.swift +++ b/Sources/PushFeature/PushHandler.swift @@ -110,7 +110,7 @@ public final class PushHandler: PushHandling { return ($0.type.unknownSenderContent!, $0) } - let name = contact.nickname ?? contact.username! + let name = (contact.nickname ?? contact.username) ?? "" return ($0.type.knownSenderContent(name)!, $0) } diff --git a/Sources/RequestsFeature/Controllers/RequestsReceivedController.swift b/Sources/RequestsFeature/Controllers/RequestsReceivedController.swift index e9de6a32..5edb7772 100644 --- a/Sources/RequestsFeature/Controllers/RequestsReceivedController.swift +++ b/Sources/RequestsFeature/Controllers/RequestsReceivedController.swift @@ -212,7 +212,7 @@ extension RequestsReceivedController { let drawerNickname = DrawerText( font: Fonts.Mulish.extraBold.font(size: 26.0), - text: contact.nickname ?? contact.username!, + text: (contact.nickname ?? contact.username) ?? "", color: Asset.neutralDark.color, spacingAfter: 20 ) @@ -393,7 +393,7 @@ extension RequestsReceivedController { let drawerUsername = DrawerText( font: Fonts.Mulish.extraBold.font(size: 26.0), - text: contact.username!, + text: contact.username ?? "", color: Asset.neutralDark.color, spacingAfter: 25 ) @@ -453,7 +453,7 @@ extension RequestsReceivedController { items.append(drawerNicknameTitle) let drawerNicknameInput = DrawerInput( - placeholder: contact.username!, + placeholder: contact.username ?? "", validator: .init( wrongIcon: .image(Asset.sharedError.image), correctIcon: .image(Asset.sharedSuccess.image), diff --git a/Sources/RequestsFeature/Views/RequestCell.swift b/Sources/RequestsFeature/Views/RequestCell.swift index d8209363..e0af9ec6 100644 --- a/Sources/RequestsFeature/Views/RequestCell.swift +++ b/Sources/RequestsFeature/Views/RequestCell.swift @@ -89,7 +89,7 @@ final class RequestCell: UICollectionViewCell { } setupContact( - title: contact.nickname ?? contact.username!, + title: (contact.nickname ?? contact.username) ?? "", photo: contact.photo, phone: phone, email: contact.email, @@ -128,7 +128,7 @@ final class RequestCell: UICollectionViewCell { } setupContact( - title: contact.nickname ?? contact.username!, + title: (contact.nickname ?? contact.username) ?? "", photo: contact.photo, phone: phone, email: contact.email, @@ -165,7 +165,7 @@ final class RequestCell: UICollectionViewCell { } setupContact( - title: contact.nickname ?? contact.username!, + title: (contact.nickname ?? contact.username) ?? "", photo: contact.photo, phone: phone, email: contact.email, -- GitLab