[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 <diegolmello@gmail.com>
This commit is contained in:
Gerzon Z 2021-02-11 17:42:50 -04:00 committed by GitHub
parent d42dab1e76
commit 4d9410ad60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 8 deletions

View File

@ -1,5 +1,8 @@
import React, { memo, useEffect } from 'react'; import React, { memo, useEffect } from 'react';
import PropTypes from 'prop-types';
import { NotifierRoot, Notifier, Easing } from 'react-native-notifier'; import { NotifierRoot, Notifier, Easing } from 'react-native-notifier';
import { connect } from 'react-redux';
import isEqual from 'deep-equal';
import NotifierComponent from './NotifierComponent'; import NotifierComponent from './NotifierComponent';
import EventEmitter from '../../utils/events'; import EventEmitter from '../../utils/events';
@ -8,13 +11,13 @@ import { getActiveRoute } from '../../utils/navigation';
export const INAPP_NOTIFICATION_EMITTER = 'NotificationInApp'; export const INAPP_NOTIFICATION_EMITTER = 'NotificationInApp';
const InAppNotification = memo(() => { const InAppNotification = memo(({ rooms }) => {
const show = (notification) => { const show = (notification) => {
const { payload } = notification; const { payload } = notification;
const state = Navigation.navigationRef.current?.getRootState(); const state = Navigation.navigationRef.current?.getRootState();
const route = getActiveRoute(state); const route = getActiveRoute(state);
if (payload.rid) { if (payload.rid) {
if ((route?.name === 'RoomView' && route.params?.rid === payload.rid) || route?.name === 'JitsiMeetView') { if (rooms.includes(payload.rid) || route?.name === 'JitsiMeetView') {
return; return;
} }
Notifier.showNotification({ Notifier.showNotification({
@ -28,13 +31,21 @@ const InAppNotification = memo(() => {
}; };
useEffect(() => { useEffect(() => {
EventEmitter.addEventListener(INAPP_NOTIFICATION_EMITTER, show); const listener = EventEmitter.addEventListener(INAPP_NOTIFICATION_EMITTER, show);
return () => { return () => {
EventEmitter.removeListener(INAPP_NOTIFICATION_EMITTER); EventEmitter.removeListener(INAPP_NOTIFICATION_EMITTER, listener);
}; };
}, []); }, [rooms]);
return <NotifierRoot />; return <NotifierRoot />;
}, (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);

View File

@ -155,7 +155,9 @@ class RoomView extends React.Component {
this.list = React.createRef(); this.list = React.createRef();
this.joinCode = React.createRef(); this.joinCode = React.createRef();
this.mounted = false; 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); this.sub = new RoomClass(this.rid);
} }
console.timeEnd(`${ this.constructor.name } init`); console.timeEnd(`${ this.constructor.name } init`);
@ -168,7 +170,7 @@ class RoomView extends React.Component {
const { isAuthenticated } = this.props; const { isAuthenticated } = this.props;
this.setHeader(); this.setHeader();
if (this.rid) { if (this.rid) {
this.sub.subscribe(); this.sub?.subscribe?.();
if (isAuthenticated) { if (isAuthenticated) {
this.init(); this.init();
} else { } else {