diff options
author | George Goldberg <george@gberg.me> | 2017-03-17 16:29:26 +0000 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2017-03-17 16:29:26 +0000 |
commit | 7f266c19511171f509ae8a60170de10c8d10b41e (patch) | |
tree | 04cd68ac4722313abec3ea47cc7cda229e463b1d /webapp/actions | |
parent | bfae88e60c7a623afae82e06ce1421ca778c06e7 (diff) | |
parent | 8568afe5b4fb4d26b14fbc0d21f088eaa490b314 (diff) | |
download | chat-7f266c19511171f509ae8a60170de10c8d10b41e.tar.gz chat-7f266c19511171f509ae8a60170de10c8d10b41e.tar.bz2 chat-7f266c19511171f509ae8a60170de10c8d10b41e.zip |
Merge branch 'release-3.7' into master.
Diffstat (limited to 'webapp/actions')
-rw-r--r-- | webapp/actions/channel_actions.jsx | 29 | ||||
-rw-r--r-- | webapp/actions/global_actions.jsx | 4 | ||||
-rw-r--r-- | webapp/actions/user_actions.jsx | 4 | ||||
-rw-r--r-- | webapp/actions/websocket_actions.jsx | 20 |
4 files changed, 49 insertions, 8 deletions
diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx index 5d3a9db35..acbc943cf 100644 --- a/webapp/actions/channel_actions.jsx +++ b/webapp/actions/channel_actions.jsx @@ -9,14 +9,14 @@ import ChannelStore from 'stores/channel_store.jsx'; import * as ChannelUtils from 'utils/channel_utils.jsx'; import PreferenceStore from 'stores/preference_store.jsx'; -import {loadProfilesForSidebar} from 'actions/user_actions.jsx'; +import {loadProfilesForSidebar, loadNewDMIfNeeded, loadNewGMIfNeeded} from 'actions/user_actions.jsx'; import {trackEvent} from 'actions/diagnostics_actions.jsx'; import Client from 'client/web_client.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; import * as UserAgent from 'utils/user_agent.jsx'; import * as Utils from 'utils/utils.jsx'; -import {Preferences, ActionTypes} from 'utils/constants.jsx'; +import {Constants, Preferences, ActionTypes} from 'utils/constants.jsx'; import {browserHistory} from 'react-router/es6'; @@ -283,8 +283,29 @@ export function unmarkFavorite(channelId) { } export function loadChannelsForCurrentUser() { - AsyncClient.getChannels(); - AsyncClient.getMyChannelMembers(); + AsyncClient.getChannels().then(() => { + AsyncClient.getMyChannelMembers().then(() => { + loadDMsAndGMsForUnreads(); + }); + }); +} + +export function loadDMsAndGMsForUnreads() { + const unreads = ChannelStore.getUnreadCounts(); + for (const id in unreads) { + if (!unreads.hasOwnProperty(id)) { + continue; + } + + if (unreads[id].msgs > 0 || unreads[id].mentions > 0) { + const channel = ChannelStore.get(id); + if (channel && channel.type === Constants.DM_CHANNEL) { + loadNewDMIfNeeded(Utils.getUserIdFromChannelName(channel)); + } else if (channel && channel.type === Constants.GM_CHANNEL) { + loadNewGMIfNeeded(channel.id); + } + } + } } export function joinChannel(channel, success, error) { diff --git a/webapp/actions/global_actions.jsx b/webapp/actions/global_actions.jsx index e22c94294..c81478069 100644 --- a/webapp/actions/global_actions.jsx +++ b/webapp/actions/global_actions.jsx @@ -46,10 +46,10 @@ export function emitChannelClickEvent(channel) { } function switchToChannel(chan) { const channelMember = ChannelStore.getMyMember(chan.id); - const getMyChannelMembersPromise = AsyncClient.getChannelMember(chan.id, UserStore.getCurrentId()); + const getMyChannelMemberPromise = AsyncClient.getChannelMember(chan.id, UserStore.getCurrentId()); const oldChannelId = ChannelStore.getCurrentId(); - getMyChannelMembersPromise.then(() => { + getMyChannelMemberPromise.then(() => { AsyncClient.getChannelStats(chan.id, true); AsyncClient.viewChannel(chan.id, oldChannelId); loadPosts(chan.id); diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx index 0f6ac3e9f..231b09f11 100644 --- a/webapp/actions/user_actions.jsx +++ b/webapp/actions/user_actions.jsx @@ -304,7 +304,7 @@ export function loadProfilesForGM() { if (!isVisible) { const member = ChannelStore.getMyMember(channel.id); - if (!member || (member.mention_count === 0 && member.msg_count < member.total_msg_count)) { + if (!member || (member.mention_count === 0 && member.msg_count >= channel.total_msg_count)) { continue; } @@ -645,7 +645,7 @@ export function checkMfa(loginId, success, error) { loginId, (data) => { if (success) { - success(data); + success(data && data.mfa_required === 'true'); } }, (err) => { diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx index 913a89221..e36d11fde 100644 --- a/webapp/actions/websocket_actions.jsx +++ b/webapp/actions/websocket_actions.jsx @@ -89,6 +89,26 @@ export function reconnect(includeWebSocket = true) { ErrorStore.emitChange(); } +let intervalId = ''; +const SYNC_INTERVAL_MILLISECONDS = 1000 * 60 * 15; // 15 minutes + +export function startPeriodicSync() { + clearInterval(intervalId); + + intervalId = setInterval( + () => { + if (UserStore.getCurrentUser() != null) { + reconnect(false); + } + }, + SYNC_INTERVAL_MILLISECONDS + ); +} + +export function stopPeriodicSync() { + clearInterval(intervalId); +} + function handleFirstConnect() { ErrorStore.clearLastError(); ErrorStore.emitChange(); |