added guardian letters with chat and multiple answer functionalities
This commit is contained in:
@@ -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 '../widget/debug/debug_tile.dart';
|
||||
import '../widget/debug/json_viewer.dart';
|
||||
@@ -42,18 +42,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());
|
||||
@@ -68,17 +65,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,13 @@ 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_renderer.dart';
|
||||
import '../push/push_target.dart';
|
||||
import '../routing/app_routes.dart';
|
||||
import '../session/session_manager.dart';
|
||||
import '../state/app/modules/app_modules.dart';
|
||||
import '../state/app/modules/chat_list/bloc/chat_list_bloc.dart';
|
||||
import '../state/app/modules/parent_letters/bloc/parent_letters_bloc.dart';
|
||||
import 'notification_service.dart';
|
||||
|
||||
class NotificationTasks {
|
||||
@@ -72,6 +75,41 @@ class NotificationTasks {
|
||||
/// even if the user has already left.
|
||||
static void updateProviders(BuildContext context) {
|
||||
context.read<ChatListBloc>().refresh();
|
||||
context.read<ParentLettersBloc>().refresh(silent: true);
|
||||
}
|
||||
|
||||
/// [title] is the notification title, when the tap came with one.
|
||||
static void openPushTarget(
|
||||
BuildContext context,
|
||||
PushTarget target, {
|
||||
String? title,
|
||||
}) {
|
||||
switch (target) {
|
||||
case ParentLetterTarget(:final letterId):
|
||||
if (AppModule.isAvailableFor(
|
||||
Modules.parentLetters,
|
||||
SessionManager().current,
|
||||
)) {
|
||||
AppRoutes.openParentLetter(context, id: letterId);
|
||||
}
|
||||
case NewsletterTarget(:final newsletterId):
|
||||
AppRoutes.openNewsletterById(context, id: newsletterId, title: title);
|
||||
case ChatTarget(:final chatToken):
|
||||
navigateToTalk(context, chatToken: chatToken);
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes the letter's tray notification (Android; iOS alerts are posted by
|
||||
/// the system and cannot be addressed by id).
|
||||
static Future<void> clearParentLetterNotification(String letterId) async {
|
||||
try {
|
||||
await NotificationService().flutterLocalNotificationsPlugin.cancel(
|
||||
id: PushRenderer.parentLetterNotificationId(letterId),
|
||||
);
|
||||
await refreshBadge();
|
||||
} on Object catch (e) {
|
||||
log('Parent letter notification cleanup failed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Switches to the Talk tab. If [chatToken] is provided, also schedules
|
||||
|
||||
Reference in New Issue
Block a user