Don't show desktop notifications for messages entering the channel th… (#4216)
* Don't show desktop notifications for messages entering the channel the user is currently on Coding style fixes Allow notifications if browser tab is not focussed * Don't show desktop notifications for messages entering the channel the user is currently on Coding style fixes Allow notifications if browser tab is not focussed * Mute sound when a user doesn't get a desktop notification * Also play sound on desktop notifications * Fixed reviewer's remarks: * Removed double notification check * Removed direct links to browser store, created separate actions
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
a798714958
Коммит
6d2882f6e7
@@ -535,3 +535,10 @@ export function toggleSideBarAction(visible) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function emitBrowserFocus(focus) {
|
||||||
|
AppDispatcher.handleViewAction({
|
||||||
|
type: ActionTypes.BROWSER_CHANGE_FOCUS,
|
||||||
|
focus
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ export default class LoggedIn extends React.Component {
|
|||||||
// Listen for user
|
// Listen for user
|
||||||
UserStore.addChangeListener(this.onUserChanged);
|
UserStore.addChangeListener(this.onUserChanged);
|
||||||
|
|
||||||
|
// Listen for focussed tab/window state
|
||||||
|
window.addEventListener('focus', this.onFocusListener);
|
||||||
|
window.addEventListener('blur', this.onBlurListener);
|
||||||
|
|
||||||
// ???
|
// ???
|
||||||
$('body').on('mouseenter mouseleave', '.post', function mouseOver(ev) {
|
$('body').on('mouseenter mouseleave', '.post', function mouseOver(ev) {
|
||||||
if (ev.type === 'mouseenter') {
|
if (ev.type === 'mouseenter') {
|
||||||
@@ -166,6 +170,10 @@ export default class LoggedIn extends React.Component {
|
|||||||
$('.modal').off('show.bs.modal');
|
$('.modal').off('show.bs.modal');
|
||||||
|
|
||||||
$(window).off('keydown.preventBackspace');
|
$(window).off('keydown.preventBackspace');
|
||||||
|
|
||||||
|
// Listen for focussed tab/window state
|
||||||
|
window.removeEventListener('focus', this.onFocusListener);
|
||||||
|
window.removeEventListener('blur', this.onBlurListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -177,6 +185,14 @@ export default class LoggedIn extends React.Component {
|
|||||||
user: this.state.user
|
user: this.state.user
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onFocusListener() {
|
||||||
|
GlobalActions.emitBrowserFocus(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
onBlurListener() {
|
||||||
|
GlobalActions.emitBrowserFocus(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LoggedIn.propTypes = {
|
LoggedIn.propTypes = {
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ class NotificationStoreClass extends EventEmitter {
|
|||||||
removeChangeListener(callback) {
|
removeChangeListener(callback) {
|
||||||
this.removeListener(CHANGE_EVENT, callback);
|
this.removeListener(CHANGE_EVENT, callback);
|
||||||
}
|
}
|
||||||
|
setFocus(focus) {
|
||||||
|
this.inFocus = focus;
|
||||||
|
}
|
||||||
|
|
||||||
handleRecievedPost(post, msgProps) {
|
handleRecievedPost(post, msgProps) {
|
||||||
// Send desktop notification
|
// Send desktop notification
|
||||||
@@ -98,11 +101,21 @@ class NotificationStoreClass extends EventEmitter {
|
|||||||
duration = parseInt(user.notify_props.desktop_duration, 10) * 1000;
|
duration = parseInt(user.notify_props.desktop_duration, 10) * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Play a sound if explicitly set in settings
|
||||||
const sound = !user.notify_props || user.notify_props.desktop_sound === 'true';
|
const sound = !user.notify_props || user.notify_props.desktop_sound === 'true';
|
||||||
Utils.notifyMe(title, body, channel, teamId, duration, !sound);
|
|
||||||
|
|
||||||
if (sound && !UserAgent.isWindowsApp() && !UserAgent.isMacApp()) {
|
// Notify if you're not looking in the right channel or when
|
||||||
Utils.ding();
|
// the window itself is not active
|
||||||
|
const activeChannel = ChannelStore.getCurrent();
|
||||||
|
const notify = activeChannel.id !== channel.id || !this.inFocus;
|
||||||
|
|
||||||
|
if (notify) {
|
||||||
|
Utils.notifyMe(title, body, channel, teamId, duration, !sound);
|
||||||
|
|
||||||
|
//Don't add extra sounds on native desktop clients
|
||||||
|
if (sound && !UserAgent.isWindowsApp() && !UserAgent.isMacApp() && !UserAgent.isMobileApp()) {
|
||||||
|
Utils.ding();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,6 +131,9 @@ NotificationStore.dispatchToken = AppDispatcher.register((payload) => {
|
|||||||
NotificationStore.handleRecievedPost(action.post, action.websocketMessageProps);
|
NotificationStore.handleRecievedPost(action.post, action.websocketMessageProps);
|
||||||
NotificationStore.emitChange();
|
NotificationStore.emitChange();
|
||||||
break;
|
break;
|
||||||
|
case ActionTypes.BROWSER_CHANGE_FOCUS:
|
||||||
|
NotificationStore.setFocus(action.focus);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -156,7 +156,9 @@ export const ActionTypes = keyMirror({
|
|||||||
SUGGESTION_CLEAR_SUGGESTIONS: null,
|
SUGGESTION_CLEAR_SUGGESTIONS: null,
|
||||||
SUGGESTION_COMPLETE_WORD: null,
|
SUGGESTION_COMPLETE_WORD: null,
|
||||||
SUGGESTION_SELECT_NEXT: null,
|
SUGGESTION_SELECT_NEXT: null,
|
||||||
SUGGESTION_SELECT_PREVIOUS: null
|
SUGGESTION_SELECT_PREVIOUS: null,
|
||||||
|
|
||||||
|
BROWSER_CHANGE_FOCUS: null
|
||||||
});
|
});
|
||||||
|
|
||||||
export const WebrtcActionTypes = keyMirror({
|
export const WebrtcActionTypes = keyMirror({
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user