summaryrefslogtreecommitdiffstats
path: root/web/react/components/channel_loader.jsx
blob: 5252f275c2df7449f04996ede0c03cc8ac4352d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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/>;
    }
});