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