Notification Events

Last Edit: Oct 19 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}`)
});
                    

channelController.subscribeFor(
        new String[]{EventType.NOTIFICATION_ADDED_TO_CHANNEL},
        addToChannel -> {
            // Handle event
            return Unit.INSTANCE;
        }
);
                    

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
    .subscribeFor<NotificationAddedToChannelEvent> { notificationEvent ->
        // Handle event
    }
                    

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