fix: No push setup

This commit is contained in:
Christian Pauly 2021-05-28 20:32:52 +02:00
parent 6d8c4d470a
commit e300048d3b
4 changed files with 23 additions and 10 deletions

View File

@ -1,4 +1,9 @@
## v0.31.2 - 2021-05-28
### Fixes
* Setting up push was broken
## v0.31.0 - 2021-05-26 ## v0.31.0 - 2021-05-26
### Chore ### Chore

View File

@ -54,6 +54,7 @@ class BackgroundPush {
GlobalKey<VRouterState> router; GlobalKey<VRouterState> router;
String _fcmToken; String _fcmToken;
LoginState _loginState; LoginState _loginState;
void Function(String errorMsg) onFcmError;
L10n l10n; L10n l10n;
Store _store; Store _store;
Store get store => _store ??= Store(); Store get store => _store ??= Store();
@ -68,7 +69,7 @@ class BackgroundPush {
DateTime lastReceivedPush; DateTime lastReceivedPush;
BackgroundPush._(this.client) { BackgroundPush._(this.client, {this.onFcmError}) {
onLogin ??= onLogin ??=
client.onLoginStateChanged.stream.listen(handleLoginStateChanged); client.onLoginStateChanged.stream.listen(handleLoginStateChanged);
onRoomSync ??= client.onSync.stream onRoomSync ??= client.onSync.stream
@ -95,10 +96,12 @@ class BackgroundPush {
} }
factory BackgroundPush(FluffyClient _client, BuildContext _context, factory BackgroundPush(FluffyClient _client, BuildContext _context,
GlobalKey<VRouterState> router) { GlobalKey<VRouterState> router,
{final void Function(String errorMsg) onFcmError}) {
final instance = BackgroundPush.clientOnly(_client); final instance = BackgroundPush.clientOnly(_client);
instance.context = _context; instance.context = _context;
instance.router = router; instance.router = router;
instance.onFcmError = onFcmError;
instance.fullInit(); instance.fullInit();
return instance; return instance;
} }
@ -249,12 +252,10 @@ class BackgroundPush {
} }
if (await store.getItemBool(SettingKeys.showNoGoogle, true)) { if (await store.getItemBool(SettingKeys.showNoGoogle, true)) {
await loadLocale(); await loadLocale();
ScaffoldMessenger.of(context).showSnackBar(SnackBar( onFcmError?.call(PlatformInfos.isAndroid
content: Text( ? l10n.noGoogleServicesWarning
PlatformInfos.isAndroid : l10n.oopsPushError);
? l10n.noGoogleServicesWarning
: l10n.oopsPushError,
)));
if (null == await store.getItem(SettingKeys.showNoGoogle)) { if (null == await store.getItem(SettingKeys.showNoGoogle)) {
await store.setItemBool(SettingKeys.showNoGoogle, false); await store.setItemBool(SettingKeys.showNoGoogle, false);
} }
@ -262,6 +263,7 @@ class BackgroundPush {
} }
Future<void> setupFirebase() async { Future<void> setupFirebase() async {
Logs().v('Setup firebase');
if (_fcmToken?.isEmpty ?? true) { if (_fcmToken?.isEmpty ?? true) {
try { try {
_fcmToken = await _fcmSharedIsolate.getToken(); _fcmToken = await _fcmSharedIsolate.getToken();

View File

@ -354,7 +354,13 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
} }
if (PlatformInfos.isMobile) { if (PlatformInfos.isMobile) {
_backgroundPush = BackgroundPush(client, navigatorContext, widget.router); _backgroundPush = BackgroundPush(
client,
context,
widget.router,
onFcmError: (errorMsg) => ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(errorMsg))),
);
} }
} }

View File

@ -1,7 +1,7 @@
name: fluffychat name: fluffychat
description: Chat with your friends. description: Chat with your friends.
publish_to: none publish_to: none
version: 0.31.1+0 version: 0.31.2+0
environment: environment:
sdk: ">=2.6.0 <3.0.0" sdk: ">=2.6.0 <3.0.0"