Fixed potential deadlock
This commit is contained in:
parent
4a4ce57864
commit
8ad466e091
2 changed files with 22 additions and 38 deletions
|
@ -50,7 +50,7 @@ class ContactViewModelFactory(private val friend: Friend) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContactViewModel(friend: Friend, async: Boolean = false) : MessageNotifierViewModel(), ContactDataInterface {
|
class ContactViewModel(friend: Friend) : MessageNotifierViewModel(), ContactDataInterface {
|
||||||
override val contact: MutableLiveData<Friend> = MutableLiveData<Friend>()
|
override val contact: MutableLiveData<Friend> = MutableLiveData<Friend>()
|
||||||
override val displayName: MutableLiveData<String> = MutableLiveData<String>()
|
override val displayName: MutableLiveData<String> = MutableLiveData<String>()
|
||||||
override val securityLevel: MutableLiveData<ChatRoom.SecurityLevel> = MutableLiveData<ChatRoom.SecurityLevel>()
|
override val securityLevel: MutableLiveData<ChatRoom.SecurityLevel> = MutableLiveData<ChatRoom.SecurityLevel>()
|
||||||
|
@ -143,21 +143,12 @@ class ContactViewModel(friend: Friend, async: Boolean = false) : MessageNotifier
|
||||||
init {
|
init {
|
||||||
fullName = friend.name ?: ""
|
fullName = friend.name ?: ""
|
||||||
|
|
||||||
if (async) {
|
contact.value = friend
|
||||||
contact.postValue(friend)
|
displayName.value = friend.name
|
||||||
displayName.postValue(friend.name)
|
isNativeContact.value = friend.refKey != null
|
||||||
isNativeContact.postValue(friend.refKey != null)
|
presenceStatus.value = friend.consolidatedPresence
|
||||||
presenceStatus.postValue(friend.consolidatedPresence)
|
readOnlyNativeAddressBook.value = corePreferences.readOnlyNativeContacts
|
||||||
readOnlyNativeAddressBook.postValue(corePreferences.readOnlyNativeContacts)
|
hasLongTermPresence.value = friend.hasLongTermPresence()
|
||||||
hasLongTermPresence.postValue(friend.hasLongTermPresence())
|
|
||||||
} else {
|
|
||||||
contact.value = friend
|
|
||||||
displayName.value = friend.name
|
|
||||||
isNativeContact.value = friend.refKey != null
|
|
||||||
presenceStatus.value = friend.consolidatedPresence
|
|
||||||
readOnlyNativeAddressBook.value = corePreferences.readOnlyNativeContacts
|
|
||||||
hasLongTermPresence.value = friend.hasLongTermPresence()
|
|
||||||
}
|
|
||||||
|
|
||||||
friend.addListener {
|
friend.addListener {
|
||||||
presenceStatus.value = it.consolidatedPresence
|
presenceStatus.value = it.consolidatedPresence
|
||||||
|
|
|
@ -150,33 +150,26 @@ class ContactsListViewModel : ViewModel() {
|
||||||
Log.i("[Contacts] Processing ${results.size} results")
|
Log.i("[Contacts] Processing ${results.size} results")
|
||||||
contactsList.value.orEmpty().forEach(ContactViewModel::destroy)
|
contactsList.value.orEmpty().forEach(ContactViewModel::destroy)
|
||||||
|
|
||||||
viewModelScope.launch {
|
val list = arrayListOf<ContactViewModel>()
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
val list = arrayListOf<ContactViewModel>()
|
|
||||||
|
|
||||||
for (result in results) {
|
for (result in results) {
|
||||||
val friend = result.friend
|
val friend = result.friend
|
||||||
|
|
||||||
val viewModel = if (friend != null) {
|
val viewModel = if (friend != null) {
|
||||||
ContactViewModel(friend, true)
|
ContactViewModel(friend)
|
||||||
} else {
|
} else {
|
||||||
Log.w("[Contacts] SearchResult [$result] has no Friend!")
|
Log.w("[Contacts] SearchResult [$result] has no Friend!")
|
||||||
val fakeFriend = coreContext.contactsManager.createFriendFromSearchResult(
|
val fakeFriend = coreContext.contactsManager.createFriendFromSearchResult(
|
||||||
result
|
result
|
||||||
)
|
)
|
||||||
ContactViewModel(fakeFriend, true)
|
ContactViewModel(fakeFriend)
|
||||||
}
|
|
||||||
|
|
||||||
list.add(viewModel)
|
|
||||||
}
|
|
||||||
|
|
||||||
contactsList.postValue(list)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
list.add(viewModel)
|
||||||
Log.i("[Contacts] Processed ${results.size} results")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contactsList.value = list
|
||||||
|
Log.i("[Contacts] Processed ${results.size} results")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteContact(friend: Friend) {
|
fun deleteContact(friend: Friend) {
|
||||||
|
|
Loading…
Reference in a new issue