fix notification on click actions
This commit is contained in:
parent
3315b37924
commit
bcf617d400
2 changed files with 83 additions and 16 deletions
|
|
@ -9,6 +9,7 @@ import 'package:go_router/go_router.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
import 'package:fluffychat/utils/client_download_content_extension.dart';
|
||||
import 'package:fluffychat/utils/client_manager.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||
|
|
@ -132,6 +133,36 @@ Future<void> notificationTap(
|
|||
.waitForRoomInSync(roomId)
|
||||
.timeout(const Duration(seconds: 30));
|
||||
}
|
||||
|
||||
// #Pangea
|
||||
const sessionIdKey = "content_pangea.activity.session_room_id";
|
||||
const activityIdKey = "content_pangea.activity.id";
|
||||
final sessionRoomId = payload.additionalData[sessionIdKey];
|
||||
final activityId = payload.additionalData[activityIdKey];
|
||||
if (sessionRoomId != null &&
|
||||
sessionRoomId.isNotEmpty &&
|
||||
activityId != null &&
|
||||
activityId.isNotEmpty) {
|
||||
try {
|
||||
final course = client.getRoomById(roomId);
|
||||
if (course == null) return;
|
||||
|
||||
final session = client.getRoomById(sessionRoomId);
|
||||
if (session?.membership == Membership.join) {
|
||||
router.go('/rooms/$sessionRoomId');
|
||||
return;
|
||||
}
|
||||
|
||||
router.go(
|
||||
'/rooms/spaces/$roomId/activity/$activityId?roomid=$sessionRoomId',
|
||||
);
|
||||
return;
|
||||
} catch (err, s) {
|
||||
ErrorHandler.logError(e: err, s: s, data: {"roomId": sessionRoomId});
|
||||
}
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
router.go(
|
||||
client.getRoomById(roomId)?.membership == Membership.invite
|
||||
? '/rooms'
|
||||
|
|
|
|||
|
|
@ -339,20 +339,20 @@ Future<void> _tryPushHelper(
|
|||
}
|
||||
|
||||
// #Pangea - Include activity session data in payload
|
||||
String payload = event.roomId!;
|
||||
final Map<String, String> additionalDataMap = {};
|
||||
if (additionalData != null) {
|
||||
const sessionIdKey = "content_pangea.activity.session_room_id";
|
||||
const activityIdKey = "content_pangea.activity.id";
|
||||
final sessionRoomId = additionalData[sessionIdKey];
|
||||
final activityId = additionalData[activityIdKey];
|
||||
if (sessionRoomId is String && activityId is String) {
|
||||
payload = jsonEncode({
|
||||
'room_id': event.roomId,
|
||||
sessionIdKey: sessionRoomId,
|
||||
activityIdKey: activityId,
|
||||
});
|
||||
}
|
||||
additionalData.forEach((key, value) {
|
||||
if (value is String) {
|
||||
additionalDataMap[key] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
final payload = FluffyChatPushPayload(
|
||||
client.clientName,
|
||||
event.room.id,
|
||||
event.eventId,
|
||||
additionalData: additionalDataMap,
|
||||
).toString();
|
||||
// Pangea#
|
||||
|
||||
await flutterLocalNotificationsPlugin.show(
|
||||
|
|
@ -374,19 +374,55 @@ Future<void> _tryPushHelper(
|
|||
|
||||
class FluffyChatPushPayload {
|
||||
final String? clientName, roomId, eventId;
|
||||
// #Pangea
|
||||
final Map<String, String> additionalData;
|
||||
// Pangea#
|
||||
|
||||
FluffyChatPushPayload(this.clientName, this.roomId, this.eventId);
|
||||
// #Pangea
|
||||
// FluffyChatPushPayload(this.clientName, this.roomId, this.eventId);
|
||||
FluffyChatPushPayload(
|
||||
this.clientName,
|
||||
this.roomId,
|
||||
this.eventId, {
|
||||
this.additionalData = const {},
|
||||
});
|
||||
// Pangea#
|
||||
|
||||
factory FluffyChatPushPayload.fromString(String payload) {
|
||||
final parts = payload.split('|');
|
||||
if (parts.length != 3) {
|
||||
// #Pangea
|
||||
// if (parts.length != 3) {
|
||||
// return FluffyChatPushPayload(null, null, null);
|
||||
// }
|
||||
// return FluffyChatPushPayload(parts[0], parts[1], parts[2]);
|
||||
if (parts.length < 3) {
|
||||
return FluffyChatPushPayload(null, null, null);
|
||||
}
|
||||
return FluffyChatPushPayload(parts[0], parts[1], parts[2]);
|
||||
|
||||
Map<String, String> additionalData = {};
|
||||
if (parts.length > 3) {
|
||||
try {
|
||||
additionalData = Map<String, String>.from(jsonDecode(parts[3]));
|
||||
} catch (e, s) {
|
||||
Logs().e('Unable to parse additional data from payload', e, s);
|
||||
}
|
||||
}
|
||||
return FluffyChatPushPayload(
|
||||
parts[0],
|
||||
parts[1],
|
||||
parts[2],
|
||||
additionalData: additionalData,
|
||||
);
|
||||
// Pangea#
|
||||
}
|
||||
|
||||
// #Pangea
|
||||
// @override
|
||||
// String toString() => '$clientName|$roomId|$eventId';
|
||||
@override
|
||||
String toString() => '$clientName|$roomId|$eventId';
|
||||
String toString() =>
|
||||
'$clientName|$roomId|$eventId|${jsonEncode(additionalData)}';
|
||||
// Pangea#
|
||||
}
|
||||
|
||||
/// Creates a shortcut for Android platform but does not block displaying the
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue