mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-20 16:10:44 +01:00
feat: add encrypted push
This commit is contained in:
parent
81164316b5
commit
ff19deb7fd
@ -131,84 +131,34 @@ class BackgroundPush {
|
|||||||
await _fcmSharedIsolate?.requestPermission();
|
await _fcmSharedIsolate?.requestPermission();
|
||||||
}
|
}
|
||||||
final clientName = PlatformInfos.clientName;
|
final clientName = PlatformInfos.clientName;
|
||||||
oldTokens ??= <String>{};
|
|
||||||
final pushers = await client.getPushers().catchError((e) {
|
|
||||||
Logs().w('[Push] Unable to request pushers', e);
|
|
||||||
return <Pusher>[];
|
|
||||||
});
|
|
||||||
var setNewPusher = false;
|
|
||||||
// Just the plain app id, we add the .data_message suffix later
|
// Just the plain app id, we add the .data_message suffix later
|
||||||
var appId = AppConfig.pushNotificationsAppId;
|
var appId = AppConfig.pushNotificationsAppId;
|
||||||
// we need the deviceAppId to remove potential legacy UP pusher
|
// we need the deviceAppId to remove potential legacy UP pusher
|
||||||
var deviceAppId = '$appId.${client.deviceID}';
|
var deviceAppId = '$appId.${client.deviceID}';
|
||||||
// appId may only be up to 64 chars as per spec
|
// appId may only be up to 64 chars as per spec
|
||||||
if (deviceAppId.length > 64) {
|
final maxLength = 64 - '.data_message'.length;
|
||||||
deviceAppId = deviceAppId.substring(0, 64);
|
if (deviceAppId.length > maxLength) {
|
||||||
|
deviceAppId = deviceAppId.substring(0, maxLength);
|
||||||
}
|
}
|
||||||
if (!useDeviceSpecificAppId && PlatformInfos.isAndroid) {
|
if (!useDeviceSpecificAppId && PlatformInfos.isAndroid) {
|
||||||
appId += '.data_message';
|
appId += '.data_message';
|
||||||
}
|
}
|
||||||
final thisAppId = useDeviceSpecificAppId ? deviceAppId : appId;
|
final thisAppId = useDeviceSpecificAppId ? deviceAppId : appId;
|
||||||
if (gatewayUrl != null && token != null && clientName != null) {
|
await client.setupPusher(
|
||||||
final currentPushers = pushers.where((pusher) => pusher.pushkey == token);
|
oldTokens: oldTokens,
|
||||||
if (currentPushers.length == 1 &&
|
pusher: Pusher(
|
||||||
currentPushers.first.kind == 'http' &&
|
pushkey: token,
|
||||||
currentPushers.first.appId == thisAppId &&
|
appId: thisAppId,
|
||||||
currentPushers.first.appDisplayName == clientName &&
|
appDisplayName: clientName,
|
||||||
currentPushers.first.deviceDisplayName == client.deviceName &&
|
deviceDisplayName: client.deviceName,
|
||||||
currentPushers.first.lang == 'en' &&
|
lang: 'en',
|
||||||
currentPushers.first.data.url.toString() == gatewayUrl &&
|
data: PusherData(
|
||||||
currentPushers.first.data.format ==
|
url: Uri.parse(gatewayUrl),
|
||||||
AppConfig.pushNotificationsPusherFormat) {
|
format: AppConfig.pushNotificationsPusherFormat,
|
||||||
Logs().i('[Push] Pusher already set');
|
),
|
||||||
} else {
|
kind: 'http',
|
||||||
Logs().i('Need to set new pusher');
|
),
|
||||||
oldTokens.add(token);
|
);
|
||||||
if (client.isLogged()) {
|
|
||||||
setNewPusher = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Logs().w('[Push] Missing required push credentials');
|
|
||||||
}
|
|
||||||
for (final pusher in pushers) {
|
|
||||||
if ((token != null &&
|
|
||||||
pusher.pushkey != token &&
|
|
||||||
deviceAppId == pusher.appId) ||
|
|
||||||
oldTokens.contains(pusher.pushkey)) {
|
|
||||||
pusher.kind = null;
|
|
||||||
try {
|
|
||||||
await client.postPusher(
|
|
||||||
pusher,
|
|
||||||
append: true,
|
|
||||||
);
|
|
||||||
Logs().i('[Push] Removed legacy pusher for this device');
|
|
||||||
} catch (err) {
|
|
||||||
Logs().w('[Push] Failed to remove old pusher', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (setNewPusher) {
|
|
||||||
try {
|
|
||||||
await client.postPusher(
|
|
||||||
Pusher(
|
|
||||||
pushkey: token,
|
|
||||||
appId: thisAppId,
|
|
||||||
appDisplayName: clientName,
|
|
||||||
deviceDisplayName: client.deviceName,
|
|
||||||
lang: 'en',
|
|
||||||
data: PusherData(
|
|
||||||
url: Uri.parse(gatewayUrl),
|
|
||||||
format: AppConfig.pushNotificationsPusherFormat,
|
|
||||||
),
|
|
||||||
kind: 'http',
|
|
||||||
),
|
|
||||||
append: false,
|
|
||||||
);
|
|
||||||
} catch (e, s) {
|
|
||||||
Logs().e('[Push] Unable to set pushers', e, s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _wentToRoomOnStartup = false;
|
bool _wentToRoomOnStartup = false;
|
||||||
@ -325,7 +275,7 @@ class BackgroundPush {
|
|||||||
Logs().v('[Push] Foreground message received');
|
Logs().v('[Push] Foreground message received');
|
||||||
Map<String, dynamic> data;
|
Map<String, dynamic> data;
|
||||||
try {
|
try {
|
||||||
data = Map<String, dynamic>.from(message['data'] ?? message);
|
data = await client.processPushPayload(Map<String, dynamic>.from(message));
|
||||||
await _onMessage(data);
|
await _onMessage(data);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().e('[Push] Error while processing notification', e, s);
|
Logs().e('[Push] Error while processing notification', e, s);
|
||||||
@ -392,7 +342,7 @@ class BackgroundPush {
|
|||||||
Future<void> _onUpMessage(String message) async {
|
Future<void> _onUpMessage(String message) async {
|
||||||
Map<String, dynamic> data;
|
Map<String, dynamic> data;
|
||||||
try {
|
try {
|
||||||
data = Map<String, dynamic>.from(json.decode(message)['notification']);
|
data = await client.processPushPayload(json.decode(message));
|
||||||
await _onMessage(data);
|
await _onMessage(data);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().e('[Push] Error while processing notification', e, s);
|
Logs().e('[Push] Error while processing notification', e, s);
|
||||||
|
16
pubspec.lock
16
pubspec.lock
@ -815,17 +815,17 @@ packages:
|
|||||||
matrix:
|
matrix:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: matrix
|
path: "/home/sorunome/repos/famedly/famedlysdk"
|
||||||
url: "https://pub.dartlang.org"
|
relative: false
|
||||||
source: hosted
|
source: path
|
||||||
version: "0.7.0"
|
version: "0.6.2"
|
||||||
matrix_api_lite:
|
matrix_api_lite:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: matrix_api_lite
|
path: "/home/sorunome/repos/famedly/frontend/libraries/matrix_api_lite"
|
||||||
url: "https://pub.dartlang.org"
|
relative: false
|
||||||
source: hosted
|
source: path
|
||||||
version: "0.5.3"
|
version: "0.4.4"
|
||||||
matrix_link_text:
|
matrix_link_text:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -48,7 +48,9 @@ dependencies:
|
|||||||
intl: any
|
intl: any
|
||||||
localstorage: ^4.0.0+1
|
localstorage: ^4.0.0+1
|
||||||
lottie: ^1.2.1
|
lottie: ^1.2.1
|
||||||
matrix: ^0.7.0
|
#matrix: ^0.7.0
|
||||||
|
matrix:
|
||||||
|
path: /home/sorunome/repos/famedly/famedlysdk
|
||||||
matrix_link_text: ^1.0.2
|
matrix_link_text: ^1.0.2
|
||||||
open_noti_settings: ^0.3.0
|
open_noti_settings: ^0.3.0
|
||||||
package_info_plus: ^1.2.1
|
package_info_plus: ^1.2.1
|
||||||
@ -113,4 +115,4 @@ dependency_overrides:
|
|||||||
hosted:
|
hosted:
|
||||||
name: geolocator_android
|
name: geolocator_android
|
||||||
url: https://hanntech-gmbh.gitlab.io/free2pass/flutter-geolocator-floss
|
url: https://hanntech-gmbh.gitlab.io/free2pass/flutter-geolocator-floss
|
||||||
provider: 5.0.0
|
provider: 5.0.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user