-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AND-170] Intercept Members and add them to ChannelState (#5517)
* Intercept Members and add them to ChannelState * Add Tests * Update CHANGELOG.md
- Loading branch information
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ava/io/getstream/chat/android/state/plugin/listener/internal/QueryMembersListenerState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2014-2024 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.state.plugin.listener.internal | ||
|
||
import io.getstream.chat.android.client.plugin.listeners.QueryMembersListener | ||
import io.getstream.chat.android.models.FilterObject | ||
import io.getstream.chat.android.models.Member | ||
import io.getstream.chat.android.models.querysort.QuerySorter | ||
import io.getstream.chat.android.state.plugin.logic.internal.LogicRegistry | ||
import io.getstream.result.Result | ||
|
||
internal class QueryMembersListenerState(private val logic: LogicRegistry) : QueryMembersListener { | ||
override suspend fun onQueryMembersResult( | ||
result: Result<List<Member>>, | ||
channelType: String, | ||
channelId: String, | ||
offset: Int, | ||
limit: Int, | ||
filter: FilterObject, | ||
sort: QuerySorter<Member>, | ||
members: List<Member>, | ||
) { | ||
result.onSuccess { logic.channelState(channelType, channelId).upsertMembers(it) } | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...io/getstream/chat/android/state/plugin/listener/internal/QueryMembersListenerStateTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) 2014-2024 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.state.plugin.listener.internal | ||
|
||
import io.getstream.chat.android.randomInt | ||
import io.getstream.chat.android.randomMembers | ||
import io.getstream.chat.android.randomString | ||
import io.getstream.chat.android.state.plugin.logic.channel.internal.ChannelStateLogic | ||
import io.getstream.chat.android.state.plugin.logic.internal.LogicRegistry | ||
import io.getstream.result.Result | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Test | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.doReturn | ||
import org.mockito.kotlin.eq | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.never | ||
import org.mockito.kotlin.verify | ||
|
||
internal class QueryMembersListenerStateTest { | ||
private val channelType = randomString() | ||
private val channelId = randomString() | ||
private val channelStateLogic: ChannelStateLogic = mock() | ||
private val logicRegistry: LogicRegistry = mock { | ||
on( | ||
it.channelState( | ||
channelType = eq(channelType), | ||
channelId = eq(channelId), | ||
), | ||
) doReturn channelStateLogic | ||
} | ||
private val queryMembersListenerState = QueryMembersListenerState(logicRegistry) | ||
|
||
@Test | ||
fun `when querying members, should call channelStateLogic upsertMembers`() = runTest { | ||
val members = randomMembers() | ||
|
||
queryMembersListenerState.onQueryMembersResult( | ||
result = Result.Success(members), | ||
channelType = channelType, | ||
channelId = channelId, | ||
offset = randomInt(), | ||
limit = randomInt(), | ||
filter = mock(), | ||
sort = mock(), | ||
members = randomMembers(), | ||
) | ||
|
||
verify(channelStateLogic).upsertMembers(members) | ||
} | ||
|
||
@Test | ||
fun `when querying members fails, should not call channelStateLogic upsertMembers`() = runTest { | ||
queryMembersListenerState.onQueryMembersResult( | ||
result = Result.Failure(mock()), | ||
channelType = channelType, | ||
channelId = channelId, | ||
offset = randomInt(), | ||
limit = randomInt(), | ||
filter = mock(), | ||
sort = mock(), | ||
members = randomMembers(), | ||
) | ||
|
||
verify(channelStateLogic, never()).upsertMembers(any()) | ||
} | ||
} |