New chat architecture + chat relay #5635
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WIP
resolve Chat relay via High-performance backend #5633
prepare to get rid of forked ChatKit #1552 by adding a solution for developers to use Jetpack Compose for rendering of the chat messages. The goal of this PR is not to come up with a polished Compose implementation but to set the stage so that Compose can be improved over time until it finally replaces chatkit.
This PR will
Use signaling to receive chat messages instead of long polling when hpb is used
Introduce a regular insurance request if somehow a signaling messages did not make it through
Change the chat architecture from an event based message handling to a state based messages handling. This change was done in this PR because adding two more ways how messages can be received (signaling and insurance request) would have made the event based messages Handling even more complex.
Before:
messages were passed to ui directly from responses (as well to DB). This was necessary as the chatkit library required different processing depending on if messages from the past or future were received
Now:
Received messages are just written to database no matter where they come from (initial request / request for scrolling into past /long polling / signaling / insurance request).
Messages are observed on database to be shown in UI via flows.
The database is the single source of truth, so no events are needed to update the ui.
To avoid messages gaps in UI, the chat block handling is used: the flow is implemented so that always the messages from the newest chat block are emitted. For this, the database is observed for the newest chat block and whenever it changes, the messages of it are emitted.
Implement a workaround so that chatkit library can handle the messages flow instead of the former events. For this, the adapter is cleared and all messages are added again. This may come with a minor performance loss on some devices, but as a temporary solution to migrate to Jetpack Compose + flow handling, this is the best way to go.
Refactor and improve the Jetpack Compose code for messages that was used for the message search window to be able to handle flows. (for now it was only able to handle a single response with a chat message list)
Add a switch for developers to use Jetpack Compose instead of chatkit. We can continue to maintain the chatkit based solution while being able to further improve the new compose solution until it's ready to replace chatkit.
To use the compose solution for developing, just change the value of
useJetpackComposeinonCreatein the ChatActvity.Add a new solution to automatically mark messages as read.
messages were marked as read as soon as they were received.
messages are marked as read until the newest message that was shown on the screen. This is transmitted whenever the user manually scrolls or when the chat is closed/brought to background.
This change was planned for ages and it was now necessary because of the signaling handling.
improve scope handling of the flows from database
TODO
insurance request and re add them??
🏁 Checklist
/backport to stable-xx.x