Add firebase stuff

This commit is contained in:
Christian Pauly 2020-01-03 17:23:40 +01:00
parent 46f5eb5abb
commit 8d7aaa44a6
7 changed files with 69 additions and 1 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@
.history .history
.svn/ .svn/
lib/generated_plugin_registrant.dart lib/generated_plugin_registrant.dart
google-services.json
# IntelliJ related # IntelliJ related
*.iml *.iml

View File

@ -85,3 +85,5 @@ dependencies {
androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
} }
apply plugin: "com.google.gms.google-services"

View File

@ -21,6 +21,10 @@
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity> </activity>
<!-- Don't delete the meta-data below. <!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->

View File

@ -8,6 +8,7 @@ buildscript {
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.5.0' classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.2'
} }
} }

View File

@ -1,4 +1,7 @@
import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:io';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/sqflite_store.dart'; import 'package:fluffychat/utils/sqflite_store.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@ -31,6 +34,8 @@ class MatrixState extends State<Matrix> {
Client client; Client client;
BuildContext context; BuildContext context;
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
/// Used to load the old account if there is no store available. /// Used to load the old account if there is no store available.
void loadAccount() async { void loadAccount() async {
final LocalStorage storage = LocalStorage('LocalStorage'); final LocalStorage storage = LocalStorage('LocalStorage');
@ -124,10 +129,50 @@ class MatrixState extends State<Matrix> {
hideLoadingDialog() => Navigator.of(_loadingDialogContext)?.pop(); hideLoadingDialog() => Navigator.of(_loadingDialogContext)?.pop();
StreamSubscription onSetupFirebase;
void setupFirebase(LoginState login) {
if (login != LoginState.logged) return;
if (Platform.isIOS) iOS_Permission();
_firebaseMessaging.getToken().then((token) {
print("Der token ist: $token");
client.setPushers(
token,
"http",
"chat.fluffy.fluffychat",
"FluffyChat",
client.deviceName,
"en",
"https://janian.de:7023/",
append: false,
format: "event_id_only",
);
});
_firebaseMessaging.configure(
onResume: (Map<String, dynamic> message) async {
print('on resume $message');
},
onLaunch: (Map<String, dynamic> message) async {
print('on launch $message');
},
);
}
void iOS_Permission() {
_firebaseMessaging.requestNotificationPermissions(
IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
}
@override @override
void initState() { void initState() {
if (widget.client == null) { if (widget.client == null) {
client = Client(widget.clientName, debug: false); client = Client(widget.clientName, debug: true);
if (!kIsWeb) { if (!kIsWeb) {
client.store = Store(client); client.store = Store(client);
} else { } else {
@ -136,9 +181,16 @@ class MatrixState extends State<Matrix> {
} else { } else {
client = widget.client; client = widget.client;
} }
onSetupFirebase ??= client.onLoginStateChanged.stream.listen(setupFirebase);
super.initState(); super.initState();
} }
@override
void dispose() {
onSetupFirebase?.cancel();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return _InheritedMatrix( return _InheritedMatrix(

View File

@ -94,6 +94,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.4.3+2" version: "1.4.3+2"
firebase_messaging:
dependency: "direct main"
description:
name: firebase_messaging
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.9"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter

View File

@ -38,6 +38,7 @@ dependencies:
url_launcher: ^5.4.1 url_launcher: ^5.4.1
sqflite: ^1.2.0 sqflite: ^1.2.0
cached_network_image: ^2.0.0 cached_network_image: ^2.0.0
firebase_messaging: ^6.0.9
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: