Skip to content

Commit 7a49bf1

Browse files
authored
Fix reaction.new clearing the OwnReactions - this field is by design empty for WS reaction.new event for performance reasons but because it's not null we apply a workaround to ignore it (#119)
1 parent f6e7ce6 commit 7a49bf1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Assets/Plugins/StreamChat/Core/StatefulModels/StreamMessage.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ internal void HandleReactionNewEvent(EventReactionNewInternalDTO eventDto, Strea
242242
AssertCid(eventDto.Cid);
243243
AssertMessageId(eventDto.Message.Id);
244244

245+
// Important! `reaction.new` has this field invalidly empty. This is for performance reasons but is left as empty for backward compatibility.
246+
// We rely on the fact that _ownReactions.TryReplaceRegularObjectsFromDto ignores null and does not clear the list when `own_reactions` is invalidly empty
247+
eventDto.Message.OwnReactions = null;
248+
245249
//StreamTodo: verify if this how we should update the message + what about events for customer to get notified
246250
Cache.TryCreateOrUpdate(eventDto.Message);
247251
ReactionAdded?.Invoke(channel, this, reaction);
@@ -252,12 +256,9 @@ internal void HandleReactionUpdatedEvent(EventReactionUpdatedInternalDTO eventDt
252256
AssertCid(eventDto.Cid);
253257
AssertMessageId(eventDto.Message.Id);
254258

255-
//Figure out what is this??? in Android SDK
256-
// // make sure we don't lose ownReactions
257-
// getMessage(message.id)?.let {
258-
// message.ownReactions = it.ownReactions
259-
// }
260-
//StreamTodo: ask android team about this code
259+
// Important! `reaction.new` has this field invalidly empty. This is for performance reasons but is left as empty for backward compatibility.
260+
// We rely on the fact that _ownReactions.TryReplaceRegularObjectsFromDto ignores null and does not clear the list when `own_reactions` is invalidly empty
261+
eventDto.Message.OwnReactions = null;
261262

262263
Cache.TryCreateOrUpdate(eventDto.Message);
263264
ReactionUpdated?.Invoke(channel, this, reaction);
@@ -267,6 +268,10 @@ internal void HandleReactionDeletedEvent(EventReactionDeletedInternalDTO eventDt
267268
{
268269
AssertCid(eventDto.Cid);
269270
AssertMessageId(eventDto.Message.Id);
271+
272+
// Important! `reaction.new` has this field invalidly empty. This is for performance reasons but is left as empty for backward compatibility.
273+
// We rely on the fact that _ownReactions.TryReplaceRegularObjectsFromDto ignores null and does not clear the list when `own_reactions` is invalidly empty
274+
eventDto.Message.OwnReactions = null;
270275

271276
Cache.TryCreateOrUpdate(eventDto.Message);
272277
ReactionRemoved?.Invoke(channel, this, reaction);

0 commit comments

Comments
 (0)