Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

pubnub/chat-engine-unread-messages

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This repository is a part of the ChatEngine Framework. For more information on building chat applications with PubNub, see our Chat Resource Center.

Unread Messages Plugin

Adds the ability to count unread messages in a ChatEngine Chat

Quick Start

  1. Have ChatEngine instantiated and connected, and have a channel you want to count unread messages on
const ChatEngine = ChatEngineCore.create({
    publishKey: 'pub-key-here',
    subscribeKey: 'sub-key-here',
});

ChatEngine.connect('Username');
ChatEngine.on('$.ready', () => { ... });
  1. Attach this plugin to the channel you want, in this case global
ChatEngine.global.plugin(ChatEngineCore.plugin['chat-engine-unread-messages']());
  1. The plugin needs to be notified when the user is considered active or inactive to properly count messages
// sets unreadCount to 0, stops counting unread messages and stops emitting events
ChatEngine.global.unreadMessages.active();
// starts counting unread messages and starts emitting events - default state
ChatEngine.global.unreadMessages.inactive();
  1. Listen for the $unread events that emit whenever your channel recieves a message while it is marked as inactive
ChatEngine.global.on('$unread', () => {
    console.log(ChatEngine.global.unreadCount);
});

Support

  • If you need help, have a general question, have a feature request or to file a bug, contact support@pubnub.com.