Merge branch 'develop' into hotfix/unreadIndicator
This commit is contained in:
+26
-1
@@ -187,8 +187,33 @@ StreamChat(
|
||||
|
||||
As you can see we generate a local notification whenever a message.new or notification.message_new event is received.
|
||||
|
||||
### Foreground notifications
|
||||
|
||||
Sometimes you may want to show a notification when the app is in the foreground.
|
||||
For example, when you're in a channel and you receive a new message from someone in another channel.
|
||||
|
||||
For this scenario, you can also use the `flutter_local_notifications` package to show a notification.
|
||||
|
||||
You need to listen for new events using `StreamChatClient.on` and handle them accordingly.
|
||||
|
||||
Here we're checking if the event is a `message.new` or `notification.message_new` event, and if the message is from a different user than the current user. In that case we'll show a notification.
|
||||
|
||||
```dart
|
||||
client.on(
|
||||
EventType.messageNew,
|
||||
EventType.notificationMessageNew,
|
||||
).listen((event) {
|
||||
if (event.message?.user?.id == client.state.currentUser?.id) {
|
||||
return;
|
||||
}
|
||||
showLocalNotification(event, client.state.currentUser!.id, context);
|
||||
});
|
||||
```
|
||||
|
||||
:::note
|
||||
Using `flutter_local_notifications` is a great way to implement notifications while the is in foreground too! You can generate a local notification listening to events using the method `streamChatClient.on()` and react to the events you want.
|
||||
You should also check that the channel of the message is different than the channel in the foreground.
|
||||
How you do this depends on your app infrastructure and how you handle navigation.
|
||||
Take a look at the [Stream Chat v1 sample app](https://github.com/GetStream/flutter-samples/blob/main/packages/stream_chat_v1/lib/home_page.dart#L11) to see how we're doing it over there.
|
||||
:::
|
||||
|
||||
### Saving notification messages to the offline storage
|
||||
@@ -3,6 +3,7 @@
|
||||
🐞 Fixed
|
||||
|
||||
- Fixed unread indicator not updating correctly
|
||||
- Fix `channel.show` not working because of null body
|
||||
|
||||
## 2.2.0
|
||||
|
||||
|
||||
@@ -292,6 +292,7 @@ class ChannelApi {
|
||||
) async {
|
||||
final response = await _client.post(
|
||||
'${_getChannelUrl(channelId, channelType)}/show',
|
||||
data: {},
|
||||
);
|
||||
return EmptyResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
@@ -550,14 +550,21 @@ void main() {
|
||||
|
||||
final path = '${_getChannelUrl(channelId, channelType)}/show';
|
||||
|
||||
when(() => client.post(path)).thenAnswer(
|
||||
(_) async => successResponse(path, data: <String, dynamic>{}));
|
||||
when(() => client.post(
|
||||
path,
|
||||
data: {},
|
||||
))
|
||||
.thenAnswer(
|
||||
(_) async => successResponse(path, data: <String, dynamic>{}));
|
||||
|
||||
final res = await channelApi.showChannel(channelId, channelType);
|
||||
|
||||
expect(res, isNotNull);
|
||||
|
||||
verify(() => client.post(path)).called(1);
|
||||
verify(() => client.post(
|
||||
path,
|
||||
data: {},
|
||||
)).called(1);
|
||||
verifyNoMoreInteractions(client);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user