summaryrefslogtreecommitdiffstats
path: root/web/react/utils
diff options
context:
space:
mode:
Diffstat (limited to 'web/react/utils')
-rw-r--r--web/react/utils/async_client.jsx55
-rw-r--r--web/react/utils/channel_intro_messages.jsx49
-rw-r--r--web/react/utils/client.jsx179
-rw-r--r--web/react/utils/constants.jsx5
-rw-r--r--web/react/utils/utils.jsx33
5 files changed, 183 insertions, 138 deletions
diff --git a/web/react/utils/async_client.jsx b/web/react/utils/async_client.jsx
index 7d5e1bd0f..b9770a6e9 100644
--- a/web/react/utils/async_client.jsx
+++ b/web/react/utils/async_client.jsx
@@ -2,6 +2,7 @@
// See License.txt for license information.
import * as client from './client.jsx';
+import * as GlobalActions from '../action_creators/global_actions.jsx';
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
import BrowserStore from '../stores/browser_store.jsx';
import ChannelStore from '../stores/channel_store.jsx';
@@ -44,15 +45,19 @@ function isCallInProgress(callName) {
export function getChannels(checkVersion) {
if (isCallInProgress('getChannels')) {
- return;
+ return null;
}
callTracker.getChannels = utils.getTimestamp();
- client.getChannels(
+ return client.getChannels(
(data, textStatus, xhr) => {
callTracker.getChannels = 0;
+ if (xhr.status === 304 || !data) {
+ return;
+ }
+
if (checkVersion) {
var serverVersion = xhr.getResponseHeader('X-Version-ID');
@@ -67,10 +72,6 @@ export function getChannels(checkVersion) {
}
}
- if (xhr.status === 304 || !data) {
- return;
- }
-
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNELS,
channels: data.channels,
@@ -392,36 +393,6 @@ export function getAllTeams() {
);
}
-export function findTeams(email) {
- if (isCallInProgress('findTeams_' + email)) {
- return;
- }
-
- var user = UserStore.getCurrentUser();
- if (user) {
- callTracker['findTeams_' + email] = utils.getTimestamp();
- client.findTeams(
- user.email,
- function findTeamsSuccess(data, textStatus, xhr) {
- callTracker['findTeams_' + email] = 0;
-
- if (xhr.status === 304 || !data) {
- return;
- }
-
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_TEAMS,
- teams: data
- });
- },
- function findTeamsFailure(err) {
- callTracker['findTeams_' + email] = 0;
- dispatchError(err, 'findTeams');
- }
- );
- }
-}
-
export function search(terms) {
if (isCallInProgress('search_' + String(terms))) {
return;
@@ -645,11 +616,11 @@ export function getPostsAfter(postId, offset, numPost) {
export function getMe() {
if (isCallInProgress('getMe')) {
- return;
+ return null;
}
callTracker.getMe = utils.getTimestamp();
- client.getMe(
+ return client.getMe(
(data, textStatus, xhr) => {
callTracker.getMe = 0;
@@ -661,6 +632,8 @@ export function getMe() {
type: ActionTypes.RECEIVED_ME,
me: data
});
+
+ GlobalActions.newLocalizationSelected(data.locale);
},
(err) => {
callTracker.getMe = 0;
@@ -706,11 +679,11 @@ export function getStatuses() {
export function getMyTeam() {
if (isCallInProgress('getMyTeam')) {
- return;
+ return null;
}
callTracker.getMyTeam = utils.getTimestamp();
- client.getMyTeam(
+ return client.getMyTeam(
function getMyTeamSuccess(data, textStatus, xhr) {
callTracker.getMyTeam = 0;
@@ -719,7 +692,7 @@ export function getMyTeam() {
}
AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_TEAM,
+ type: ActionTypes.RECEIVED_MY_TEAM,
team: data
});
},
diff --git a/web/react/utils/channel_intro_messages.jsx b/web/react/utils/channel_intro_messages.jsx
index ed94f94b8..94f3f0ce0 100644
--- a/web/react/utils/channel_intro_messages.jsx
+++ b/web/react/utils/channel_intro_messages.jsx
@@ -8,8 +8,7 @@ import ToggleModalButton from '../components/toggle_modal_button.jsx';
import UserProfile from '../components/user_profile.jsx';
import ChannelStore from '../stores/channel_store.jsx';
import Constants from '../utils/constants.jsx';
-import TeamStore from '../stores/team_store.jsx';
-import * as EventHelpers from '../dispatcher/event_helpers.jsx';
+import * as GlobalActions from '../action_creators/global_actions.jsx';
import {FormattedMessage, FormattedHTMLMessage, FormattedDate} from 'mm-intl';
@@ -40,7 +39,7 @@ export function createDMIntroMessage(channel) {
<div className='post-profile-img__container channel-intro-img'>
<img
className='post-profile-img'
- src={'/api/v1/users/' + teammate.id + '/image?time=' + teammate.update_at + '&' + Utils.getSessionIndex()}
+ src={'/api/v1/users/' + teammate.id + '/image?time=' + teammate.update_at}
height='50'
width='50'
/>
@@ -93,37 +92,19 @@ export function createOffTopicIntroMessage(channel) {
}
export function createDefaultIntroMessage(channel) {
- const team = TeamStore.getCurrent();
- let inviteModalLink;
- if (team.type === Constants.INVITE_TEAM) {
- inviteModalLink = (
- <a
- className='intro-links'
- href='#'
- onClick={EventHelpers.showInviteMemberModal}
- >
- <i className='fa fa-user-plus'></i>
- <FormattedMessage
- id='intro_messages.inviteOthers'
- defaultMessage='Invite others to this team'
- />
- </a>
- );
- } else {
- inviteModalLink = (
- <a
- className='intro-links'
- href='#'
- onClick={EventHelpers.showGetTeamInviteLinkModal}
- >
- <i className='fa fa-user-plus'></i>
- <FormattedMessage
- id='intro_messages.inviteOthers'
- defaultMessage='Invite others to this team'
- />
- </a>
- );
- }
+ const inviteModalLink = (
+ <a
+ className='intro-links'
+ href='#'
+ onClick={GlobalActions.showGetTeamInviteLinkModal}
+ >
+ <i className='fa fa-user-plus'></i>
+ <FormattedMessage
+ id='intro_messages.inviteOthers'
+ defaultMessage='Invite others to this team'
+ />
+ </a>
+ );
return (
<div className='channel-intro'>
diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx
index 76d42137a..e00f28a14 100644
--- a/web/react/utils/client.jsx
+++ b/web/react/utils/client.jsx
@@ -1,8 +1,8 @@
// See License.txt for license information.
import BrowserStore from '../stores/browser_store.jsx';
-import TeamStore from '../stores/team_store.jsx';
-import ErrorStore from '../stores/error_store.jsx';
+
+import {browserHistory} from 'react-router';
let translations = {
connectionError: 'There appears to be a problem with your internet connection.',
@@ -50,10 +50,10 @@ function handleError(methodName, xhr, status, err) {
if (xhr.status === 401) {
if (window.location.href.indexOf('/channels') === 0) {
- window.location.pathname = '/login?redirect=' + encodeURIComponent(window.location.pathname + window.location.search);
+ browserHistory.push('/login?extra=expired&redirect=' + encodeURIComponent(window.location.pathname + window.location.search));
} else {
- var teamURL = window.location.href.split('/channels')[0];
- window.location.href = teamURL + '/login?redirect=' + encodeURIComponent(window.location.pathname + window.location.search);
+ var teamURL = window.location.pathname.split('/channels')[0];
+ browserHistory.push(teamURL + '/login?extra=expired&redirect=' + encodeURIComponent(window.location.pathname + window.location.search));
}
}
@@ -289,13 +289,17 @@ export function switchToEmail(data, success, error) {
track('api', 'api_users_switch_to_email');
}
-export function logout() {
+export function logout(success, error) {
track('api', 'api_users_logout');
- var currentTeamUrl = TeamStore.getCurrentTeamUrl();
- BrowserStore.signalLogout();
- BrowserStore.clear();
- ErrorStore.clearLastError();
- window.location.href = currentTeamUrl + '/logout';
+ $.ajax({
+ url: '/api/v1/users/logout',
+ type: 'POST',
+ success,
+ error: function onError(xhr, status, err) {
+ var e = handleError('logout', xhr, status, err);
+ error(e);
+ }
+ });
}
export function loginByEmail(name, email, password, success, error) {
@@ -437,7 +441,7 @@ export function getServerAudits(success, error) {
}
export function getConfig(success, error) {
- $.ajax({
+ return $.ajax({
url: '/api/v1/admin/config',
dataType: 'json',
contentType: 'application/json',
@@ -457,7 +461,6 @@ export function getAnalytics(name, teamId, success, error) {
} else {
url += teamId + '/' + name;
}
-
$.ajax({
url,
dataType: 'json',
@@ -471,6 +474,34 @@ export function getAnalytics(name, teamId, success, error) {
});
}
+export function getClientConfig(success, error) {
+ return $.ajax({
+ url: '/api/v1/admin/client_props',
+ dataType: 'json',
+ contentType: 'application/json',
+ type: 'GET',
+ success,
+ error: function onError(xhr, status, err) {
+ var e = handleError('getClientConfig', xhr, status, err);
+ error(e);
+ }
+ });
+}
+
+export function getTeamAnalytics(teamId, name, success, error) {
+ $.ajax({
+ url: '/api/v1/admin/analytics/' + teamId + '/' + name,
+ dataType: 'json',
+ contentType: 'application/json',
+ type: 'GET',
+ success,
+ error: (xhr, status, err) => {
+ var e = handleError('getTeamAnalytics', xhr, status, err);
+ error(e);
+ }
+ });
+}
+
export function saveConfig(config, success, error) {
$.ajax({
url: '/api/v1/admin/save_config',
@@ -529,6 +560,21 @@ export function getAllTeams(success, error) {
});
}
+export function getMeLoggedIn(success, error) {
+ return $.ajax({
+ cache: false,
+ url: '/api/v1/users/me_logged_in',
+ dataType: 'json',
+ contentType: 'application/json',
+ type: 'GET',
+ success,
+ error: function onError(xhr, status, err) {
+ var e = handleError('getMeLoggedIn', xhr, status, err);
+ error(e);
+ }
+ });
+}
+
export function getMe(success, error) {
var currentUser = null;
$.ajax({
@@ -635,38 +681,6 @@ export function findTeamByName(teamName, success, error) {
});
}
-export function findTeamsSendEmail(email, success, error) {
- $.ajax({
- url: '/api/v1/teams/email_teams',
- dataType: 'json',
- contentType: 'application/json',
- type: 'POST',
- data: JSON.stringify({email: email}),
- success,
- error: function onError(xhr, status, err) {
- var e = handleError('findTeamsSendEmail', xhr, status, err);
- error(e);
- }
- });
-
- track('api', 'api_teams_email_teams');
-}
-
-export function findTeams(email, success, error) {
- $.ajax({
- url: '/api/v1/teams/find_teams',
- dataType: 'json',
- contentType: 'application/json',
- type: 'POST',
- data: JSON.stringify({email: email}),
- success,
- error: function onError(xhr, status, err) {
- var e = handleError('findTeams', xhr, status, err);
- error(e);
- }
- });
-}
-
export function createChannel(channel, success, error) {
$.ajax({
url: '/api/v1/channels/create',
@@ -835,7 +849,7 @@ export function updateLastViewedAt(channelId, success, error) {
}
export function getChannels(success, error) {
- $.ajax({
+ return $.ajax({
cache: false,
url: '/api/v1/channels/',
dataType: 'json',
@@ -901,7 +915,7 @@ export function getChannelExtraInfo(id, memberLimit, success, error) {
url += '/' + memberLimit;
}
- $.ajax({
+ return $.ajax({
url,
dataType: 'json',
contentType: 'application/json',
@@ -1018,7 +1032,7 @@ export function getPostsPage(channelId, offset, limit, success, error, complete)
}
export function getPosts(channelId, since, success, error, complete) {
- $.ajax({
+ return $.ajax({
url: '/api/v1/channels/' + channelId + '/posts/' + since,
dataType: 'json',
type: 'GET',
@@ -1347,7 +1361,7 @@ export function getStatuses(ids, success, error) {
}
export function getMyTeam(success, error) {
- $.ajax({
+ return $.ajax({
url: '/api/v1/teams/me',
dataType: 'json',
type: 'GET',
@@ -1437,7 +1451,7 @@ export function listIncomingHooks(success, error) {
}
export function getAllPreferences(success, error) {
- $.ajax({
+ return $.ajax({
url: '/api/v1/preferences/',
dataType: 'json',
type: 'GET',
@@ -1569,3 +1583,68 @@ export function removeLicenseFile(success, error) {
track('api', 'api_license_upload');
}
+
+export function getClientLicenceConfig(success, error) {
+ return $.ajax({
+ url: '/api/v1/license/client_config',
+ dataType: 'json',
+ contentType: 'application/json',
+ type: 'GET',
+ success,
+ error: function onError(xhr, status, err) {
+ var e = handleError('getClientLicenceConfig', xhr, status, err);
+ error(e);
+ }
+ });
+}
+
+export function getInviteInfo(success, error, id) {
+ $.ajax({
+ url: '/api/v1/teams/get_invite_info',
+ type: 'POST',
+ dataType: 'json',
+ contentType: 'application/json',
+ data: JSON.stringify({invite_id: id}),
+ success,
+ error: function onError(xhr, status, err) {
+ var e = handleError('getInviteInfo', xhr, status, err);
+ if (error) {
+ error(e);
+ }
+ }
+ });
+}
+
+export function verifyEmail(success, error, uid, hid) {
+ $.ajax({
+ url: '/api/v1/users/verify_email',
+ type: 'POST',
+ contentType: 'application/json',
+ dataType: 'text',
+ data: JSON.stringify({uid, hid}),
+ success,
+ error: function onError(xhr, status, err) {
+ var e = handleError('verifyEmail', xhr, status, err);
+ if (error) {
+ error(e);
+ }
+ }
+ });
+}
+
+export function resendVerification(success, error, teamName, email) {
+ $.ajax({
+ url: '/api/v1/users/resend_verification',
+ type: 'POST',
+ contentType: 'application/json',
+ dataType: 'text',
+ data: JSON.stringify({team_name: teamName, email}),
+ success,
+ error: function onError(xhr, status, err) {
+ var e = handleError('resendVerification', xhr, status, err);
+ if (error) {
+ error(e);
+ }
+ }
+ });
+}
diff --git a/web/react/utils/constants.jsx b/web/react/utils/constants.jsx
index daea9f43e..2cff4dbed 100644
--- a/web/react/utils/constants.jsx
+++ b/web/react/utils/constants.jsx
@@ -42,13 +42,15 @@ export default {
RECEIVED_MSG: null,
- RECEIVED_TEAM: null,
+ RECEIVED_MY_TEAM: null,
RECEIVED_CONFIG: null,
RECEIVED_LOGS: null,
RECEIVED_SERVER_AUDITS: null,
RECEIVED_ALL_TEAMS: null,
+ RECEIVED_LOCALE: null,
+
SHOW_SEARCH: null,
TOGGLE_IMPORT_THEME_MODAL: null,
@@ -143,6 +145,7 @@ export default {
EMAIL_SERVICE: 'email',
SIGNIN_CHANGE: 'signin_change',
SIGNIN_VERIFIED: 'verified',
+ SESSION_EXPIRED: 'expired',
POST_CHUNK_SIZE: 60,
MAX_POST_CHUNKS: 3,
POST_FOCUS_CONTEXT_RADIUS: 10,
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index 6942a8e08..88777164b 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -2,9 +2,10 @@
// See License.txt for license information.
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
-import * as EventHelpers from '../dispatcher/event_helpers.jsx';
+import * as GlobalActions from '../action_creators/global_actions.jsx';
import ChannelStore from '../stores/channel_store.jsx';
import UserStore from '../stores/user_store.jsx';
+import LocalizationStore from '../stores/localization_store.jsx';
import PreferenceStore from '../stores/preference_store.jsx';
import TeamStore from '../stores/team_store.jsx';
import Constants from '../utils/constants.jsx';
@@ -941,7 +942,7 @@ export function updateAddressBar(channelName) {
}
export function switchChannel(channel) {
- EventHelpers.emitChannelClickEvent(channel);
+ GlobalActions.emitChannelClickEvent(channel);
updateAddressBar(channel.name);
@@ -1130,8 +1131,8 @@ export function fileSizeToString(bytes) {
// Converts a filename (like those attached to Post objects) to a url that can be used to retrieve attachments from the server.
export function getFileUrl(filename, isDownload) {
- const downloadParam = isDownload ? '&download=1' : '';
- return getWindowLocationOrigin() + '/api/v1/files/get' + filename + '?' + getSessionIndex() + downloadParam;
+ const downloadParam = isDownload ? '?download=1' : '';
+ return getWindowLocationOrigin() + '/api/v1/files/get' + filename + downloadParam;
}
// Gets the name of a file (including extension) from a given url or file path.
@@ -1151,14 +1152,6 @@ export function getWebsocketPort(protocol) {
return '';
}
-export function getSessionIndex() {
- if (global.window.mm_session_token_index >= 0) {
- return 'session_token_index=' + global.window.mm_session_token_index;
- }
-
- return '';
-}
-
// Generates a RFC-4122 version 4 compliant globally unique identifier.
export function generateId() {
// implementation taken from http://stackoverflow.com/a/2117523
@@ -1405,3 +1398,19 @@ export function isPostEphemeral(post) {
export function getRootId(post) {
return post.root_id === '' ? post.id : post.root_id;
}
+
+export function localizeMessage(id, defaultMessage) {
+ const translations = LocalizationStore.getTranslations();
+ if (translations) {
+ const value = translations[id];
+ if (value) {
+ return value;
+ }
+ }
+
+ if (defaultMessage) {
+ return defaultMessage;
+ }
+
+ return id;
+}