mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Do not show notifications for messages received in currently displayed chat room
This commit is contained in:
parent
b3396fa62e
commit
db72bffcbd
4 changed files with 50 additions and 5 deletions
|
|
@ -132,8 +132,15 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
Log.i("$TAG Received ${messages.size} aggregated messages")
|
||||
if (corePreferences.disableChat) return
|
||||
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
|
||||
if (id == currentlyDisplayedChatRoomId) {
|
||||
Log.i(
|
||||
"$TAG Do not notify received messages for currently displayed chat room [$id]"
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (chatRoom.muted) {
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
|
||||
Log.i("$TAG Chat room $id has been muted")
|
||||
return
|
||||
}
|
||||
|
|
@ -158,8 +165,15 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
)
|
||||
if (corePreferences.disableChat) return
|
||||
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
|
||||
if (id == currentlyDisplayedChatRoomId) {
|
||||
Log.i(
|
||||
"$TAG Do not notify received reaction for currently displayed chat room [$id]"
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (chatRoom.muted) {
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
|
||||
Log.i("$TAG Chat room $id has been muted")
|
||||
return
|
||||
}
|
||||
|
|
@ -273,6 +287,8 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
private val chatNotificationsMap: HashMap<String, Notifiable> = HashMap()
|
||||
private val previousChatNotifications: ArrayList<Int> = arrayListOf()
|
||||
|
||||
private var currentlyDisplayedChatRoomId: String = ""
|
||||
|
||||
init {
|
||||
createServiceChannel()
|
||||
createIncomingCallNotificationChannel()
|
||||
|
|
@ -294,6 +310,16 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
}
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun setCurrentlyDisplayedChatRoomId(id: String) {
|
||||
currentlyDisplayedChatRoomId = id
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun resetCurrentlyDisplayedChatRoomId() {
|
||||
currentlyDisplayedChatRoomId = ""
|
||||
}
|
||||
|
||||
@MainThread
|
||||
fun onServiceStarted(service: CoreForegroundService) {
|
||||
Log.i("$TAG Service has been started")
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import androidx.navigation.fragment.findNavController
|
|||
import androidx.navigation.fragment.navArgs
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.ChatConversationFragmentBinding
|
||||
|
|
@ -51,6 +52,7 @@ import org.linphone.ui.main.chat.viewmodel.ConversationViewModel
|
|||
import org.linphone.ui.main.fragment.GenericFragment
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.LinphoneUtils
|
||||
import org.linphone.utils.hideKeyboard
|
||||
import org.linphone.utils.showKeyboard
|
||||
|
||||
|
|
@ -195,6 +197,20 @@ class ConversationFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
val id = LinphoneUtils.getChatRoomId(args.localSipUri, args.remoteSipUri)
|
||||
Log.i("$TAG Asking notifications manager not to notify chat messages for chat room [$id]")
|
||||
coreContext.notificationsManager.setCurrentlyDisplayedChatRoomId(id)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
coreContext.notificationsManager.resetCurrentlyDisplayedChatRoomId()
|
||||
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
private fun showChatMessageLongPressMenu(chatMessageModel: ChatMessageModel) {
|
||||
// TODO: handle backward compat for blurring
|
||||
val blurEffect = RenderEffect.createBlurEffect(16F, 16F, Shader.TileMode.MIRROR)
|
||||
|
|
|
|||
|
|
@ -74,8 +74,6 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
private lateinit var chatRoom: ChatRoom
|
||||
|
||||
private var currentFilter = ""
|
||||
|
||||
private val avatarsMap = hashMapOf<String, ContactAvatarModel>()
|
||||
|
||||
private val chatRoomListener = object : ChatRoomListenerStub() {
|
||||
|
|
|
|||
|
|
@ -196,7 +196,12 @@ class LinphoneUtils {
|
|||
localSipUri.clean()
|
||||
val remoteSipUri = remoteAddress.clone()
|
||||
remoteSipUri.clean()
|
||||
return "${localSipUri.asStringUriOnly()}~${remoteSipUri.asStringUriOnly()}"
|
||||
return getChatRoomId(localSipUri.asStringUriOnly(), remoteSipUri.asStringUriOnly())
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun getChatRoomId(localSipUri: String, remoteSipUri: String): String {
|
||||
return "$localSipUri~$remoteSipUri"
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue