diff options
author | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
commit | 56e74239d6b34df8f30ef046f0b0ff4ff0866a71 (patch) | |
tree | 044da29848cf0f5c8607eac34de69065171669cf /web/react/components/channel_loader.jsx | |
download | chat-56e74239d6b34df8f30ef046f0b0ff4ff0866a71.tar.gz chat-56e74239d6b34df8f30ef046f0b0ff4ff0866a71.tar.bz2 chat-56e74239d6b34df8f30ef046f0b0ff4ff0866a71.zip |
first commit
Diffstat (limited to 'web/react/components/channel_loader.jsx')
-rw-r--r-- | web/react/components/channel_loader.jsx | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/web/react/components/channel_loader.jsx b/web/react/components/channel_loader.jsx new file mode 100644 index 000000000..5252f275c --- /dev/null +++ b/web/react/components/channel_loader.jsx @@ -0,0 +1,62 @@ +// Copyright (c) 2015 Spinpunch, 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. */ + +var AsyncClient = require('../utils/async_client.jsx'); +var SocketStore = require('../stores/socket_store.jsx'); +var Constants = require('../utils/constants.jsx'); + +module.exports = React.createClass({ + componentDidMount: function() { + /* Start initial aysnc loads */ + AsyncClient.getMe(); + AsyncClient.getPosts(true); + AsyncClient.getChannels(true, true); + AsyncClient.getChannelExtraInfo(true); + AsyncClient.findTeams(); + AsyncClient.getStatuses(); + /* End of async loads */ + + + /* Start interval functions */ + setInterval(function(){AsyncClient.getStatuses();}, 30000); + /* End interval functions */ + + + /* Start device tracking setup */ + var iOS = /(iPad|iPhone|iPod)/g.test( navigator.userAgent ); + if (iOS) { + $("body").addClass("ios"); + } + /* End device tracking setup */ + + + /* Start window active tracking setup */ + window.isActive = true; + + $(window).focus(function() { + AsyncClient.updateLastViewedAt(); + window.isActive = true; + }); + + $(window).blur(function() { + window.isActive = false; + }); + /* End window active tracking setup */ + + /* Start global change listeners setup */ + SocketStore.addChangeListener(this._onSocketChange); + /* End global change listeners setup */ + }, + _onSocketChange: function(msg) { + if (msg && msg.user_id) { + UserStore.setStatus(msg.user_id, "online"); + } + }, + render: function() { + return <div/>; + } +}); |