Notification Events

Last Edit: Jun 06 2020

Notification events help you update your UI (web+mobile, multiple tabs, ...) even if you're not watching a particular channel. Notification events are sent to channel members that are not currently watching the channel. There are six notification events:

  1. notification.message_new
  2. notification.mark_read
  3. notification.invited
  4. notification.invite_accepted
  5. notification.added_to_channel
  6. notification.removed_from_channel
  7. notification.mutes_updated
  8. notification.channel_deleted
  9. notification.channel_truncated

Notification events are triggered on the client level. Here's an example of how you can render a new conversation when a user is added to a channel:


client.on('notification.added_to_channel', event => {
    console.log(`you were just added to channel ${event.channel}`)
});
                    

Integer subscriptionId = client.addEventHandler(new ChatEventHandler() {
  @Override
  public void onNotificationAddedToChannel(Channel channel, Event event) {

  }
});
                    

let subscription = Client.shared.subscribe(forEvents: [.notificationAddedToChannel]) { event in
    // handle new notification event
}
// Cancel subscription when you want to stop receiving events
subscription.cancel()
                    

channelController
    .events()
    .filter("notification.added_to_channel")
    .subscribe { notificationEvent ->
        notificationEvent
    }
                    

final subscription = channel.on("notification.added_to_channel").listen((Event event) {
  print("you were just added to channel ${event.channel}");
});