diff --git a/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogViewModel.kt index 778a6f9b78..a3f406454a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogViewModel.kt @@ -82,6 +82,7 @@ class CallLogViewModel( disposables += AppDependencies .signalCallManager .peekInfoCache + .skipWhile { cache -> cache.isEmpty() || cache.values.all { it.isCompletelyInactive } } .observeOn(Schedulers.computation()) .distinctUntilChanged() .subscribe { diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/CallLinkPeekInfo.kt b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/CallLinkPeekInfo.kt index 5e4ff78ad1..20769ef989 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/CallLinkPeekInfo.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/CallLinkPeekInfo.kt @@ -17,6 +17,10 @@ data class CallLinkPeekInfo( val isActive: Boolean, val isJoined: Boolean ) { + + val isCompletelyInactive + get() = callId == null && !isActive && !isJoined + companion object { @JvmStatic fun fromPeekInfo(peekInfo: PeekInfo): CallLinkPeekInfo { diff --git a/core-util/src/main/java/org/signal/core/util/concurrent/RxExtensions.kt b/core-util/src/main/java/org/signal/core/util/concurrent/RxExtensions.kt index aab2f92faf..2d2ad45552 100644 --- a/core-util/src/main/java/org/signal/core/util/concurrent/RxExtensions.kt +++ b/core-util/src/main/java/org/signal/core/util/concurrent/RxExtensions.kt @@ -73,3 +73,20 @@ fun , T : Any> Single.subscribeWithSubject( return subject } + +/** + * Skips the first item emitted from the flowable, but only if it matches the provided [predicate]. + */ +fun Flowable.skipFirstIf(predicate: (T) -> Boolean): Flowable { + return this + .scan(Pair(false, null)) { acc, item -> + val firstItemInList = !acc.first + if (firstItemInList && predicate(item)) { + true to null + } else { + true to item + } + } + .filter { it.second != null } + .map { it.second!! } +}