Skip to content

Commit 9128303

Browse files
committed
Revert showing muted icon on DM channels with muted users
1 parent 994d6c3 commit 9128303

3 files changed

Lines changed: 3 additions & 124 deletions

File tree

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/viewmodel/channels/ChannelListViewModel.kt

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import io.getstream.chat.android.models.querysort.QuerySortByField
5252
import io.getstream.chat.android.models.querysort.QuerySorter
5353
import io.getstream.chat.android.ui.common.state.channels.actions.ChannelAction
5454
import io.getstream.chat.android.ui.common.utils.extensions.defaultChannelListFilter
55-
import io.getstream.chat.android.ui.common.utils.extensions.isOneToOne
5655
import io.getstream.log.taggedLogger
5756
import io.getstream.result.call.toUnitCall
5857
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -434,8 +433,7 @@ public class ChannelListViewModel(
434433
channelMutes,
435434
typingChannels,
436435
channelDraftMessages,
437-
globalMuted,
438-
) { state, channelMutes, typingChannels, channelDraftMessages, userMutes ->
436+
) { state, channelMutes, typingChannels, channelDraftMessages ->
439437
when (state) {
440438
ChannelsStateData.NoQueryActive,
441439
ChannelsStateData.Loading,
@@ -460,8 +458,6 @@ public class ChannelListViewModel(
460458
channelItems = createChannelItems(
461459
channels = state.channels,
462460
channelMutes = channelMutes,
463-
userMutes = userMutes,
464-
currentUser = user.value,
465461
typingEvents = typingChannels,
466462
draftMessages = channelDraftMessages.takeIf { isDraftMessageEnabled } ?: emptyMap(),
467463
),
@@ -805,41 +801,25 @@ public class ChannelListViewModel(
805801
*
806802
* @param channels The channels to show.
807803
* @param channelMutes The list of channels muted for the current user.
808-
* @param userMutes The list of users muted by the current user.
809-
* @param currentUser The currently logged in user.
804+
*
810805
*/
811-
@Suppress("LongParameterList")
812806
private fun createChannelItems(
813807
channels: List<Channel>,
814808
channelMutes: List<ChannelMute>,
815-
userMutes: List<Mute>,
816-
currentUser: User?,
817809
typingEvents: Map<String, TypingEvent>,
818810
draftMessages: Map<String, DraftMessage>,
819811
): List<ItemState.ChannelItemState> {
820812
val mutedChannelIds = channelMutes.map { channelMute -> channelMute.channel?.cid }.toSet()
821-
val mutedUserIds = userMutes.mapNotNullTo(mutableSetOf()) { it.target?.id }
822813
return channels.map {
823814
ItemState.ChannelItemState(
824815
channel = it,
825-
isMuted = it.cid in mutedChannelIds || it.isOneToOneMutedByUser(currentUser, mutedUserIds),
816+
isMuted = it.cid in mutedChannelIds,
826817
typingUsers = typingEvents[it.cid]?.users ?: emptyList(),
827818
draftMessage = draftMessages[it.cid],
828819
)
829820
}
830821
}
831822

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-
843823
internal companion object {
844824
/**
845825
* Default value of number of channels to return when querying channels.

stream-chat-android-compose/src/test/kotlin/io/getstream/chat/android/compose/viewmodel/channels/ChannelListViewModelTest.kt

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ import io.getstream.chat.android.models.ChannelMute
3636
import io.getstream.chat.android.models.FilterObject
3737
import io.getstream.chat.android.models.Filters
3838
import io.getstream.chat.android.models.InitializationState
39-
import io.getstream.chat.android.models.Member
4039
import io.getstream.chat.android.models.Message
41-
import io.getstream.chat.android.models.Mute
4240
import io.getstream.chat.android.models.OrFilterObject
4341
import io.getstream.chat.android.models.SearchMessagesResult
4442
import io.getstream.chat.android.models.TypingEvent
@@ -193,68 +191,6 @@ internal class ChannelListViewModelTest {
193191
verify(chatClient).unmuteChannel("messaging", "channel1")
194192
}
195193

196-
@Test
197-
fun `Given a DM with a muted user Should mark the channel as muted`() = runTest {
198-
val viewModel = Fixture()
199-
.givenCurrentUser(currentUser)
200-
.givenChannelsQuery()
201-
.givenChannelsState(
202-
channelsStateData = ChannelsStateData.Result(listOf(directChannel)),
203-
loading = false,
204-
)
205-
.givenChannelMutes()
206-
.givenUserMutes(listOf(otherUserMute))
207-
.givenTypingChannels()
208-
.get(this)
209-
210-
val channelItem = viewModel.channelsState.channelItems.first() as ItemState.ChannelItemState
211-
assertTrue(channelItem.isMuted)
212-
}
213-
214-
@Test
215-
fun `Given a DM without a muted user Should not mark the channel as muted`() = runTest {
216-
val viewModel = Fixture()
217-
.givenCurrentUser(currentUser)
218-
.givenChannelsQuery()
219-
.givenChannelsState(
220-
channelsStateData = ChannelsStateData.Result(listOf(directChannel)),
221-
loading = false,
222-
)
223-
.givenChannelMutes()
224-
.givenTypingChannels()
225-
.get(this)
226-
227-
val channelItem = viewModel.channelsState.channelItems.first() as ItemState.ChannelItemState
228-
assertFalse(channelItem.isMuted)
229-
}
230-
231-
@Test
232-
fun `Given a group channel with a muted user Should not mark the channel as muted`() = runTest {
233-
val groupChannel = Channel(
234-
type = "messaging",
235-
id = "groupChannel",
236-
members = listOf(
237-
Member(user = currentUser),
238-
Member(user = otherUser),
239-
Member(user = User(id = "thirdUser")),
240-
),
241-
)
242-
val viewModel = Fixture()
243-
.givenCurrentUser(currentUser)
244-
.givenChannelsQuery()
245-
.givenChannelsState(
246-
channelsStateData = ChannelsStateData.Result(listOf(groupChannel)),
247-
loading = false,
248-
)
249-
.givenChannelMutes()
250-
.givenUserMutes(listOf(otherUserMute))
251-
.givenTypingChannels()
252-
.get(this)
253-
254-
val channelItem = viewModel.channelsState.channelItems.first() as ItemState.ChannelItemState
255-
assertFalse(channelItem.isMuted)
256-
}
257-
258194
@Test
259195
fun `Given channel list in content state When selecting a channel and dismissing the menu Should hide the menu`() =
260196
runTest {
@@ -633,10 +569,6 @@ internal class ChannelListViewModelTest {
633569
whenever(globalState.channelMutes) doReturn MutableStateFlow(channelMutes)
634570
}
635571

636-
fun givenUserMutes(userMutes: List<Mute> = emptyList()) = apply {
637-
whenever(globalState.muted) doReturn MutableStateFlow(userMutes)
638-
}
639-
640572
fun givenTypingChannels(typingChannels: Map<String, TypingEvent> = emptyMap()) = apply {
641573
whenever(globalState.typingChannels) doReturn MutableStateFlow(typingChannels)
642574
}
@@ -717,9 +649,6 @@ internal class ChannelListViewModelTest {
717649
)
718650
private val querySort = QuerySortByField.descByName<Channel>("lastUpdated")
719651

720-
private val currentUser = User(id = "currentUser")
721-
private val otherUser = User(id = "otherUser")
722-
723652
private val channel1: Channel = Channel(
724653
type = "messaging",
725654
id = "channel1",
@@ -728,20 +657,5 @@ internal class ChannelListViewModelTest {
728657
type = "messaging",
729658
id = "channel2",
730659
)
731-
private val directChannel = Channel(
732-
type = "messaging",
733-
id = "!members-currentUser-otherUser",
734-
members = listOf(
735-
Member(user = currentUser),
736-
Member(user = otherUser),
737-
),
738-
)
739-
private val otherUserMute = Mute(
740-
user = currentUser,
741-
target = otherUser,
742-
createdAt = Date(),
743-
updatedAt = Date(),
744-
expires = null,
745-
)
746660
}
747661
}

stream-chat-android-ui-common/api/stream-chat-android-ui-common.api

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Ar
18931893
public fun getIcon ()I
18941894
public fun getLabel ()Ljava/lang/String;
18951895
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1896-
public fun getRequiredCapability ()Ljava/lang/String;
18971896
public fun isDestructive ()Z
18981897
}
18991898

@@ -1905,7 +1904,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Bl
19051904
public fun getIcon ()I
19061905
public fun getLabel ()Ljava/lang/String;
19071906
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1908-
public fun getRequiredCapability ()Ljava/lang/String;
19091907
public fun isDestructive ()Z
19101908
}
19111909

@@ -1915,13 +1913,11 @@ public abstract interface class io/getstream/chat/android/ui/common/state/channe
19151913
public abstract fun getIcon ()I
19161914
public abstract fun getLabel ()Ljava/lang/String;
19171915
public abstract fun getOnAction ()Lkotlin/jvm/functions/Function0;
1918-
public fun getRequiredCapability ()Ljava/lang/String;
19191916
public fun isDestructive ()Z
19201917
}
19211918

19221919
public final class io/getstream/chat/android/ui/common/state/channels/actions/ChannelAction$DefaultImpls {
19231920
public static fun getConfirmationPopup (Lio/getstream/chat/android/ui/common/state/channels/actions/ChannelAction;)Lio/getstream/chat/android/ui/common/state/channels/actions/ConfirmationPopup;
1924-
public static fun getRequiredCapability (Lio/getstream/chat/android/ui/common/state/channels/actions/ChannelAction;)Ljava/lang/String;
19251921
public static fun isDestructive (Lio/getstream/chat/android/ui/common/state/channels/actions/ChannelAction;)Z
19261922
}
19271923

@@ -1950,7 +1946,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/De
19501946
public fun getIcon ()I
19511947
public fun getLabel ()Ljava/lang/String;
19521948
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1953-
public fun getRequiredCapability ()Ljava/lang/String;
19541949
public fun isDestructive ()Z
19551950
}
19561951

@@ -1963,7 +1958,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Le
19631958
public fun getIcon ()I
19641959
public fun getLabel ()Ljava/lang/String;
19651960
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1966-
public fun getRequiredCapability ()Ljava/lang/String;
19671961
public fun isDestructive ()Z
19681962
}
19691963

@@ -1975,7 +1969,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Mu
19751969
public fun getIcon ()I
19761970
public fun getLabel ()Ljava/lang/String;
19771971
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1978-
public fun getRequiredCapability ()Ljava/lang/String;
19791972
public fun isDestructive ()Z
19801973
}
19811974

@@ -1987,7 +1980,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Mu
19871980
public fun getIcon ()I
19881981
public fun getLabel ()Ljava/lang/String;
19891982
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1990-
public fun getRequiredCapability ()Ljava/lang/String;
19911983
public fun isDestructive ()Z
19921984
}
19931985

@@ -1999,7 +1991,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Pi
19991991
public fun getIcon ()I
20001992
public fun getLabel ()Ljava/lang/String;
20011993
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
2002-
public fun getRequiredCapability ()Ljava/lang/String;
20031994
public fun isDestructive ()Z
20041995
}
20051996

@@ -2011,7 +2002,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Un
20112002
public fun getIcon ()I
20122003
public fun getLabel ()Ljava/lang/String;
20132004
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
2014-
public fun getRequiredCapability ()Ljava/lang/String;
20152005
public fun isDestructive ()Z
20162006
}
20172007

@@ -2023,7 +2013,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Un
20232013
public fun getIcon ()I
20242014
public fun getLabel ()Ljava/lang/String;
20252015
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
2026-
public fun getRequiredCapability ()Ljava/lang/String;
20272016
public fun isDestructive ()Z
20282017
}
20292018

@@ -2035,7 +2024,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Un
20352024
public fun getIcon ()I
20362025
public fun getLabel ()Ljava/lang/String;
20372026
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
2038-
public fun getRequiredCapability ()Ljava/lang/String;
20392027
public fun isDestructive ()Z
20402028
}
20412029

@@ -2047,7 +2035,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Un
20472035
public fun getIcon ()I
20482036
public fun getLabel ()Ljava/lang/String;
20492037
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
2050-
public fun getRequiredCapability ()Ljava/lang/String;
20512038
public fun isDestructive ()Z
20522039
}
20532040

@@ -2059,7 +2046,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Un
20592046
public fun getIcon ()I
20602047
public fun getLabel ()Ljava/lang/String;
20612048
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
2062-
public fun getRequiredCapability ()Ljava/lang/String;
20632049
public fun isDestructive ()Z
20642050
}
20652051

@@ -2071,7 +2057,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Vi
20712057
public fun getIcon ()I
20722058
public fun getLabel ()Ljava/lang/String;
20732059
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
2074-
public fun getRequiredCapability ()Ljava/lang/String;
20752060
public fun isDestructive ()Z
20762061
}
20772062

0 commit comments

Comments
 (0)