Improved how chatRoom.markAsRead() and notifications are handled
This commit is contained in:
parent
efc84d4054
commit
ecc318d084
7 changed files with 9 additions and 21 deletions
|
@ -21,7 +21,6 @@ size=vga
|
||||||
|
|
||||||
[app]
|
[app]
|
||||||
tunnel=disabled
|
tunnel=disabled
|
||||||
push_notification=1
|
|
||||||
auto_start=1
|
auto_start=1
|
||||||
|
|
||||||
[tunnel]
|
[tunnel]
|
||||||
|
|
|
@ -146,7 +146,7 @@ class ChatBubbleActivity : GenericActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.setCloseBubbleClickListener {
|
binding.setCloseBubbleClickListener {
|
||||||
coreContext.notificationsManager.cancelChatNotificationIdForSipUri(viewModel.chatRoom.peerAddress.asStringUriOnly())
|
coreContext.notificationsManager.dismissChatNotification(viewModel.chatRoom)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.setSendMessageClickListener {
|
binding.setSendMessageClickListener {
|
||||||
|
|
|
@ -83,7 +83,6 @@ class ChatRoomsListAdapter(
|
||||||
selectionViewModel.onToggleSelect(adapterPosition)
|
selectionViewModel.onToggleSelect(adapterPosition)
|
||||||
} else {
|
} else {
|
||||||
selectedChatRoomEvent.value = Event(chatRoomViewModel.chatRoom)
|
selectedChatRoomEvent.value = Event(chatRoomViewModel.chatRoom)
|
||||||
chatRoomViewModel.chatRoom.markAsRead()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -449,7 +449,7 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
||||||
// Prevent notifications for this chat room to be displayed
|
// Prevent notifications for this chat room to be displayed
|
||||||
val peerAddress = viewModel.chatRoom.peerAddress.asStringUriOnly()
|
val peerAddress = viewModel.chatRoom.peerAddress.asStringUriOnly()
|
||||||
coreContext.notificationsManager.currentlyDisplayedChatRoomAddress = peerAddress
|
coreContext.notificationsManager.currentlyDisplayedChatRoomAddress = peerAddress
|
||||||
coreContext.notificationsManager.cancelChatNotificationIdForSipUri(peerAddress)
|
viewModel.chatRoom.markAsRead()
|
||||||
} else {
|
} else {
|
||||||
Log.e("[Chat Room] Fragment resuming but viewModel lateinit property isn't initialized!")
|
Log.e("[Chat Room] Fragment resuming but viewModel lateinit property isn't initialized!")
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,6 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
||||||
override fun onLeftToRightSwipe(viewHolder: RecyclerView.ViewHolder) {
|
override fun onLeftToRightSwipe(viewHolder: RecyclerView.ViewHolder) {
|
||||||
val chatRoomViewModel = adapter.currentList[viewHolder.adapterPosition]
|
val chatRoomViewModel = adapter.currentList[viewHolder.adapterPosition]
|
||||||
chatRoomViewModel.chatRoom.markAsRead()
|
chatRoomViewModel.chatRoom.markAsRead()
|
||||||
coreContext.notificationsManager.dismissChatNotification(chatRoomViewModel.chatRoom)
|
|
||||||
adapter.notifyItemChanged(viewHolder.adapterPosition)
|
adapter.notifyItemChanged(viewHolder.adapterPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +265,6 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
||||||
val chatRoom = coreContext.core.searchChatRoom(null, localAddress, remoteSipAddress, arrayOfNulls(0))
|
val chatRoom = coreContext.core.searchChatRoom(null, localAddress, remoteSipAddress, arrayOfNulls(0))
|
||||||
if (chatRoom != null) {
|
if (chatRoom != null) {
|
||||||
Log.i("[Chat] Found matching chat room $chatRoom")
|
Log.i("[Chat] Found matching chat room $chatRoom")
|
||||||
chatRoom.markAsRead()
|
|
||||||
adapter.selectedChatRoomEvent.value = Event(chatRoom)
|
adapter.selectedChatRoomEvent.value = Event(chatRoom)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -23,7 +23,6 @@ import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
|
||||||
import org.linphone.activities.main.chat.data.EventLogData
|
import org.linphone.activities.main.chat.data.EventLogData
|
||||||
import org.linphone.core.*
|
import org.linphone.core.*
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
|
@ -58,11 +57,6 @@ class ChatMessagesListViewModel(private val chatRoom: ChatRoom) : ViewModel() {
|
||||||
|
|
||||||
private val chatRoomListener: ChatRoomListenerStub = object : ChatRoomListenerStub() {
|
private val chatRoomListener: ChatRoomListenerStub = object : ChatRoomListenerStub() {
|
||||||
override fun onChatMessageReceived(chatRoom: ChatRoom, eventLog: EventLog) {
|
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) {
|
if (eventLog.type == EventLog.Type.ConferenceChatMessage) {
|
||||||
val chatMessage = eventLog.chatMessage
|
val chatMessage = eventLog.chatMessage
|
||||||
chatMessage ?: return
|
chatMessage ?: return
|
||||||
|
|
|
@ -140,7 +140,8 @@ class NotificationsManager(private val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentlyDisplayedChatRoomAddress == room.peerAddress.asStringUriOnly()) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +163,11 @@ class NotificationsManager(private val context: Context) {
|
||||||
}
|
}
|
||||||
displayIncomingChatNotification(room, message)
|
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() {
|
val chatListener: ChatMessageListener = object : ChatMessageListenerStub() {
|
||||||
|
@ -231,14 +237,6 @@ class NotificationsManager(private val context: Context) {
|
||||||
notificationManager.cancel(id)
|
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) {
|
fun resetChatNotificationCounterForSipUri(sipUri: String) {
|
||||||
val notifiable: Notifiable? = chatNotificationsMap[sipUri]
|
val notifiable: Notifiable? = chatNotificationsMap[sipUri]
|
||||||
notifiable?.messages?.clear()
|
notifiable?.messages?.clear()
|
||||||
|
|
Loading…
Reference in a new issue