Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid multiple ConnectUser invocations by sharing the Call #5439

Merged
merged 2 commits into from
Oct 16, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Sanitize User Agen Header to avoid issues with ilegal characters on the Http Headers. [#5440](https://github.com/GetStream/stream-chat-android/pull/5440)

### ⬆️ Improved
- Avoid multiple `ChatClient::connectUser` invocations by sharing the `Call`. [#5439](https://github.com/GetStream/stream-chat-android/pull/5439)

### ✅ Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import io.getstream.chat.android.client.api.models.QueryThreadsRequest
import io.getstream.chat.android.client.api.models.QueryUsersRequest
import io.getstream.chat.android.client.api.models.SendActionRequest
import io.getstream.chat.android.client.api.models.identifier.AddDeviceIdentifier
import io.getstream.chat.android.client.api.models.identifier.ConnectUserIdentifier
import io.getstream.chat.android.client.api.models.identifier.DeleteDeviceIdentifier
import io.getstream.chat.android.client.api.models.identifier.DeleteMessageIdentifier
import io.getstream.chat.android.client.api.models.identifier.DeleteReactionIdentifier
Expand Down Expand Up @@ -645,6 +646,7 @@ internal constructor(
userScope.userId.value = user.id
connectUserSuspend(user, tokenProvider, timeoutMilliseconds)
}
.share(clientScope) { ConnectUserIdentifier(user) }
}

private suspend fun connectUserSuspend(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import io.getstream.chat.android.models.FilterObject
import io.getstream.chat.android.models.Member
import io.getstream.chat.android.models.Message
import io.getstream.chat.android.models.Reaction
import io.getstream.chat.android.models.User
import io.getstream.chat.android.models.querysort.QuerySorter

/**
Expand Down Expand Up @@ -323,3 +324,15 @@ internal fun DeleteDeviceIdentifier(
result = 31 * result + device.hashCode()
return result
}

/**
* Identifier for a [ChatClient.connectUser] call.
*/
@Suppress("FunctionName", "MagicNumber")
internal fun ConnectUserIdentifier(
user: User,
): Int {
var result = "ConnectUser".hashCode()
result = 31 * result + user.id.hashCode()
return result
}
Loading