Browse Source

hangup call notification after 1 minute

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 3 years ago
parent
commit
ec40ca9b66

+ 9 - 11
app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt

@@ -64,6 +64,7 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FROM_NOTIFICATION_START_CA
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
 import com.nextcloud.talk.utils.preferences.AppPreferences
 import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder
+import io.reactivex.Observable
 import io.reactivex.Observer
 import io.reactivex.disposables.Disposable
 import io.reactivex.schedulers.Schedulers
@@ -78,6 +79,7 @@ import java.net.CookieManager
 import java.security.InvalidKeyException
 import java.security.NoSuchAlgorithmException
 import java.security.PrivateKey
+import java.util.concurrent.TimeUnit
 import javax.crypto.Cipher
 import javax.crypto.NoSuchPaddingException
 import javax.inject.Inject
@@ -308,7 +310,7 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
         val ncApi = retrofit!!.newBuilder()
             .client(okHttpClient!!.newBuilder().cookieJar(JavaNetCookieJar(CookieManager())).build()).build()
             .create(NcApi::class.java)
-        var hasParticipantsInCall = false
+        var hasParticipantsInCall = true
         var inCallOnDifferentDevice = false
 
         val apiVersion = ApiUtils.getConversationApiVersion(
@@ -324,8 +326,10 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
                 decryptedPushMessage.id
             )
         )
-            .takeWhile {
-                isServiceInForeground
+            .repeatWhen { completed ->
+                completed.zipWith(Observable.range(1, 12), { _, i -> i })
+                    .flatMap { Observable.timer(5, TimeUnit.SECONDS) }
+                    .takeWhile { isServiceInForeground && hasParticipantsInCall && !inCallOnDifferentDevice }
             }
             .subscribeOn(Schedulers.io())
             .subscribe(object : Observer<ParticipantsOverall> {
@@ -343,23 +347,17 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
                             }
                         }
                     }
-
                     if (!hasParticipantsInCall || inCallOnDifferentDevice) {
                         Log.d(TAG, "no participants in call OR inCallOnDifferentDevice")
                         stopForeground(true)
                         handler.removeCallbacksAndMessages(null)
-                    } else if (isServiceInForeground) {
-                        handler.postDelayed(
-                            {
-                                checkIfCallIsActive(signatureVerification, decryptedPushMessage)
-                            },
-                            5000
-                        )
                     }
                 }
 
                 override fun onError(e: Throwable) {}
                 override fun onComplete() {
+                    stopForeground(true)
+                    handler.removeCallbacksAndMessages(null)
                 }
             })
     }