Merge pull request #7874 from jfsiebel/sound-alert-different-tab-or-minimized

Send audo alert for new messages when in another tab or browser minimized
This commit is contained in:
Anton Georgiev 2019-08-01 12:59:29 -04:00 committed by GitHub
commit 28bdffca49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 6 deletions

View File

@ -1,11 +1,11 @@
import React from 'react';
import { Component } from 'react';
import PropTypes from 'prop-types';
const propTypes = {
play: PropTypes.bool.isRequired,
};
class ChatAudioAlert extends React.Component {
class ChatAudioAlert extends Component {
constructor(props) {
super(props);
this.audio = new Audio(`${Meteor.settings.public.app.cdn + Meteor.settings.public.app.basename}/resources/sounds/notify.mp3`);

View File

@ -173,11 +173,18 @@ class ChatAlert extends PureComponent {
pendingNotificationsByChat,
} = this.state;
const shouldPlay = Object.keys(pendingNotificationsByChat).length > 0;
const notCurrentTabOrMinimized = document.hidden;
const shouldPlayChatAlert = notCurrentTabOrMinimized
|| Object.keys(pendingNotificationsByChat).length > 0;
return (
<Fragment>
{!audioAlertDisabled ? <ChatAudioAlert play={shouldPlay} /> : null}
{
!audioAlertDisabled && notCurrentTabOrMinimized
? <ChatAudioAlert play={shouldPlayChatAlert} />
: null
}
{
!pushAlertDisabled
? Object.keys(pendingNotificationsByChat)

View File

@ -3,7 +3,6 @@ import { withTracker } from 'meteor/react-meteor-data';
import UserListService from '/imports/ui/components/user-list/service';
import Settings from '/imports/ui/services/settings';
import ChatAlert from './component';
import ChatService from '/imports/ui/components/chat/service.js';
import Auth from '/imports/ui/services/auth';
import Users from '/imports/api/users';
@ -14,7 +13,7 @@ const ChatAlertContainer = props => (
export default withTracker(() => {
const AppSettings = Settings.application;
const activeChats = UserListService.getActiveChats();
const loginTime = Users.findOne({ userId: Auth.userID }).loginTime;
const { loginTime } = Users.findOne({ userId: Auth.userID }, { fields: { loginTime: 1 } });
return {
audioAlertDisabled: !AppSettings.chatAudioAlerts,
pushAlertDisabled: !AppSettings.chatPushAlerts,