Skip to content

Instantly share code, notes, and snippets.

@LukeSmetham
Last active September 24, 2019 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LukeSmetham/867533b3bfd9741caa6a1953baba0c8f to your computer and use it in GitHub Desktop.
Save LukeSmetham/867533b3bfd9741caa6a1953baba0c8f to your computer and use it in GitHub Desktop.
...
class AttendeesChat extends Component {
...
async componentDidUpdate(prevProps, prevState) {
const { attendeesChatOpened, setUnreadCount } = this.props;
const { channel } = this.state;
if (!prevState.channel && channel) {
this.init();
}
...
}
async init() {
const { channel } = this.state;
await channel.watch();
channel.on('message.new', this.handleNewMessage);
}
handleNewMessage = async () => {
const { attendeesChatOpened, setUnreadCount } = this.props;
const { channel } = this.state;
const unread = await channel.countUnread();
setUnreadCount(attendeesChatOpened ? 0 : unread);
}
...
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment