Skip to content

Commit

Permalink
fix: ANRs when getting identities [WPB-8753] (#2721)
Browse files Browse the repository at this point in the history
  • Loading branch information
saleniuk authored Apr 26, 2024
1 parent a0bb7fa commit 1982c59
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.wire.kalium.logic.data.user.UserRepository
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
Expand Down Expand Up @@ -55,6 +56,6 @@ class ObserveConversationMembersUseCaseImpl internal constructor(
}
}.flatMapLatest { detailsFlows ->
combine(detailsFlows) { it.toList() }
}
}.distinctUntilChanged()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,37 @@ class ObserveConversationMembersUseCaseTest {
awaitComplete()
}
}


@Test
fun givenAConversationID_whenObservingMembersAnDataDidNotChange_thenDoNotEmitTheSameValuesAgain() = runTest {
val conversationID = TestConversation.ID
val otherUser = TestUser.OTHER
val selfUser = TestUser.SELF
val membersListChannel = Channel<List<Member>>(Channel.UNLIMITED)

coEvery {
userRepository.observeUser(eq(TestUser.SELF.id))
}.returns(flowOf(selfUser))

coEvery {
userRepository.observeUser(eq(otherUser.id))
}.returns(flowOf(otherUser))

coEvery {
conversationRepository.observeConversationMembers(eq(conversationID))
}.returns(membersListChannel.consumeAsFlow())

observeConversationMembers(conversationID).test {

membersListChannel.send(listOf(Member(otherUser.id, Member.Role.Member)))
assertContentEquals(listOf(MemberDetails(otherUser, Member.Role.Member)), awaitItem())

membersListChannel.send(listOf(Member(otherUser.id, Member.Role.Member)))
expectNoEvents()

membersListChannel.close()
awaitComplete()
}
}
}

0 comments on commit 1982c59

Please sign in to comment.