@@ -9,6 +9,7 @@ import 'package:lichess_mobile/src/model/common/id.dart';
99import 'package:lichess_mobile/src/model/game/playable_game.dart' ;
1010import 'package:lichess_mobile/src/model/user/user.dart' show TemporaryBan;
1111import 'package:lichess_mobile/src/utils/json.dart' ;
12+ import 'package:lichess_mobile/src/utils/l10n.dart' show relativeDate;
1213import 'package:meta/meta.dart' ;
1314
1415/// FCM Messages
@@ -226,6 +227,8 @@ sealed class LocalNotification {
226227 return ChallengeAcceptedNotification .fromJson (json);
227228 case 'challengeCreate' :
228229 return ChallengeCreatedNotification .fromJson (json);
230+ case 'announce' :
231+ return AnnounceNotification .fromJson (json);
229232 default :
230233 throw ArgumentError ('Unknown notification channel: $channel ' );
231234 }
@@ -518,6 +521,84 @@ class ChallengeCreatedNotification extends LocalNotification {
518521 );
519522}
520523
524+ /// A notification for a server-wide announcement.
525+ ///
526+ /// There can only be one announce notification at a time. It is shown when the server
527+ /// sends an announce message through the WebSocket, and cancelled when the server
528+ /// clears it or the optional countdown date is reached.
529+ class AnnounceNotification extends LocalNotification {
530+ const AnnounceNotification (this .message, {this .date});
531+
532+ final String message;
533+
534+ /// Optional date shown as a relative time in the notification body.
535+ final DateTime ? date;
536+
537+ static final int notificationId = 'announce' .hashCode;
538+
539+ static const _channelId = 'announce' ;
540+
541+ static const dismissActionId = 'dismiss' ;
542+
543+ static const darwinCategoryId = 'announce-notification' ;
544+
545+ factory AnnounceNotification .fromJson (Map <String , dynamic > json) {
546+ final dateStr = json['date' ] as String ? ;
547+ return AnnounceNotification (
548+ json['message' ] as String ,
549+ date: dateStr != null ? DateTime .parse (dateStr) : null ,
550+ );
551+ }
552+
553+ static DarwinNotificationCategory darwinCategory (AppLocalizations l10n) =>
554+ DarwinNotificationCategory (
555+ darwinCategoryId,
556+ actions: [
557+ DarwinNotificationAction .plain (dismissActionId, l10n.mobileCustomizeHomeTipDismiss),
558+ ],
559+ );
560+
561+ @override
562+ int get id => notificationId;
563+
564+ @override
565+ String get channelId => _channelId;
566+
567+ @override
568+ Map <String , dynamic > get _concretePayload => {
569+ 'message' : message,
570+ if (date != null ) 'date' : date! .toIso8601String (),
571+ };
572+
573+ @override
574+ String title (AppLocalizations _) => message;
575+
576+ @override
577+ String ? body (AppLocalizations l10n) => date != null ? relativeDate (l10n, date! ) : null ;
578+
579+ @override
580+ NotificationDetails details (AppLocalizations l10n) => NotificationDetails (
581+ android: AndroidNotificationDetails (
582+ _channelId,
583+ 'Lichess Announcements' ,
584+ importance: Importance .high,
585+ priority: Priority .high,
586+ autoCancel: false ,
587+ actions: [
588+ AndroidNotificationAction (
589+ dismissActionId,
590+ l10n.mobileCustomizeHomeTipDismiss,
591+ showsUserInterface: false ,
592+ ),
593+ ],
594+ ),
595+ iOS: const DarwinNotificationDetails (
596+ threadIdentifier: _channelId,
597+ categoryIdentifier: darwinCategoryId,
598+ ),
599+ );
600+ }
601+
521602/// A notification for a received challenge.
522603///
523604/// This notification is shown when a challenge is received from the server through
0 commit comments