mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 03:59:35 +01:00
add check that missed call notification is not shown accidentally
for example when call is hangup on mobile and immediately after on web, the loop in "checkIfCallIsActive" is still active and might trigger to send the "missed call" notification. Because of this, there is now another check if the "ongoing call" notification is still visible. It makes only sense to show the missed call notification, when the ongoing call notification is still visible. Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
9c4b0a00c6
commit
e121d32984
@ -256,7 +256,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
|
||||
|
||||
sendNotification(pushMessage.timestamp.toInt(), notification)
|
||||
|
||||
checkIfCallIsActive(signatureVerification, pushMessage)
|
||||
checkIfCallIsActive(signatureVerification)
|
||||
}
|
||||
|
||||
private fun initNcApiAndCredentials() {
|
||||
@ -661,10 +661,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
|
||||
notificationManager.cancel(notificationId)
|
||||
}
|
||||
|
||||
private fun checkIfCallIsActive(
|
||||
signatureVerification: SignatureVerification,
|
||||
decryptedPushMessage: DecryptedPushMessage
|
||||
) {
|
||||
private fun checkIfCallIsActive(signatureVerification: SignatureVerification) {
|
||||
Log.d(TAG, "checkIfCallIsActive")
|
||||
var hasParticipantsInCall = true
|
||||
var inCallOnDifferentDevice = false
|
||||
@ -681,7 +678,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
|
||||
ApiUtils.getUrlForCall(
|
||||
apiVersion,
|
||||
signatureVerification.user!!.baseUrl,
|
||||
decryptedPushMessage.id
|
||||
pushMessage.id
|
||||
)
|
||||
)
|
||||
.repeatWhen { completed ->
|
||||
@ -708,18 +705,18 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
|
||||
}
|
||||
if (inCallOnDifferentDevice) {
|
||||
Log.d(TAG, "inCallOnDifferentDevice is true")
|
||||
removeNotification(decryptedPushMessage.timestamp.toInt())
|
||||
removeNotification(pushMessage.timestamp.toInt())
|
||||
}
|
||||
|
||||
if (!hasParticipantsInCall) {
|
||||
showMissedCallNotification()
|
||||
Log.d(TAG, "no participants in call")
|
||||
removeNotification(decryptedPushMessage.timestamp.toInt())
|
||||
removeNotification(pushMessage.timestamp.toInt())
|
||||
}
|
||||
|
||||
isCallNotificationVisible = NotificationUtils.isNotificationVisible(
|
||||
context,
|
||||
decryptedPushMessage.timestamp.toInt()
|
||||
pushMessage.timestamp.toInt()
|
||||
)
|
||||
}
|
||||
|
||||
@ -734,71 +731,78 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
|
||||
showMissedCallNotification()
|
||||
}
|
||||
|
||||
removeNotification(decryptedPushMessage.timestamp.toInt())
|
||||
removeNotification(pushMessage.timestamp.toInt())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun showMissedCallNotification() {
|
||||
val apiVersion = ApiUtils.getConversationApiVersion(
|
||||
signatureVerification.user,
|
||||
intArrayOf(
|
||||
ApiUtils.APIv4,
|
||||
ApiUtils.APIv3, 1
|
||||
)
|
||||
val isOngoingCallNotificationVisible = NotificationUtils.isNotificationVisible(
|
||||
context,
|
||||
pushMessage.timestamp.toInt()
|
||||
)
|
||||
ncApi.getRoom(
|
||||
credentials,
|
||||
ApiUtils.getUrlForRoom(
|
||||
apiVersion, signatureVerification.user?.baseUrl,
|
||||
pushMessage.id
|
||||
|
||||
if (isOngoingCallNotificationVisible) {
|
||||
val apiVersion = ApiUtils.getConversationApiVersion(
|
||||
signatureVerification.user,
|
||||
intArrayOf(
|
||||
ApiUtils.APIv4,
|
||||
ApiUtils.APIv3, 1
|
||||
)
|
||||
)
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.retry(GET_ROOM_RETRY_COUNT)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Observer<RoomOverall> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// unused atm
|
||||
}
|
||||
ncApi.getRoom(
|
||||
credentials,
|
||||
ApiUtils.getUrlForRoom(
|
||||
apiVersion, signatureVerification.user?.baseUrl,
|
||||
pushMessage.id
|
||||
)
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.retry(GET_ROOM_RETRY_COUNT)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Observer<RoomOverall> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onNext(roomOverall: RoomOverall) {
|
||||
val currentConversation = roomOverall.ocs!!.data
|
||||
val notificationBuilder: NotificationCompat.Builder?
|
||||
override fun onNext(roomOverall: RoomOverall) {
|
||||
val currentConversation = roomOverall.ocs!!.data
|
||||
val notificationBuilder: NotificationCompat.Builder?
|
||||
|
||||
notificationBuilder = NotificationCompat.Builder(
|
||||
context!!,
|
||||
NotificationUtils.NotificationChannels
|
||||
.NOTIFICATION_CHANNEL_MESSAGES_V4.name
|
||||
)
|
||||
|
||||
val notification: Notification = notificationBuilder
|
||||
.setContentTitle(
|
||||
String.format(
|
||||
context!!.resources.getString(R.string.nc_missed_call),
|
||||
currentConversation!!.displayName
|
||||
)
|
||||
notificationBuilder = NotificationCompat.Builder(
|
||||
context!!,
|
||||
NotificationUtils.NotificationChannels
|
||||
.NOTIFICATION_CHANNEL_MESSAGES_V4.name
|
||||
)
|
||||
.setSmallIcon(R.drawable.ic_baseline_phone_missed_24)
|
||||
.setOngoing(false)
|
||||
.setAutoCancel(true)
|
||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||
.setContentIntent(getIntentToOpenConversation())
|
||||
.build()
|
||||
|
||||
val notificationId: Int = SystemClock.uptimeMillis().toInt()
|
||||
notificationManager.notify(notificationId, notification)
|
||||
Log.d(TAG, "'you missed a call' notification was created")
|
||||
}
|
||||
val notification: Notification = notificationBuilder
|
||||
.setContentTitle(
|
||||
String.format(
|
||||
context!!.resources.getString(R.string.nc_missed_call),
|
||||
currentConversation!!.displayName
|
||||
)
|
||||
)
|
||||
.setSmallIcon(R.drawable.ic_baseline_phone_missed_24)
|
||||
.setOngoing(false)
|
||||
.setAutoCancel(true)
|
||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||
.setContentIntent(getIntentToOpenConversation())
|
||||
.build()
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "An error occurred while fetching room for the 'missed call' notification", e)
|
||||
}
|
||||
val notificationId: Int = SystemClock.uptimeMillis().toInt()
|
||||
notificationManager.notify(notificationId, notification)
|
||||
Log.d(TAG, "'you missed a call' notification was created")
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
})
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "An error occurred while fetching room for the 'missed call' notification", e)
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun getIntentToOpenConversation(): PendingIntent? {
|
||||
|
Loading…
Reference in New Issue
Block a user