mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-23 12:39:29 +01:00
Add firebase stuff
This commit is contained in:
parent
46f5eb5abb
commit
8d7aaa44a6
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,6 +9,7 @@
|
||||
.history
|
||||
.svn/
|
||||
lib/generated_plugin_registrant.dart
|
||||
google-services.json
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
|
@ -85,3 +85,5 @@ dependencies {
|
||||
androidTestImplementation 'androidx.test:runner:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||
}
|
||||
|
||||
apply plugin: "com.google.gms.google-services"
|
@ -21,6 +21,10 @@
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Don't delete the meta-data below.
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
|
@ -8,6 +8,7 @@ buildscript {
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath 'com.google.gms:google-services:4.3.2'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/sqflite_store.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
@ -31,6 +34,8 @@ class MatrixState extends State<Matrix> {
|
||||
Client client;
|
||||
BuildContext context;
|
||||
|
||||
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
|
||||
|
||||
/// Used to load the old account if there is no store available.
|
||||
void loadAccount() async {
|
||||
final LocalStorage storage = LocalStorage('LocalStorage');
|
||||
@ -124,10 +129,50 @@ class MatrixState extends State<Matrix> {
|
||||
|
||||
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
|
||||
void initState() {
|
||||
if (widget.client == null) {
|
||||
client = Client(widget.clientName, debug: false);
|
||||
client = Client(widget.clientName, debug: true);
|
||||
if (!kIsWeb) {
|
||||
client.store = Store(client);
|
||||
} else {
|
||||
@ -136,9 +181,16 @@ class MatrixState extends State<Matrix> {
|
||||
} else {
|
||||
client = widget.client;
|
||||
}
|
||||
onSetupFirebase ??= client.onLoginStateChanged.stream.listen(setupFirebase);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
onSetupFirebase?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _InheritedMatrix(
|
||||
|
@ -94,6 +94,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
|
@ -38,6 +38,7 @@ dependencies:
|
||||
url_launcher: ^5.4.1
|
||||
sqflite: ^1.2.0
|
||||
cached_network_image: ^2.0.0
|
||||
firebase_messaging: ^6.0.9
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Loading…
Reference in New Issue
Block a user