Factorized code

This commit is contained in:
Sylvain Berfini 2024-02-15 11:53:34 +01:00
parent 8204f6d2da
commit d9b0d6c740
10 changed files with 218 additions and 338 deletions

View file

@ -100,7 +100,7 @@ class ConversationsFilesAdapter : ListAdapter<FileModel, RecyclerView.ViewHolder
}
override fun areContentsTheSame(oldItem: FileModel, newItem: FileModel): Boolean {
return true
return oldItem.mimeType == newItem.mimeType
}
}
}

View file

@ -108,17 +108,15 @@ class ConversationDocumentsListFragment : SlidingPaneChildFragment() {
it.consume {
(view.parent as? ViewGroup)?.doOnPreDraw {
startPostponedEnterTransition()
viewModel.loadDocumentsList()
}
}
}
viewModel.documentsList.observe(viewLifecycleOwner) { items ->
val count = items.size
Log.i(
"$TAG Found [$count] documents for conversation with local SIP URI [$localSipUri] and remote SIP URI [$remoteSipUri]"
)
adapter.submitList(items)
if (items != adapter.currentList || items.size != adapter.itemCount) {
adapter.submitList(items)
Log.i("$TAG Documents list updated with [${items.size}] items")
}
}
viewModel.openDocumentEvent.observe(viewLifecycleOwner) {

View file

@ -379,13 +379,15 @@ class ConversationFragment : SlidingPaneChildFragment() {
sendMessageViewModel.configureChatRoom(viewModel.chatRoom)
if (viewModel.isEndToEndEncrypted.value == true) {
headerItemDecoration = RecyclerViewHeaderDecoration(
requireContext(),
adapter,
false
)
binding.eventsList.addItemDecoration(headerItemDecoration)
binding.eventsList.addOnItemTouchListener(listItemTouchListener)
if (binding.eventsList.itemDecorationCount == 0) {
headerItemDecoration = RecyclerViewHeaderDecoration(
requireContext(),
adapter,
false
)
binding.eventsList.addItemDecoration(headerItemDecoration)
binding.eventsList.addOnItemTouchListener(listItemTouchListener)
}
}
// Wait for chat room to be ready before trying to forward a message in it
@ -406,8 +408,10 @@ class ConversationFragment : SlidingPaneChildFragment() {
}
viewModel.events.observe(viewLifecycleOwner) { items ->
adapter.submitList(items)
Log.i("$TAG Events (messages) list updated with [${items.size}] items")
if (items != adapter.currentList || items.size != adapter.itemCount) {
adapter.submitList(items)
Log.i("$TAG Events (messages) list updated with [${items.size}] items")
}
(view.parent as? ViewGroup)?.doOnPreDraw {
sharedViewModel.openSlidingPaneEvent.value = Event(true)

View file

@ -114,17 +114,15 @@ class ConversationMediaListFragment : SlidingPaneChildFragment() {
it.consume {
(view.parent as? ViewGroup)?.doOnPreDraw {
startPostponedEnterTransition()
viewModel.loadMediaList()
}
}
}
viewModel.mediaList.observe(viewLifecycleOwner) { items ->
val count = items.size
Log.i(
"$TAG Found [$count] media for conversation with local SIP URI [$localSipUri] and remote SIP URI [$remoteSipUri]"
)
adapter.submitList(items)
if (items != adapter.currentList || items.size != adapter.itemCount) {
adapter.submitList(items)
Log.i("$TAG Media list updated with [${items.size}] items")
}
}
viewModel.openMediaEvent.observe(viewLifecycleOwner) {

View file

@ -0,0 +1,123 @@
/*
* Copyright (c) 2010-2023 Belledonne Communications SARL.
*
* This file is part of linphone-android
* (see https://www.linphone.org).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.linphone.ui.main.chat.viewmodel
import androidx.annotation.UiThread
import androidx.annotation.WorkerThread
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication
import org.linphone.core.ChatRoom
import org.linphone.core.Factory
import org.linphone.core.tools.Log
import org.linphone.utils.Event
abstract class AbstractConversationViewModel : ViewModel() {
companion object {
private const val TAG = "[Abstract Conversation ViewModel]"
}
val chatRoomFoundEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
lateinit var chatRoom: ChatRoom
lateinit var localSipUri: String
lateinit var remoteSipUri: String
fun isChatRoomInitialized(): Boolean {
return ::chatRoom.isInitialized
}
@WorkerThread
open fun beforeNotifyingChatRoomFound(sameOne: Boolean) {
}
@WorkerThread
open fun afterNotifyingChatRoomFound(sameOne: Boolean) {
}
@UiThread
fun findChatRoom(room: ChatRoom?, localSipUri: String, remoteSipUri: String) {
this.localSipUri = localSipUri
this.remoteSipUri = remoteSipUri
LinphoneApplication.coreContext.postOnCoreThread { core ->
Log.i(
"$TAG Looking for conversation with local SIP URI [$localSipUri] and remote SIP URI [$remoteSipUri]"
)
if (room != null && ::chatRoom.isInitialized && chatRoom == room) {
Log.i("$TAG Conversation object already in memory, skipping")
beforeNotifyingChatRoomFound(sameOne = true)
chatRoomFoundEvent.postValue(Event(true))
afterNotifyingChatRoomFound(sameOne = true)
return@postOnCoreThread
}
val localAddress = Factory.instance().createAddress(localSipUri)
val remoteAddress = Factory.instance().createAddress(remoteSipUri)
if (room != null && (!::chatRoom.isInitialized || chatRoom != room)) {
if (localAddress?.weakEqual(room.localAddress) == true && remoteAddress?.weakEqual(
room.peerAddress
) == true
) {
Log.i("$TAG Conversation object available in sharedViewModel, using it")
chatRoom = room
beforeNotifyingChatRoomFound(sameOne = false)
chatRoomFoundEvent.postValue(Event(true))
afterNotifyingChatRoomFound(sameOne = false)
return@postOnCoreThread
}
}
if (localAddress != null && remoteAddress != null) {
Log.i("$TAG Searching for conversation in Core using local & peer SIP addresses")
val found = core.searchChatRoom(
null,
localAddress,
remoteAddress,
arrayOfNulls(
0
)
)
if (found != null) {
chatRoom = found
beforeNotifyingChatRoomFound(sameOne = false)
chatRoomFoundEvent.postValue(Event(true))
afterNotifyingChatRoomFound(sameOne = false)
} else {
Log.e("$TAG Failed to find conversation given local & remote addresses!")
chatRoomFoundEvent.postValue(Event(false))
}
} else {
Log.e("$TAG Failed to parse local or remote SIP URI as Address!")
chatRoomFoundEvent.postValue(Event(false))
}
}
}
}

View file

@ -20,17 +20,14 @@
package org.linphone.ui.main.chat.viewmodel
import androidx.annotation.UiThread
import androidx.annotation.WorkerThread
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.core.ChatRoom
import org.linphone.core.Factory
import org.linphone.core.tools.Log
import org.linphone.ui.main.chat.model.FileModel
import org.linphone.utils.Event
import org.linphone.utils.LinphoneUtils
class ConversationDocumentsListViewModel @UiThread constructor() : ViewModel() {
class ConversationDocumentsListViewModel @UiThread constructor() : AbstractConversationViewModel() {
companion object {
private const val TAG = "[Conversation Documents List ViewModel]"
}
@ -39,98 +36,40 @@ class ConversationDocumentsListViewModel @UiThread constructor() : ViewModel() {
val operationInProgress = MutableLiveData<Boolean>()
val chatRoomFoundEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
val openDocumentEvent: MutableLiveData<Event<FileModel>> by lazy {
MutableLiveData<Event<FileModel>>()
}
private lateinit var chatRoom: ChatRoom
lateinit var localSipUri: String
lateinit var remoteSipUri: String
@UiThread
fun findChatRoom(room: ChatRoom?, localSipUri: String, remoteSipUri: String) {
this.localSipUri = localSipUri
this.remoteSipUri = remoteSipUri
coreContext.postOnCoreThread { core ->
Log.i(
"$TAG Looking for conversation with local SIP URI [$localSipUri] and remote SIP URI [$remoteSipUri]"
)
if (room != null && ::chatRoom.isInitialized && chatRoom == room) {
Log.i("$TAG Conversation object already in memory, skipping")
chatRoomFoundEvent.postValue(Event(true))
return@postOnCoreThread
}
val localAddress = Factory.instance().createAddress(localSipUri)
val remoteAddress = Factory.instance().createAddress(remoteSipUri)
if (room != null && (!::chatRoom.isInitialized || chatRoom != room)) {
if (localAddress?.weakEqual(room.localAddress) == true && remoteAddress?.weakEqual(
room.peerAddress
) == true
) {
Log.i("$TAG Conversation object available in sharedViewModel, using it")
chatRoom = room
chatRoomFoundEvent.postValue(Event(true))
return@postOnCoreThread
}
}
if (localAddress != null && remoteAddress != null) {
Log.i("$TAG Searching for conversation in Core using local & peer SIP addresses")
val found = core.searchChatRoom(
null,
localAddress,
remoteAddress,
arrayOfNulls(
0
)
)
if (found != null) {
chatRoom = found
chatRoomFoundEvent.postValue(Event(true))
}
}
}
override fun beforeNotifyingChatRoomFound(sameOne: Boolean) {
loadDocumentsList()
}
@UiThread
fun loadDocumentsList() {
operationInProgress.value = true
@WorkerThread
private fun loadDocumentsList() {
operationInProgress.postValue(true)
coreContext.postOnCoreThread {
val list = arrayListOf<FileModel>()
if (::chatRoom.isInitialized) {
Log.i(
"$TAG Loading document contents for conversation [${LinphoneUtils.getChatRoomId(
chatRoom
)}]"
)
val documents = chatRoom.documentContents
Log.i("$TAG [${documents.size}] documents have been fetched")
for (documentContent in documents) {
val path = documentContent.filePath.orEmpty()
val name = documentContent.name.orEmpty()
val size = documentContent.size.toLong()
if (path.isNotEmpty() && name.isNotEmpty()) {
val model = FileModel(path, name, size) {
openDocumentEvent.postValue(Event(it))
}
list.add(model)
}
val list = arrayListOf<FileModel>()
Log.i(
"$TAG Loading document contents for conversation [${LinphoneUtils.getChatRoomId(
chatRoom
)}]"
)
val documents = chatRoom.documentContents
Log.i("$TAG [${documents.size}] documents have been fetched")
for (documentContent in documents) {
val path = documentContent.filePath.orEmpty()
val name = documentContent.name.orEmpty()
val size = documentContent.size.toLong()
if (path.isNotEmpty() && name.isNotEmpty()) {
val model = FileModel(path, name, size) {
openDocumentEvent.postValue(Event(it))
}
Log.i("$TAG [${documents.size}] documents have been processed")
list.add(model)
}
documentsList.postValue(list)
operationInProgress.postValue(false)
}
Log.i("$TAG [${documents.size}] documents have been processed")
documentsList.postValue(list)
operationInProgress.postValue(false)
}
}

View file

@ -23,7 +23,6 @@ import android.view.View
import androidx.annotation.UiThread
import androidx.annotation.WorkerThread
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.core.Address
@ -44,7 +43,7 @@ import org.linphone.utils.Event
import org.linphone.utils.ImageUtils
import org.linphone.utils.LinphoneUtils
class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
class ConversationInfoViewModel @UiThread constructor() : AbstractConversationViewModel() {
companion object {
private const val TAG = "[Conversation Info ViewModel]"
}
@ -69,8 +68,6 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
val expandParticipants = MutableLiveData<Boolean>()
val chatRoomFoundEvent = MutableLiveData<Event<Boolean>>()
val oneToOneParticipantRefKey = MutableLiveData<String>()
val groupLeftEvent: MutableLiveData<Event<Boolean>> by lazy {
@ -101,8 +98,6 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
MutableLiveData<Event<Pair<String, Int>>>()
}
private lateinit var chatRoom: ChatRoom
private val chatRoomListener = object : ChatRoomListenerStub() {
@WorkerThread
override fun onParticipantAdded(chatRoom: ChatRoom, eventLog: EventLog) {
@ -220,72 +215,23 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
super.onCleared()
coreContext.postOnCoreThread {
if (::chatRoom.isInitialized) {
if (isChatRoomInitialized()) {
chatRoom.removeListener(chatRoomListener)
}
}
}
@UiThread
fun findChatRoom(room: ChatRoom?, localSipUri: String, remoteSipUri: String) {
coreContext.postOnCoreThread { core ->
Log.i(
"$TAG Looking for conversation with local SIP URI [$localSipUri] and remote SIP URI [$remoteSipUri]"
)
if (room != null && ::chatRoom.isInitialized && chatRoom == room) {
Log.i("$TAG Conversation object already in memory, skipping")
chatRoomFoundEvent.postValue(Event(true))
return@postOnCoreThread
}
val localAddress = Factory.instance().createAddress(localSipUri)
val remoteAddress = Factory.instance().createAddress(remoteSipUri)
if (room != null && (!::chatRoom.isInitialized || chatRoom != room)) {
if (localAddress?.weakEqual(room.localAddress) == true && remoteAddress?.weakEqual(
room.peerAddress
) == true
) {
Log.i("$TAG Conversation object available in sharedViewModel, using it")
chatRoom = room
chatRoom.addListener(chatRoomListener)
configureChatRoom()
chatRoomFoundEvent.postValue(Event(true))
return@postOnCoreThread
}
}
if (localAddress != null && remoteAddress != null) {
Log.i("$TAG Searching for conversation in Core using local & peer SIP addresses")
val found = core.searchChatRoom(
null,
localAddress,
remoteAddress,
arrayOfNulls(
0
)
)
if (found != null) {
chatRoom = found
chatRoom.addListener(chatRoomListener)
configureChatRoom()
chatRoomFoundEvent.postValue(Event(true))
} else {
Log.e("$TAG Failed to find conversation given local & remote addresses!")
chatRoomFoundEvent.postValue(Event(false))
}
} else {
Log.e("$TAG Failed to parse local or remote SIP URI as Address!")
chatRoomFoundEvent.postValue(Event(false))
}
override fun beforeNotifyingChatRoomFound(sameOne: Boolean) {
if (!sameOne) {
chatRoom.addListener(chatRoomListener)
configureChatRoom()
}
}
@UiThread
fun leaveGroup() {
coreContext.postOnCoreThread {
if (::chatRoom.isInitialized) {
if (isChatRoomInitialized()) {
Log.i("$TAG Leaving conversation [${LinphoneUtils.getChatRoomId(chatRoom)}]")
chatRoom.leave()
}
@ -297,7 +243,7 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
fun deleteHistory() {
coreContext.postOnCoreThread {
// TODO: confirmation dialog ?
if (::chatRoom.isInitialized) {
if (isChatRoomInitialized()) {
Log.i(
"$TAG Cleaning conversation [${LinphoneUtils.getChatRoomId(chatRoom)}] history"
)
@ -428,7 +374,7 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
@UiThread
fun addParticipants(toAdd: ArrayList<String>) {
coreContext.postOnCoreThread {
if (::chatRoom.isInitialized) {
if (isChatRoomInitialized()) {
if (!LinphoneUtils.isChatRoomAGroup(chatRoom)) {
Log.e("$TAG Can't add participants to a conversation that's not a group!")
return@postOnCoreThread
@ -462,7 +408,7 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
@UiThread
fun updateSubject(newSubject: String) {
coreContext.postOnCoreThread {
if (::chatRoom.isInitialized) {
if (isChatRoomInitialized()) {
Log.i("$TAG Updating conversation subject to [$newSubject]")
chatRoom.subject = newSubject
}

View file

@ -20,17 +20,14 @@
package org.linphone.ui.main.chat.viewmodel
import androidx.annotation.UiThread
import androidx.annotation.WorkerThread
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.core.ChatRoom
import org.linphone.core.Factory
import org.linphone.core.tools.Log
import org.linphone.ui.main.chat.model.FileModel
import org.linphone.utils.Event
import org.linphone.utils.LinphoneUtils
class ConversationMediaListViewModel @UiThread constructor() : ViewModel() {
class ConversationMediaListViewModel @UiThread constructor() : AbstractConversationViewModel() {
companion object {
private const val TAG = "[Conversation Media List ViewModel]"
}
@ -43,98 +40,40 @@ class ConversationMediaListViewModel @UiThread constructor() : ViewModel() {
val operationInProgress = MutableLiveData<Boolean>()
val chatRoomFoundEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
val openMediaEvent: MutableLiveData<Event<FileModel>> by lazy {
MutableLiveData<Event<FileModel>>()
}
private lateinit var chatRoom: ChatRoom
lateinit var localSipUri: String
lateinit var remoteSipUri: String
@UiThread
fun findChatRoom(room: ChatRoom?, localSipUri: String, remoteSipUri: String) {
this.localSipUri = localSipUri
this.remoteSipUri = remoteSipUri
coreContext.postOnCoreThread { core ->
Log.i(
"$TAG Looking for conversation with local SIP URI [$localSipUri] and remote SIP URI [$remoteSipUri]"
)
if (room != null && ::chatRoom.isInitialized && chatRoom == room) {
Log.i("$TAG Conversation object already in memory, skipping")
chatRoomFoundEvent.postValue(Event(true))
return@postOnCoreThread
}
val localAddress = Factory.instance().createAddress(localSipUri)
val remoteAddress = Factory.instance().createAddress(remoteSipUri)
if (room != null && (!::chatRoom.isInitialized || chatRoom != room)) {
if (localAddress?.weakEqual(room.localAddress) == true && remoteAddress?.weakEqual(
room.peerAddress
) == true
) {
Log.i("$TAG Conversation object available in sharedViewModel, using it")
chatRoom = room
chatRoomFoundEvent.postValue(Event(true))
return@postOnCoreThread
}
}
if (localAddress != null && remoteAddress != null) {
Log.i("$TAG Searching for conversation in Core using local & peer SIP addresses")
val found = core.searchChatRoom(
null,
localAddress,
remoteAddress,
arrayOfNulls(
0
)
)
if (found != null) {
chatRoom = found
chatRoomFoundEvent.postValue(Event(true))
}
}
}
override fun beforeNotifyingChatRoomFound(sameOne: Boolean) {
loadMediaList()
}
@UiThread
fun loadMediaList() {
operationInProgress.value = true
@WorkerThread
private fun loadMediaList() {
operationInProgress.postValue(true)
coreContext.postOnCoreThread {
val list = arrayListOf<FileModel>()
if (::chatRoom.isInitialized) {
Log.i(
"$TAG Loading media contents for conversation [${LinphoneUtils.getChatRoomId(
chatRoom
)}]"
)
val media = chatRoom.mediaContents
Log.i("$TAG [${media.size}] media have been fetched")
for (mediaContent in media) {
val path = mediaContent.filePath.orEmpty()
val name = mediaContent.name.orEmpty()
val size = mediaContent.size.toLong()
if (path.isNotEmpty() && name.isNotEmpty()) {
val model = FileModel(path, name, size) {
openMediaEvent.postValue(Event(it))
}
list.add(model)
}
val list = arrayListOf<FileModel>()
Log.i(
"$TAG Loading media contents for conversation [${LinphoneUtils.getChatRoomId(
chatRoom
)}]"
)
val media = chatRoom.mediaContents
Log.i("$TAG [${media.size}] media have been fetched")
for (mediaContent in media) {
val path = mediaContent.filePath.orEmpty()
val name = mediaContent.name.orEmpty()
val size = mediaContent.size.toLong()
if (path.isNotEmpty() && name.isNotEmpty()) {
val model = FileModel(path, name, size) {
openMediaEvent.postValue(Event(it))
}
Log.i("$TAG [${media.size}] media have been processed")
list.add(model)
}
mediaList.postValue(list)
operationInProgress.postValue(false)
}
Log.i("$TAG [${media.size}] media have been processed")
mediaList.postValue(list)
operationInProgress.postValue(false)
}
}

View file

@ -22,7 +22,6 @@ package org.linphone.ui.main.chat.viewmodel
import androidx.annotation.UiThread
import androidx.annotation.WorkerThread
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.core.Address
@ -47,7 +46,7 @@ import org.linphone.utils.Event
import org.linphone.utils.ImageUtils
import org.linphone.utils.LinphoneUtils
class ConversationViewModel @UiThread constructor() : ViewModel() {
class ConversationViewModel @UiThread constructor() : AbstractConversationViewModel() {
companion object {
private const val TAG = "[Conversation ViewModel]"
private const val MESSAGES_PER_PAGE = 30
@ -114,14 +113,6 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
MutableLiveData<Event<Pair<String, Int>>>()
}
val chatRoomFoundEvent = MutableLiveData<Event<Boolean>>()
lateinit var chatRoom: ChatRoom
lateinit var localSipUri: String
lateinit var remoteSipUri: String
private var eventsList = arrayListOf<EventLogModel>()
private val chatRoomListener = object : ChatRoomListenerStub() {
@ -330,13 +321,20 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
super.onCleared()
coreContext.postOnCoreThread {
if (::chatRoom.isInitialized) {
if (isChatRoomInitialized()) {
chatRoom.removeListener(chatRoomListener)
}
eventsList.forEach(EventLogModel::destroy)
}
}
override fun beforeNotifyingChatRoomFound(sameOne: Boolean) {
if (!sameOne) {
chatRoom.addListener(chatRoomListener)
configureChatRoom()
}
}
@UiThread
fun openSearchBar() {
searchBarVisible.value = true
@ -355,65 +353,6 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
searchFilter.value = ""
}
@UiThread
fun findChatRoom(room: ChatRoom?, localSipUri: String, remoteSipUri: String) {
this.localSipUri = localSipUri
this.remoteSipUri = remoteSipUri
coreContext.postOnCoreThread { core ->
Log.i(
"$TAG Looking for conversation with local SIP URI [$localSipUri] and remote SIP URI [$remoteSipUri]"
)
if (room != null && ::chatRoom.isInitialized && chatRoom == room) {
Log.i("$TAG Conversation object already in memory, skipping")
chatRoomFoundEvent.postValue(Event(true))
return@postOnCoreThread
}
val localAddress = Factory.instance().createAddress(localSipUri)
val remoteAddress = Factory.instance().createAddress(remoteSipUri)
if (room != null && (!::chatRoom.isInitialized || chatRoom != room)) {
if (localAddress?.weakEqual(room.localAddress) == true && remoteAddress?.weakEqual(
room.peerAddress
) == true
) {
Log.i("$TAG Conversation object available in sharedViewModel, using it")
chatRoom = room
chatRoom.addListener(chatRoomListener)
configureChatRoom()
chatRoomFoundEvent.postValue(Event(true))
return@postOnCoreThread
}
}
if (localAddress != null && remoteAddress != null) {
Log.i("$TAG Searching for conversation in Core using local & peer SIP addresses")
val found = core.searchChatRoom(
null,
localAddress,
remoteAddress,
arrayOfNulls(
0
)
)
if (found != null) {
chatRoom = found
chatRoom.addListener(chatRoomListener)
configureChatRoom()
chatRoomFoundEvent.postValue(Event(true))
} else {
Log.e("$TAG Failed to find conversation given local & remote addresses!")
chatRoomFoundEvent.postValue(Event(false))
}
} else {
Log.e("$TAG Failed to parse local or remote SIP URI as Address!")
chatRoomFoundEvent.postValue(Event(false))
}
}
}
@UiThread
fun refresh() {
coreContext.postOnCoreThread {

View file

@ -102,12 +102,6 @@ class MediaListViewerFragment : GenericFragment() {
val chatRoom = sharedViewModel.displayedChatRoom
viewModel.findChatRoom(chatRoom, localSipUri, remoteSipUri)
viewModel.chatRoomFoundEvent.observe(viewLifecycleOwner) {
it.consume {
viewModel.loadMediaList()
}
}
viewModel.mediaList.observe(viewLifecycleOwner) {
val count = it.size
Log.i(