Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ import io.getstream.chat.android.client.api2.optimisation.hash.GetReactionsHash
import io.getstream.chat.android.client.api2.optimisation.hash.GetRepliesAroundHash
import io.getstream.chat.android.client.api2.optimisation.hash.GetRepliesHash
import io.getstream.chat.android.client.api2.optimisation.hash.QueryBanedUsersHash
import io.getstream.chat.android.client.api2.optimisation.hash.QueryGroupedChannelsHash
import io.getstream.chat.android.client.api2.optimisation.hash.QueryMembersHash
import io.getstream.chat.android.models.BannedUser
import io.getstream.chat.android.models.BannedUsersSort
import io.getstream.chat.android.models.Channel
import io.getstream.chat.android.models.FilterObject
import io.getstream.chat.android.models.GroupedChannels
import io.getstream.chat.android.models.GroupedChannelsGroupQuery
import io.getstream.chat.android.models.Member
import io.getstream.chat.android.models.Message
import io.getstream.chat.android.models.PendingMessage
Expand Down Expand Up @@ -153,6 +156,22 @@ internal class DistinctChatApi(
}
}

override fun queryGroupedChannels(
limit: Int?,
groups: Map<String, GroupedChannelsGroupQuery>?,
watch: Boolean,
presence: Boolean,
): Call<GroupedChannels> {
val uniqueKey = QueryGroupedChannelsHash(limit, groups, watch, presence).hashCode()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
StreamLog.d(TAG) {
"[queryGroupedChannels] limit: $limit, groups: $groups, watch: $watch, " +
"presence: $presence, uniqueKey: $uniqueKey"
}
return getOrCreate(uniqueKey) {
delegate.queryGroupedChannels(limit, groups, watch, presence)
}
}

override fun queryBannedUsers(
filter: FilterObject,
sort: QuerySorter<BannedUsersSort>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import io.getstream.chat.android.models.BannedUser
import io.getstream.chat.android.models.BannedUsersSort
import io.getstream.chat.android.models.Channel
import io.getstream.chat.android.models.FilterObject
import io.getstream.chat.android.models.GroupedChannels
import io.getstream.chat.android.models.GroupedChannelsGroupQuery
import io.getstream.chat.android.models.Member
import io.getstream.chat.android.models.Message
import io.getstream.chat.android.models.PendingMessage
Expand Down Expand Up @@ -86,6 +88,15 @@ internal class DistinctChatApiEnabler(
return getApi().queryChannels(query)
}

override fun queryGroupedChannels(
limit: Int?,
groups: Map<String, GroupedChannelsGroupQuery>?,
watch: Boolean,
presence: Boolean,
): Call<GroupedChannels> {
return getApi().queryGroupedChannels(limit, groups, watch, presence)
}

override fun queryBannedUsers(
filter: FilterObject,
sort: QuerySorter<BannedUsersSort>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2014-2026 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.getstream.chat.android.client.api2.optimisation.hash

import io.getstream.chat.android.models.GroupedChannelsGroupQuery

internal data class QueryGroupedChannelsHash(
val limit: Int?,
val groups: Map<String, GroupedChannelsGroupQuery>?,
val watch: Boolean,
val presence: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.getstream.chat.android.randomString
import kotlinx.coroutines.test.TestScope
import org.junit.Test
import org.mockito.kotlin.any
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
import org.mockito.kotlin.times
Expand Down Expand Up @@ -100,6 +101,7 @@ internal class DistinctChatApiEnablerTest {
members = members,
)
enabler.queryChannel(channelType, channelId, channelRequest)
enabler.queryGroupedChannels(limit, null, watch = true, presence = false)
// then
verify(distinctApi, times(1)).getRepliesMore(messageId, firstId, limit)
verify(distinctApi, times(1)).getReplies(messageId, limit)
Expand Down Expand Up @@ -136,6 +138,7 @@ internal class DistinctChatApiEnablerTest {
members = members,
)
verify(distinctApi, times(1)).queryChannel(channelType, channelId, channelRequest)
verify(distinctApi, times(1)).queryGroupedChannels(limit, null, watch = true, presence = false)
verifyNoInteractions(api)
}

Expand Down Expand Up @@ -177,6 +180,7 @@ internal class DistinctChatApiEnablerTest {
members = members,
)
enabler.queryChannel(channelType, channelId, channelRequest)
enabler.queryGroupedChannels(limit, null, watch = true, presence = false)

// then
verify(api, times(1)).getRepliesMore(messageId, firstId, limit)
Expand Down Expand Up @@ -208,6 +212,7 @@ internal class DistinctChatApiEnablerTest {
members = members,
)
verify(api, times(1)).queryChannel(channelType, channelId, channelRequest)
verify(api, times(1)).queryGroupedChannels(limit, null, watch = true, presence = false)
verify(distinctApi, times(0)).getRepliesMore(any(), any(), any())
verify(distinctApi, times(0)).getReplies(any(), any())
verify(distinctApi, times(0)).getNewerReplies(any(), any(), any())
Expand All @@ -219,5 +224,6 @@ internal class DistinctChatApiEnablerTest {
verify(distinctApi, times(0)).queryBannedUsers(any(), any(), any(), any(), any(), any(), any(), any())
verify(distinctApi, times(0)).queryMembers(any(), any(), any(), any(), any(), any(), any())
verify(distinctApi, times(0)).queryChannel(any(), any(), any())
verify(distinctApi, times(0)).queryGroupedChannels(anyOrNull(), anyOrNull(), any(), any())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,46 @@ internal class DistinctChatApiTest {
Assert.assertFalse(call1 === call2)
}

@Test
fun `When calling queryGroupedChannels with same arguments, Then same instance of Call is returned`() {
// given
val distinctChatApi = DistinctChatApi(TestScope(), mock())
// when
val call1 = distinctChatApi.queryGroupedChannels(limit = 30, groups = null, watch = true, presence = false)
val call2 = distinctChatApi.queryGroupedChannels(limit = 30, groups = null, watch = true, presence = false)
// then
// verify same instance of call is reused
Assert.assertTrue(call1 === call2)
}

@Test
fun `When calling queryGroupedChannels with same arguments and first call finishes, Then different instance of Call is returned`() =
runTest {
// given
val delegateApi = mock<ChatApi>()
whenever(delegateApi.queryGroupedChannels(any(), anyOrNull(), any(), any())).thenReturn(mock())
val distinctChatApi = DistinctChatApi(backgroundScope, delegateApi)
// when
val call1 = distinctChatApi.queryGroupedChannels(limit = 30, groups = null, watch = true, presence = false)
call1.await()
val call2 = distinctChatApi.queryGroupedChannels(limit = 30, groups = null, watch = true, presence = false)
// then
// verify different instance of call is returned
Assert.assertFalse(call1 === call2)
}

@Test
fun `When calling queryGroupedChannels with different arguments, Then different instance of Call is returned`() {
// given
val distinctChatApi = DistinctChatApi(TestScope(), mock())
// when
val call1 = distinctChatApi.queryGroupedChannels(limit = 30, groups = null, watch = true, presence = false)
val call2 = distinctChatApi.queryGroupedChannels(limit = 60, groups = null, watch = true, presence = false)
// then
// verify different instance of call is returned
Assert.assertFalse(call1 === call2)
}

@Test
fun `When calling queryBannedUsers with same arguments, Then same instance of Call is returned`() {
// given
Expand Down
Loading