[IMPROVEMENT] Check for focused rooms on in-app notifications (#2857)
* Update InAppNotification and room reducer
* Update InAppNotification
This reverts commit 60330a1e04
.
* Stop subscribing to threads
* Remove ref
* Fix prop-types
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
d42dab1e76
commit
4d9410ad60
|
@ -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 <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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue