Improved how chatRoom.markAsRead() and notifications are handled

This commit is contained in:
Sylvain Berfini 2021-09-01 17:14:21 +02:00
parent efc84d4054
commit ecc318d084
7 changed files with 9 additions and 21 deletions

View file

@ -21,7 +21,6 @@ size=vga
[app]
tunnel=disabled
push_notification=1
auto_start=1
[tunnel]

View file

@ -146,7 +146,7 @@ class ChatBubbleActivity : GenericActivity() {
}
binding.setCloseBubbleClickListener {
coreContext.notificationsManager.cancelChatNotificationIdForSipUri(viewModel.chatRoom.peerAddress.asStringUriOnly())
coreContext.notificationsManager.dismissChatNotification(viewModel.chatRoom)
}
binding.setSendMessageClickListener {

View file

@ -83,7 +83,6 @@ class ChatRoomsListAdapter(
selectionViewModel.onToggleSelect(adapterPosition)
} else {
selectedChatRoomEvent.value = Event(chatRoomViewModel.chatRoom)
chatRoomViewModel.chatRoom.markAsRead()
}
}

View file

@ -449,7 +449,7 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
// Prevent notifications for this chat room to be displayed
val peerAddress = viewModel.chatRoom.peerAddress.asStringUriOnly()
coreContext.notificationsManager.currentlyDisplayedChatRoomAddress = peerAddress
coreContext.notificationsManager.cancelChatNotificationIdForSipUri(peerAddress)
viewModel.chatRoom.markAsRead()
} else {
Log.e("[Chat Room] Fragment resuming but viewModel lateinit property isn't initialized!")
}

View file

@ -159,7 +159,6 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
override fun onLeftToRightSwipe(viewHolder: RecyclerView.ViewHolder) {
val chatRoomViewModel = adapter.currentList[viewHolder.adapterPosition]
chatRoomViewModel.chatRoom.markAsRead()
coreContext.notificationsManager.dismissChatNotification(chatRoomViewModel.chatRoom)
adapter.notifyItemChanged(viewHolder.adapterPosition)
}
@ -266,7 +265,6 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
val chatRoom = coreContext.core.searchChatRoom(null, localAddress, remoteSipAddress, arrayOfNulls(0))
if (chatRoom != null) {
Log.i("[Chat] Found matching chat room $chatRoom")
chatRoom.markAsRead()
adapter.selectedChatRoomEvent.value = Event(chatRoom)
}
} else {

View file

@ -23,7 +23,6 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import java.util.*
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.activities.main.chat.data.EventLogData
import org.linphone.core.*
import org.linphone.core.tools.Log
@ -58,11 +57,6 @@ class ChatMessagesListViewModel(private val chatRoom: ChatRoom) : ViewModel() {
private val chatRoomListener: ChatRoomListenerStub = object : ChatRoomListenerStub() {
override fun onChatMessageReceived(chatRoom: ChatRoom, eventLog: EventLog) {
// Do not mark as read if DetailChatRoomFragment was opened before app was put in background
if (coreContext.notificationsManager.currentlyDisplayedChatRoomAddress == chatRoom.peerAddress.asStringUriOnly()) {
chatRoom.markAsRead()
}
if (eventLog.type == EventLog.Type.ConferenceChatMessage) {
val chatMessage = eventLog.chatMessage
chatMessage ?: return

View file

@ -140,7 +140,8 @@ class NotificationsManager(private val context: Context) {
}
if (currentlyDisplayedChatRoomAddress == room.peerAddress.asStringUriOnly()) {
Log.i("[Notifications Manager] Chat room is currently displayed, do not notify received message")
Log.i("[Notifications Manager] Chat room is currently displayed, do not notify received message & mark it as read")
room.markAsRead()
return
}
@ -162,6 +163,11 @@ class NotificationsManager(private val context: Context) {
}
displayIncomingChatNotification(room, message)
}
override fun onChatRoomRead(core: Core, chatRoom: ChatRoom) {
Log.i("[Notifications Manager] Chat room [$chatRoom] has been marked as read, removing notification if any")
dismissChatNotification(chatRoom)
}
}
val chatListener: ChatMessageListener = object : ChatMessageListenerStub() {
@ -231,14 +237,6 @@ class NotificationsManager(private val context: Context) {
notificationManager.cancel(id)
}
fun cancelChatNotificationIdForSipUri(sipUri: String) {
val notifiable: Notifiable? = chatNotificationsMap[sipUri]
if (notifiable != null) {
notifiable.messages.clear()
cancel(notifiable.notificationId)
}
}
fun resetChatNotificationCounterForSipUri(sipUri: String) {
val notifiable: Notifiable? = chatNotificationsMap[sipUri]
notifiable?.messages?.clear()