diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-03-14 00:56:37 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-03-14 00:56:37 -0400 |
commit | 975159b52ac6bf0ee6b2d5b73d2391b2e0c6e165 (patch) | |
tree | a0852f9faf6de9962b5478ed3f1bbaccd71062c0 /web/react/components/channel_loader.jsx | |
parent | 160e1a8bea6d8280ef3b41a4a9f80674b75f3eb0 (diff) | |
parent | d7cdcf082fab6c0cb7c2fe4bed821bd1a8000e69 (diff) | |
download | chat-975159b52ac6bf0ee6b2d5b73d2391b2e0c6e165.tar.gz chat-975159b52ac6bf0ee6b2d5b73d2391b2e0c6e165.tar.bz2 chat-975159b52ac6bf0ee6b2d5b73d2391b2e0c6e165.zip |
Merge pull request #2331 from mattermost/plt-1680
PLT-1680 Converting client to react-router. Stage 1
Diffstat (limited to 'web/react/components/channel_loader.jsx')
-rw-r--r-- | web/react/components/channel_loader.jsx | 204 |
1 files changed, 0 insertions, 204 deletions
diff --git a/web/react/components/channel_loader.jsx b/web/react/components/channel_loader.jsx deleted file mode 100644 index e47f2aa50..000000000 --- a/web/react/components/channel_loader.jsx +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -/* This is a special React control with the sole purpose of making all the AsyncClient calls - to the server on page load. This is to prevent other React controls from spamming - AsyncClient with requests. */ - -import * as AsyncClient from '../utils/async_client.jsx'; -import * as Client from '../utils/client.jsx'; -import SocketStore from '../stores/socket_store.jsx'; -import ChannelStore from '../stores/channel_store.jsx'; -import PostStore from '../stores/post_store.jsx'; -import UserStore from '../stores/user_store.jsx'; -import PreferenceStore from '../stores/preference_store.jsx'; - -import * as Utils from '../utils/utils.jsx'; -import Constants from '../utils/constants.jsx'; - -import {intlShape, injectIntl, defineMessages} from 'mm-intl'; - -const holders = defineMessages({ - socketError: { - id: 'channel_loader.socketError', - defaultMessage: 'Please check connection, Mattermost unreachable. If issue persists, ask administrator to check WebSocket port.' - }, - someone: { - id: 'channel_loader.someone', - defaultMessage: 'Someone' - }, - posted: { - id: 'channel_loader.posted', - defaultMessage: 'Posted' - }, - uploadedImage: { - id: 'channel_loader.uploadedImage', - defaultMessage: ' uploaded an image' - }, - uploadedFile: { - id: 'channel_loader.uploadedFile', - defaultMessage: ' uploaded a file' - }, - something: { - id: 'channel_loader.something', - defaultMessage: ' did something new' - }, - wrote: { - id: 'channel_loader.wrote', - defaultMessage: ' wrote: ' - }, - connectionError: { - id: 'channel_loader.connection_error', - defaultMessage: 'There appears to be a problem with your internet connection.' - }, - unknownError: { - id: 'channel_loader.unknown_error', - defaultMessage: 'We received an unexpected status code from the server.' - } -}); - -class ChannelLoader extends React.Component { - constructor(props) { - super(props); - - this.intervalId = null; - - this.onSocketChange = this.onSocketChange.bind(this); - - const {formatMessage} = this.props.intl; - SocketStore.setTranslations({ - socketError: formatMessage(holders.socketError), - someone: formatMessage(holders.someone), - posted: formatMessage(holders.posted), - uploadedImage: formatMessage(holders.uploadedImage), - uploadedFile: formatMessage(holders.uploadedFile), - something: formatMessage(holders.something), - wrote: formatMessage(holders.wrote) - }); - - Client.setTranslations({ - connectionError: formatMessage(holders.connectionError), - unknownError: formatMessage(holders.unknownError) - }); - - this.state = {}; - } - componentDidMount() { - /* Initial aysnc loads */ - AsyncClient.getPosts(ChannelStore.getCurrentId()); - AsyncClient.getChannels(); - AsyncClient.getChannelExtraInfo(); - AsyncClient.findTeams(); - AsyncClient.getMyTeam(); - setTimeout(() => AsyncClient.getStatuses(), 3000); // temporary until statuses are reworked a bit - - /* Perform pending post clean-up */ - PostStore.clearPendingPosts(); - - /* Set up interval functions */ - this.intervalId = setInterval(() => AsyncClient.getStatuses(), 30000); - - /* Device tracking setup */ - var iOS = (/(iPad|iPhone|iPod)/g).test(navigator.userAgent); - if (iOS) { - $('body').addClass('ios'); - } - - /* Set up tracking for whether the window is active */ - window.isActive = true; - - $(window).on('focus', function windowFocus() { - AsyncClient.updateLastViewedAt(); - ChannelStore.resetCounts(ChannelStore.getCurrentId()); - ChannelStore.emitChange(); - window.isActive = true; - }); - - $(window).on('blur', function windowBlur() { - window.isActive = false; - }); - - /* Start global change listeners setup */ - SocketStore.addChangeListener(this.onSocketChange); - - /* Update CSS classes to match user theme */ - var user = UserStore.getCurrentUser(); - - if ($.isPlainObject(user.theme_props) && !$.isEmptyObject(user.theme_props)) { - Utils.applyTheme(user.theme_props); - } else { - Utils.applyTheme(Constants.THEMES.default); - } - - // if preferences have already been stored in local storage do not wait until preference store change is fired and handled in channel.jsx - const selectedFont = PreferenceStore.get(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'selected_font', Constants.DEFAULT_FONT); - Utils.applyFont(selectedFont); - - $('body').on('mouseenter mouseleave', '.post', function mouseOver(ev) { - if (ev.type === 'mouseenter') { - $(this).parent('div').prev('.date-separator, .new-separator').addClass('hovered--after'); - $(this).parent('div').next('.date-separator, .new-separator').addClass('hovered--before'); - } else { - $(this).parent('div').prev('.date-separator, .new-separator').removeClass('hovered--after'); - $(this).parent('div').next('.date-separator, .new-separator').removeClass('hovered--before'); - } - }); - - $('body').on('mouseenter mouseleave', '.search-item__container .post', function mouseOver(ev) { - if (ev.type === 'mouseenter') { - $(this).closest('.search-item__container').find('.date-separator').addClass('hovered--after'); - $(this).closest('.search-item__container').next('div').find('.date-separator').addClass('hovered--before'); - } else { - $(this).closest('.search-item__container').find('.date-separator').removeClass('hovered--after'); - $(this).closest('.search-item__container').next('div').find('.date-separator').removeClass('hovered--before'); - } - }); - - $('body').on('mouseenter mouseleave', '.post.post--comment.same--root', function mouseOver(ev) { - if (ev.type === 'mouseenter') { - $(this).parent('div').prev('.date-separator, .new-separator').addClass('hovered--comment'); - $(this).parent('div').next('.date-separator, .new-separator').addClass('hovered--comment'); - } else { - $(this).parent('div').prev('.date-separator, .new-separator').removeClass('hovered--comment'); - $(this).parent('div').next('.date-separator, .new-separator').removeClass('hovered--comment'); - } - }); - - /* Prevent backspace from navigating back a page */ - $(window).on('keydown.preventBackspace', (e) => { - if (e.which === 8 && !$(e.target).is('input, textarea')) { - e.preventDefault(); - } - }); - } - componentWillUnmount() { - clearInterval(this.intervalId); - - $(window).off('focus'); - $(window).off('blur'); - - SocketStore.removeChangeListener(this.onSocketChange); - - $('body').off('click.userpopover'); - $('body').off('mouseenter mouseleave', '.post'); - $('body').off('mouseenter mouseleave', '.post.post--comment.same--root'); - - $('.modal').off('show.bs.modal'); - - $(window).off('keydown.preventBackspace'); - } - onSocketChange(msg) { - if (msg && msg.user_id && msg.user_id !== UserStore.getCurrentId()) { - UserStore.setStatus(msg.user_id, 'online'); - } - } - render() { - return <div/>; - } -} - -ChannelLoader.propTypes = { - intl: intlShape.isRequired -}; - -export default injectIntl(ChannelLoader); |