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

contact requests: prevent double loading and double ns lookup

- Checks existing contact requests for duplicates before appending
  those accrued from getTrustRequests, as incomingTrustRequests
  may have already done so, prior to loadContactRequests being
  called.

- Changes hasInvitations to return an abservable boolean that
  representing the non-zero count of the contact request list
  only.

Change-Id: I9d0c2165e26ac0c031c261ed9c05d6f2587d7574
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent 899126bd
......@@ -47,14 +47,16 @@ class ContactRequestsViewModel: ViewModel {
let item = ContactRequestItem(withContactRequest: contactRequest)
self.lookupUserName(withItem: item)
return item
}
}
})
}()
lazy var hasInvitations: Observable<Bool> = {
return self.contactRequestItems.map({ items in
return !items.isEmpty
})
return self.contactsService.contactRequests
.asObservable()
.map({ items in
return !items.isEmpty
})
}()
func accept(withItem item: ContactRequestItem) -> Observable<Void> {
......
......@@ -54,11 +54,11 @@ class ContactsService {
}
func contactRequest(withRingId ringId: String) -> ContactRequestModel? {
guard let contact = self.contactRequests.value.filter({ $0.ringId == ringId }).first else {
guard let contactRequest = self.contactRequests.value.filter({ $0.ringId == ringId }).first else {
return nil
}
return contact
return contactRequest
}
func loadContacts(withAccount account: AccountModel) {
......@@ -84,7 +84,9 @@ class ContactsService {
return ContactRequestModel(withDictionary: dictionary, accountId: account.id)
}) {
for contactRequest in contactRequests {
self.contactRequests.value.append(contactRequest)
if self.contactRequest(withRingId: contactRequest.ringId) == nil {
self.contactRequests.value.append(contactRequest)
}
}
}
}
......
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