Skip to content

Commit 1982c59

Browse files
authored
fix: ANRs when getting identities [WPB-8753] (#2721)
1 parent a0bb7fa commit 1982c59

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationMembersUseCase.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.wire.kalium.logic.data.user.UserRepository
2525
import kotlinx.coroutines.ExperimentalCoroutinesApi
2626
import kotlinx.coroutines.flow.Flow
2727
import kotlinx.coroutines.flow.combine
28+
import kotlinx.coroutines.flow.distinctUntilChanged
2829
import kotlinx.coroutines.flow.filterNotNull
2930
import kotlinx.coroutines.flow.flatMapLatest
3031
import kotlinx.coroutines.flow.map
@@ -55,6 +56,6 @@ class ObserveConversationMembersUseCaseImpl internal constructor(
5556
}
5657
}.flatMapLatest { detailsFlows ->
5758
combine(detailsFlows) { it.toList() }
58-
}
59+
}.distinctUntilChanged()
5960
}
6061
}

logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationMembersUseCaseTest.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,37 @@ class ObserveConversationMembersUseCaseTest {
171171
awaitComplete()
172172
}
173173
}
174+
175+
176+
@Test
177+
fun givenAConversationID_whenObservingMembersAnDataDidNotChange_thenDoNotEmitTheSameValuesAgain() = runTest {
178+
val conversationID = TestConversation.ID
179+
val otherUser = TestUser.OTHER
180+
val selfUser = TestUser.SELF
181+
val membersListChannel = Channel<List<Member>>(Channel.UNLIMITED)
182+
183+
coEvery {
184+
userRepository.observeUser(eq(TestUser.SELF.id))
185+
}.returns(flowOf(selfUser))
186+
187+
coEvery {
188+
userRepository.observeUser(eq(otherUser.id))
189+
}.returns(flowOf(otherUser))
190+
191+
coEvery {
192+
conversationRepository.observeConversationMembers(eq(conversationID))
193+
}.returns(membersListChannel.consumeAsFlow())
194+
195+
observeConversationMembers(conversationID).test {
196+
197+
membersListChannel.send(listOf(Member(otherUser.id, Member.Role.Member)))
198+
assertContentEquals(listOf(MemberDetails(otherUser, Member.Role.Member)), awaitItem())
199+
200+
membersListChannel.send(listOf(Member(otherUser.id, Member.Role.Member)))
201+
expectNoEvents()
202+
203+
membersListChannel.close()
204+
awaitComplete()
205+
}
206+
}
174207
}

0 commit comments

Comments
 (0)