diff --git a/app/containers/InAppNotification/index.js b/app/containers/InAppNotification/index.js index dd6573f332..2083b8f1ba 100644 --- a/app/containers/InAppNotification/index.js +++ b/app/containers/InAppNotification/index.js @@ -1,5 +1,8 @@ import React, { memo, useEffect } from 'react'; +import PropTypes from 'prop-types'; import { NotifierRoot, Notifier, Easing } from 'react-native-notifier'; +import { connect } from 'react-redux'; +import isEqual from 'deep-equal'; import NotifierComponent from './NotifierComponent'; import EventEmitter from '../../utils/events'; @@ -8,13 +11,13 @@ import { getActiveRoute } from '../../utils/navigation'; export const INAPP_NOTIFICATION_EMITTER = 'NotificationInApp'; -const InAppNotification = memo(() => { +const InAppNotification = memo(({ rooms }) => { const show = (notification) => { const { payload } = notification; const state = Navigation.navigationRef.current?.getRootState(); const route = getActiveRoute(state); if (payload.rid) { - if ((route?.name === 'RoomView' && route.params?.rid === payload.rid) || route?.name === 'JitsiMeetView') { + if (rooms.includes(payload.rid) || route?.name === 'JitsiMeetView') { return; } Notifier.showNotification({ @@ -28,13 +31,21 @@ const InAppNotification = memo(() => { }; useEffect(() => { - EventEmitter.addEventListener(INAPP_NOTIFICATION_EMITTER, show); + const listener = EventEmitter.addEventListener(INAPP_NOTIFICATION_EMITTER, show); return () => { - EventEmitter.removeListener(INAPP_NOTIFICATION_EMITTER); + EventEmitter.removeListener(INAPP_NOTIFICATION_EMITTER, listener); }; - }, []); + }, [rooms]); return ; +}, (prevProps, nextProps) => isEqual(prevProps.rooms, nextProps.rooms)); + +const mapStateToProps = state => ({ + rooms: state.room.rooms }); -export default InAppNotification; +InAppNotification.propTypes = { + rooms: PropTypes.array +}; + +export default connect(mapStateToProps)(InAppNotification); diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 38a39d9795..0ef67a80a1 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -155,7 +155,9 @@ class RoomView extends React.Component { this.list = React.createRef(); this.joinCode = React.createRef(); this.mounted = false; - if (this.rid) { + + // we don't need to subscribe to threads + if (this.rid && !this.tmid) { this.sub = new RoomClass(this.rid); } console.timeEnd(`${ this.constructor.name } init`); @@ -168,7 +170,7 @@ class RoomView extends React.Component { const { isAuthenticated } = this.props; this.setHeader(); if (this.rid) { - this.sub.subscribe(); + this.sub?.subscribe?.(); if (isAuthenticated) { this.init(); } else {