fixed notification taps being ignored when they cold-started the app

This commit is contained in:
2026-09-27 14:38:48 +02:00
parent 2ca9feb49a
commit 1fd6264d10
7 changed files with 146 additions and 59 deletions
+32
View File
@@ -0,0 +1,32 @@
/// 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<String, dynamic> 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;
}