fix: Push on iOS

This commit is contained in:
Christian Pauly 2021-03-28 09:20:34 +02:00
parent dd4b4c511a
commit cb6217c059
5 changed files with 81 additions and 11 deletions

View File

@ -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();
}),
],
);
}
}

View File

@ -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<String> oldTokens,
bool useDeviceSpecificAppId = false,
}) async {
if (PlatformInfos.isIOS) {
FirebaseMessaging()
.requestNotificationPermissions(IosNotificationSettings(
sound: true,
alert: true,
badge: true,
));
}
final clientName = PlatformInfos.clientName;
oldTokens ??= <String>{};
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 = <String>{};
try {
final fcmToken = await _fcmSharedIsolate.getToken();
Logs().v('[Push] New token: $fcmToken');
oldTokens.add(fcmToken);
} catch (_) {}
await setupPusher(

View File

@ -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<Chat> {
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<Chat> {
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

View File

@ -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:

View File

@ -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