diff --git a/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt b/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt index 4708f42e1..9e23e1c7e 100644 --- a/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt +++ b/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt @@ -63,7 +63,7 @@ import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FROM_NOTIFICATION_START_CALL 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 +78,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 +309,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 +325,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 { @@ -337,29 +340,24 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() { hasParticipantsInCall = participantList.isNotEmpty() if (hasParticipantsInCall) { for (participant in participantList) { - if (participant.userId == signatureVerification.userEntity.userId) { + if (participant.actorId == signatureVerification.userEntity.userId && + participant.actorType == Participant.ActorType.USERS) { inCallOnDifferentDevice = true break } } } - 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) } }) } diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallNotificationActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallNotificationActivity.java index 7c126e4d6..4d211e030 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallNotificationActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallNotificationActivity.java @@ -69,6 +69,7 @@ import org.parceler.Parcels; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import javax.inject.Inject; @@ -76,6 +77,7 @@ import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import autodagger.AutoInjector; import butterknife.OnClick; +import io.reactivex.Observable; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -217,7 +219,9 @@ public class CallNotificationActivity extends CallBaseActivity { ncApi.getPeersForCall(credentials, ApiUtils.getUrlForCall(apiVersion, userBeingCalled.getBaseUrl(), currentConversation.getToken())) .subscribeOn(Schedulers.io()) - .takeWhile(observable -> !leavingScreen) + .repeatWhen(completed -> completed.zipWith(Observable.range(1, 12), (n, i) -> i) + .flatMap(retryCount -> Observable.timer(5, TimeUnit.SECONDS)) + .takeWhile(observable -> !leavingScreen)) .subscribe(new Observer() { @Override public void onSubscribe(Disposable d) { @@ -253,9 +257,7 @@ public class CallNotificationActivity extends CallBaseActivity { @Override public void onComplete() { - if (!leavingScreen) { - handler.postDelayed(() -> checkIfAnyParticipantsRemainInRoom(), 5000); - } + runOnUiThread(() -> hangup()); } }); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 0ed221e10..d314a82d5 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -279,7 +279,7 @@ class ChatController(args: Bundle) : this.sharedText = args.getString(BundleKeys.KEY_SHARED_TEXT, "") Log.d(TAG, " roomToken = $roomToken") - if (roomToken.isNullOrEmpty()){ + if (roomToken.isNullOrEmpty()) { Log.d(TAG, " roomToken was null or empty!") } @@ -322,7 +322,10 @@ class ChatController(args: Bundle) : @Suppress("Detekt.TooGenericExceptionCaught") override fun onNext(roomOverall: RoomOverall) { currentConversation = roomOverall.ocs.data - Log.d(TAG, "getRoomInfo. token: " + currentConversation?.getToken() + " sessionId: " + currentConversation?.sessionId) + Log.d( + TAG, "getRoomInfo. token: " + currentConversation?.getToken() + + " sessionId: " + currentConversation?.sessionId + ) loadAvatarForStatusBar() setTitle() @@ -1627,9 +1630,10 @@ class ChatController(args: Bundle) : private fun joinRoomWithPassword() { - if (currentConversation == null - || TextUtils.isEmpty(currentConversation?.sessionId) - || currentConversation?.sessionId == "0") { + if (currentConversation == null || + TextUtils.isEmpty(currentConversation?.sessionId) || + currentConversation?.sessionId == "0" + ) { var apiVersion = 1 // FIXME Fix API checking with guests? if (conversationUser != null) {