onMessageNew method

void onMessageNew(
  1. Event event,
  2. StreamChannelListController controller
)

Function which gets called for the event EventType.messageNew.

This event is fired when a new message is created in one of the channels we are currently watching.

By default, this moves the channel to the top of the list.

Implementation

void onMessageNew(Event event, StreamChannelListController controller) {
  final channelCid = event.cid;
  if (channelCid == null) return;

  final channels = [...controller.currentItems];

  final channelIndex = channels.indexWhere((it) => it.cid == channelCid);
  if (channelIndex <= 0) return;

  final channel = channels.removeAt(channelIndex);
  channels.insert(0, channel);

  controller.channels = [...channels];
}