Fixed chat bubbles sometimes closing when opened
This commit is contained in:
parent
0e17da27e8
commit
8c790929c4
2 changed files with 31 additions and 19 deletions
|
@ -94,10 +94,6 @@ class ChatBubbleActivity : GenericActivity() {
|
|||
return
|
||||
}
|
||||
|
||||
// Workaround for the removed notification when a chat room is marked as read
|
||||
coreContext.notificationsManager.disableDismissNotificationUponReadForChatRoom(chatRoom)
|
||||
chatRoom.markAsRead()
|
||||
|
||||
viewModel = ViewModelProvider(
|
||||
this,
|
||||
ChatRoomViewModelFactory(chatRoom)
|
||||
|
@ -158,6 +154,7 @@ class ChatBubbleActivity : GenericActivity() {
|
|||
|
||||
binding.setOpenAppClickListener {
|
||||
coreContext.notificationsManager.currentlyDisplayedChatRoomAddress = null
|
||||
coreContext.notificationsManager.changeDismissNotificationUponReadForChatRoom(viewModel.chatRoom, false)
|
||||
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
intent.putExtra("RemoteSipUri", remoteSipUri)
|
||||
|
@ -182,6 +179,10 @@ class ChatBubbleActivity : GenericActivity() {
|
|||
|
||||
viewModel.chatRoom.addListener(listener)
|
||||
|
||||
// Workaround for the removed notification when a chat room is marked as read
|
||||
coreContext.notificationsManager.changeDismissNotificationUponReadForChatRoom(viewModel.chatRoom, true)
|
||||
viewModel.chatRoom.markAsRead()
|
||||
|
||||
val peerAddress = viewModel.chatRoom.peerAddress.asStringUriOnly()
|
||||
coreContext.notificationsManager.currentlyDisplayedChatRoomAddress = peerAddress
|
||||
coreContext.notificationsManager.resetChatNotificationCounterForSipUri(peerAddress)
|
||||
|
@ -197,6 +198,7 @@ class ChatBubbleActivity : GenericActivity() {
|
|||
viewModel.chatRoom.removeListener(listener)
|
||||
|
||||
coreContext.notificationsManager.currentlyDisplayedChatRoomAddress = null
|
||||
coreContext.notificationsManager.changeDismissNotificationUponReadForChatRoom(viewModel.chatRoom, false)
|
||||
|
||||
super.onPause()
|
||||
}
|
||||
|
|
|
@ -63,7 +63,6 @@ class Notifiable(val notificationId: Int) {
|
|||
var localIdentity: String? = null
|
||||
var myself: String? = null
|
||||
var remoteAddress: String? = null
|
||||
var dismissNotificationUponReadChatRoom: Boolean = true
|
||||
}
|
||||
|
||||
class NotifiableMessage(
|
||||
|
@ -102,6 +101,7 @@ class NotificationsManager(private val context: Context) {
|
|||
private val chatNotificationsMap: HashMap<String, Notifiable> = HashMap()
|
||||
private val callNotificationsMap: HashMap<String, Notifiable> = HashMap()
|
||||
private val previousChatNotifications: ArrayList<Int> = arrayListOf()
|
||||
private val chatBubbleNotifications: ArrayList<Int> = arrayListOf()
|
||||
|
||||
private var currentForegroundServiceNotificationId: Int = 0
|
||||
private var serviceNotification: Notification? = null
|
||||
|
@ -174,15 +174,20 @@ class NotificationsManager(private val context: Context) {
|
|||
val address = chatRoom.peerAddress.asStringUriOnly()
|
||||
val notifiable = chatNotificationsMap[address]
|
||||
if (notifiable != null) {
|
||||
if (notifiable.dismissNotificationUponReadChatRoom) {
|
||||
if (chatBubbleNotifications.contains(notifiable.notificationId)) {
|
||||
Log.i("[Notifications Manager] Chat room [$chatRoom] has been marked as read, not removing notification because of a chat bubble")
|
||||
} else {
|
||||
Log.i("[Notifications Manager] Chat room [$chatRoom] has been marked as read, removing notification if any")
|
||||
dismissChatNotification(chatRoom)
|
||||
} else {
|
||||
Log.i("[Notifications Manager] Chat room [$chatRoom] has been marked as read, not removing notification, maybe because of a chat bubble?")
|
||||
}
|
||||
} else {
|
||||
Log.i("[Notifications Manager] Chat room [$chatRoom] has been marked as read but no notifiable found, removing notification if any")
|
||||
dismissChatNotification(chatRoom)
|
||||
val notificationId = chatRoom.creationTime.toInt()
|
||||
if (chatBubbleNotifications.contains(notificationId)) {
|
||||
Log.i("[Notifications Manager] Chat room [$chatRoom] has been marked as read but no notifiable found, not removing notification because of a chat bubble")
|
||||
} else {
|
||||
Log.i("[Notifications Manager] Chat room [$chatRoom] has been marked as read but no notifiable found, removing notification if any")
|
||||
dismissChatNotification(chatRoom)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -696,21 +701,26 @@ class NotificationsManager(private val context: Context) {
|
|||
} else {
|
||||
val previousNotificationId = previousChatNotifications.find { id -> id == room.creationTime.toInt() }
|
||||
if (previousNotificationId != null) {
|
||||
Log.i("[Notifications Manager] Found previous notification with same ID [$previousNotificationId], canceling it")
|
||||
cancel(previousNotificationId, CHAT_TAG)
|
||||
if (chatBubbleNotifications.contains(previousNotificationId)) {
|
||||
Log.i("[Notifications Manager] Found previous notification with same ID [$previousNotificationId] but not cancelling it as it's ID is in chat bubbles list")
|
||||
} else {
|
||||
Log.i("[Notifications Manager] Found previous notification with same ID [$previousNotificationId], canceling it")
|
||||
cancel(previousNotificationId, CHAT_TAG)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun disableDismissNotificationUponReadForChatRoom(chatRoom: ChatRoom) {
|
||||
val address = chatRoom.peerAddress.asStringUriOnly()
|
||||
val notifiable: Notifiable? = chatNotificationsMap[address]
|
||||
if (notifiable != null) {
|
||||
Log.i("[Notifications Manager] Prevent notification with id [${notifiable.notificationId}] from being dismissed when chat room will be marked as read")
|
||||
notifiable.dismissNotificationUponReadChatRoom = false
|
||||
chatNotificationsMap[address] = notifiable
|
||||
fun changeDismissNotificationUponReadForChatRoom(chatRoom: ChatRoom, dismiss: Boolean) {
|
||||
val notificationId = chatRoom.creationTime.toInt()
|
||||
if (dismiss) {
|
||||
Log.i("[Notifications Manager] Allow notification with id [$notificationId] to be dismissed when chat room will be marked as read, used for chat bubble")
|
||||
chatBubbleNotifications.add(notificationId)
|
||||
} else {
|
||||
Log.i("[Notifications Manager] Prevent notification with id [$notificationId] from being dismissed when chat room will be marked as read, used for chat bubble")
|
||||
chatBubbleNotifications.remove(notificationId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue