Merge pull request #1043 from GetStream/fix/thread-offline-reactions
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
## Upcoming
|
## Upcoming
|
||||||
|
|
||||||
|
🐞 Fixed
|
||||||
|
|
||||||
|
- Fixed reactions not working for threads in offline mode.
|
||||||
|
|
||||||
✅ Added
|
✅ Added
|
||||||
|
|
||||||
- Handle `event.message` in `channel.truncate` events
|
- Handle `event.message` in `channel.truncate` events
|
||||||
@@ -7,6 +11,7 @@
|
|||||||
## 3.5.1
|
## 3.5.1
|
||||||
|
|
||||||
🐞 Fixed
|
🐞 Fixed
|
||||||
|
|
||||||
- `channel.unreadCount` was being set as using global unread count on a very specific case.
|
- `channel.unreadCount` was being set as using global unread count on a very specific case.
|
||||||
- The reconnection logic for the WebSocket connection is now more robust.
|
- The reconnection logic for the WebSocket connection is now more robust.
|
||||||
|
|
||||||
@@ -22,7 +27,7 @@
|
|||||||
- [[#890]](https://github.com/GetStream/stream-chat-flutter/pull/890) Fixed Reactions not updating on thread messages.
|
- [[#890]](https://github.com/GetStream/stream-chat-flutter/pull/890) Fixed Reactions not updating on thread messages.
|
||||||
Thanks [bstolinski](https://github.com/bstolinski).
|
Thanks [bstolinski](https://github.com/bstolinski).
|
||||||
- [[#897]](https://github.com/GetStream/stream-chat-flutter/issues/897) Fixed error type mis-match in `AuthInterceptor`.
|
- [[#897]](https://github.com/GetStream/stream-chat-flutter/issues/897) Fixed error type mis-match in `AuthInterceptor`.
|
||||||
- [[#891]](https://github.com/GetStream/stream-chat-flutter/pull/891) Fixed reply counter for parent message not
|
- [[#891]](https://github.com/GetStream/stream-chat-flutter/pull/891) Fixed reply counter for parent message not
|
||||||
updating correctly after deleting thread message.
|
updating correctly after deleting thread message.
|
||||||
- Fix `channelState.copyWith` with respect to pinnedMessages.
|
- Fix `channelState.copyWith` with respect to pinnedMessages.
|
||||||
|
|
||||||
|
|||||||
@@ -2122,12 +2122,12 @@ class ChannelClientState {
|
|||||||
final BehaviorSubject<Map<String, List<Message>>> _threadsController =
|
final BehaviorSubject<Map<String, List<Message>>> _threadsController =
|
||||||
BehaviorSubject.seeded({});
|
BehaviorSubject.seeded({});
|
||||||
|
|
||||||
set _threads(Map<String, List<Message>> v) {
|
set _threads(Map<String, List<Message>> threads) {
|
||||||
_channel.client.chatPersistenceClient?.updateMessages(
|
_threadsController.add(threads);
|
||||||
|
_channel.client.chatPersistenceClient?.updateChannelThreads(
|
||||||
_channel.cid!,
|
_channel.cid!,
|
||||||
v.values.expand((v) => v).toList(),
|
threads,
|
||||||
);
|
);
|
||||||
_threadsController.add(v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel related typing users last value.
|
/// Channel related typing users last value.
|
||||||
|
|||||||
@@ -197,6 +197,22 @@ abstract class ChatPersistenceClient {
|
|||||||
/// Deletes all the members by channel [cids]
|
/// Deletes all the members by channel [cids]
|
||||||
Future<void> deleteMembersByCids(List<String> cids);
|
Future<void> deleteMembersByCids(List<String> cids);
|
||||||
|
|
||||||
|
/// Updates the channel [cid] threads data along with reactions and users.
|
||||||
|
Future<void> updateChannelThreads(
|
||||||
|
String cid,
|
||||||
|
Map<String, List<Message>> threads,
|
||||||
|
) async {
|
||||||
|
final messages = threads.values.expand((it) => it).toList();
|
||||||
|
final reactions = messages.expand(_expandReactions).toList();
|
||||||
|
final users = messages.map((it) => it.user).withNullifyer.toList();
|
||||||
|
|
||||||
|
await Future.wait([
|
||||||
|
updateMessages(cid, messages),
|
||||||
|
updateReactions(reactions),
|
||||||
|
updateUsers(users),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/// Update the channel state data using [channelState]
|
/// Update the channel state data using [channelState]
|
||||||
Future<void> updateChannelState(ChannelState channelState) =>
|
Future<void> updateChannelState(ChannelState channelState) =>
|
||||||
updateChannelStates([channelState]);
|
updateChannelStates([channelState]);
|
||||||
@@ -239,17 +255,8 @@ abstract class ChatPersistenceClient {
|
|||||||
channelWithMessages[cid] = messages;
|
channelWithMessages[cid] = messages;
|
||||||
channelWithPinnedMessages[cid] = pinnedMessages;
|
channelWithPinnedMessages[cid] = pinnedMessages;
|
||||||
|
|
||||||
List<Reaction> expandReactions(Message message) {
|
reactions.addAll(messages.expand(_expandReactions));
|
||||||
final own = message.ownReactions;
|
pinnedReactions.addAll(pinnedMessages.expand(_expandReactions));
|
||||||
final latest = message.latestReactions;
|
|
||||||
return [
|
|
||||||
if (own != null) ...own.where((r) => r.userId != null),
|
|
||||||
if (latest != null) ...latest.where((r) => r.userId != null),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
reactions.addAll(messages.expand(expandReactions));
|
|
||||||
pinnedReactions.addAll(pinnedMessages.expand(expandReactions));
|
|
||||||
|
|
||||||
users.addAll([
|
users.addAll([
|
||||||
channel.createdBy,
|
channel.createdBy,
|
||||||
@@ -292,4 +299,13 @@ abstract class ChatPersistenceClient {
|
|||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Reaction> _expandReactions(Message message) {
|
||||||
|
final own = message.ownReactions;
|
||||||
|
final latest = message.latestReactions;
|
||||||
|
return [
|
||||||
|
if (own != null) ...own.where((r) => r.userId != null),
|
||||||
|
if (latest != null) ...latest.where((r) => r.userId != null),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -645,8 +645,8 @@ void main() {
|
|||||||
|
|
||||||
when(() => persistence.getChannelThreads(any()))
|
when(() => persistence.getChannelThreads(any()))
|
||||||
.thenAnswer((_) async => {});
|
.thenAnswer((_) async => {});
|
||||||
when(() => persistence.updateMessages(any(), any()))
|
when(() => persistence.updateChannelThreads(any(), any()))
|
||||||
.thenAnswer((_) => Future.value());
|
.thenAnswer((_) async => {});
|
||||||
when(() => persistence.getChannelStateByCid(any(),
|
when(() => persistence.getChannelStateByCid(any(),
|
||||||
messagePagination: any(named: 'messagePagination'),
|
messagePagination: any(named: 'messagePagination'),
|
||||||
pinnedMessagePagination:
|
pinnedMessagePagination:
|
||||||
@@ -692,7 +692,7 @@ void main() {
|
|||||||
|
|
||||||
verify(() => persistence.getChannelThreads(any()))
|
verify(() => persistence.getChannelThreads(any()))
|
||||||
.called((persistentChannelStates + channelStates).length);
|
.called((persistentChannelStates + channelStates).length);
|
||||||
verify(() => persistence.updateMessages(any(), any()))
|
verify(() => persistence.updateChannelThreads(any(), any()))
|
||||||
.called((persistentChannelStates + channelStates).length);
|
.called((persistentChannelStates + channelStates).length);
|
||||||
verify(
|
verify(
|
||||||
() => persistence.getChannelStateByCid(any(),
|
() => persistence.getChannelStateByCid(any(),
|
||||||
@@ -733,8 +733,8 @@ void main() {
|
|||||||
|
|
||||||
when(() => persistence.getChannelThreads(any()))
|
when(() => persistence.getChannelThreads(any()))
|
||||||
.thenAnswer((_) async => {});
|
.thenAnswer((_) async => {});
|
||||||
when(() => persistence.updateMessages(any(), any()))
|
when(() => persistence.updateChannelThreads(any(), any()))
|
||||||
.thenAnswer((_) => Future.value());
|
.thenAnswer((_) async => {});
|
||||||
when(() => persistence.getChannelStateByCid(any(),
|
when(() => persistence.getChannelStateByCid(any(),
|
||||||
messagePagination: any(named: 'messagePagination'),
|
messagePagination: any(named: 'messagePagination'),
|
||||||
pinnedMessagePagination:
|
pinnedMessagePagination:
|
||||||
@@ -775,7 +775,7 @@ void main() {
|
|||||||
|
|
||||||
verify(() => persistence.getChannelThreads(any()))
|
verify(() => persistence.getChannelThreads(any()))
|
||||||
.called(persistentChannelStates.length);
|
.called(persistentChannelStates.length);
|
||||||
verify(() => persistence.updateMessages(any(), any()))
|
verify(() => persistence.updateChannelThreads(any(), any()))
|
||||||
.called(persistentChannelStates.length);
|
.called(persistentChannelStates.length);
|
||||||
verify(
|
verify(
|
||||||
() => persistence.getChannelStateByCid(any(),
|
() => persistence.getChannelStateByCid(any(),
|
||||||
|
|||||||
Reference in New Issue
Block a user