diff --git a/lib/config/app_config.dart b/lib/config/app_config.dart index 4cf3c8248..42f2405b2 100644 --- a/lib/config/app_config.dart +++ b/lib/config/app_config.dart @@ -84,6 +84,9 @@ abstract class AppConfig { path: '/en/privacy', ); + static const String mainIsolatePortName = 'main_isolate'; + static const String pushIsolatePortName = 'push_isolate'; + // #Pangea static String assetsBaseURL = "https://pangea-chat-client-assets.s3.us-east-1.amazonaws.com"; diff --git a/lib/main.dart b/lib/main.dart index ee15ef78d..ca021cafb 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,12 +12,14 @@ import 'package:matrix/matrix.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/pangea/common/config/environment.dart'; import 'package:fluffychat/pangea/common/utils/error_handler.dart'; import 'package:fluffychat/pangea/common/utils/firebase_analytics.dart'; import 'package:fluffychat/pangea/languages/locale_provider.dart'; import 'package:fluffychat/pangea/languages/p_language_store.dart'; import 'package:fluffychat/utils/client_manager.dart'; +import 'package:fluffychat/utils/notification_background_handler.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'config/setting_keys.dart'; import 'utils/background_push.dart'; @@ -54,10 +56,12 @@ void main() async { if (PlatformInfos.isAndroid) { final port = mainIsolateReceivePort = ReceivePort(); + IsolateNameServer.removePortNameMapping(AppConfig.mainIsolatePortName); IsolateNameServer.registerPortWithName( port.sendPort, - 'main_isolate', + AppConfig.mainIsolatePortName, ); + await waitForPushIsolateDone(); } // Our background push shared isolate accesses flutter-internal things very early in the startup proccess diff --git a/lib/pages/chat/events/message.dart b/lib/pages/chat/events/message.dart index 1259d2e29..1f42723e1 100644 --- a/lib/pages/chat/events/message.dart +++ b/lib/pages/chat/events/message.dart @@ -703,10 +703,12 @@ class Message extends StatelessWidget { CrossAxisAlignment .start, children: [ - if (RelationshipTypes - .reply == - event - .relationshipType) + if (event + .inReplyToEventId( + includingFallback: + false, + ) != + null) FutureBuilder< Event?>( future: event diff --git a/lib/pages/homeserver_picker/homeserver_picker.dart b/lib/pages/homeserver_picker/homeserver_picker.dart index 2d3130201..4b88bd7f3 100644 --- a/lib/pages/homeserver_picker/homeserver_picker.dart +++ b/lib/pages/homeserver_picker/homeserver_picker.dart @@ -81,7 +81,7 @@ class HomeserverPickerController extends State { homeserver = Uri.https(homeserverInput, ''); } final client = await Matrix.of(context).getLoginClient(); - final (_, _, loginFlows) = await client.checkHomeserver(homeserver); + final (_, _, loginFlows, _) = await client.checkHomeserver(homeserver); this.loginFlows = loginFlows; if (supportsSso && !legacyPasswordLogin) { if (!PlatformInfos.isMobile) { diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index 31fd338ba..5a41978af 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -35,6 +35,7 @@ import 'package:unifiedpush/unifiedpush.dart'; import 'package:unifiedpush_ui/unifiedpush_ui.dart'; import 'package:fluffychat/l10n/l10n.dart'; +import 'package:fluffychat/main.dart'; import 'package:fluffychat/pangea/common/utils/error_handler.dart'; import 'package:fluffychat/pangea/languages/language_constants.dart'; import 'package:fluffychat/utils/notification_background_handler.dart'; @@ -85,6 +86,20 @@ class BackgroundPush { FirebaseMessaging.instance.getInitialMessage().then(_onOpenNotification); FirebaseMessaging.onMessageOpenedApp.listen(_onOpenNotification); // Pangea# + mainIsolateReceivePort?.listen( + (message) async { + try { + await notificationTap( + NotificationResponseJson.fromJsonString(message), + client: client, + router: FluffyChatApp.router, + l10n: l10n, + ); + } catch (e, s) { + Logs().wtf('Main Notification Tap crashed', e, s); + } + }, + ); if (PlatformInfos.isAndroid) { final port = ReceivePort(); IsolateNameServer.removePortNameMapping('background_tab_port'); diff --git a/lib/utils/notification_background_handler.dart b/lib/utils/notification_background_handler.dart index 32113502a..1a694615a 100644 --- a/lib/utils/notification_background_handler.dart +++ b/lib/utils/notification_background_handler.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:isolate'; import 'dart:ui'; import 'package:collection/collection.dart'; @@ -42,17 +43,34 @@ extension NotificationResponseJson on NotificationResponse { } } +Future waitForPushIsolateDone() async { + if (IsolateNameServer.lookupPortByName(AppConfig.pushIsolatePortName) != + null) { + Logs().i('Wait for Push Isolate to be done...'); + await Future.delayed(const Duration(milliseconds: 300)); + } +} + @pragma('vm:entry-point') void notificationTapBackground( NotificationResponse notificationResponse, ) async { - Logs().i('Notification tap in background'); - - final sendPort = IsolateNameServer.lookupPortByName('main_isolate'); + final sendPort = + IsolateNameServer.lookupPortByName(AppConfig.mainIsolatePortName); if (sendPort != null) { sendPort.send(notificationResponse.toJsonString()); + Logs().i('Notification tap sent to main isolate!'); return; } + Logs().i( + 'Main isolate no up - Create temporary client for notification tap intend!', + ); + + final pushIsolateReceivePort = ReceivePort(); + IsolateNameServer.registerPortWithName( + pushIsolateReceivePort.sendPort, + AppConfig.pushIsolatePortName, + ); if (!_vodInitialized) { await vod.init(); @@ -77,6 +95,8 @@ void notificationTapBackground( await notificationTap(notificationResponse, client: client); } finally { await client.dispose(closeDatabase: false); + pushIsolateReceivePort.sendPort.send('DONE'); + IsolateNameServer.removePortNameMapping(AppConfig.pushIsolatePortName); } return; } diff --git a/pubspec.lock b/pubspec.lock index 83abf96f7..642bc03e3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1204,10 +1204,10 @@ packages: dependency: "direct main" description: name: image_picker - sha256: "736eb56a911cf24d1859315ad09ddec0b66104bc41a7f8c5b96b4e2620cf5041" + sha256: "784210112be18ea55f69d7076e2c656a4e24949fa9e76429fe53af0c0f4fa320" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" image_picker_android: dependency: transitive description: @@ -2693,10 +2693,10 @@ packages: dependency: "direct main" description: name: video_player - sha256: "0d55b1f1a31e5ad4c4967bfaa8ade0240b07d20ee4af1dfef5f531056512961a" + sha256: "096bc28ce10d131be80dfb00c223024eb0fba301315a406728ab43dd99c45bdf" url: "https://pub.dev" source: hosted - version: "2.10.0" + version: "2.10.1" video_player_android: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 35d2131bf..5efea722b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -55,7 +55,7 @@ dependencies: html: ^0.15.4 http: ^1.6.0 image: ^4.1.7 - image_picker: ^1.2.0 + image_picker: ^1.2.1 intl: any just_audio: ^0.10.5 latlong2: ^0.9.1 @@ -95,7 +95,7 @@ dependencies: universal_html: ^2.2.4 url_launcher: ^6.3.2 video_compress: ^3.1.4 - video_player: ^2.9.5 + video_player: ^2.10.1 wakelock_plus: ^1.3.3 webrtc_interface: ^1.3.0 # #Pangea