Skip to content

Commit b265dea

Browse files
committed
Refactor: Convert ChannelInfoMemberViewController.state to use stateIn
This commit refactors the `state` property in `ChannelInfoMemberViewController` to utilize the `stateIn` operator. This simplifies the state management by directly transforming the upstream flow into a `StateFlow`. The `onChannelInfoData` function is removed as its logic is now incorporated into the `map` operation within the `stateIn` flow.
1 parent 57d3d31 commit b265dea

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/channel/info/ChannelInfoMemberViewController.kt

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,30 @@ public class ChannelInfoMemberViewController(
7777
*/
7878
@OptIn(ExperimentalCoroutinesApi::class)
7979
public val state: StateFlow<ChannelInfoMemberViewState> =
80-
channelState
81-
.flatMapLatest { channel ->
82-
combine(
83-
channel.channelData,
84-
channel.members
85-
.mapNotNull { members -> members.firstOrNull { it.getUserId() == memberId } }
86-
.onEach { logger.d { "[onMember] name: ${it.user.name}" } },
87-
queryDistinctChannel(),
88-
::ChannelInfoMemberData,
89-
)
90-
}
91-
.map { (channelData, member, distinctChannel) ->
92-
this.member = member
93-
this.distinctCid = distinctChannel?.cid
94-
ChannelInfoMemberViewState.Content(
80+
channelState.flatMapLatest { channel ->
81+
combine(
82+
channel.channelData,
83+
channel.members
84+
.mapNotNull { members -> members.firstOrNull { it.getUserId() == memberId } }
85+
.onEach { logger.d { "[onMember] name: ${it.user.name}" } },
86+
queryDistinctChannel(),
87+
::ChannelInfoMemberData,
88+
)
89+
}.map { (channelData, member, distinctChannel) ->
90+
this.member = member
91+
this.distinctCid = distinctChannel?.cid
92+
ChannelInfoMemberViewState.Content(
93+
member = member,
94+
options = buildOptionList(
9595
member = member,
96-
options = buildOptionList(
97-
member = member,
98-
capabilities = channelData.ownCapabilities,
99-
),
100-
)
101-
}
102-
.stateIn(
103-
scope = scope,
104-
started = WhileSubscribed(STOP_TIMEOUT_IN_MILLIS),
105-
initialValue = ChannelInfoMemberViewState.Loading,
96+
capabilities = channelData.ownCapabilities,
97+
),
10698
)
99+
}.stateIn(
100+
scope = scope,
101+
started = WhileSubscribed(STOP_TIMEOUT_IN_MILLIS),
102+
initialValue = ChannelInfoMemberViewState.Loading,
103+
)
107104

108105
private val _events = MutableSharedFlow<ChannelInfoMemberViewEvent>(extraBufferCapacity = 1)
109106

0 commit comments

Comments
 (0)