braze-inc / braze-flutter-sdk

Public repo for the Braze Flutter SDK
Other
15 stars 29 forks source link

[bug][regression] the new streaming api's broke an existing fix #28

Closed JordyLangen closed 1 year ago

JordyLangen commented 1 year ago

Some time ago, the "queued messages" was introduced:

  /// Sets a callback to receive in-app message data from Braze.
  @Deprecated(
      'Use subscribeToInAppMessages(void onEvent(List<BrazeContentCard> contentCard)) instead.')
  void setBrazeInAppMessageCallback(Function(BrazeInAppMessage) callback) {
    _brazeInAppMessageHandler = callback;

    if (_replayCallbacksConfigEnabled() && _queuedInAppMessages.isNotEmpty) {
      print("Replaying callback on previously queued Braze in-app messages.");
      _queuedInAppMessages.forEach((message) => callback(message));
      _queuedInAppMessages.clear();
    }
  }

Where queued messages got replayed.

Now you've introduced the Stream api, which looks like this:

  /// Subscribes to the stream of in-app messages and calls [onEvent] when it
  /// receives an in-app message.
  StreamSubscription subscribeToInAppMessages(
      void onEvent(BrazeInAppMessage inAppMessage)) {
    StreamSubscription subscription =
        inAppMessageStreamController.stream.listen((inAppMessage) {
      onEvent(inAppMessage);
    });
    return subscription;
  }

To prove my point, the following:

      final controller = StreamController<int>.broadcast();
      controller.add(1);
      controller.stream.listen(print);
      controller.add(2);

      controller.close();

prints 2;

Thus, queued messages are not replayed.

spkersten commented 1 year ago

Off-topic: it looks like the old (Dart 1) syntax is used for the onEvent parameter. See https://dart.dev/guides/language/effective-dart/design#prefer-using-function-type-syntax-for-parameters

hokstuff commented 1 year ago

Hi @JordyLangen and @spkersten,

Thanks for raising this issue. It looks like support to be able to replay the "queued messages" wasn't added to the Streams feature. We will add this behavior in a future release to match with the Callbacks integration and respond back here when it is released.

hokstuff commented 1 year ago

Hi @JordyLangen and @spkersten,

We have released Flutter SDK version 2.6.1 which addresses both of the issues raised here.

Thanks!