From 4d9410ad604526012e04a6d7edfe012755ff55da Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Thu, 11 Feb 2021 17:42:50 -0400 Subject: [PATCH] [IMPROVEMENT] Check for focused rooms on in-app notifications (#2857) * Update InAppNotification and room reducer * Update InAppNotification This reverts commit 60330a1e04cfe8d2e5aa311f367083d831682c49. * Stop subscribing to threads * Remove ref * Fix prop-types Co-authored-by: Diego Mello --- app/containers/InAppNotification/index.js | 23 +++++++++++++++++------ app/views/RoomView/index.js | 6 ++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/containers/InAppNotification/index.js b/app/containers/InAppNotification/index.js index dd6573f3..2083b8f1 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 38a39d97..0ef67a80 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 {