Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
...
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
You can’t perform that action at this time.