@@ -45,12 +45,14 @@ import io.getstream.chat.android.models.DraftMessage
4545import io.getstream.chat.android.models.FilterObject
4646import io.getstream.chat.android.models.Filters
4747import io.getstream.chat.android.models.Message
48+ import io.getstream.chat.android.models.Mute
4849import io.getstream.chat.android.models.TypingEvent
4950import io.getstream.chat.android.models.User
5051import io.getstream.chat.android.models.querysort.QuerySortByField
5152import io.getstream.chat.android.models.querysort.QuerySorter
5253import io.getstream.chat.android.ui.common.state.channels.actions.ChannelAction
5354import io.getstream.chat.android.ui.common.utils.extensions.defaultChannelListFilter
55+ import io.getstream.chat.android.ui.common.utils.extensions.isOneToOne
5456import io.getstream.log.taggedLogger
5557import io.getstream.result.call.toUnitCall
5658import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -200,7 +202,7 @@ public class ChannelListViewModel(
200202 .flatMapLatest { it.channelMutes }
201203 .stateIn(viewModelScope, SharingStarted .Eagerly , emptyList())
202204
203- private val globalMuted: StateFlow <List <io.getstream.chat.android.models. Mute >> = globalState
205+ private val globalMuted: StateFlow <List <Mute >> = globalState
204206 .flatMapLatest { it.muted }
205207 .stateIn(viewModelScope, SharingStarted .Eagerly , emptyList())
206208
@@ -432,7 +434,8 @@ public class ChannelListViewModel(
432434 channelMutes,
433435 typingChannels,
434436 channelDraftMessages,
435- ) { state, channelMutes, typingChannels, channelDraftMessages ->
437+ globalMuted,
438+ ) { state, channelMutes, typingChannels, channelDraftMessages, userMutes ->
436439 when (state) {
437440 ChannelsStateData .NoQueryActive ,
438441 ChannelsStateData .Loading ,
@@ -457,6 +460,8 @@ public class ChannelListViewModel(
457460 channelItems = createChannelItems(
458461 channels = state.channels,
459462 channelMutes = channelMutes,
463+ userMutes = userMutes,
464+ currentUser = user.value,
460465 typingEvents = typingChannels,
461466 draftMessages = channelDraftMessages.takeIf { isDraftMessageEnabled } ? : emptyMap(),
462467 ),
@@ -800,25 +805,41 @@ public class ChannelListViewModel(
800805 *
801806 * @param channels The channels to show.
802807 * @param channelMutes The list of channels muted for the current user.
803- *
808+ * @param userMutes The list of users muted by the current user.
809+ * @param currentUser The currently logged in user.
804810 */
811+ @Suppress(" LongParameterList" )
805812 private fun createChannelItems (
806813 channels : List <Channel >,
807814 channelMutes : List <ChannelMute >,
815+ userMutes : List <Mute >,
816+ currentUser : User ? ,
808817 typingEvents : Map <String , TypingEvent >,
809818 draftMessages : Map <String , DraftMessage >,
810819 ): List <ItemState .ChannelItemState > {
811820 val mutedChannelIds = channelMutes.map { channelMute -> channelMute.channel?.cid }.toSet()
821+ val mutedUserIds = userMutes.mapNotNullTo(mutableSetOf ()) { it.target?.id }
812822 return channels.map {
813823 ItemState .ChannelItemState (
814824 channel = it,
815- isMuted = it.cid in mutedChannelIds,
825+ isMuted = it.cid in mutedChannelIds || it.isOneToOneMutedByUser(currentUser, mutedUserIds) ,
816826 typingUsers = typingEvents[it.cid]?.users ? : emptyList(),
817827 draftMessage = draftMessages[it.cid],
818828 )
819829 }
820830 }
821831
832+ /* *
833+ * Checks if a 1:1 channel is muted via user mute (i.e. the other member is muted).
834+ */
835+ private fun Channel.isOneToOneMutedByUser (currentUser : User ? , mutedUserIds : Set <String >) =
836+ if (mutedUserIds.isEmpty() || currentUser == null || ! isOneToOne(currentUser)) {
837+ false
838+ } else {
839+ val otherUser = members.find { it.user.id != currentUser.id }?.user
840+ otherUser != null && otherUser.id in mutedUserIds
841+ }
842+
822843 internal companion object {
823844 /* *
824845 * Default value of number of channels to return when querying channels.
0 commit comments