Merge pull request #873 from GetStream/hotfix/ownReactions
fix(llc): fix ownReactions population
This commit is contained in:
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
- [[#871]](https://github.com/GetStream/stream-chat-flutter/issues/871) Fixed thread message deletion.
|
- [[#871]](https://github.com/GetStream/stream-chat-flutter/issues/871) Fixed thread message deletion.
|
||||||
|
|
||||||
|
- [[#846]](https://github.com/GetStream/stream-chat-flutter/issues/846) Fixed `message.ownReactions` getting truncated when receiving a reaction event.
|
||||||
|
|
||||||
## 3.3.1
|
## 3.3.1
|
||||||
|
|
||||||
🐞 Fixed
|
🐞 Fixed
|
||||||
|
|||||||
@@ -819,7 +819,7 @@ class Channel {
|
|||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
final user = _client.state.currentUser;
|
final user = _client.state.currentUser;
|
||||||
|
|
||||||
final latestReactions = [...message.latestReactions ?? <Reaction>[]];
|
var latestReactions = [...message.latestReactions ?? <Reaction>[]];
|
||||||
if (enforceUnique) {
|
if (enforceUnique) {
|
||||||
latestReactions.removeWhere((it) => it.userId == user!.id);
|
latestReactions.removeWhere((it) => it.userId == user!.id);
|
||||||
}
|
}
|
||||||
@@ -833,10 +833,17 @@ class Channel {
|
|||||||
extraData: extraData,
|
extraData: extraData,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Inserting at the 0th index as it's the latest reaction
|
latestReactions = (latestReactions
|
||||||
latestReactions.insert(0, newReaction);
|
// Inserting at the 0th index as it's the latest reaction
|
||||||
final ownReactions = [...latestReactions]
|
..insert(0, newReaction))
|
||||||
..removeWhere((it) => it.userId != user!.id);
|
.take(10)
|
||||||
|
.toList();
|
||||||
|
final ownReactions = enforceUnique
|
||||||
|
? <Reaction>[newReaction]
|
||||||
|
: <Reaction>[
|
||||||
|
...message.ownReactions ?? [],
|
||||||
|
newReaction,
|
||||||
|
];
|
||||||
|
|
||||||
final newMessage = message.copyWith(
|
final newMessage = message.copyWith(
|
||||||
reactionCounts: {...message.reactionCounts ?? <String, int>{}}
|
reactionCounts: {...message.reactionCounts ?? <String, int>{}}
|
||||||
@@ -876,7 +883,6 @@ class Channel {
|
|||||||
Reaction reaction,
|
Reaction reaction,
|
||||||
) async {
|
) async {
|
||||||
final type = reaction.type;
|
final type = reaction.type;
|
||||||
final user = _client.state.currentUser;
|
|
||||||
|
|
||||||
final reactionCounts = {...message.reactionCounts ?? <String, int>{}};
|
final reactionCounts = {...message.reactionCounts ?? <String, int>{}};
|
||||||
if (reactionCounts.containsKey(type)) {
|
if (reactionCounts.containsKey(type)) {
|
||||||
@@ -893,8 +899,11 @@ class Channel {
|
|||||||
r.type == reaction.type &&
|
r.type == reaction.type &&
|
||||||
r.messageId == reaction.messageId);
|
r.messageId == reaction.messageId);
|
||||||
|
|
||||||
final ownReactions = [...latestReactions]
|
final ownReactions = message.ownReactions
|
||||||
..removeWhere((it) => it.userId != user!.id);
|
?..removeWhere((r) =>
|
||||||
|
r.userId == reaction.userId &&
|
||||||
|
r.type == reaction.type &&
|
||||||
|
r.messageId == reaction.messageId);
|
||||||
|
|
||||||
final newMessage = message.copyWith(
|
final newMessage = message.copyWith(
|
||||||
reactionCounts: reactionCounts..removeWhere((_, value) => value == 0),
|
reactionCounts: reactionCounts..removeWhere((_, value) => value == 0),
|
||||||
@@ -1678,10 +1687,19 @@ class ChannelClientState {
|
|||||||
|
|
||||||
void _listenReactionDeleted() {
|
void _listenReactionDeleted() {
|
||||||
_subscriptions.add(_channel.on(EventType.reactionDeleted).listen((event) {
|
_subscriptions.add(_channel.on(EventType.reactionDeleted).listen((event) {
|
||||||
final userId = _channel.client.state.currentUser!.id;
|
final oldMessage =
|
||||||
|
messages.firstWhereOrNull((it) => it.id == event.message?.id);
|
||||||
|
final reaction = event.reaction;
|
||||||
|
final ownReactions = oldMessage?.ownReactions
|
||||||
|
?.whereNot((it) =>
|
||||||
|
it.type == reaction?.type &&
|
||||||
|
it.score == reaction?.score &&
|
||||||
|
it.messageId == reaction?.messageId &&
|
||||||
|
it.userId == reaction?.userId &&
|
||||||
|
it.extraData == reaction?.extraData)
|
||||||
|
.toList(growable: false);
|
||||||
final message = event.message!.copyWith(
|
final message = event.message!.copyWith(
|
||||||
ownReactions: [...event.message!.latestReactions!]
|
ownReactions: ownReactions,
|
||||||
..removeWhere((it) => it.userId != userId),
|
|
||||||
);
|
);
|
||||||
addMessage(message);
|
addMessage(message);
|
||||||
}));
|
}));
|
||||||
@@ -1689,10 +1707,10 @@ class ChannelClientState {
|
|||||||
|
|
||||||
void _listenReactions() {
|
void _listenReactions() {
|
||||||
_subscriptions.add(_channel.on(EventType.reactionNew).listen((event) {
|
_subscriptions.add(_channel.on(EventType.reactionNew).listen((event) {
|
||||||
final userId = _channel.client.state.currentUser!.id;
|
final oldMessage =
|
||||||
|
messages.firstWhereOrNull((it) => it.id == event.message?.id);
|
||||||
final message = event.message!.copyWith(
|
final message = event.message!.copyWith(
|
||||||
ownReactions: [...event.message!.latestReactions!]
|
ownReactions: oldMessage?.ownReactions,
|
||||||
..removeWhere((it) => it.userId != userId),
|
|
||||||
);
|
);
|
||||||
addMessage(message);
|
addMessage(message);
|
||||||
}));
|
}));
|
||||||
@@ -1705,10 +1723,11 @@ class ChannelClientState {
|
|||||||
EventType.reactionUpdated,
|
EventType.reactionUpdated,
|
||||||
)
|
)
|
||||||
.listen((event) {
|
.listen((event) {
|
||||||
final userId = _channel.client.state.currentUser!.id;
|
final oldMessage =
|
||||||
|
messages.firstWhereOrNull((it) => it.id == event.message?.id);
|
||||||
|
|
||||||
final message = event.message!.copyWith(
|
final message = event.message!.copyWith(
|
||||||
ownReactions: [...event.message!.latestReactions!]
|
ownReactions: oldMessage?.ownReactions,
|
||||||
..removeWhere((it) => it.userId != userId),
|
|
||||||
);
|
);
|
||||||
addMessage(message);
|
addMessage(message);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user