mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Add sync logic for DMs/GMs when network reconnects (#5676)
This commit is contained in:
committed by
George Goldberg
parent
2bea17251e
commit
db7540b111
@@ -9,14 +9,14 @@ import ChannelStore from 'stores/channel_store.jsx';
|
|||||||
import * as ChannelUtils from 'utils/channel_utils.jsx';
|
import * as ChannelUtils from 'utils/channel_utils.jsx';
|
||||||
import PreferenceStore from 'stores/preference_store.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 {trackEvent} from 'actions/diagnostics_actions.jsx';
|
||||||
|
|
||||||
import Client from 'client/web_client.jsx';
|
import Client from 'client/web_client.jsx';
|
||||||
import * as AsyncClient from 'utils/async_client.jsx';
|
import * as AsyncClient from 'utils/async_client.jsx';
|
||||||
import * as UserAgent from 'utils/user_agent.jsx';
|
import * as UserAgent from 'utils/user_agent.jsx';
|
||||||
import * as Utils from 'utils/utils.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';
|
import {browserHistory} from 'react-router/es6';
|
||||||
|
|
||||||
@@ -283,8 +283,29 @@ export function unmarkFavorite(channelId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function loadChannelsForCurrentUser() {
|
export function loadChannelsForCurrentUser() {
|
||||||
AsyncClient.getChannels();
|
AsyncClient.getChannels().then(() => {
|
||||||
AsyncClient.getMyChannelMembers();
|
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) {
|
export function joinChannel(channel, success, error) {
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ export function emitChannelClickEvent(channel) {
|
|||||||
}
|
}
|
||||||
function switchToChannel(chan) {
|
function switchToChannel(chan) {
|
||||||
const channelMember = ChannelStore.getMyMember(chan.id);
|
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();
|
const oldChannelId = ChannelStore.getCurrentId();
|
||||||
|
|
||||||
getMyChannelMembersPromise.then(() => {
|
getMyChannelMemberPromise.then(() => {
|
||||||
AsyncClient.getChannelStats(chan.id, true);
|
AsyncClient.getChannelStats(chan.id, true);
|
||||||
AsyncClient.viewChannel(chan.id, oldChannelId);
|
AsyncClient.viewChannel(chan.id, oldChannelId);
|
||||||
loadPosts(chan.id);
|
loadPosts(chan.id);
|
||||||
|
|||||||
@@ -89,6 +89,26 @@ export function reconnect(includeWebSocket = true) {
|
|||||||
ErrorStore.emitChange();
|
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() {
|
function handleFirstConnect() {
|
||||||
ErrorStore.clearLastError();
|
ErrorStore.clearLastError();
|
||||||
ErrorStore.emitChange();
|
ErrorStore.emitChange();
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import PreferenceStore from 'stores/preference_store.jsx';
|
|||||||
import ChannelStore from 'stores/channel_store.jsx';
|
import ChannelStore from 'stores/channel_store.jsx';
|
||||||
import * as GlobalActions from 'actions/global_actions.jsx';
|
import * as GlobalActions from 'actions/global_actions.jsx';
|
||||||
import {startPeriodicStatusUpdates, stopPeriodicStatusUpdates} from 'actions/status_actions.jsx';
|
import {startPeriodicStatusUpdates, stopPeriodicStatusUpdates} from 'actions/status_actions.jsx';
|
||||||
|
import {startPeriodicSync, stopPeriodicSync} from 'actions/websocket_actions.jsx';
|
||||||
|
|
||||||
import Constants from 'utils/constants.jsx';
|
import Constants from 'utils/constants.jsx';
|
||||||
const TutorialSteps = Constants.TutorialSteps;
|
const TutorialSteps = Constants.TutorialSteps;
|
||||||
const Preferences = Constants.Preferences;
|
const Preferences = Constants.Preferences;
|
||||||
@@ -94,6 +96,7 @@ export default class NeedsTeam extends React.Component {
|
|||||||
GlobalActions.viewLoggedIn();
|
GlobalActions.viewLoggedIn();
|
||||||
|
|
||||||
startPeriodicStatusUpdates();
|
startPeriodicStatusUpdates();
|
||||||
|
startPeriodicSync();
|
||||||
|
|
||||||
// Set up tracking for whether the window is active
|
// Set up tracking for whether the window is active
|
||||||
window.isActive = true;
|
window.isActive = true;
|
||||||
@@ -140,6 +143,7 @@ export default class NeedsTeam extends React.Component {
|
|||||||
iNoBounce.disable();
|
iNoBounce.disable();
|
||||||
}
|
}
|
||||||
stopPeriodicStatusUpdates();
|
stopPeriodicStatusUpdates();
|
||||||
|
stopPeriodicSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@@ -64,26 +64,31 @@ export function checkVersion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getChannels() {
|
export function getChannels() {
|
||||||
if (isCallInProgress('getChannels')) {
|
return new Promise((resolve, reject) => {
|
||||||
return null;
|
if (isCallInProgress('getChannels')) {
|
||||||
}
|
resolve();
|
||||||
|
return;
|
||||||
callTracker.getChannels = utils.getTimestamp();
|
|
||||||
|
|
||||||
return Client.getChannels(
|
|
||||||
(data) => {
|
|
||||||
callTracker.getChannels = 0;
|
|
||||||
|
|
||||||
AppDispatcher.handleServerAction({
|
|
||||||
type: ActionTypes.RECEIVED_CHANNELS,
|
|
||||||
channels: data
|
|
||||||
});
|
|
||||||
},
|
|
||||||
(err) => {
|
|
||||||
callTracker.getChannels = 0;
|
|
||||||
dispatchError(err, 'getChannels');
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
callTracker.getChannels = utils.getTimestamp();
|
||||||
|
|
||||||
|
Client.getChannels(
|
||||||
|
(data) => {
|
||||||
|
callTracker.getChannels = 0;
|
||||||
|
|
||||||
|
AppDispatcher.handleServerAction({
|
||||||
|
type: ActionTypes.RECEIVED_CHANNELS,
|
||||||
|
channels: data
|
||||||
|
});
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
callTracker.getChannels = 0;
|
||||||
|
dispatchError(err, 'getChannels');
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getChannel(id) {
|
export function getChannel(id) {
|
||||||
@@ -130,7 +135,7 @@ export function getMyChannelMembers() {
|
|||||||
resolve();
|
resolve();
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
callTracker.getChannelsUnread = 0;
|
callTracker.getMyChannelMembers = 0;
|
||||||
dispatchError(err, 'getMyChannelMembers');
|
dispatchError(err, 'getMyChannelMembers');
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user