Merge pull request #1634 from nextcloud/feature/noid/timeoutCallNotification

timeout call notification after 1 minute
This commit is contained in:
Marcel Hibbe 2021-11-23 12:32:19 +01:00 committed by GitHub
commit 706573212f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 22 deletions

View File

@ -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<ParticipantsOverall> {
@ -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)
}
})
}

View File

@ -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<ParticipantsOverall>() {
@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());
}
});

View File

@ -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) {