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
+6 -22
View File
@@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../push/push_message_handler.dart';
import '../routing/app_routes.dart';
import '../push/push_target.dart';
import '../state/app/modules/chat/bloc/chat_bloc.dart';
import '../state/app/modules/chat_list/bloc/chat_list_bloc.dart';
import '../utils/debouncer.dart';
@@ -51,18 +51,15 @@ class NotificationController {
RemoteMessage message,
BuildContext context,
) async {
final newsletterId = _extractNewsletterId(message);
if (newsletterId != null) {
AppRoutes.openNewsletterById(
final target = resolvePushTarget(message.data);
if (target != null) {
NotificationTasks.openPushTarget(
context,
id: newsletterId,
target,
title: message.notification?.title,
);
} else {
NotificationTasks.navigateToTalk(
context,
chatToken: _extractChatToken(message),
);
NotificationTasks.navigateToTalk(context);
}
NotificationTasks.updateProviders(context);
unawaited(NotificationTasks.refreshBadge());
@@ -77,17 +74,4 @@ class NotificationController {
);
});
}
static String? _extractChatToken(RemoteMessage message) {
for (final key in const ['chatToken', 'token', 'roomToken']) {
final value = message.data[key];
if (value is String && value.isNotEmpty) return value;
}
return null;
}
static String? _extractNewsletterId(RemoteMessage message) {
final value = message.data['newsletterId'];
return value is String && value.isNotEmpty ? value : null;
}
}
+15
View File
@@ -7,6 +7,7 @@ import 'package:flutter_app_badge/flutter_app_badge.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../push/chat_thread_store.dart';
import '../push/push_target.dart';
import '../routing/app_routes.dart';
import '../state/app/modules/chat_list/bloc/chat_list_bloc.dart';
import 'notification_service.dart';
@@ -72,6 +73,20 @@ class NotificationTasks {
context.read<ChatListBloc>().refresh();
}
/// [title] is the notification title, when the tap came with one.
static void openPushTarget(
BuildContext context,
PushTarget target, {
String? title,
}) {
switch (target) {
case NewsletterTarget(:final newsletterId):
AppRoutes.openNewsletterById(context, id: newsletterId, title: title);
case ChatTarget(:final chatToken):
navigateToTalk(context, chatToken: chatToken);
}
}
/// Switches to the Talk tab. If [chatToken] is provided, also schedules
/// the matching chat to be opened automatically once the chat list view
/// resolves the token (handled inside [ChatList]).