From ec40ca9b666d429379dfc21cf62d3bb3db690e04 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 15 Oct 2021 00:08:19 +0200 Subject: [PATCH 1/4] hangup call notification after 1 minute Signed-off-by: Marcel Hibbe --- .../firebase/MagicFirebaseMessagingService.kt | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) 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..d8fd3fdb8 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 @@ -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 { @@ -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) } }) } From 5bb8de673eab187d6e52fb8ea2612d9cd13772cf Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 11 Nov 2021 15:24:43 +0100 Subject: [PATCH 2/4] hangup call notification screen after 1 minute Signed-off-by: Marcel Hibbe --- .../talk/activities/CallNotificationActivity.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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()); } }); From b652b1136e3371da52ecb1d393c5ea3514ac7e92 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 11 Nov 2021 15:37:39 +0100 Subject: [PATCH 3/4] fix to stop notification if user joined on other device Signed-off-by: Marcel Hibbe --- .../talk/services/firebase/MagicFirebaseMessagingService.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 d8fd3fdb8..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,6 @@ 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 @@ -341,7 +340,8 @@ 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 } From d377b6f1368bd534fd626ed747173285e387e42e Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 23 Nov 2021 11:42:46 +0100 Subject: [PATCH 4/4] fix klint Signed-off-by: Marcel Hibbe --- .../nextcloud/talk/controllers/ChatController.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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) {