From 0f56be785ae7a2b7540ec8ddea81be13f7a5c92c Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Sat, 26 Mar 2016 14:02:45 -0300 Subject: Fix HTML Notifications not showing - fix filename typo --- webapp/action_creators/websocket_actions.jsx | 1 + webapp/stores/notificaiton_store.jsx | 98 ---------------------------- webapp/stores/notification_store.jsx | 98 ++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 98 deletions(-) delete mode 100644 webapp/stores/notificaiton_store.jsx create mode 100644 webapp/stores/notification_store.jsx (limited to 'webapp') diff --git a/webapp/action_creators/websocket_actions.jsx b/webapp/action_creators/websocket_actions.jsx index 611d53bf7..93b12692a 100644 --- a/webapp/action_creators/websocket_actions.jsx +++ b/webapp/action_creators/websocket_actions.jsx @@ -7,6 +7,7 @@ import PostStore from 'stores/post_store.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import BrowserStore from 'stores/browser_store.jsx'; import ErrorStore from 'stores/error_store.jsx'; +import NotificationStore from 'stores/notification_store.jsx'; //eslint-disable-line no-unused-vars import * as Utils from 'utils/utils.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; diff --git a/webapp/stores/notificaiton_store.jsx b/webapp/stores/notificaiton_store.jsx deleted file mode 100644 index 70caffeb6..000000000 --- a/webapp/stores/notificaiton_store.jsx +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; -import EventEmitter from 'events'; -import Constants from 'utils/constants.jsx'; -import UserStore from './user_store.jsx'; -import ChannelStore from './channel_store.jsx'; -import * as Utils from 'utils/utils.jsx'; -const ActionTypes = Constants.ActionTypes; - -const CHANGE_EVENT = 'change'; - -class NotificationStoreClass extends EventEmitter { - emitChange() { - this.emit(CHANGE_EVENT); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - handleRecievedPost(post, msgProps) { - // Send desktop notification - if ((UserStore.getCurrentId() !== post.user_id || post.props.from_webhook === 'true') && !Utils.isSystemMessage(post)) { - let mentions = []; - if (msgProps.mentions) { - mentions = JSON.parse(msgProps.mentions); - } - - const channel = ChannelStore.get(post.channel_id); - const user = UserStore.getCurrentUser(); - const member = ChannelStore.getMember(post.channel_id); - - let notifyLevel = member && member.notify_props ? member.notify_props.desktop : 'default'; - if (notifyLevel === 'default') { - notifyLevel = user.notify_props.desktop; - } - - if (notifyLevel === 'none') { - return; - } else if (notifyLevel === 'mention' && mentions.indexOf(user.id) === -1 && channel.type !== Constants.DM_CHANNEL) { - return; - } - - let username = Utils.localizeMessage('channel_loader.someone', 'Someone'); - if (post.props.override_username && global.window.mm_config.EnablePostUsernameOverride === 'true') { - username = post.props.override_username; - } else if (UserStore.hasProfile(post.user_id)) { - username = UserStore.getProfile(post.user_id).username; - } - - let title = Utils.localizeMessage('channel_loader.posted', 'Posted'); - if (channel) { - title = channel.display_name; - } - - let notifyText = post.message.replace(/\n+/g, ' '); - if (notifyText.length > 50) { - notifyText = notifyText.substring(0, 49) + '...'; - } - - if (notifyText.length === 0) { - if (msgProps.image) { - Utils.notifyMe(title, username + Utils.localizeMessage('channel_loader.uploadedImage', ' uploaded an image'), channel); - } else if (msgProps.otherFile) { - Utils.notifyMe(title, username + Utils.localizeMessage('channel_loader.uploadedFile', ' uploaded a file'), channel); - } else { - Utils.notifyMe(title, username + Utils.localizeMessage('channel_loader.something', ' did something new'), channel); - } - } else { - Utils.notifyMe(title, username + Utils.localizeMessage('channel_loader.wrote', ' wrote: ') + notifyText, channel); - } - if (!user.notify_props || user.notify_props.desktop_sound === 'true') { - Utils.ding(); - } - } - } -} - -var NotificationStore = new NotificationStoreClass(); - -NotificationStore.dispatchToken = AppDispatcher.register((payload) => { - const action = payload.action; - - switch (action.type) { - case ActionTypes.RECEIVED_POST: - NotificationStore.handleRecievedPost(action.post, action.webspcketMessageProps); - NotificationStore.emitChange(); - break; - } -}); - -export default NotificationStore; diff --git a/webapp/stores/notification_store.jsx b/webapp/stores/notification_store.jsx new file mode 100644 index 000000000..70caffeb6 --- /dev/null +++ b/webapp/stores/notification_store.jsx @@ -0,0 +1,98 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; +import EventEmitter from 'events'; +import Constants from 'utils/constants.jsx'; +import UserStore from './user_store.jsx'; +import ChannelStore from './channel_store.jsx'; +import * as Utils from 'utils/utils.jsx'; +const ActionTypes = Constants.ActionTypes; + +const CHANGE_EVENT = 'change'; + +class NotificationStoreClass extends EventEmitter { + emitChange() { + this.emit(CHANGE_EVENT); + } + + addChangeListener(callback) { + this.on(CHANGE_EVENT, callback); + } + + removeChangeListener(callback) { + this.removeListener(CHANGE_EVENT, callback); + } + + handleRecievedPost(post, msgProps) { + // Send desktop notification + if ((UserStore.getCurrentId() !== post.user_id || post.props.from_webhook === 'true') && !Utils.isSystemMessage(post)) { + let mentions = []; + if (msgProps.mentions) { + mentions = JSON.parse(msgProps.mentions); + } + + const channel = ChannelStore.get(post.channel_id); + const user = UserStore.getCurrentUser(); + const member = ChannelStore.getMember(post.channel_id); + + let notifyLevel = member && member.notify_props ? member.notify_props.desktop : 'default'; + if (notifyLevel === 'default') { + notifyLevel = user.notify_props.desktop; + } + + if (notifyLevel === 'none') { + return; + } else if (notifyLevel === 'mention' && mentions.indexOf(user.id) === -1 && channel.type !== Constants.DM_CHANNEL) { + return; + } + + let username = Utils.localizeMessage('channel_loader.someone', 'Someone'); + if (post.props.override_username && global.window.mm_config.EnablePostUsernameOverride === 'true') { + username = post.props.override_username; + } else if (UserStore.hasProfile(post.user_id)) { + username = UserStore.getProfile(post.user_id).username; + } + + let title = Utils.localizeMessage('channel_loader.posted', 'Posted'); + if (channel) { + title = channel.display_name; + } + + let notifyText = post.message.replace(/\n+/g, ' '); + if (notifyText.length > 50) { + notifyText = notifyText.substring(0, 49) + '...'; + } + + if (notifyText.length === 0) { + if (msgProps.image) { + Utils.notifyMe(title, username + Utils.localizeMessage('channel_loader.uploadedImage', ' uploaded an image'), channel); + } else if (msgProps.otherFile) { + Utils.notifyMe(title, username + Utils.localizeMessage('channel_loader.uploadedFile', ' uploaded a file'), channel); + } else { + Utils.notifyMe(title, username + Utils.localizeMessage('channel_loader.something', ' did something new'), channel); + } + } else { + Utils.notifyMe(title, username + Utils.localizeMessage('channel_loader.wrote', ' wrote: ') + notifyText, channel); + } + if (!user.notify_props || user.notify_props.desktop_sound === 'true') { + Utils.ding(); + } + } + } +} + +var NotificationStore = new NotificationStoreClass(); + +NotificationStore.dispatchToken = AppDispatcher.register((payload) => { + const action = payload.action; + + switch (action.type) { + case ActionTypes.RECEIVED_POST: + NotificationStore.handleRecievedPost(action.post, action.webspcketMessageProps); + NotificationStore.emitChange(); + break; + } +}); + +export default NotificationStore; -- cgit v1.2.3-1-g7c22