mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-12 02:32:54 +01:00
fix: Push on iOS
This commit is contained in:
parent
dd4b4c511a
commit
cb6217c059
52
lib/components/unread_badge_back_button.dart
Normal file
52
lib/components/unread_badge_back_button.dart
Normal 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();
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -34,7 +34,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|||||||
import 'package:flutter_gen/gen_l10n/l10n_en.dart';
|
import 'package:flutter_gen/gen_l10n/l10n_en.dart';
|
||||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'platform_infos.dart';
|
import 'platform_infos.dart';
|
||||||
import '../app_config.dart';
|
import '../app_config.dart';
|
||||||
import '../config/setting_keys.dart';
|
import '../config/setting_keys.dart';
|
||||||
@ -75,11 +75,11 @@ class BackgroundPush {
|
|||||||
onRoomSync ??= client.onSync.stream
|
onRoomSync ??= client.onSync.stream
|
||||||
.where((s) => s.hasRoomUpdate)
|
.where((s) => s.hasRoomUpdate)
|
||||||
.listen((s) => _onClearingPush(getFromServer: false));
|
.listen((s) => _onClearingPush(getFromServer: false));
|
||||||
if (Platform.isAndroid) {
|
|
||||||
_fcmSharedIsolate.setListeners(
|
_fcmSharedIsolate.setListeners(
|
||||||
onMessage: _onFcmMessage,
|
onMessage: _onFcmMessage,
|
||||||
onNewToken: _newFcmToken,
|
onNewToken: _newFcmToken,
|
||||||
);
|
);
|
||||||
|
if (Platform.isAndroid) {
|
||||||
UnifiedPush.initializeWithReceiver(
|
UnifiedPush.initializeWithReceiver(
|
||||||
onNewEndpoint: _newUpEndpoint,
|
onNewEndpoint: _newUpEndpoint,
|
||||||
onRegistrationFailed: _upUnregistered,
|
onRegistrationFailed: _upUnregistered,
|
||||||
@ -129,6 +129,14 @@ class BackgroundPush {
|
|||||||
Set<String> oldTokens,
|
Set<String> oldTokens,
|
||||||
bool useDeviceSpecificAppId = false,
|
bool useDeviceSpecificAppId = false,
|
||||||
}) async {
|
}) async {
|
||||||
|
if (PlatformInfos.isIOS) {
|
||||||
|
FirebaseMessaging()
|
||||||
|
.requestNotificationPermissions(IosNotificationSettings(
|
||||||
|
sound: true,
|
||||||
|
alert: true,
|
||||||
|
badge: true,
|
||||||
|
));
|
||||||
|
}
|
||||||
final clientName = PlatformInfos.clientName;
|
final clientName = PlatformInfos.clientName;
|
||||||
oldTokens ??= <String>{};
|
oldTokens ??= <String>{};
|
||||||
final pushers = await client.requestPushers().catchError((e) {
|
final pushers = await client.requestPushers().catchError((e) {
|
||||||
@ -261,7 +269,6 @@ class BackgroundPush {
|
|||||||
if (_fcmToken?.isEmpty ?? true) {
|
if (_fcmToken?.isEmpty ?? true) {
|
||||||
try {
|
try {
|
||||||
_fcmToken = await _fcmSharedIsolate.getToken();
|
_fcmToken = await _fcmSharedIsolate.getToken();
|
||||||
Logs().v('[Push] Got token: $_fcmToken');
|
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().e('[Push] cannot get token', e, s);
|
Logs().e('[Push] cannot get token', e, s);
|
||||||
await _noFcmWarning();
|
await _noFcmWarning();
|
||||||
@ -360,7 +367,6 @@ class BackgroundPush {
|
|||||||
final oldTokens = <String>{};
|
final oldTokens = <String>{};
|
||||||
try {
|
try {
|
||||||
final fcmToken = await _fcmSharedIsolate.getToken();
|
final fcmToken = await _fcmSharedIsolate.getToken();
|
||||||
Logs().v('[Push] New token: $fcmToken');
|
|
||||||
oldTokens.add(fcmToken);
|
oldTokens.add(fcmToken);
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
await setupPusher(
|
await setupPusher(
|
||||||
|
@ -12,6 +12,7 @@ import 'package:fluffychat/components/avatar.dart';
|
|||||||
import 'package:fluffychat/components/chat_settings_popup_menu.dart';
|
import 'package:fluffychat/components/chat_settings_popup_menu.dart';
|
||||||
import 'package:fluffychat/components/connection_status_header.dart';
|
import 'package:fluffychat/components/connection_status_header.dart';
|
||||||
import 'package:fluffychat/components/dialogs/recording_dialog.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:fluffychat/config/themes.dart';
|
||||||
import 'package:flushbar/flushbar_helper.dart';
|
import 'package:flushbar/flushbar_helper.dart';
|
||||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||||
@ -529,6 +530,7 @@ class _ChatState extends State<Chat> {
|
|||||||
if (room.membership == Membership.invite) {
|
if (room.membership == Membership.invite) {
|
||||||
showFutureLoadingDialog(context: context, future: () => room.join());
|
showFutureLoadingDialog(context: context, future: () => room.join());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
leading: selectMode
|
leading: selectMode
|
||||||
@ -537,7 +539,9 @@ class _ChatState extends State<Chat> {
|
|||||||
onPressed: () => setState(() => selectedEvents.clear()),
|
onPressed: () => setState(() => selectedEvents.clear()),
|
||||||
tooltip: L10n.of(context).close,
|
tooltip: L10n.of(context).close,
|
||||||
)
|
)
|
||||||
: null,
|
: AdaptivePageLayout.of(context).columnMode(context)
|
||||||
|
? null
|
||||||
|
: UnreadBadgeBackButton(roomId: widget.id),
|
||||||
titleSpacing:
|
titleSpacing:
|
||||||
AdaptivePageLayout.of(context).columnMode(context) ? null : 0,
|
AdaptivePageLayout.of(context).columnMode(context) ? null : 0,
|
||||||
title: selectedEvents.isEmpty
|
title: selectedEvents.isEmpty
|
||||||
|
11
pubspec.lock
11
pubspec.lock
@ -238,8 +238,8 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: HEAD
|
ref: ios
|
||||||
resolved-ref: "19f36c2ad7df214cae34c870f3888e24dac90b86"
|
resolved-ref: "86519130e5e122a20fdd31de34013d62a88f106d"
|
||||||
url: "https://gitlab.com/famedly/libraries/fcm_shared_isolate.git"
|
url: "https://gitlab.com/famedly/libraries/fcm_shared_isolate.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.1"
|
version: "0.0.1"
|
||||||
@ -299,6 +299,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.1+1"
|
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:
|
flushbar:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -24,7 +24,8 @@ dependencies:
|
|||||||
fcm_shared_isolate:
|
fcm_shared_isolate:
|
||||||
git:
|
git:
|
||||||
url: https://gitlab.com/famedly/libraries/fcm_shared_isolate.git
|
url: https://gitlab.com/famedly/libraries/fcm_shared_isolate.git
|
||||||
|
ref: ios
|
||||||
|
firebase_messaging: any
|
||||||
cupertino_icons: any
|
cupertino_icons: any
|
||||||
localstorage: ^3.0.6+9
|
localstorage: ^3.0.6+9
|
||||||
file_picker_cross: ^4.2.8
|
file_picker_cross: ^4.2.8
|
||||||
|
Loading…
Reference in New Issue
Block a user