Skip to content
Snippets Groups Projects
Commit a7bb3f0a authored by Adrien Béraud's avatar Adrien Béraud
Browse files

contact: only observe account profile when needed

Change-Id: Ia9db10be09e4003d15e3a357d7f0ef1b90f39cc6
parent db89b0e7
Branches
Tags
No related merge requests found
......@@ -69,7 +69,7 @@ class ConversationMembersFragment : Fragment() {
}
}
.flatMap { (conversation, contacts) ->
contactService.observeContact(path.accountId, contacts, false)
contactService.observeContact(path.accountId, contacts, false, withUser = true)
.map { contactViewModels -> Pair(conversation, contactViewModels) }
}
.observeOn(DeviceUtils.uiScheduler)
......
......@@ -82,7 +82,7 @@ class Account(
}
private val mProfileSubject: Subject<Single<Profile>> = BehaviorSubject.create()
val loadedProfileObservable: Observable<Profile> = mProfileSubject.switchMapSingle { single -> single }
val loadedProfileObservable: Observable<Profile> = mProfileSubject.switchMapSingle { it }
fun cleanup() {
conversationSubject.onComplete()
......
......@@ -408,7 +408,6 @@ class AccountService(
Observable.just(account)
.concatWith(observableAccounts.filter { acc -> acc === account })
// Todo: Doubt on this working correctly. No updates on `account.username` on account created.
val currentProfileAccountSubject: Observable<Pair<Account, Profile>>
get() = currentAccountSubject.flatMap { a: Account ->
mVCardService.loadProfile(a).map { profile -> Pair(a, profile) }
......
......@@ -121,14 +121,15 @@ abstract class ContactService(
}
}
fun observeContact(accountId: String, contacts: Collection<Contact>, withPresence: Boolean): Observable<List<ContactViewModel>> =
fun observeContact(accountId: String, contacts: Collection<Contact>, withPresence: Boolean, withUser: Boolean = false): Observable<List<ContactViewModel>> =
if (contacts.isEmpty()) {
Observable.just(emptyList())
} else if (contacts.size == 1 && contacts.first().isUser) {
} else if (contacts.size == 1) {
observeContact(accountId, contacts.first(), withPresence).map(Collections::singletonList)
} else {
val observables: MutableList<Observable<ContactViewModel>> = ArrayList(contacts.size)
for (contact in contacts)
if (!contact.isUser || withUser)
observables.add(observeContact(accountId, contact, withPresence))
if (observables.isEmpty()) Observable.just(emptyList()) else Observable.combineLatest(observables) { a: Array<Any> ->
a.map { it as ContactViewModel }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment