diff options
author | enahum <nahumhbl@gmail.com> | 2016-05-31 09:14:59 -0300 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2016-05-31 08:14:59 -0400 |
commit | 64cce071a9ae28444e95b6389b229d80f20acf68 (patch) | |
tree | b42ec402f2c52c27d78d1458c6bbe6f2e6e70552 | |
parent | f920b80e54f83f797a2c2e4fdec527ee701238c1 (diff) | |
download | chat-64cce071a9ae28444e95b6389b229d80f20acf68.tar.gz chat-64cce071a9ae28444e95b6389b229d80f20acf68.tar.bz2 chat-64cce071a9ae28444e95b6389b229d80f20acf68.zip |
PLT-3061 Load user statuses as soon as possible (#3132)
-rw-r--r-- | webapp/components/logged_in.jsx | 85 |
1 files changed, 43 insertions, 42 deletions
diff --git a/webapp/components/logged_in.jsx b/webapp/components/logged_in.jsx index 0c37d62cb..dce92dd64 100644 --- a/webapp/components/logged_in.jsx +++ b/webapp/components/logged_in.jsx @@ -25,6 +25,46 @@ export default class LoggedIn extends React.Component { this.onUserChanged = this.onUserChanged.bind(this); this.setupUser = this.setupUser.bind(this); + // Initalize websockets + Websockets.initialize(); + + // Force logout of all tabs if one tab is logged out + $(window).bind('storage', (e) => { + // when one tab on a browser logs out, it sets __logout__ in localStorage to trigger other tabs to log out + if (e.originalEvent.key === '__logout__' && e.originalEvent.storageArea === localStorage && e.originalEvent.newValue) { + // make sure it isn't this tab that is sending the logout signal (only necessary for IE11) + if (BrowserStore.isSignallingLogout(e.originalEvent.newValue)) { + return; + } + + console.log('detected logout from a different tab'); //eslint-disable-line no-console + browserHistory.push('/'); + } + + if (e.originalEvent.key === '__login__' && e.originalEvent.storageArea === localStorage && e.originalEvent.newValue) { + // make sure it isn't this tab that is sending the logout signal (only necessary for IE11) + if (BrowserStore.isSignallingLogin(e.originalEvent.newValue)) { + return; + } + + console.log('detected login from a different tab'); //eslint-disable-line no-console + location.reload(); + } + }); + + // Because current CSS requires the root tag to have specific stuff + $('#root').attr('class', 'channel-view'); + + // Device tracking setup + var iOS = (/(iPad|iPhone|iPod)/g).test(navigator.userAgent); + if (iOS) { + $('body').addClass('ios'); + } + + // 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); + this.state = { user: UserStore.getCurrentUser() }; @@ -71,43 +111,14 @@ export default class LoggedIn extends React.Component { } } - componentWillMount() { + componentDidMount() { // Listen for user UserStore.addChangeListener(this.onUserChanged); - // Initalize websockets - Websockets.initialize(); - // Get all statuses regularally. (Soon to be switched to websocket) + AsyncClient.getStatuses(); this.intervalId = setInterval(() => AsyncClient.getStatuses(), CLIENT_STATUS_INTERVAL); - // Force logout of all tabs if one tab is logged out - $(window).bind('storage', (e) => { - // when one tab on a browser logs out, it sets __logout__ in localStorage to trigger other tabs to log out - if (e.originalEvent.key === '__logout__' && e.originalEvent.storageArea === localStorage && e.originalEvent.newValue) { - // make sure it isn't this tab that is sending the logout signal (only necessary for IE11) - if (BrowserStore.isSignallingLogout(e.originalEvent.newValue)) { - return; - } - - console.log('detected logout from a different tab'); //eslint-disable-line no-console - browserHistory.push('/'); - } - - if (e.originalEvent.key === '__login__' && e.originalEvent.storageArea === localStorage && e.originalEvent.newValue) { - // make sure it isn't this tab that is sending the logout signal (only necessary for IE11) - if (BrowserStore.isSignallingLogin(e.originalEvent.newValue)) { - return; - } - - console.log('detected login from a different tab'); //eslint-disable-line no-console - location.reload(); - } - }); - - // Because current CSS requires the root tag to have specific stuff - $('#root').attr('class', 'channel-view'); - // ??? $('body').on('mouseenter mouseleave', '.post', function mouseOver(ev) { if (ev.type === 'mouseenter') { @@ -139,16 +150,6 @@ export default class LoggedIn extends React.Component { } }); - // Device tracking setup - var iOS = (/(iPad|iPhone|iPod)/g).test(navigator.userAgent); - if (iOS) { - $('body').addClass('ios'); - } - - // 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); - // Pervent backspace from navigating back a page $(window).on('keydown.preventBackspace', (e) => { if (e.which === BACKSPACE_CHAR && !$(e.target).is('input, textarea')) { @@ -186,4 +187,4 @@ export default class LoggedIn extends React.Component { LoggedIn.propTypes = { children: React.PropTypes.object -}; +};
\ No newline at end of file |