mirror of
https://github.com/lichess-org/mobile.git
synced 2026-05-26 13:50:52 +00:00
Only display the challenge received notifications from the socket if the
app is in the foregroud because fcm already shows the notification when the app is in the background. Before this fix, when the app is in the background, it might show the notification from the socket (when the socket is still alive in the background) which is later overriden by the notification from fcm resulting in a confusing experience for the user.
This commit is contained in:
@@ -94,14 +94,18 @@ class ChallengeService {
|
||||
);
|
||||
|
||||
// new incoming challenges
|
||||
await Future.wait(
|
||||
_current?.inward.whereNot((challenge) => prevInwardIds.contains(challenge.id)).map((
|
||||
challenge,
|
||||
) async {
|
||||
return await notificationService.show(ChallengeNotification(challenge));
|
||||
}) ??
|
||||
<Future<int>>[],
|
||||
);
|
||||
// only display the notifications if the app is in the foregroud because fcm already
|
||||
// shows notifications when the app is in the background
|
||||
if (WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed) {
|
||||
await Future.wait(
|
||||
_current?.inward.whereNot((challenge) => prevInwardIds.contains(challenge.id)).map((
|
||||
challenge,
|
||||
) async {
|
||||
return await notificationService.show(ChallengeNotification(challenge));
|
||||
}) ??
|
||||
<Future<int>>[],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Stop listening to challenge events from the server.
|
||||
|
||||
@@ -464,8 +464,8 @@ class ChallengeAcceptedNotification extends LocalNotification {
|
||||
|
||||
/// A notification for a challenge creation.
|
||||
///
|
||||
/// This notification is shown when a challenge is created on the server while the user is not connected to lichess (e.g., app is in background).
|
||||
/// If the user is connected, challenges are handled by Websocket and a [ChallengeNotification] is shown instead.
|
||||
/// This notification is shown when a challenge is created on the server while the app is in background.
|
||||
/// If the app is in foreground, challenges are handled by Websocket and a [ChallengeNotification] is shown instead.
|
||||
class ChallengeCreatedNotification extends LocalNotification {
|
||||
const ChallengeCreatedNotification(this.challengeId, String title, String body)
|
||||
: _title = title,
|
||||
|
||||
@@ -134,6 +134,10 @@ void main() {
|
||||
),
|
||||
).thenAnswer((_) => Future.value());
|
||||
|
||||
// notifications from socket are only displayed if app is in foreground
|
||||
final binding = TestWidgetsFlutterBinding.ensureInitialized();
|
||||
binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
|
||||
final container = await makeContainer(
|
||||
authUser: fakeAuthUser,
|
||||
overrides: {
|
||||
@@ -223,6 +227,10 @@ void main() {
|
||||
() => notificationDisplayMock.cancel(id: any(named: 'id')),
|
||||
).thenAnswer((_) => Future.value());
|
||||
|
||||
// notifications from socket are only displayed if app is in foreground
|
||||
final binding = TestWidgetsFlutterBinding.ensureInitialized();
|
||||
binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
|
||||
final container = await makeContainer(
|
||||
authUser: fakeAuthUser,
|
||||
overrides: {
|
||||
|
||||
Reference in New Issue
Block a user