Commit 71ffa200 authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Kateryna Kostiuk

smartlist: filters out conversations

In smart list display conversation if one of the conditions is met:
- contact exists
- history of messaging is not empty

Change-Id: I344c3ed66f637366c3435f3aee11e045e7da6a1b
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent 5e1c5c68
......@@ -73,31 +73,36 @@ class SmartlistViewModel: Stateable, ViewModel {
//Create observable from sorted conversations and flatMap them to view models
let conversationsObservable: Observable<[ConversationViewModel]> = self.conversationsService.conversations.asObservable().map({ conversations in
return conversations.sorted(by: { conversation1, conversations2 in
return conversations
.sorted(by: { conversation1, conversations2 in
guard let lastMessage1 = conversation1.messages.last,
let lastMessage2 = conversations2.messages.last else {
return true
}
return lastMessage1.receivedDate > lastMessage2.receivedDate
}).flatMap({ conversationModel in
var conversationViewModel: ConversationViewModel?
guard let lastMessage1 = conversation1.messages.last,
let lastMessage2 = conversations2.messages.last else {
return true
}
//Get the current ConversationViewModel if exists or create it
if let foundConversationViewModel = self.conversationViewModels.filter({ conversationViewModel in
return conversationViewModel.conversation.isEqual(conversationModel)
}).first {
conversationViewModel = foundConversationViewModel
} else {
conversationViewModel = ConversationViewModel(with: injectionBag)
conversationViewModel?.conversation = conversationModel
self.conversationViewModels.append(conversationViewModel!)
}
return lastMessage1.receivedDate > lastMessage2.receivedDate
})
.filter({ self.contactsService.contact(withRingId: $0.recipientRingId) != nil
|| (!$0.messages.isEmpty && (self.contactsService.contactRequest(withRingId:$0.recipientRingId) == nil))
})
.flatMap({ conversationModel in
var conversationViewModel: ConversationViewModel?
//Get the current ConversationViewModel if exists or create it
if let foundConversationViewModel = self.conversationViewModels.filter({ conversationViewModel in
return conversationViewModel.conversation.isEqual(conversationModel)
}).first {
conversationViewModel = foundConversationViewModel
} else {
conversationViewModel = ConversationViewModel(with: injectionBag)
conversationViewModel?.conversation = conversationModel
self.conversationViewModels.append(conversationViewModel!)
}
return conversationViewModel
})
return conversationViewModel
})
})
//Create observable from conversations viewModels to ConversationSection
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment