summaryrefslogtreecommitdiffstats
path: root/webapp/utils
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/utils')
-rw-r--r--webapp/utils/async_client.jsx60
-rw-r--r--webapp/utils/channel_intro_messages.jsx37
-rw-r--r--webapp/utils/constants.jsx237
-rw-r--r--webapp/utils/text_formatting.jsx21
-rw-r--r--webapp/utils/utils.jsx10
-rw-r--r--webapp/utils/websocket_client.jsx7
6 files changed, 228 insertions, 144 deletions
diff --git a/webapp/utils/async_client.jsx b/webapp/utils/async_client.jsx
index e55742140..b31a2a6b9 100644
--- a/webapp/utils/async_client.jsx
+++ b/webapp/utils/async_client.jsx
@@ -145,6 +145,43 @@ export function updateLastViewedAt(id) {
);
}
+export function setLastViewedAt(lastViewedAt, id) {
+ let channelId;
+ if (id) {
+ channelId = id;
+ } else {
+ channelId = ChannelStore.getCurrentId();
+ }
+
+ if (channelId == null) {
+ return;
+ }
+
+ if (lastViewedAt == null) {
+ return;
+ }
+
+ if (isCallInProgress(`setLastViewedAt${channelId}${lastViewedAt}`)) {
+ return;
+ }
+
+ callTracker[`setLastViewedAt${channelId}${lastViewedAt}`] = utils.getTimestamp();
+ Client.setLastViewedAt(
+ channelId,
+ lastViewedAt,
+ () => {
+ callTracker.setLastViewedAt = 0;
+ ErrorStore.clearLastError();
+ },
+ (err) => {
+ callTracker.setLastViewedAt = 0;
+ var count = ErrorStore.getConnectionErrorCount();
+ ErrorStore.setConnectionErrorCount(count + 1);
+ dispatchError(err, 'setLastViewedAt');
+ }
+ );
+}
+
export function getMoreChannels(force) {
if (isCallInProgress('getMoreChannels')) {
return;
@@ -815,6 +852,29 @@ export function savePreferences(preferences, success, error) {
);
}
+export function deletePreferences(preferences, success, error) {
+ Client.deletePreferences(
+ preferences,
+ (data) => {
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.DELETED_PREFERENCES,
+ preferences
+ });
+
+ if (success) {
+ success(data);
+ }
+ },
+ (err) => {
+ dispatchError(err, 'deletePreferences');
+
+ if (error) {
+ error();
+ }
+ }
+ );
+}
+
export function getSuggestedCommands(command, suggestionId, component) {
Client.listCommands(
(data) => {
diff --git a/webapp/utils/channel_intro_messages.jsx b/webapp/utils/channel_intro_messages.jsx
index 50d12ed42..6418615a4 100644
--- a/webapp/utils/channel_intro_messages.jsx
+++ b/webapp/utils/channel_intro_messages.jsx
@@ -16,20 +16,25 @@ import Client from 'utils/web_client.jsx';
import React from 'react';
import {FormattedMessage, FormattedHTMLMessage, FormattedDate} from 'react-intl';
-export function createChannelIntroMessage(channel) {
+export function createChannelIntroMessage(channel, fullWidthIntro) {
+ let centeredIntro = '';
+ if (!fullWidthIntro) {
+ centeredIntro = 'channel-intro--centered';
+ }
+
if (channel.type === 'D') {
- return createDMIntroMessage(channel);
+ return createDMIntroMessage(channel, centeredIntro);
} else if (ChannelStore.isDefault(channel)) {
- return createDefaultIntroMessage(channel);
+ return createDefaultIntroMessage(channel, centeredIntro);
} else if (channel.name === Constants.OFFTOPIC_CHANNEL) {
- return createOffTopicIntroMessage(channel);
+ return createOffTopicIntroMessage(channel, centeredIntro);
} else if (channel.type === 'O' || channel.type === 'P') {
- return createStandardIntroMessage(channel);
+ return createStandardIntroMessage(channel, centeredIntro);
}
return null;
}
-export function createDMIntroMessage(channel) {
+export function createDMIntroMessage(channel, centeredIntro) {
var teammate = Utils.getDirectTeammate(channel.id);
if (teammate) {
@@ -39,7 +44,7 @@ export function createDMIntroMessage(channel) {
}
return (
- <div className='channel-intro'>
+ <div className={'channel-intro ' + centeredIntro}>
<div className='post-profile-img__container channel-intro-img'>
<img
className='post-profile-img'
@@ -68,7 +73,7 @@ export function createDMIntroMessage(channel) {
}
return (
- <div className='channel-intro'>
+ <div className={'channel-intro ' + centeredIntro}>
<p className='channel-intro-text'>
<FormattedMessage
id='intro_messages.teammate'
@@ -79,9 +84,9 @@ export function createDMIntroMessage(channel) {
);
}
-export function createOffTopicIntroMessage(channel) {
+export function createOffTopicIntroMessage(channel, centeredIntro) {
return (
- <div className='channel-intro'>
+ <div className={'channel-intro ' + centeredIntro}>
<FormattedHTMLMessage
id='intro_messages.offTopic'
defaultMessage='<h4 class="channel-intro__title">Beginning of {display_name}</h4><p class="channel-intro__content">This is the start of {display_name}, a channel for non-work-related conversations.<br/></p>'
@@ -95,7 +100,7 @@ export function createOffTopicIntroMessage(channel) {
);
}
-export function createDefaultIntroMessage(channel) {
+export function createDefaultIntroMessage(channel, centeredIntro) {
let inviteModalLink = (
<a
className='intro-links'
@@ -122,7 +127,7 @@ export function createDefaultIntroMessage(channel) {
}
return (
- <div className='channel-intro'>
+ <div className={'channel-intro ' + centeredIntro}>
<FormattedHTMLMessage
id='intro_messages.default'
defaultMessage="<h4 class='channel-intro__title'>Beginning of {display_name}</h4><p class='channel-intro__content'><strong>Welcome to {display_name}!</strong><br/><br/>This is the first channel teammates see when they sign up - use it for posting updates everyone needs to know.</p>"
@@ -137,7 +142,7 @@ export function createDefaultIntroMessage(channel) {
);
}
-export function createStandardIntroMessage(channel) {
+export function createStandardIntroMessage(channel, centeredIntro) {
var uiName = channel.display_name;
var creatorName = '';
@@ -189,7 +194,7 @@ export function createStandardIntroMessage(channel) {
values={{
name: (uiName),
type: (uiType),
- date: (date)
+ date
}}
/>
);
@@ -202,7 +207,7 @@ export function createStandardIntroMessage(channel) {
values={{
name: (uiName),
type: (uiType),
- date: (date),
+ date,
creator: creatorName
}}
/>
@@ -211,7 +216,7 @@ export function createStandardIntroMessage(channel) {
}
return (
- <div className='channel-intro'>
+ <div className={'channel-intro ' + centeredIntro}>
<h4 className='channel-intro__title'>
<FormattedMessage
id='intro_messages.beginning'
diff --git a/webapp/utils/constants.jsx b/webapp/utils/constants.jsx
index 52fb23d51..d780efe30 100644
--- a/webapp/utils/constants.jsx
+++ b/webapp/utils/constants.jsx
@@ -33,100 +33,125 @@ import mattermostDarkThemeImage from 'images/themes/mattermost_dark.png';
import mattermostThemeImage from 'images/themes/mattermost.png';
import windows10ThemeImage from 'images/themes/windows_dark.png';
-export default {
- ActionTypes: keyMirror({
- RECEIVED_ERROR: null,
-
- CLICK_CHANNEL: null,
- CREATE_CHANNEL: null,
- LEAVE_CHANNEL: null,
- CREATE_POST: null,
- CREATE_COMMENT: null,
- POST_DELETED: null,
- REMOVE_POST: null,
-
- RECEIVED_CHANNELS: null,
- RECEIVED_CHANNEL: null,
- RECEIVED_MORE_CHANNELS: null,
- RECEIVED_CHANNEL_EXTRA_INFO: null,
-
- FOCUS_POST: null,
- RECEIVED_POSTS: null,
- RECEIVED_FOCUSED_POST: null,
- RECEIVED_POST: null,
- RECEIVED_EDIT_POST: null,
- RECEIVED_SEARCH: null,
- RECEIVED_SEARCH_TERM: null,
- RECEIVED_POST_SELECTED: null,
- RECEIVED_MENTION_DATA: null,
- RECEIVED_ADD_MENTION: null,
-
- RECEIVED_PROFILES_FOR_DM_LIST: null,
- RECEIVED_PROFILES: null,
- RECEIVED_DIRECT_PROFILES: null,
- RECEIVED_ME: null,
- RECEIVED_SESSIONS: null,
- RECEIVED_AUDITS: null,
- RECEIVED_TEAMS: null,
- RECEIVED_STATUSES: null,
- RECEIVED_PREFERENCE: null,
- RECEIVED_PREFERENCES: null,
- RECEIVED_FILE_INFO: null,
- RECEIVED_ANALYTICS: null,
-
- RECEIVED_INCOMING_WEBHOOKS: null,
- RECEIVED_INCOMING_WEBHOOK: null,
- REMOVED_INCOMING_WEBHOOK: null,
- RECEIVED_OUTGOING_WEBHOOKS: null,
- RECEIVED_OUTGOING_WEBHOOK: null,
- UPDATED_OUTGOING_WEBHOOK: null,
- REMOVED_OUTGOING_WEBHOOK: null,
- RECEIVED_COMMANDS: null,
- RECEIVED_COMMAND: null,
- UPDATED_COMMAND: null,
- REMOVED_COMMAND: null,
-
- RECEIVED_CUSTOM_EMOJIS: null,
- RECEIVED_CUSTOM_EMOJI: null,
- UPDATED_CUSTOM_EMOJI: null,
- REMOVED_CUSTOM_EMOJI: null,
-
- RECEIVED_MSG: null,
-
- RECEIVED_MY_TEAM: null,
- CREATED_TEAM: null,
-
- RECEIVED_CONFIG: null,
- RECEIVED_LOGS: null,
- RECEIVED_SERVER_AUDITS: null,
- RECEIVED_SERVER_COMPLIANCE_REPORTS: null,
- RECEIVED_ALL_TEAMS: null,
- RECEIVED_ALL_TEAM_LISTINGS: null,
- RECEIVED_TEAM_MEMBERS: null,
- RECEIVED_MEMBERS_FOR_TEAM: null,
-
- RECEIVED_LOCALE: null,
-
- SHOW_SEARCH: null,
-
- USER_TYPING: null,
-
- TOGGLE_IMPORT_THEME_MODAL: null,
- TOGGLE_INVITE_MEMBER_MODAL: null,
- TOGGLE_LEAVE_TEAM_MODAL: null,
- TOGGLE_DELETE_POST_MODAL: null,
- TOGGLE_GET_POST_LINK_MODAL: null,
- TOGGLE_GET_TEAM_INVITE_LINK_MODAL: null,
- TOGGLE_REGISTER_APP_MODAL: null,
- TOGGLE_GET_PUBLIC_LINK_MODAL: null,
-
- SUGGESTION_PRETEXT_CHANGED: null,
- SUGGESTION_RECEIVED_SUGGESTIONS: null,
- SUGGESTION_CLEAR_SUGGESTIONS: null,
- SUGGESTION_COMPLETE_WORD: null,
- SUGGESTION_SELECT_NEXT: null,
- SUGGESTION_SELECT_PREVIOUS: null
- }),
+export const Preferences = {
+ CATEGORY_DIRECT_CHANNEL_SHOW: 'direct_channel_show',
+ CATEGORY_DISPLAY_SETTINGS: 'display_settings',
+ DISPLAY_PREFER_NICKNAME: 'nickname_full_name',
+ DISPLAY_PREFER_FULL_NAME: 'full_name',
+ CATEGORY_ADVANCED_SETTINGS: 'advanced_settings',
+ TUTORIAL_STEP: 'tutorial_step',
+ CHANNEL_DISPLAY_MODE: 'channel_display_mode',
+ CHANNEL_DISPLAY_MODE_CENTERED: 'centered',
+ CHANNEL_DISPLAY_MODE_FULL_SCREEN: 'full',
+ CHANNEL_DISPLAY_MODE_DEFAULT: 'centered',
+ MESSAGE_DISPLAY: 'message_display',
+ MESSAGE_DISPLAY_CLEAN: 'clean',
+ MESSAGE_DISPLAY_COMPACT: 'compact',
+ MESSAGE_DISPLAY_DEFAULT: 'clean',
+ COLLAPSE_DISPLAY: 'collapse_previews',
+ COLLAPSE_DISPLAY_DEFAULT: 'false',
+ USE_MILITARY_TIME: 'use_military_time',
+ CATEGORY_THEME: 'theme'
+};
+
+export const ActionTypes = keyMirror({
+ RECEIVED_ERROR: null,
+
+ CLICK_CHANNEL: null,
+ CREATE_CHANNEL: null,
+ LEAVE_CHANNEL: null,
+ CREATE_POST: null,
+ CREATE_COMMENT: null,
+ POST_DELETED: null,
+ REMOVE_POST: null,
+
+ RECEIVED_CHANNELS: null,
+ RECEIVED_CHANNEL: null,
+ RECEIVED_MORE_CHANNELS: null,
+ RECEIVED_CHANNEL_EXTRA_INFO: null,
+
+ FOCUS_POST: null,
+ RECEIVED_POSTS: null,
+ RECEIVED_FOCUSED_POST: null,
+ RECEIVED_POST: null,
+ RECEIVED_EDIT_POST: null,
+ RECEIVED_SEARCH: null,
+ RECEIVED_SEARCH_TERM: null,
+ RECEIVED_POST_SELECTED: null,
+ RECEIVED_MENTION_DATA: null,
+ RECEIVED_ADD_MENTION: null,
+
+ RECEIVED_PROFILES_FOR_DM_LIST: null,
+ RECEIVED_PROFILES: null,
+ RECEIVED_DIRECT_PROFILES: null,
+ RECEIVED_ME: null,
+ RECEIVED_SESSIONS: null,
+ RECEIVED_AUDITS: null,
+ RECEIVED_TEAMS: null,
+ RECEIVED_STATUSES: null,
+ RECEIVED_PREFERENCE: null,
+ RECEIVED_PREFERENCES: null,
+ DELETED_PREFERENCES: null,
+ RECEIVED_FILE_INFO: null,
+ RECEIVED_ANALYTICS: null,
+
+ RECEIVED_INCOMING_WEBHOOKS: null,
+ RECEIVED_INCOMING_WEBHOOK: null,
+ REMOVED_INCOMING_WEBHOOK: null,
+ RECEIVED_OUTGOING_WEBHOOKS: null,
+ RECEIVED_OUTGOING_WEBHOOK: null,
+ UPDATED_OUTGOING_WEBHOOK: null,
+ REMOVED_OUTGOING_WEBHOOK: null,
+ RECEIVED_COMMANDS: null,
+ RECEIVED_COMMAND: null,
+ UPDATED_COMMAND: null,
+ REMOVED_COMMAND: null,
+
+ RECEIVED_CUSTOM_EMOJIS: null,
+ RECEIVED_CUSTOM_EMOJI: null,
+ UPDATED_CUSTOM_EMOJI: null,
+ REMOVED_CUSTOM_EMOJI: null,
+
+ RECEIVED_MSG: null,
+
+ RECEIVED_MY_TEAM: null,
+ CREATED_TEAM: null,
+
+ RECEIVED_CONFIG: null,
+ RECEIVED_LOGS: null,
+ RECEIVED_SERVER_AUDITS: null,
+ RECEIVED_SERVER_COMPLIANCE_REPORTS: null,
+ RECEIVED_ALL_TEAMS: null,
+ RECEIVED_ALL_TEAM_LISTINGS: null,
+ RECEIVED_TEAM_MEMBERS: null,
+ RECEIVED_MEMBERS_FOR_TEAM: null,
+
+ RECEIVED_LOCALE: null,
+
+ SHOW_SEARCH: null,
+
+ USER_TYPING: null,
+
+ TOGGLE_IMPORT_THEME_MODAL: null,
+ TOGGLE_INVITE_MEMBER_MODAL: null,
+ TOGGLE_LEAVE_TEAM_MODAL: null,
+ TOGGLE_DELETE_POST_MODAL: null,
+ TOGGLE_GET_POST_LINK_MODAL: null,
+ TOGGLE_GET_TEAM_INVITE_LINK_MODAL: null,
+ TOGGLE_REGISTER_APP_MODAL: null,
+ TOGGLE_GET_PUBLIC_LINK_MODAL: null,
+
+ SUGGESTION_PRETEXT_CHANGED: null,
+ SUGGESTION_RECEIVED_SUGGESTIONS: null,
+ SUGGESTION_CLEAR_SUGGESTIONS: null,
+ SUGGESTION_COMPLETE_WORD: null,
+ SUGGESTION_SELECT_NEXT: null,
+ SUGGESTION_SELECT_PREVIOUS: null
+});
+
+export const Constants = {
+ Preferences,
+ ActionTypes,
PayloadSources: keyMirror({
SERVER_ACTION: null,
@@ -174,7 +199,6 @@ export default {
FULLNAME: 'fullname',
NICKNAME: 'nickname',
EMAIL: 'email',
- THEME: 'theme',
LANGUAGE: 'language'
},
@@ -551,25 +575,6 @@ export default {
Ubuntu: 'font--ubuntu'
},
DEFAULT_FONT: 'Open Sans',
- Preferences: {
- CATEGORY_DIRECT_CHANNEL_SHOW: 'direct_channel_show',
- CATEGORY_DISPLAY_SETTINGS: 'display_settings',
- DISPLAY_PREFER_NICKNAME: 'nickname_full_name',
- DISPLAY_PREFER_FULL_NAME: 'full_name',
- CATEGORY_ADVANCED_SETTINGS: 'advanced_settings',
- TUTORIAL_STEP: 'tutorial_step',
- CHANNEL_DISPLAY_MODE: 'channel_display_mode',
- CHANNEL_DISPLAY_MODE_CENTERED: 'centered',
- CHANNEL_DISPLAY_MODE_FULL_SCREEN: 'full',
- CHANNEL_DISPLAY_MODE_DEFAULT: 'full',
- MESSAGE_DISPLAY: 'message_display',
- MESSAGE_DISPLAY_CLEAN: 'clean',
- MESSAGE_DISPLAY_COMPACT: 'compact',
- MESSAGE_DISPLAY_DEFAULT: 'clean',
- COLLAPSE_DISPLAY: 'collapse_previews',
- COLLAPSE_DISPLAY_DEFAULT: 'false',
- USE_MILITARY_TIME: 'use_military_time'
- },
TutorialSteps: {
INTRO_SCREENS: 0,
POST_POPOVER: 1,
@@ -761,6 +766,8 @@ export default {
MAX_PASSWORD_LENGTH: 64,
MIN_TRIGGER_LENGTH: 1,
MAX_TRIGGER_LENGTH: 128,
+ MAX_TEXTSETTING_LENGTH: 1024,
+ MAX_SITENAME_LENGTH: 30,
TIME_SINCE_UPDATE_INTERVAL: 30000,
MIN_HASHTAG_LINK_LENGTH: 3,
CHANNEL_SCROLL_ADJUSTMENT: 100,
@@ -777,3 +784,5 @@ export default {
PERMISSIONS_TEAM_ADMIN: 'team_admin',
PERMISSIONS_SYSTEM_ADMIN: 'system_admin'
};
+
+export default Constants;
diff --git a/webapp/utils/text_formatting.jsx b/webapp/utils/text_formatting.jsx
index 0b46edaeb..5ada7727f 100644
--- a/webapp/utils/text_formatting.jsx
+++ b/webapp/utils/text_formatting.jsx
@@ -263,7 +263,8 @@ function autolinkHashtags(text, tokens) {
newTokens.set(newAlias, {
value: `<a class='mention-link' href='#' data-hashtag='${token.originalText}'>${token.originalText}</a>`,
- originalText: token.originalText
+ originalText: token.originalText,
+ hashtag: token.originalText.substring(1)
});
output = output.replace(alias, newAlias);
@@ -276,19 +277,19 @@ function autolinkHashtags(text, tokens) {
}
// look for hashtags in the text
- function replaceHashtagWithToken(fullMatch, prefix, hashtag) {
+ function replaceHashtagWithToken(fullMatch, prefix, originalText) {
const index = tokens.size;
const alias = `MM_HASHTAG${index}`;
- let value = hashtag;
-
- if (hashtag.length > Constants.MIN_HASHTAG_LINK_LENGTH) {
- value = `<a class='mention-link' href='#' data-hashtag='${hashtag}'>${hashtag}</a>`;
+ if (text.length < Constants.MIN_HASHTAG_LINK_LENGTH + 1) {
+ // too short to be a hashtag
+ return fullMatch;
}
tokens.set(alias, {
- value,
- originalText: hashtag
+ value: `<a class='mention-link' href='#' data-hashtag='${originalText}'>${originalText}</a>`,
+ originalText,
+ hashtag: originalText.substring(1)
});
return prefix + alias;
@@ -393,9 +394,11 @@ export function highlightSearchTerms(text, tokens, searchTerm) {
for (const term of terms) {
// highlight existing tokens matching search terms
+ const trimmedTerm = term.replace(/\*$/, '').toLowerCase();
var newTokens = new Map();
for (const [alias, token] of tokens) {
- if (token.originalText.toLowerCase() === term.replace(/\*$/, '').toLowerCase()) {
+ if (token.originalText.toLowerCase() === trimmedTerm ||
+ (token.hashtag && token.hashtag.toLowerCase() === trimmedTerm)) {
const index = tokens.size + newTokens.size;
const newAlias = `MM_SEARCHTERM${index}`;
diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx
index bb17c2fdc..907c01229 100644
--- a/webapp/utils/utils.jsx
+++ b/webapp/utils/utils.jsx
@@ -139,7 +139,7 @@ export function notifyMe(title, body, channel, teamId) {
Notification.requestPermission((permission) => {
if (permission === 'granted') {
try {
- var notification = new Notification(title, {body: body, tag: body, icon: icon50});
+ var notification = new Notification(title, {body, tag: body, icon: icon50});
notification.onclick = () => {
window.focus();
if (channel) {
@@ -413,7 +413,7 @@ export function insertHtmlEntities(text) {
export function searchForTerm(term) {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_SEARCH_TERM,
- term: term,
+ term,
do_search: true
});
}
@@ -494,7 +494,7 @@ export function splitFileLocation(fileLocation) {
var filePath = fileSplit.join('.');
var filename = filePath.split('/')[filePath.split('/').length - 1];
- return {ext: ext, name: filename, path: filePath};
+ return {ext, name: filename, path: filePath};
}
export function getPreviewImagePath(filename) {
@@ -1079,7 +1079,7 @@ export function generateId() {
if (c === 'x') {
v = r;
} else {
- v = r & 0x3 | 0x8;
+ v = (r & 0x3) | 0x8;
}
return v.toString(16);
@@ -1297,7 +1297,7 @@ export function fillArray(value, length) {
// Checks if a data transfer contains files not text, folders, etc..
// Slightly modified from http://stackoverflow.com/questions/6848043/how-do-i-detect-a-file-is-being-dragged-rather-than-a-draggable-element-on-my-pa
export function isFileTransfer(files) {
- if (isBrowserIE()) {
+ if (isBrowserIE() || isBrowserEdge()) {
return files.types != null && files.types.contains('Files');
}
diff --git a/webapp/utils/websocket_client.jsx b/webapp/utils/websocket_client.jsx
new file mode 100644
index 000000000..135d96466
--- /dev/null
+++ b/webapp/utils/websocket_client.jsx
@@ -0,0 +1,7 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import WebSocketClient from 'mattermost/websocket_client.jsx';
+
+var WebClient = new WebSocketClient();
+export default WebClient;