Closed taherfattahi closed 2 years ago
@taherfattahi I don't think we can accept this in is current state. If you're interested in making the changes I requested, let us know, but I'm going to close this for now.
This isn't directly related to FluffyChat, but to the underlying matrix
library implementation in Dart: https://pub.dev/packages/matrix
The PushNotification
object in the library has a mandatory devices
field: https://github.com/famedly/matrix-dart-sdk/blob/v0.34.0/lib/src/utils/push_notification.dart#L20
I believe they decided to make it required because of the following text in the matrix push gateway API spec: https://spec.matrix.org/v1.12/push-gateway-api/
I believe it's not used in any capacity by the library
Filed an issue in matrix-dart-sdk
repo: https://github.com/famedly/matrix-dart-sdk/issues/1947
unread
and missed_calls
fields also appear to be incompatible with matrix-dart-sdk
(as they are wrapped in a counts
object). Filed an issue: https://github.com/famedly/matrix-dart-sdk/issues/1948
Here's an example of how to workaround both issues on the client-side without breaking compatibility with other Push Gateway implementations:
Future<void> _handlePushMessage(Map<dynamic, dynamic> messageData) {
// Workaround: https://github.com/famedly/matrix-dart-sdk/issues/1947
const String devicesKey = 'devices';
if (!messageData.containsKey(devicesKey)) {
messageData[devicesKey] = <PushNotificationDevice>[];
}
// Workaround: https://github.com/famedly/matrix-dart-sdk/issues/1948
const String countsKey = 'counts';
const String unreadKey = 'unread';
const String missedCallsKey = 'missed_calls';
if (!messageData.containsKey(countsKey) &&
(messageData.containsKey(unreadKey) ||
messageData.containsKey(missedCallsKey))) {
messageData[countsKey] = PushNotificationCounts(
unread: int.tryParse(messageData[unreadKey]),
missedCalls: int.tryParse(messageData[missedCallsKey]),
).toJson();
}
final PushNotification notification = PushNotification.fromJson(
Map<String, dynamic>.from(messageData),
);
// The rest of the logic
}
I tested FluffyChat application and I realized we need to add this line of code for working with FCM push notification