Commit f756586e authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

fix: Tab Bar

Fix badge value on Conversation TabBarItem:
- handle case when account does not exists
- filter out messages that shown on contact request conversation

Change-Id: Ife44a70b2d0b728876be648ebad2e3d772128ce5
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 743768be
......@@ -28,12 +28,18 @@ class ChatTabBarItemViewModel: ViewModel, TabBarItemViewModel {
required init(with injectionBag: InjectionBag) {
let accountService = injectionBag.accountService
let conversationService = injectionBag.conversationsService
let accountHelper = AccountModelHelper(withAccount: accountService.currentAccount!)
let contactsService = injectionBag.contactsService
self.itemBadgeValue = {
return conversationService.conversations.map({ conversations in
return conversations.map({ conversation in
return conversation.messages.filter({ message in
return message.status != .read && message.author != accountHelper.ringId!
if let account = accountService.currentAccount {
let accountHelper = AccountModelHelper(withAccount: account)
//filtre out read messages, outgoing messages and messages that are displayed in contactrequest conversation
return message.status != .read && message.author != accountHelper.ringId
&& (contactsService.contactRequest(withRingId: message.author) == nil)
}
return false
}).count
}).reduce(0, +)
})
......
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