-
Notifications
You must be signed in to change notification settings - Fork 212
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
Add support for transforming Messages and Channels #3564
base: develop
Are you sure you want to change the base?
Conversation
SDK Size
|
6066703
to
206c580
Compare
Generated by 🚫 Danger |
try $0.asModel( | ||
transformer: self.client.config.modelsTransformer | ||
) as ChatChannel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When thinking ahead to cleaning up deletedMessagesVisibility
and others then that would require to have an access to ChatConfig
within asModel()
. Therefore, should we just pass in the config here and read the transformer within the asModel
implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'm not sure how that will look like, but we can improve it once we work on that 👍 But I don't think we need to pass the whole config to the asModel though 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, can be changed later if needed. When I briefly checked it then ChannelDTO.asModel
requires multiple values from the config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, in that case I will probably change this yet 👍
StateLayer needs also this. |
@laevandus I've add it to the state layer already 🤔 |
c7b09f2
to
c2307b6
Compare
Co-authored-by: Toomas Vahter <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, I like this approach more! Few more finishing touches (docs, tests) and we're good to 🚢
class CustomStreamModelsTransformer: StreamModelsTransformer { | ||
func transform(channel: ChatChannel) -> ChatChannel { | ||
channel.replacing( | ||
name: "Hey!", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: maybe just uppercase all the letter of the channel name? Would feel weird otherwise to see only "Hey!" everywhere.
Same for messages, some small transformation of the original text would be nice.
@@ -228,6 +228,46 @@ public struct ChatChannel { | |||
self.muteDetails = muteDetails | |||
self.previewMessage = previewMessage | |||
} | |||
|
|||
public func replacing( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to document this one (and the one below)
🔗 Issue Links
TODO
🎯 Goal
Add support for transforming Messages and Channels. This will allow changing some of the data of these models at run time.
The most common use case for this feature is to easily allow E2EE encryption of Channels and Messages.
📝 Summary
A new
StreamModelsTransformer
protocol is added and can be implemented by customers. Currently, only Channels and Messages are transformable, with limited data that can be changed.Example usage:
With the
replacing
function, if customers want to only change the data of a specific controller, they can do it like so:🛠 Implementation
The way it works is that we pass the transformer to our DTO -> Mapping, and right before creating the models, we pass it to the transformer so that a new Message/Channel can be returned.
For now, the models from events are not mapped since they are not rendered in the UI. We can add them in the future if needed.
🧪 Manual Testing Notes
N/A
☑️ Contributor Checklist
docs-content
repo