talkjs / talkjs-flutter

Flutter SDK for the TalkJS Chat API
https://talkjs.com
BSD 3-Clause "New" or "Revised" License
9 stars 13 forks source link

Updated JS event handlers and implemented onCustomMessageAction #5

Closed bugnano closed 2 years ago

bugnano commented 2 years ago

cc @eteeselink

bugnano commented 2 years ago

How is someone meant to unsubscribe from an event?

This actually is a known memory leak, but I don't think it will be that serious.

The way I envisioned it is this:

You put the actions that you want to subscribe to as keys of the mapping.

If you want to subscribe to a new custom action, you add the key to the mapping, and internally, I handle the JS to handle the subscription.

If you don't want to be subscribed anymore, you remove the key from the mapping, and it will work.

Internally the JS will still be subscribed, but no handler will be called from the Dart side.

I know it's not optimal, but I don't think it's a problem.

@eteeselink what do you think?

eteeselink commented 2 years ago

My Flutter-fu fails me, but I'd like to understand this.

With this code, how would someone subscribe to a custom action?

bugnano commented 2 years ago

My Flutter-fu fails me, but I'd like to understand this.

With this code, how would someone subscribe to a custom action?

With a mapping, as per the (already approved) docs:

onCustomMessageAction: {
  'favourite': (event) {
    print('Favourited message with id: ${event.message.id}');
  },
  'report': (event) {
    print('Reported message with id: ${event.message.id}');
  },
},
eteeselink commented 2 years ago

ok clear. that's delightful btw :) not sure if i already said that.