-
-
Save LukeSmetham/867533b3bfd9741caa6a1953baba0c8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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