Fixed missing toasts in conversations list + improved conversation removal (no longer scrolling back to top)

This commit is contained in:
Sylvain Berfini 2024-07-01 09:59:24 +02:00
parent 57f8ff3341
commit af3cab475b
3 changed files with 16 additions and 6 deletions

View file

@ -72,10 +72,7 @@ class ConversationsListFragment : AbstractMainFragment() {
binding.conversationsList.scrollToPosition(0)
}
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
Log.i("$TAG [$itemCount] removed, scrolling to top")
binding.conversationsList.scrollToPosition(0)
}
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) { }
}
override fun onDefaultAccountChanged() {
@ -118,6 +115,7 @@ class ConversationsListFragment : AbstractMainFragment() {
binding.lifecycleOwner = viewLifecycleOwner
binding.viewModel = listViewModel
observeToastEvents(listViewModel)
binding.conversationsList.setHasFixedSize(true)
binding.conversationsList.layoutManager = LinearLayoutManager(requireContext())
@ -150,7 +148,6 @@ class ConversationsListFragment : AbstractMainFragment() {
{ // onDeleteConversation
Log.i("$TAG Deleting conversation [${model.id}]")
model.delete()
listViewModel.applyFilter()
},
{ // onLeaveGroup
Log.i("$TAG Leaving group conversation [${model.id}]")

View file

@ -227,6 +227,7 @@ class ConversationModel @WorkerThread constructor(val chatRoom: ChatRoom) {
val basic = chatRoom.hasCapability(Capabilities.Basic.toInt())
ShortcutUtils.removeShortcutToChatRoom(chatRoom)
core.deleteChatRoom(chatRoom)
if (basic) {
Log.i("$TAG Conversation [$id] has been deleted")
isBeingDeleted.postValue(false)

View file

@ -60,7 +60,19 @@ class ConversationsListViewModel @UiThread constructor() : AbstractMainViewModel
computeChatRoomsList(currentFilter)
}
ChatRoom.State.Deleted -> {
computeChatRoomsList(currentFilter)
val currentList = conversations.value.orEmpty()
val found = currentList.find {
it.chatRoom == chatRoom
}
if (found != null) {
val newList = arrayListOf<ConversationModel>()
newList.addAll(currentList)
newList.remove(found)
Log.i("$TAG Removing chat room from list")
conversations.postValue(newList)
} else {
Log.w("$TAG Failed to find item in list matching deleted chat room")
}
showGreenToastEvent.postValue(
Event(