Skip to content
Snippets Groups Projects
Commit 6b1a73e5 authored by Bruno Muniz's avatar Bruno Muniz :apple:
Browse files

Avoiding some force unwraps and using assertNoFailure

parent 996d2fb9
No related branches found
No related tags found
2 merge requests!40v1.1.2b166,!38Using new database structure
...@@ -326,7 +326,9 @@ extension GroupChatController: UICollectionViewDataSource { ...@@ -326,7 +326,9 @@ extension GroupChatController: UICollectionViewDataSource {
) -> UICollectionViewCell { ) -> UICollectionViewCell {
let item = sections[indexPath.section].elements[indexPath.item] 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 let performReply: () -> Void = { [weak self] in
self?.viewModel.didRequestReply(item) self?.viewModel.didRequestReply(item)
...@@ -337,13 +339,13 @@ extension GroupChatController: UICollectionViewDataSource { ...@@ -337,13 +339,13 @@ extension GroupChatController: UICollectionViewDataSource {
let replyContent: (Data) -> (String, String) = viewModel.getReplyContent(for:) let replyContent: (Data) -> (String, String) = viewModel.getReplyContent(for:)
if item.status == .received { if item.status == .received {
if item.replyMessageId != nil { if let replyMessageId = item.replyMessageId {
let cell: IncomingGroupReplyCell = collectionView.dequeueReusableCell(forIndexPath: indexPath) let cell: IncomingGroupReplyCell = collectionView.dequeueReusableCell(forIndexPath: indexPath)
Bubbler.buildReplyGroup( Bubbler.buildReplyGroup(
bubble: cell.leftView, bubble: cell.leftView,
with: item, with: item,
reply: replyContent(item.replyMessageId!), reply: replyContent(replyMessageId),
sender: name(item.senderId) sender: name(item.senderId)
) )
...@@ -367,13 +369,13 @@ extension GroupChatController: UICollectionViewDataSource { ...@@ -367,13 +369,13 @@ extension GroupChatController: UICollectionViewDataSource {
return cell return cell
} }
} else if item.status == .sendingFailed { } else if item.status == .sendingFailed {
if item.replyMessageId != nil { if let replyMessageId = item.replyMessageId {
let cell: OutgoingFailedGroupReplyCell = collectionView.dequeueReusableCell(forIndexPath: indexPath) let cell: OutgoingFailedGroupReplyCell = collectionView.dequeueReusableCell(forIndexPath: indexPath)
Bubbler.buildReplyGroup( Bubbler.buildReplyGroup(
bubble: cell.rightView, bubble: cell.rightView,
with: item, with: item,
reply: replyContent(item.replyMessageId!), reply: replyContent(item.replyMessageId),
sender: name(item.senderId) sender: name(item.senderId)
) )
...@@ -396,13 +398,13 @@ extension GroupChatController: UICollectionViewDataSource { ...@@ -396,13 +398,13 @@ extension GroupChatController: UICollectionViewDataSource {
return cell return cell
} }
} else { } else {
if item.replyMessageId != nil { if let replyMessageId = item.replyMessageId {
let cell: OutgoingGroupReplyCell = collectionView.dequeueReusableCell(forIndexPath: indexPath) let cell: OutgoingGroupReplyCell = collectionView.dequeueReusableCell(forIndexPath: indexPath)
Bubbler.buildReplyGroup( Bubbler.buildReplyGroup(
bubble: cell.rightView, bubble: cell.rightView,
with: item, with: item,
reply: replyContent(item.replyMessageId!), reply: replyContent(item.replyMessageId),
sender: name(item.senderId) sender: name(item.senderId)
) )
......
...@@ -24,8 +24,8 @@ final class ContactListViewModel { ...@@ -24,8 +24,8 @@ final class ContactListViewModel {
]) ])
return Publishers.CombineLatest( return Publishers.CombineLatest(
session.dbManager.fetchContactsPublisher(contactsQuery).catch { _ in Just([]) }, session.dbManager.fetchContactsPublisher(contactsQuery).assertNoFailure(),
session.dbManager.fetchGroupsPublisher(groupQuery).catch { _ in Just([]) } session.dbManager.fetchGroupsPublisher(groupQuery).assertNoFailure()
) )
.map { $0.0.count + $0.1.count } .map { $0.0.count + $0.1.count }
.eraseToAnyPublisher() .eraseToAnyPublisher()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment