Added notify server update on app startup
This commit is contained in:
parent
82586cb764
commit
b18aa5a99e
@ -76,9 +76,9 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
||||
|
||||
// User Notifications
|
||||
if(Provider.of<SettingsProvider>(context, listen: false).val().notificationSettings.enabled) {
|
||||
FirebaseMessaging.instance.onTokenRefresh.listen((event) {
|
||||
NotifyUpdater.registerToServer();
|
||||
});
|
||||
update() => NotifyUpdater.registerToServer();
|
||||
FirebaseMessaging.instance.onTokenRefresh.listen((event) => update());
|
||||
update();
|
||||
}
|
||||
|
||||
FirebaseMessaging.onMessage.listen((message) => NotificationController.onForegroundMessageHandler(message, context));
|
||||
|
@ -1,16 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:fast_rsa/fast_rsa.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
|
||||
import '../api/mhsl/notify/register/notifyRegister.dart';
|
||||
import '../api/mhsl/notify/register/notifyRegisterParams.dart';
|
||||
import '../model/accountData.dart';
|
||||
import '../model/endpointData.dart';
|
||||
import '../storage/base/settingsProvider.dart';
|
||||
import '../widget/confirmDialog.dart';
|
||||
|
||||
@ -46,40 +39,4 @@ class NotifyUpdater {
|
||||
),
|
||||
).run();
|
||||
}
|
||||
|
||||
static Future<void> registerNcPush() async {
|
||||
log("Starting");
|
||||
log("Generate keys");
|
||||
final rsaKey = await RSA.generate(2048);
|
||||
final devicePrivateKey = rsaKey.privateKey.toString();
|
||||
final devicePublicKey = rsaKey.publicKey.toString();
|
||||
log("Private: \n$devicePrivateKey");
|
||||
log("Public: \n$devicePublicKey");
|
||||
final pushToken = await FirebaseMessaging.instance.getToken();
|
||||
log("PushToken: $pushToken}");
|
||||
final pushTokenHash = sha512.convert(utf8.encode(pushToken!));
|
||||
log("PushTokenHash: $pushTokenHash");
|
||||
|
||||
final requestMap = {
|
||||
"format": "json",
|
||||
"pushTokenHash": pushTokenHash.toString(),
|
||||
"devicePublicKey": devicePublicKey.replaceAll("\n", "").replaceAll("-----END RSA PUBLIC KEY-----", "").replaceAll("-----BEGIN RSA PUBLIC KEY-----", "").toString(),
|
||||
"proxyServer": "https://push-notifications.nextcloud.com/devices"
|
||||
};
|
||||
|
||||
log(jsonEncode(requestMap));
|
||||
http.post(
|
||||
//${AccountData().buildHttpAuthString()}@
|
||||
Uri.parse("https://${EndpointData().nextcloud().full()}/ocs/v2.php/apps/notifications/api/v2/push"),
|
||||
headers: {
|
||||
"OCS-APIRequest": "true",
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json",
|
||||
"Authorization": "Bearer Fv3g7g9jW91FXNjZLaJmyprClfy8pX1jEM3hJGbXjPEFcx4oGIEVcpwEnuT4mPs39D9xT063"
|
||||
},
|
||||
body: jsonEncode(requestMap),
|
||||
).then((response) {
|
||||
log("Response: ${response.statusCode}\n${response.body}");
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user