Skip to content

Commit 20c9d85

Browse files
committed
Revert showing muted icon on DM channels with muted users
1 parent 1060ee2 commit 20c9d85

File tree

3 files changed

+3
-124
lines changed

3 files changed

+3
-124
lines changed

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
@@ -1821,7 +1821,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Ar
18211821
public fun getIcon ()I
18221822
public fun getLabel ()Ljava/lang/String;
18231823
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1824-
public fun getRequiredCapability ()Ljava/lang/String;
18251824
public fun isDestructive ()Z
18261825
}
18271826

@@ -1833,7 +1832,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Bl
18331832
public fun getIcon ()I
18341833
public fun getLabel ()Ljava/lang/String;
18351834
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1836-
public fun getRequiredCapability ()Ljava/lang/String;
18371835
public fun isDestructive ()Z
18381836
}
18391837

@@ -1843,13 +1841,11 @@ public abstract interface class io/getstream/chat/android/ui/common/state/channe
18431841
public abstract fun getIcon ()I
18441842
public abstract fun getLabel ()Ljava/lang/String;
18451843
public abstract fun getOnAction ()Lkotlin/jvm/functions/Function0;
1846-
public fun getRequiredCapability ()Ljava/lang/String;
18471844
public fun isDestructive ()Z
18481845
}
18491846

18501847
public final class io/getstream/chat/android/ui/common/state/channels/actions/ChannelAction$DefaultImpls {
18511848
public static fun getConfirmationPopup (Lio/getstream/chat/android/ui/common/state/channels/actions/ChannelAction;)Lio/getstream/chat/android/ui/common/state/channels/actions/ConfirmationPopup;
1852-
public static fun getRequiredCapability (Lio/getstream/chat/android/ui/common/state/channels/actions/ChannelAction;)Ljava/lang/String;
18531849
public static fun isDestructive (Lio/getstream/chat/android/ui/common/state/channels/actions/ChannelAction;)Z
18541850
}
18551851

@@ -1878,7 +1874,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/De
18781874
public fun getIcon ()I
18791875
public fun getLabel ()Ljava/lang/String;
18801876
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1881-
public fun getRequiredCapability ()Ljava/lang/String;
18821877
public fun isDestructive ()Z
18831878
}
18841879

@@ -1891,7 +1886,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Le
18911886
public fun getIcon ()I
18921887
public fun getLabel ()Ljava/lang/String;
18931888
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1894-
public fun getRequiredCapability ()Ljava/lang/String;
18951889
public fun isDestructive ()Z
18961890
}
18971891

@@ -1903,7 +1897,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Mu
19031897
public fun getIcon ()I
19041898
public fun getLabel ()Ljava/lang/String;
19051899
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1906-
public fun getRequiredCapability ()Ljava/lang/String;
19071900
public fun isDestructive ()Z
19081901
}
19091902

@@ -1915,7 +1908,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Mu
19151908
public fun getIcon ()I
19161909
public fun getLabel ()Ljava/lang/String;
19171910
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1918-
public fun getRequiredCapability ()Ljava/lang/String;
19191911
public fun isDestructive ()Z
19201912
}
19211913

@@ -1927,7 +1919,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Pi
19271919
public fun getIcon ()I
19281920
public fun getLabel ()Ljava/lang/String;
19291921
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1930-
public fun getRequiredCapability ()Ljava/lang/String;
19311922
public fun isDestructive ()Z
19321923
}
19331924

@@ -1939,7 +1930,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Un
19391930
public fun getIcon ()I
19401931
public fun getLabel ()Ljava/lang/String;
19411932
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1942-
public fun getRequiredCapability ()Ljava/lang/String;
19431933
public fun isDestructive ()Z
19441934
}
19451935

@@ -1951,7 +1941,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Un
19511941
public fun getIcon ()I
19521942
public fun getLabel ()Ljava/lang/String;
19531943
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1954-
public fun getRequiredCapability ()Ljava/lang/String;
19551944
public fun isDestructive ()Z
19561945
}
19571946

@@ -1963,7 +1952,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Un
19631952
public fun getIcon ()I
19641953
public fun getLabel ()Ljava/lang/String;
19651954
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1966-
public fun getRequiredCapability ()Ljava/lang/String;
19671955
public fun isDestructive ()Z
19681956
}
19691957

@@ -1975,7 +1963,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Un
19751963
public fun getIcon ()I
19761964
public fun getLabel ()Ljava/lang/String;
19771965
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1978-
public fun getRequiredCapability ()Ljava/lang/String;
19791966
public fun isDestructive ()Z
19801967
}
19811968

@@ -1987,7 +1974,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Un
19871974
public fun getIcon ()I
19881975
public fun getLabel ()Ljava/lang/String;
19891976
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
1990-
public fun getRequiredCapability ()Ljava/lang/String;
19911977
public fun isDestructive ()Z
19921978
}
19931979

@@ -1999,7 +1985,6 @@ public final class io/getstream/chat/android/ui/common/state/channels/actions/Vi
19991985
public fun getIcon ()I
20001986
public fun getLabel ()Ljava/lang/String;
20011987
public fun getOnAction ()Lkotlin/jvm/functions/Function0;
2002-
public fun getRequiredCapability ()Ljava/lang/String;
20031988
public fun isDestructive ()Z
20041989
}
20051990

0 commit comments

Comments
 (0)