diff --git a/lib/components/unread_badge_back_button.dart b/lib/components/unread_badge_back_button.dart new file mode 100644 index 00000000..00ac903c --- /dev/null +++ b/lib/components/unread_badge_back_button.dart @@ -0,0 +1,52 @@ +import 'package:famedlysdk/famedlysdk.dart'; +import 'package:flutter/material.dart'; + +import '../app_config.dart'; +import 'matrix.dart'; + +class UnreadBadgeBackButton extends StatelessWidget { + final String roomId; + + const UnreadBadgeBackButton({ + Key key, + @required this.roomId, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Stack( + children: [ + Center(child: BackButton()), + StreamBuilder( + stream: Matrix.of(context).client.onSync.stream, + builder: (context, _) { + final unreadCount = Matrix.of(context) + .client + .rooms + .where((r) => + r.id != roomId && + (r.isUnread || r.membership == Membership.invite)) + .length; + return unreadCount > 0 + ? Align( + alignment: Alignment.bottomRight, + child: Container( + padding: EdgeInsets.all(4), + margin: EdgeInsets.only(bottom: 4, right: 8), + decoration: BoxDecoration( + color: Colors.red, + borderRadius: + BorderRadius.circular(AppConfig.borderRadius), + ), + child: Text( + '$unreadCount', + style: TextStyle(fontSize: 12), + ), + ), + ) + : Container(); + }), + ], + ); + } +} diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index ff090bd4..809ea9e2 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -34,7 +34,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n_en.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:path_provider/path_provider.dart'; - +import 'package:firebase_messaging/firebase_messaging.dart'; import 'platform_infos.dart'; import '../app_config.dart'; import '../config/setting_keys.dart'; @@ -75,11 +75,11 @@ class BackgroundPush { onRoomSync ??= client.onSync.stream .where((s) => s.hasRoomUpdate) .listen((s) => _onClearingPush(getFromServer: false)); + _fcmSharedIsolate.setListeners( + onMessage: _onFcmMessage, + onNewToken: _newFcmToken, + ); if (Platform.isAndroid) { - _fcmSharedIsolate.setListeners( - onMessage: _onFcmMessage, - onNewToken: _newFcmToken, - ); UnifiedPush.initializeWithReceiver( onNewEndpoint: _newUpEndpoint, onRegistrationFailed: _upUnregistered, @@ -129,6 +129,14 @@ class BackgroundPush { Set oldTokens, bool useDeviceSpecificAppId = false, }) async { + if (PlatformInfos.isIOS) { + FirebaseMessaging() + .requestNotificationPermissions(IosNotificationSettings( + sound: true, + alert: true, + badge: true, + )); + } final clientName = PlatformInfos.clientName; oldTokens ??= {}; final pushers = await client.requestPushers().catchError((e) { @@ -261,7 +269,6 @@ class BackgroundPush { if (_fcmToken?.isEmpty ?? true) { try { _fcmToken = await _fcmSharedIsolate.getToken(); - Logs().v('[Push] Got token: $_fcmToken'); } catch (e, s) { Logs().e('[Push] cannot get token', e, s); await _noFcmWarning(); @@ -360,7 +367,6 @@ class BackgroundPush { final oldTokens = {}; try { final fcmToken = await _fcmSharedIsolate.getToken(); - Logs().v('[Push] New token: $fcmToken'); oldTokens.add(fcmToken); } catch (_) {} await setupPusher( diff --git a/lib/views/chat.dart b/lib/views/chat.dart index 34db74c9..30e3ae0a 100644 --- a/lib/views/chat.dart +++ b/lib/views/chat.dart @@ -12,6 +12,7 @@ import 'package:fluffychat/components/avatar.dart'; import 'package:fluffychat/components/chat_settings_popup_menu.dart'; import 'package:fluffychat/components/connection_status_header.dart'; import 'package:fluffychat/components/dialogs/recording_dialog.dart'; +import 'package:fluffychat/components/unread_badge_back_button.dart'; import 'package:fluffychat/config/themes.dart'; import 'package:flushbar/flushbar_helper.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart'; @@ -529,6 +530,7 @@ class _ChatState extends State { if (room.membership == Membership.invite) { showFutureLoadingDialog(context: context, future: () => room.join()); } + return Scaffold( appBar: AppBar( leading: selectMode @@ -537,7 +539,9 @@ class _ChatState extends State { onPressed: () => setState(() => selectedEvents.clear()), tooltip: L10n.of(context).close, ) - : null, + : AdaptivePageLayout.of(context).columnMode(context) + ? null + : UnreadBadgeBackButton(roomId: widget.id), titleSpacing: AdaptivePageLayout.of(context).columnMode(context) ? null : 0, title: selectedEvents.isEmpty diff --git a/pubspec.lock b/pubspec.lock index dccd7994..313e2568 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -238,8 +238,8 @@ packages: dependency: "direct main" description: path: "." - ref: HEAD - resolved-ref: "19f36c2ad7df214cae34c870f3888e24dac90b86" + ref: ios + resolved-ref: "86519130e5e122a20fdd31de34013d62a88f106d" url: "https://gitlab.com/famedly/libraries/fcm_shared_isolate.git" source: git version: "0.0.1" @@ -299,6 +299,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.2.1+1" + firebase_messaging: + dependency: "direct main" + description: + name: firebase_messaging + url: "https://pub.dartlang.org" + source: hosted + version: "7.0.3" flushbar: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 9da4c044..0da01e4d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,7 +24,8 @@ dependencies: fcm_shared_isolate: git: url: https://gitlab.com/famedly/libraries/fcm_shared_isolate.git - + ref: ios + firebase_messaging: any cupertino_icons: any localstorage: ^3.0.6+9 file_picker_cross: ^4.2.8