/// Where a tapped notification leads. sealed class PushTarget { const PushTarget(); } class NewsletterTarget extends PushTarget { final String newsletterId; const NewsletterTarget(this.newsletterId); } class ChatTarget extends PushTarget { final String chatToken; const ChatTarget(this.chatToken); } /// Resolves the data of a tapped notification — the payload of a locally /// rendered one as well as the data of an FCM message. Null when it names no /// known target. PushTarget? resolvePushTarget(Map data) { String? value(String key) { final value = data[key]; return value is String && value.isNotEmpty ? value : null; } if (value('newsletterId') case final newsletterId?) { return NewsletterTarget(newsletterId); } for (final key in const ['chatToken', 'token', 'roomToken']) { if (value(key) case final chatToken?) return ChatTarget(chatToken); } return null; }