diff --git a/app/containers/InAppNotification/index.js b/app/containers/InAppNotification/index.js index dd6573f33..6076bef78 100644 --- a/app/containers/InAppNotification/index.js +++ b/app/containers/InAppNotification/index.js @@ -1,5 +1,8 @@ -import React, { memo, useEffect } from 'react'; +import React, { memo, useEffect, useRef } from 'react'; import { NotifierRoot, Notifier, Easing } from 'react-native-notifier'; +import { PropTypes } from 'react-native'; +import { connect } from 'react-redux'; +import isEqual from 'deep-equal'; import NotifierComponent from './NotifierComponent'; import EventEmitter from '../../utils/events'; @@ -8,13 +11,14 @@ import { getActiveRoute } from '../../utils/navigation'; export const INAPP_NOTIFICATION_EMITTER = 'NotificationInApp'; -const InAppNotification = memo(() => { +const InAppNotification = memo(({ rooms }) => { + const roomsRef = useRef(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 (roomsRef?.current.includes(payload.rid) || route?.name === 'JitsiMeetView') { return; } Notifier.showNotification({ @@ -27,6 +31,12 @@ const InAppNotification = memo(() => { } }; + useEffect(() => { + if (!isEqual(rooms, roomsRef?.current)) { + roomsRef.current = rooms; + } + }, [rooms]); + useEffect(() => { EventEmitter.addEventListener(INAPP_NOTIFICATION_EMITTER, show); return () => { @@ -37,4 +47,12 @@ const InAppNotification = memo(() => { return ; }); -export default InAppNotification; +const mapStateToProps = state => ({ + rooms: state.room.rooms +}); + +InAppNotification.propTypes = { + rooms: PropTypes.array +}; + +export default connect(mapStateToProps)(InAppNotification); diff --git a/app/reducers/room.js b/app/reducers/room.js index 20f86d1cc..aabaa1ce5 100644 --- a/app/reducers/room.js +++ b/app/reducers/room.js @@ -17,7 +17,7 @@ export default function(state = initialState, action) { return { ...state, rooms: state.rooms - .filter(rid => rid !== action.rid) + .filter((_, index, self) => index !== self.indexOf(action.rid)) }; case ROOM.LEAVE: return {