mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-27 14:59:29 +01:00
chore: Upgrade unifiedpush to 4.0.0
This commit is contained in:
parent
935ab6d296
commit
8b5a5b4fb8
@ -86,7 +86,6 @@ dependencies {
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test:runner:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||
implementation 'com.github.UnifiedPush:android-connector:1.2.3' // needed for unifiedpush
|
||||
implementation 'androidx.multidex:multidex:2.0.1'
|
||||
}
|
||||
|
||||
|
@ -110,13 +110,17 @@
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<receiver android:exported="true" android:enabled="true" android:name=".UnifiedPushReceiver">
|
||||
<receiver android:name="org.unifiedpush.flutter.connector.UnifiedPushReceiver"
|
||||
tools:replace="android:enabled"
|
||||
android:enabled="false">
|
||||
</receiver>
|
||||
|
||||
<receiver android:exported="false" android:enabled="true" android:name=".UnifiedPushReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="org.unifiedpush.android.connector.MESSAGE"/>
|
||||
<action android:name="org.unifiedpush.android.connector.UNREGISTERED"/>
|
||||
<action android:name="org.unifiedpush.android.connector.NEW_ENDPOINT"/>
|
||||
<action android:name="org.unifiedpush.android.connector.REGISTRATION_FAILED" />
|
||||
<action android:name="org.unifiedpush.android.connector.REGISTRATION_REFUSED" />
|
||||
<action android:name="org.unifiedpush.flutter.connector.MESSAGE"/>
|
||||
<action android:name="org.unifiedpush.flutter.connector.UNREGISTERED"/>
|
||||
<action android:name="org.unifiedpush.flutter.connector.NEW_ENDPOINT"/>
|
||||
<action android:name="org.unifiedpush.flutter.connector.REGISTRATION_FAILED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
@ -4,9 +4,6 @@ import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.WindowManager
|
||||
import androidx.multidex.MultiDex
|
||||
|
||||
class MainActivity : FlutterActivity() {
|
||||
@ -15,10 +12,6 @@ class MainActivity : FlutterActivity() {
|
||||
MultiDex.install(this)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
};
|
||||
|
||||
override fun provideFlutterEngine(context: Context): FlutterEngine? {
|
||||
return provideEngine(this)
|
||||
}
|
||||
@ -30,7 +23,7 @@ class MainActivity : FlutterActivity() {
|
||||
companion object {
|
||||
var engine: FlutterEngine? = null
|
||||
fun provideEngine(context: Context): FlutterEngine {
|
||||
var eng = engine ?: FlutterEngine(context, emptyArray(), true, false)
|
||||
val eng = engine ?: FlutterEngine(context, emptyArray(), true, false)
|
||||
engine = eng
|
||||
return eng
|
||||
}
|
||||
|
@ -1,36 +1,23 @@
|
||||
package chat.fluffy.fluffychat
|
||||
|
||||
import org.unifiedpush.flutter.connector.UnifiedPushHandler
|
||||
|
||||
import chat.fluffy.fluffychat.MainActivity
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.view.FlutterMain
|
||||
import io.flutter.embedding.engine.dart.DartExecutor.DartEntrypoint
|
||||
import org.unifiedpush.android.connector.MessagingReceiver
|
||||
import io.flutter.embedding.engine.dart.DartExecutor
|
||||
import org.unifiedpush.flutter.connector.UnifiedPushReceiver
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.WindowManager
|
||||
|
||||
val receiverHandler = object : UnifiedPushHandler() {
|
||||
class UnifiedPushReceiver : UnifiedPushReceiver() {
|
||||
override fun getEngine(context: Context): FlutterEngine {
|
||||
return provideEngine(context)
|
||||
}
|
||||
|
||||
fun provideEngine(context: Context): FlutterEngine {
|
||||
var engine = MainActivity.engine
|
||||
if (engine == null) {
|
||||
engine = MainActivity.provideEngine(context)
|
||||
engine.getLocalizationPlugin().sendLocalesToFlutter(
|
||||
context.getResources().getConfiguration())
|
||||
engine.getDartExecutor().executeDartEntrypoint(
|
||||
DartEntrypoint.createDefault())
|
||||
engine.localizationPlugin.sendLocalesToFlutter(
|
||||
context.resources.configuration
|
||||
)
|
||||
engine.dartExecutor.executeDartEntrypoint(
|
||||
DartExecutor.DartEntrypoint.createDefault()
|
||||
)
|
||||
}
|
||||
return engine
|
||||
}
|
||||
}
|
||||
|
||||
class UnifiedPushReceiver : MessagingReceiver(receiverHandler)
|
||||
|
@ -20,6 +20,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@ -29,7 +30,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:unifiedpush/unifiedpush.dart' hide Message;
|
||||
import 'package:unifiedpush/unifiedpush.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/client_stories_extension.dart';
|
||||
@ -80,10 +81,9 @@ class BackgroundPush {
|
||||
onNewToken: _newFcmToken,
|
||||
);
|
||||
if (Platform.isAndroid) {
|
||||
UnifiedPush.initializeWithReceiver(
|
||||
UnifiedPush.initialize(
|
||||
onNewEndpoint: _newUpEndpoint,
|
||||
onRegistrationFailed: _upUnregistered,
|
||||
onRegistrationRefused: _upUnregistered,
|
||||
onUnregistered: _upUnregistered,
|
||||
onMessage: _onUpMessage,
|
||||
);
|
||||
@ -329,7 +329,7 @@ class BackgroundPush {
|
||||
}
|
||||
|
||||
Future<void> setupUp() async {
|
||||
await UnifiedPush.registerAppWithDialog();
|
||||
await UnifiedPush.registerAppWithDialog(context!);
|
||||
}
|
||||
|
||||
Future<void> _onFcmMessage(Map<dynamic, dynamic> message) async {
|
||||
@ -343,10 +343,10 @@ class BackgroundPush {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _newUpEndpoint(String newEndpoint) async {
|
||||
Future<void> _newUpEndpoint(String newEndpoint, String i) async {
|
||||
upAction = true;
|
||||
if (newEndpoint.isEmpty) {
|
||||
await _upUnregistered();
|
||||
await _upUnregistered(i);
|
||||
return;
|
||||
}
|
||||
var endpoint =
|
||||
@ -387,7 +387,7 @@ class BackgroundPush {
|
||||
await store.setItemBool(SettingKeys.unifiedPushRegistered, true);
|
||||
}
|
||||
|
||||
Future<void> _upUnregistered() async {
|
||||
Future<void> _upUnregistered(String i) async {
|
||||
upAction = true;
|
||||
Logs().i('[Push] Removing UnifiedPush endpoint...');
|
||||
final oldEndpoint = await store.getItem(SettingKeys.unifiedPushEndpoint);
|
||||
@ -401,10 +401,10 @@ class BackgroundPush {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onUpMessage(String message) async {
|
||||
Future<void> _onUpMessage(Uint8List message, String i) async {
|
||||
upAction = true;
|
||||
final data =
|
||||
Map<String, dynamic>.from(json.decode(message)['notification']);
|
||||
final data = Map<String, dynamic>.from(
|
||||
json.decode(utf8.decode(message))['notification']);
|
||||
try {
|
||||
await _onMessage(data);
|
||||
} catch (e, s) {
|
||||
|
@ -79,7 +79,7 @@ dependencies:
|
||||
slugify: ^2.0.0
|
||||
swipe_to_action: ^0.2.0
|
||||
uni_links: ^0.5.1
|
||||
unifiedpush: ^3.0.1
|
||||
unifiedpush: ^4.0.0
|
||||
universal_html: ^2.0.8
|
||||
url_launcher: ^6.0.20
|
||||
video_compress: ^3.1.0
|
||||
|
Loading…
Reference in New Issue
Block a user