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 <andreas.traczyk@savoirfairelinux.com>
diff --git a/Ring/Ring/TabBar/ChatTabBarItemViewModel.swift b/Ring/Ring/TabBar/ChatTabBarItemViewModel.swift
index 65c1ac4..97ae27b 100644
--- a/Ring/Ring/TabBar/ChatTabBarItemViewModel.swift
+++ b/Ring/Ring/TabBar/ChatTabBarItemViewModel.swift
@@ -28,12 +28,18 @@
     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, +)
             })