Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVEMENT] Check for focused rooms on in-app notifications #2857

Merged
merged 7 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions app/containers/InAppNotification/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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({
Expand All @@ -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);
6 changes: 4 additions & 2 deletions app/views/RoomView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -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 {
Expand Down