Closed deerawan closed 3 years ago
hey @deerawan,
Keep in mind that the message you get from message.new
event is the exact message sent by API, however, the message we store in the channel.state
is a bit different since we add some extra attributes and convert the timestamps to actual Date objects and convert it to immutable.
We are actually in the process of removing the Immutable wrappers but in the meantime, you can fix this either by using the channel.state.messageToImmutable()
function on the event response or calling message.asMutable()
on the message from the channel sate. If you still had issues with TS, try casting the message like message.asMutable() as MessageResponse
you can see the messageToImmutable here.
Please upgrade to v3 of the SDK which no longer uses ImmutableJS.
Hi GetStream team,
Please close this if it's not appropriate place to ask.
Tech stack
Issue
I'm building a service class in Angular as a wrapper for Stream. One of the functions is to get the messages from the active channel then convert it to our message schema using
convertMessage
function as seen below.The
convertMessage
is also used to convert message when receiving a new message from websocket.chat.service.ts
The error was
The problem is the typing for
state.messages
is using Immutable which is not compatible withMessageResponse
in the new message event. The Immutable typing seems to add more complexity there. What is the reason to make them different? Is there a way to convert Immutable toMessageResponse
or vice versa?What is the best way to handle this?
Thank you very much