matrix-org / sygnal

Sygnal: reference Push Gateway for Matrix
Apache License 2.0
167 stars 148 forks source link

add data["devices"] for Fluffychat messenger #319

Closed taherfattahi closed 2 years ago

taherfattahi commented 2 years ago

I tested FluffyChat application and I realized we need to add this line of code for working with FCM push notification

richvdh commented 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.

vanyasem commented 1 month ago

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

vanyasem commented 1 month ago

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

vanyasem commented 1 month ago

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
}