2015-10-08 12:27:09 -04:00
|
|
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
2015-06-14 23:53:32 -08:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
2016-03-14 08:50:46 -04:00
|
|
|
import $ from 'jquery';
|
2015-11-19 21:12:56 -05:00
|
|
|
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
|
2016-03-14 08:50:46 -04:00
|
|
|
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';
|
2015-06-14 23:53:32 -08:00
|
|
|
var ActionTypes = Constants.ActionTypes;
|
2015-11-19 21:12:56 -05:00
|
|
|
import * as Client from './client.jsx';
|
|
|
|
|
import * as AsyncClient from './async_client.jsx';
|
|
|
|
|
import * as client from './client.jsx';
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2016-03-14 08:50:46 -04:00
|
|
|
import React from 'react';
|
2016-03-24 11:05:13 -04:00
|
|
|
import {browserHistory} from 'react-router';
|
2016-03-14 08:50:46 -04:00
|
|
|
import {FormattedTime} from 'react-intl';
|
|
|
|
|
|
|
|
|
|
import icon50 from 'images/icon50x50.png';
|
2016-03-18 12:29:04 -03:00
|
|
|
import bing from 'images/bing.mp3';
|
2016-02-04 11:53:38 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function isEmail(email) {
|
2016-01-06 15:30:11 -05:00
|
|
|
// writing a regex to match all valid email addresses is really, really hard (see http://stackoverflow.com/a/201378)
|
|
|
|
|
// so we just do a simple check and rely on a verification email to tell if it's a real address
|
2016-02-23 17:14:49 -05:00
|
|
|
return (/^.+@.+$/).test(email);
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function cleanUpUrlable(input) {
|
2015-07-08 11:50:10 -04:00
|
|
|
var cleaned = input.trim().replace(/-/g, ' ').replace(/[^\w\s]/gi, '').toLowerCase().replace(/\s/g, '-');
|
2015-10-26 14:48:00 +05:30
|
|
|
cleaned = cleaned.replace(/-{2,}/, '-');
|
2015-07-08 11:50:10 -04:00
|
|
|
cleaned = cleaned.replace(/^\-+/, '');
|
|
|
|
|
cleaned = cleaned.replace(/\-+$/, '');
|
|
|
|
|
return cleaned;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function isTestDomain() {
|
2015-08-18 09:43:22 -04:00
|
|
|
if ((/^localhost/).test(window.location.hostname)) {
|
2015-06-14 23:53:32 -08:00
|
|
|
return true;
|
2015-08-18 09:43:22 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
if ((/^dockerhost/).test(window.location.hostname)) {
|
2015-06-18 10:55:51 -08:00
|
|
|
return true;
|
2015-08-18 09:43:22 -04:00
|
|
|
}
|
2015-06-18 10:55:51 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
if ((/^test/).test(window.location.hostname)) {
|
2015-06-14 23:53:32 -08:00
|
|
|
return true;
|
2015-08-18 09:43:22 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
if ((/^127.0./).test(window.location.hostname)) {
|
2015-06-14 23:53:32 -08:00
|
|
|
return true;
|
2015-08-18 09:43:22 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
if ((/^192.168./).test(window.location.hostname)) {
|
2015-06-14 23:53:32 -08:00
|
|
|
return true;
|
2015-08-18 09:43:22 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
if ((/^10./).test(window.location.hostname)) {
|
2015-06-14 23:53:32 -08:00
|
|
|
return true;
|
2015-08-18 09:43:22 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
if ((/^176./).test(window.location.hostname)) {
|
2015-06-14 23:53:32 -08:00
|
|
|
return true;
|
2015-08-18 09:43:22 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-03 21:56:18 +05:00
|
|
|
export function isChrome() {
|
|
|
|
|
if (navigator.userAgent.indexOf('Chrome') > -1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isSafari() {
|
|
|
|
|
if (navigator.userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('Chrome') === -1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-09 12:42:34 -05:00
|
|
|
export function isIosChrome() {
|
|
|
|
|
// https://developer.chrome.com/multidevice/user-agent
|
|
|
|
|
return navigator.userAgent.indexOf('CriOS') !== -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isMobileApp() {
|
|
|
|
|
const userAgent = navigator.userAgent;
|
|
|
|
|
|
|
|
|
|
// the mobile app has different user agents for the native api calls and the shim, so handle them both
|
|
|
|
|
const isApi = userAgent.indexOf('Mattermost') !== -1;
|
|
|
|
|
const isShim = userAgent.indexOf('iPhone') !== -1 && userAgent.indexOf('Safari') === -1 && userAgent.indexOf('Chrome') === -1;
|
|
|
|
|
|
|
|
|
|
return isApi || isShim;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-17 22:00:33 -07:00
|
|
|
export function isInRole(roles, inRole) {
|
|
|
|
|
var parts = roles.split(' ');
|
|
|
|
|
for (var i = 0; i < parts.length; i++) {
|
|
|
|
|
if (parts[i] === inRole) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isAdmin(roles) {
|
|
|
|
|
if (isInRole(roles, 'admin')) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isInRole(roles, 'system_admin')) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-29 13:16:55 -07:00
|
|
|
export function isSystemAdmin(roles) {
|
|
|
|
|
if (isInRole(roles, 'system_admin')) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getDomainWithOutSub() {
|
2015-08-18 09:43:22 -04:00
|
|
|
var parts = window.location.host.split('.');
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
if (parts.length === 1) {
|
|
|
|
|
if (parts[0].indexOf('dockerhost') > -1) {
|
|
|
|
|
return 'dockerhost:8065';
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
return 'localhost:8065';
|
2015-06-18 10:55:51 -08:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
return parts[1] + '.' + parts[2];
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getCookie(name) {
|
2015-08-18 09:43:22 -04:00
|
|
|
var value = '; ' + document.cookie;
|
|
|
|
|
var parts = value.split('; ' + name + '=');
|
|
|
|
|
if (parts.length === 2) {
|
|
|
|
|
return parts.pop().split(';').shift();
|
|
|
|
|
}
|
2016-02-22 08:31:10 -05:00
|
|
|
return '';
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-08-12 11:02:47 -07:00
|
|
|
|
2016-02-04 16:51:32 -05:00
|
|
|
var requestedNotificationPermission = false;
|
|
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function notifyMe(title, body, channel) {
|
2016-02-04 16:51:32 -05:00
|
|
|
if (!('Notification' in window)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Notification.permission === 'granted' || (Notification.permission === 'default' && !requestedNotificationPermission)) {
|
|
|
|
|
requestedNotificationPermission = true;
|
|
|
|
|
|
|
|
|
|
Notification.requestPermission((permission) => {
|
2015-08-18 09:43:22 -04:00
|
|
|
if (permission === 'granted') {
|
2016-02-17 09:59:55 -05:00
|
|
|
try {
|
2016-03-14 08:50:46 -04:00
|
|
|
var notification = new Notification(title, {body: body, tag: body, icon: icon50});
|
2016-02-17 09:59:55 -05:00
|
|
|
notification.onclick = () => {
|
|
|
|
|
window.focus();
|
|
|
|
|
if (channel) {
|
2016-04-04 11:09:59 -04:00
|
|
|
browserHistory.push(getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name);
|
2016-02-17 09:59:55 -05:00
|
|
|
} else {
|
2016-03-24 11:05:13 -04:00
|
|
|
browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/town-square');
|
2016-02-17 09:59:55 -05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
notification.close();
|
|
|
|
|
}, 5000);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e); //eslint-disable-line no-console
|
|
|
|
|
}
|
2015-08-18 09:43:22 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-11-05 10:44:38 -05:00
|
|
|
var canDing = true;
|
|
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function ding() {
|
2015-11-05 10:44:38 -05:00
|
|
|
if (!isBrowserFirefox() && canDing) {
|
2016-03-18 12:29:04 -03:00
|
|
|
var audio = new Audio(bing);
|
2015-08-12 15:27:46 -07:00
|
|
|
audio.play();
|
2015-11-05 10:44:38 -05:00
|
|
|
canDing = false;
|
2016-02-22 08:31:10 -05:00
|
|
|
setTimeout(() => {
|
|
|
|
|
canDing = true;
|
|
|
|
|
return;
|
|
|
|
|
}, 3000);
|
2015-08-12 15:27:46 -07:00
|
|
|
}
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getUrlParameter(sParam) {
|
2015-06-14 23:53:32 -08:00
|
|
|
var sPageURL = window.location.search.substring(1);
|
|
|
|
|
var sURLVariables = sPageURL.split('&');
|
2015-08-18 09:43:22 -04:00
|
|
|
for (var i = 0; i < sURLVariables.length; i++) {
|
2015-06-14 23:53:32 -08:00
|
|
|
var sParameterName = sURLVariables[i].split('=');
|
2015-08-18 09:43:22 -04:00
|
|
|
if (sParameterName[0] === sParam) {
|
2015-06-14 23:53:32 -08:00
|
|
|
return sParameterName[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getDateForUnixTicks(ticks) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return new Date(ticks);
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function displayDate(ticks) {
|
2015-08-18 09:43:22 -04:00
|
|
|
var d = new Date(ticks);
|
|
|
|
|
var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
return monthNames[d.getMonth()] + ' ' + d.getDate() + ', ' + d.getFullYear();
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2016-02-05 09:23:40 -08:00
|
|
|
export function displayTime(ticks, utc) {
|
|
|
|
|
const d = new Date(ticks);
|
|
|
|
|
let hours;
|
|
|
|
|
let minutes;
|
|
|
|
|
let ampm = '';
|
|
|
|
|
let timezone = '';
|
|
|
|
|
|
|
|
|
|
if (utc) {
|
|
|
|
|
hours = d.getUTCHours();
|
|
|
|
|
minutes = d.getUTCMinutes();
|
|
|
|
|
timezone = ' UTC';
|
|
|
|
|
} else {
|
|
|
|
|
hours = d.getHours();
|
|
|
|
|
minutes = d.getMinutes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (minutes <= 9) {
|
|
|
|
|
minutes = '0' + minutes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const useMilitaryTime = PreferenceStore.getBool(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'use_military_time');
|
|
|
|
|
if (!useMilitaryTime) {
|
|
|
|
|
ampm = ' AM';
|
|
|
|
|
if (hours >= 12) {
|
|
|
|
|
ampm = ' PM';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hours = hours % 12;
|
|
|
|
|
if (!hours) {
|
|
|
|
|
hours = '12';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hours + ':' + minutes + ampm + timezone;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function displayTimeFormatted(ticks) {
|
2015-12-15 11:36:14 -05:00
|
|
|
const useMilitaryTime = PreferenceStore.getBool(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'use_military_time');
|
2015-10-14 20:36:12 +03:00
|
|
|
|
2016-02-04 11:53:38 -08:00
|
|
|
return (
|
|
|
|
|
<FormattedTime
|
|
|
|
|
value={ticks}
|
|
|
|
|
hour='numeric'
|
|
|
|
|
minute='numeric'
|
|
|
|
|
hour12={!useMilitaryTime}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2016-02-11 16:46:46 -03:00
|
|
|
export function isMilitaryTime() {
|
2016-02-11 16:29:52 -03:00
|
|
|
return PreferenceStore.getBool(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'use_military_time');
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function displayDateTime(ticks) {
|
2015-08-18 09:43:22 -04:00
|
|
|
var seconds = Math.floor((Date.now() - ticks) / 1000);
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
var interval = Math.floor(seconds / 3600);
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
if (interval > 24) {
|
|
|
|
|
return this.displayTime(ticks);
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
if (interval > 1) {
|
|
|
|
|
return interval + ' hours ago';
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
if (interval === 1) {
|
|
|
|
|
return interval + ' hour ago';
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
interval = Math.floor(seconds / 60);
|
2015-10-28 01:19:15 +01:00
|
|
|
if (interval >= 2) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return interval + ' minutes ago';
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-28 01:19:15 +01:00
|
|
|
if (interval >= 1) {
|
|
|
|
|
return '1 minute ago';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 'just now';
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function displayCommentDateTime(ticks) {
|
|
|
|
|
return displayDate(ticks) + ' ' + displayTime(ticks);
|
2015-08-18 08:31:25 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-14 23:53:32 -08:00
|
|
|
// returns Unix timestamp in milliseconds
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getTimestamp() {
|
2015-06-14 23:53:32 -08:00
|
|
|
return Date.now();
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-10-28 09:13:41 -04:00
|
|
|
// extracts links not styled by Markdown
|
2016-04-01 12:40:07 -03:00
|
|
|
export function extractFirstLink(text) {
|
|
|
|
|
const pattern = /(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/i;
|
2016-02-22 17:58:20 -05:00
|
|
|
let inText = text;
|
|
|
|
|
|
|
|
|
|
// strip out code blocks
|
|
|
|
|
inText = inText.replace(/`[^`]*`/g, '');
|
|
|
|
|
|
|
|
|
|
// strip out inline markdown images
|
|
|
|
|
inText = inText.replace(/!\[[^\]]*\]\([^\)]*\)/g, '');
|
2015-10-28 09:13:41 -04:00
|
|
|
|
2016-04-01 12:40:07 -03:00
|
|
|
const match = pattern.exec(inText);
|
|
|
|
|
if (match) {
|
|
|
|
|
return match[0].trim();
|
|
|
|
|
}
|
2015-07-07 09:24:42 -07:00
|
|
|
|
2016-04-01 12:40:07 -03:00
|
|
|
return '';
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function escapeRegExp(string) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-08-18 09:43:22 -04:00
|
|
|
|
2015-11-12 11:19:59 -05:00
|
|
|
// Taken from http://stackoverflow.com/questions/1068834/object-comparison-in-javascript and modified slightly
|
|
|
|
|
export function areObjectsEqual(x, y) {
|
|
|
|
|
let p;
|
|
|
|
|
const leftChain = [];
|
|
|
|
|
const rightChain = [];
|
|
|
|
|
|
|
|
|
|
// Remember that NaN === NaN returns false
|
|
|
|
|
// and isNaN(undefined) returns true
|
|
|
|
|
if (isNaN(x) && isNaN(y) && typeof x === 'number' && typeof y === 'number') {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compare primitives and functions.
|
|
|
|
|
// Check if both arguments link to the same object.
|
|
|
|
|
// Especially useful on step when comparing prototypes
|
|
|
|
|
if (x === y) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Works in case when functions are created in constructor.
|
|
|
|
|
// Comparing dates is a common scenario. Another built-ins?
|
|
|
|
|
// We can even handle functions passed across iframes
|
|
|
|
|
if ((typeof x === 'function' && typeof y === 'function') ||
|
|
|
|
|
(x instanceof Date && y instanceof Date) ||
|
|
|
|
|
(x instanceof RegExp && y instanceof RegExp) ||
|
|
|
|
|
(x instanceof String && y instanceof String) ||
|
|
|
|
|
(x instanceof Number && y instanceof Number)) {
|
|
|
|
|
return x.toString() === y.toString();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-08 13:35:38 -05:00
|
|
|
if (x instanceof Map && y instanceof Map) {
|
|
|
|
|
return areMapsEqual(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-12 11:19:59 -05:00
|
|
|
// At last checking prototypes as good a we can
|
|
|
|
|
if (!(x instanceof Object && y instanceof Object)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x.isPrototypeOf(y) || y.isPrototypeOf(x)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x.constructor !== y.constructor) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x.prototype !== y.prototype) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for infinitive linking loops
|
|
|
|
|
if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Quick checking of one object beeing a subset of another.
|
|
|
|
|
for (p in y) {
|
|
|
|
|
if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
|
|
|
|
|
return false;
|
|
|
|
|
} else if (typeof y[p] !== typeof x[p]) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (p in x) {
|
|
|
|
|
if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
|
|
|
|
|
return false;
|
|
|
|
|
} else if (typeof y[p] !== typeof x[p]) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (typeof (x[p])) {
|
|
|
|
|
case 'object':
|
|
|
|
|
case 'function':
|
|
|
|
|
|
|
|
|
|
leftChain.push(x);
|
|
|
|
|
rightChain.push(y);
|
|
|
|
|
|
|
|
|
|
if (!areObjectsEqual(x[p], y[p])) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
leftChain.pop();
|
|
|
|
|
rightChain.pop();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (x[p] !== y[p]) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2016-02-08 13:35:38 -05:00
|
|
|
export function areMapsEqual(a, b) {
|
|
|
|
|
if (a.size !== b.size) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const [key, value] of a) {
|
|
|
|
|
if (!b.has(key)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!areObjectsEqual(value, b.get(key))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function replaceHtmlEntities(text) {
|
2015-06-14 23:53:32 -08:00
|
|
|
var tagsToReplace = {
|
|
|
|
|
'&': '&',
|
|
|
|
|
'<': '<',
|
|
|
|
|
'>': '>'
|
|
|
|
|
};
|
2015-08-18 09:43:22 -04:00
|
|
|
var newtext = text;
|
2015-06-14 23:53:32 -08:00
|
|
|
for (var tag in tagsToReplace) {
|
2015-08-18 09:43:22 -04:00
|
|
|
if ({}.hasOwnProperty.call(tagsToReplace, tag)) {
|
|
|
|
|
var regex = new RegExp(tag, 'g');
|
|
|
|
|
newtext = newtext.replace(regex, tagsToReplace[tag]);
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
2015-08-18 09:43:22 -04:00
|
|
|
return newtext;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function insertHtmlEntities(text) {
|
2015-06-14 23:53:32 -08:00
|
|
|
var tagsToReplace = {
|
|
|
|
|
'&': '&',
|
|
|
|
|
'<': '<',
|
|
|
|
|
'>': '>'
|
|
|
|
|
};
|
2015-08-18 09:43:22 -04:00
|
|
|
var newtext = text;
|
2015-06-14 23:53:32 -08:00
|
|
|
for (var tag in tagsToReplace) {
|
2015-08-18 09:43:22 -04:00
|
|
|
if ({}.hasOwnProperty.call(tagsToReplace, tag)) {
|
|
|
|
|
var regex = new RegExp(tag, 'g');
|
|
|
|
|
newtext = newtext.replace(regex, tagsToReplace[tag]);
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
2015-08-18 09:43:22 -04:00
|
|
|
return newtext;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function searchForTerm(term) {
|
2015-06-14 23:53:32 -08:00
|
|
|
AppDispatcher.handleServerAction({
|
2016-02-08 10:33:59 -05:00
|
|
|
type: ActionTypes.RECEIVED_SEARCH_TERM,
|
2015-06-14 23:53:32 -08:00
|
|
|
term: term,
|
|
|
|
|
do_search: true
|
|
|
|
|
});
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getFileType(extin) {
|
2015-08-18 09:43:22 -04:00
|
|
|
var ext = extin.toLowerCase();
|
2015-06-14 23:53:32 -08:00
|
|
|
if (Constants.IMAGE_TYPES.indexOf(ext) > -1) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return 'image';
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Constants.AUDIO_TYPES.indexOf(ext) > -1) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return 'audio';
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Constants.VIDEO_TYPES.indexOf(ext) > -1) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return 'video';
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Constants.SPREADSHEET_TYPES.indexOf(ext) > -1) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return 'spreadsheet';
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Constants.CODE_TYPES.indexOf(ext) > -1) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return 'code';
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Constants.WORD_TYPES.indexOf(ext) > -1) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return 'word';
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
if (Constants.PRESENTATION_TYPES.indexOf(ext) > -1) {
|
|
|
|
|
return 'presentation';
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Constants.PDF_TYPES.indexOf(ext) > -1) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return 'pdf';
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Constants.PATCH_TYPES.indexOf(ext) > -1) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return 'patch';
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
return 'other';
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getPreviewImagePathForFileType(fileTypeIn) {
|
2015-08-18 09:43:22 -04:00
|
|
|
var fileType = fileTypeIn.toLowerCase();
|
2015-07-24 17:04:02 -04:00
|
|
|
|
|
|
|
|
var icon;
|
|
|
|
|
if (fileType in Constants.ICON_FROM_TYPE) {
|
|
|
|
|
icon = Constants.ICON_FROM_TYPE[fileType];
|
|
|
|
|
} else {
|
2015-08-18 09:43:22 -04:00
|
|
|
icon = Constants.ICON_FROM_TYPE.other;
|
2015-07-24 17:04:02 -04:00
|
|
|
}
|
|
|
|
|
|
2016-03-14 08:50:46 -04:00
|
|
|
return icon;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-07-24 17:04:02 -04:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getIconClassName(fileTypeIn) {
|
2015-08-18 09:43:22 -04:00
|
|
|
var fileType = fileTypeIn.toLowerCase();
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2016-03-14 08:50:46 -04:00
|
|
|
if (fileType in Constants.ICON_NAME_FROM_TYPE) {
|
|
|
|
|
return Constants.ICON_NAME_FROM_TYPE[fileType];
|
2015-08-18 09:43:22 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
return 'glyphicon-file';
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function splitFileLocation(fileLocation) {
|
2015-06-14 23:53:32 -08:00
|
|
|
var fileSplit = fileLocation.split('.');
|
|
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
var ext = '';
|
2015-07-27 12:36:14 -04:00
|
|
|
if (fileSplit.length > 1) {
|
|
|
|
|
ext = fileSplit[fileSplit.length - 1];
|
|
|
|
|
fileSplit.splice(fileSplit.length - 1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-14 23:53:32 -08:00
|
|
|
var filePath = fileSplit.join('.');
|
2015-08-18 09:43:22 -04:00
|
|
|
var filename = filePath.split('/')[filePath.split('/').length - 1];
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
return {ext: ext, name: filename, path: filePath};
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2016-01-05 15:49:45 -05:00
|
|
|
export function getPreviewImagePath(filename) {
|
|
|
|
|
// Returns the path to a preview image that can be used to represent a file.
|
|
|
|
|
const fileInfo = splitFileLocation(filename);
|
|
|
|
|
const fileType = getFileType(fileInfo.ext);
|
|
|
|
|
|
|
|
|
|
if (fileType === 'image') {
|
2016-01-06 09:54:05 -05:00
|
|
|
return getFileUrl(fileInfo.path + '_preview.jpg');
|
2016-01-05 15:49:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// only images have proper previews, so just use a placeholder icon for non-images
|
|
|
|
|
return getPreviewImagePathForFileType(fileType);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function toTitleCase(str) {
|
2015-08-18 09:43:22 -04:00
|
|
|
function doTitleCase(txt) {
|
|
|
|
|
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
return str.replace(/\w\S*/g, doTitleCase);
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-23 10:12:40 -04:00
|
|
|
export function applyTheme(theme) {
|
|
|
|
|
if (theme.sidebarBg) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .sidebar--left, .app__body .modal .settings-modal .settings-table .settings-links, .app__body .sidebar--menu', 'background:' + theme.sidebarBg, 1);
|
|
|
|
|
changeCss('body.app__body', 'scrollbar-face-color:' + theme.sidebarBg, 3);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme.sidebarText) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .sidebar--left .nav-pills__container li>a, .app__body .sidebar--right, .app__body .modal .settings-modal .nav-pills>li a, .app__body .sidebar--menu', 'color:' + changeOpacity(theme.sidebarText, 0.6), 1);
|
|
|
|
|
changeCss('@media(max-width: 768px){.app__body .modal .settings-modal .settings-table .nav>li>a', 'color:' + theme.sidebarText, 1);
|
|
|
|
|
changeCss('.app__body .sidebar--left .nav-pills__container li>h4, .app__body .sidebar--left .add-channel-btn', 'color:' + changeOpacity(theme.sidebarText, 0.6), 1);
|
|
|
|
|
changeCss('.app__body .sidebar--left .add-channel-btn:hover, .app__body .sidebar--left .add-channel-btn:focus', 'color:' + theme.sidebarText, 1);
|
|
|
|
|
changeCss('.app__body .sidebar--left .status .offline--icon, .app__body .sidebar--left .status .offline--icon', 'fill:' + theme.sidebarText, 1);
|
|
|
|
|
changeCss('@media(max-width: 768px){.app__body .modal .settings-modal .settings-table .nav>li>a', 'border-color:' + changeOpacity(theme.sidebarText, 0.2), 2);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme.sidebarUnreadText) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .sidebar--left .nav-pills__container li>a.unread-title', 'color:' + theme.sidebarUnreadText + '!important;', 2);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme.sidebarTextHoverBg) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .sidebar--left .nav-pills__container li>a:hover, .app__body .sidebar--left .nav-pills__container li>a:focus, .app__body .modal .settings-modal .nav-pills>li:hover a, .app__body .modal .settings-modal .nav-pills>li:focus a', 'background:' + theme.sidebarTextHoverBg, 1);
|
|
|
|
|
changeCss('@media(max-width: 768px){.app__body .modal .settings-modal .settings-table .nav>li:hover a', 'background:' + theme.sidebarTextHoverBg, 1);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
2015-10-22 20:18:31 +05:00
|
|
|
if (theme.sidebarTextActiveBorder) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .sidebar--left .nav li.active a:before, .app__body .modal .settings-modal .nav-pills>li.active a:before', 'background:' + theme.sidebarTextActiveBorder, 1);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme.sidebarTextActiveColor) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .sidebar--left .nav-pills__container li.active a, .app__body .sidebar--left .nav-pills__container li.active a:hover, .app__body .sidebar--left .nav-pills__container li.active a:focus, .app__body .modal .settings-modal .nav-pills>li.active a, .app__body .modal .settings-modal .nav-pills>li.active a:hover, .app__body .modal .settings-modal .nav-pills>li.active a:active', 'color:' + theme.sidebarTextActiveColor, 2);
|
|
|
|
|
changeCss('.app__body .sidebar--left .nav li.active a, .app__body .sidebar--left .nav li.active a:hover, .app__body .sidebar--left .nav li.active a:focus', 'background:' + changeOpacity(theme.sidebarTextActiveColor, 0.1), 1);
|
2015-10-12 19:22:05 +05:00
|
|
|
}
|
|
|
|
|
|
2015-09-23 10:12:40 -04:00
|
|
|
if (theme.sidebarHeaderBg) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .sidebar--left .team__header, .app__body .sidebar--menu .team__header, .app__body .post-list__timestamp > div', 'background:' + theme.sidebarHeaderBg, 1);
|
|
|
|
|
changeCss('.app__body .modal .modal-header', 'background:' + theme.sidebarHeaderBg, 1);
|
|
|
|
|
changeCss('.app__body #navbar .navbar-default', 'background:' + theme.sidebarHeaderBg, 1);
|
|
|
|
|
changeCss('@media(max-width: 768px){.app__body .search-bar__container', 'background:' + theme.sidebarHeaderBg, 1);
|
|
|
|
|
changeCss('.app__body .attachment .attachment__container', 'border-left-color:' + theme.sidebarHeaderBg, 1);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme.sidebarHeaderTextColor) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .sidebar--left .team__header .header__info, .app__body .sidebar--menu .team__header .header__info, .app__body .post-list__timestamp > div', 'color:' + theme.sidebarHeaderTextColor, 1);
|
|
|
|
|
changeCss('.app__body .sidebar--left .team__header .navbar-right .dropdown__icon, .app__body .sidebar--menu .team__header .navbar-right .dropdown__icon', 'fill:' + theme.sidebarHeaderTextColor, 1);
|
|
|
|
|
changeCss('.app__body .sidebar--left .team__header .user__name, .app__body .sidebar--menu .team__header .user__name', 'color:' + changeOpacity(theme.sidebarHeaderTextColor, 0.8), 1);
|
|
|
|
|
changeCss('.app__body .sidebar--left .team__header:hover .user__name, .app__body .sidebar--menu .team__header:hover .user__name', 'color:' + theme.sidebarHeaderTextColor, 1);
|
|
|
|
|
changeCss('.app__body .modal .modal-header .modal-title, .app__body .modal .modal-header .modal-title .name, .app__body .modal .modal-header button.close', 'color:' + theme.sidebarHeaderTextColor, 1);
|
|
|
|
|
changeCss('.app__body #navbar .navbar-default .navbar-brand .heading', 'color:' + theme.sidebarHeaderTextColor, 1);
|
|
|
|
|
changeCss('.app__body #navbar .navbar-default .navbar-toggle .icon-bar, ', 'background:' + theme.sidebarHeaderTextColor, 1);
|
|
|
|
|
changeCss('@media(max-width: 768px){.app__body .search-bar__container', 'color:' + theme.sidebarHeaderTextColor, 2);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme.onlineIndicator) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .sidebar--left .status .online--icon', 'fill:' + theme.onlineIndicator, 1);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
2016-01-11 20:32:31 +05:00
|
|
|
if (theme.awayIndicator) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .sidebar--left .status .away--icon', 'fill:' + theme.awayIndicator, 1);
|
2016-01-11 20:32:31 +05:00
|
|
|
}
|
|
|
|
|
|
2015-09-23 10:12:40 -04:00
|
|
|
if (theme.mentionBj) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .sidebar--left .nav-pills__unread-indicator', 'background:' + theme.mentionBj, 1);
|
|
|
|
|
changeCss('.app__body .sidebar--left .badge', 'background:' + theme.mentionBj + '!important;', 1);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme.mentionColor) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .sidebar--left .nav-pills__unread-indicator', 'color:' + theme.mentionColor, 2);
|
|
|
|
|
changeCss('.app__body .sidebar--left .badge', 'color:' + theme.mentionColor + '!important;', 2);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme.centerChannelBg) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .app__content, .app__body .markdown__table, .app__body .markdown__table tbody tr, .app__body .suggestion-list__content, .app__body .modal .modal-content', 'background:' + theme.centerChannelBg, 1);
|
2015-09-23 10:12:40 -04:00
|
|
|
changeCss('#post-list .post-list-holder-by-time', 'background:' + theme.centerChannelBg, 1);
|
|
|
|
|
changeCss('#post-create', 'background:' + theme.centerChannelBg, 1);
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .date-separator .separator__text, .app__body .new-separator .separator__text', 'background:' + theme.centerChannelBg, 1);
|
|
|
|
|
changeCss('.app__body .post-image__details, .app__body .search-help-popover .search-autocomplete__divider span', 'background:' + theme.centerChannelBg, 1);
|
|
|
|
|
changeCss('.app__body .sidebar--right, .app__body .dropdown-menu, .app__body .popover, .app__body .tip-overlay', 'background:' + theme.centerChannelBg, 1);
|
|
|
|
|
changeCss('.app__body .popover.bottom>.arrow:after', 'border-bottom-color:' + theme.centerChannelBg, 1);
|
|
|
|
|
changeCss('.app__body .popover.right>.arrow:after, .app__body .tip-overlay.tip-overlay--sidebar .arrow, .app__body .tip-overlay.tip-overlay--header .arrow', 'border-right-color:' + theme.centerChannelBg, 1);
|
|
|
|
|
changeCss('.app__body .popover.left>.arrow:after', 'border-left-color:' + theme.centerChannelBg, 1);
|
|
|
|
|
changeCss('.app__body .popover.top>.arrow:after, .app__body .tip-overlay.tip-overlay--chat .arrow', 'border-top-color:' + theme.centerChannelBg, 1);
|
|
|
|
|
changeCss('@media(min-width: 768px){.app__body .search-bar__container .search__form .search-bar, .app__body .form-control', 'background:' + theme.centerChannelBg, 1);
|
|
|
|
|
changeCss('.app__body .attachment__content', 'background:' + theme.centerChannelBg, 1);
|
|
|
|
|
changeCss('body.app__body', 'scrollbar-face-color:' + theme.centerChannelBg, 2);
|
|
|
|
|
changeCss('body.app__body', 'scrollbar-track-color:' + theme.centerChannelBg, 2);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme.centerChannelColor) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .post-list__arrows', 'fill:' + changeOpacity(theme.centerChannelColor, 0.3), 1);
|
|
|
|
|
changeCss('.app__body .sidebar--left, .app__body .sidebar--right .sidebar--right__header, .app__body .suggestion-list__content .command', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.2), 1);
|
|
|
|
|
changeCss('.app__body .app__content, .app__body .post-create__container .post-create-body .btn-file, .app__body .post-create__container .post-create-footer .msg-typing, .app__body .suggestion-list__content .command, .app__body .modal .modal-content, .app__body .dropdown-menu, .app__body .popover, .app__body .mentions__name, .app__body .tip-overlay', 'color:' + theme.centerChannelColor, 1);
|
|
|
|
|
changeCss('.app__body #archive-link-home', 'background:' + changeOpacity(theme.centerChannelColor, 0.15), 1);
|
|
|
|
|
changeCss('.app__body #post-create', 'color:' + theme.centerChannelColor, 2);
|
|
|
|
|
changeCss('.app__body .mentions--top, .app__body .suggestion-list', 'box-shadow:' + changeOpacity(theme.centerChannelColor, 0.2) + ' 1px -3px 12px', 3);
|
|
|
|
|
changeCss('.app__body .mentions--top, .app__body .suggestion-list', '-webkit-box-shadow:' + changeOpacity(theme.centerChannelColor, 0.2) + ' 1px -3px 12px', 2);
|
|
|
|
|
changeCss('.app__body .mentions--top, .app__body .suggestion-list', '-moz-box-shadow:' + changeOpacity(theme.centerChannelColor, 0.2) + ' 1px -3px 12px', 1);
|
|
|
|
|
changeCss('.app__body .dropdown-menu, .app__body .popover ', 'box-shadow:' + changeOpacity(theme.centerChannelColor, 0.1) + ' 0px 6px 12px', 3);
|
|
|
|
|
changeCss('.app__body .dropdown-menu, .app__body .popover ', '-webkit-box-shadow:' + changeOpacity(theme.centerChannelColor, 0.1) + ' 0px 6px 12px', 2);
|
|
|
|
|
changeCss('.app__body .dropdown-menu, .app__body .popover ', '-moz-box-shadow:' + changeOpacity(theme.centerChannelColor, 0.1) + ' 0px 6px 12px', 1);
|
|
|
|
|
changeCss('.app__body .post__body hr, .app__body .loading-screen .loading__content .round, .app__body .tutorial__circles .circle', 'background:' + theme.centerChannelColor, 1);
|
|
|
|
|
changeCss('.app__body .channel-header .heading', 'color:' + theme.centerChannelColor, 1);
|
|
|
|
|
changeCss('.app__body .markdown__table tbody tr:nth-child(2n)', 'background:' + changeOpacity(theme.centerChannelColor, 0.07), 1);
|
|
|
|
|
changeCss('.app__body .channel-header__info>div.dropdown .header-dropdown__icon', 'color:' + changeOpacity(theme.centerChannelColor, 0.8), 1);
|
|
|
|
|
changeCss('.app__body .channel-header #member_popover', 'color:' + changeOpacity(theme.centerChannelColor, 0.8), 1);
|
|
|
|
|
changeCss('.app__body .custom-textarea, .app__body .custom-textarea:focus, .app__body .file-preview, .app__body .post-image__details, .app__body .sidebar--right .sidebar-right__body, .app__body .markdown__table th, .app__body .markdown__table td, .app__body .suggestion-list__content, .app__body .modal .modal-content, .app__body .modal .settings-modal .settings-table .settings-content .divider-light, .app__body .webhooks__container, .app__body .dropdown-menu, .app__body .modal .modal-header, .app__body .popover', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.2), 1);
|
|
|
|
|
changeCss('.app__body .popover.bottom>.arrow', 'border-bottom-color:' + changeOpacity(theme.centerChannelColor, 0.25), 1);
|
|
|
|
|
changeCss('.app__body .search-help-popover .search-autocomplete__divider span', 'color:' + changeOpacity(theme.centerChannelColor, 0.7), 1);
|
|
|
|
|
changeCss('.app__body .popover.right>.arrow', 'border-right-color:' + changeOpacity(theme.centerChannelColor, 0.25), 1);
|
|
|
|
|
changeCss('.app__body .popover.left>.arrow', 'border-left-color:' + changeOpacity(theme.centerChannelColor, 0.25), 1);
|
|
|
|
|
changeCss('.app__body .popover.top>.arrow', 'border-top-color:' + changeOpacity(theme.centerChannelColor, 0.25), 1);
|
|
|
|
|
changeCss('.app__body .suggestion-list__content .command, .app__body .popover .popover-title', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.2), 1);
|
|
|
|
|
changeCss('.app__body .dropdown-menu .divider, .app__body .search-help-popover .search-autocomplete__divider:before', 'background:' + theme.centerChannelColor, 1);
|
|
|
|
|
changeCss('.app__body .custom-textarea', 'color:' + theme.centerChannelColor, 1);
|
|
|
|
|
changeCss('.app__body .post-image__column', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.2), 2);
|
|
|
|
|
changeCss('.app__body .post-image__details', 'color:' + theme.centerChannelColor, 2);
|
|
|
|
|
changeCss('.app__body .post-image__column a, .app__body .post-image__column a:hover, .app__body .post-image__column a:focus', 'color:' + theme.centerChannelColor, 1);
|
|
|
|
|
changeCss('@media(min-width: 768px){.app__body .search-bar__container .search__form .search-bar, .app__body .form-control', 'color:' + theme.centerChannelColor, 2);
|
|
|
|
|
changeCss('.app__body .input-group-addon, .app__body .search-bar__container .search__form, .app__body .form-control', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.2), 1);
|
|
|
|
|
changeCss('.app__body .form-control:focus', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.3), 1);
|
|
|
|
|
changeCss('.app__body .attachment .attachment__content', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.3), 1);
|
|
|
|
|
changeCss('.app__body .channel-intro .channel-intro__content, .app__body .webhooks__container', 'background:' + changeOpacity(theme.centerChannelColor, 0.05), 1);
|
|
|
|
|
changeCss('.app__body .date-separator .separator__text', 'color:' + theme.centerChannelColor, 2);
|
|
|
|
|
changeCss('.app__body .date-separator .separator__hr, .app__body .modal-footer, .app__body .modal .custom-textarea', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.2), 1);
|
|
|
|
|
changeCss('.app__body .search-item-container, .app__body .post-right__container .post.post--root', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.1), 1);
|
|
|
|
|
changeCss('.app__body .modal .custom-textarea:focus', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.3), 1);
|
|
|
|
|
changeCss('.app__body .channel-intro, .app__body .modal .settings-modal .settings-table .settings-content .divider-dark, .app__body hr, .app__body .modal .settings-modal .settings-table .settings-links, .app__body .modal .settings-modal .settings-table .settings-content .appearance-section .theme-elements__header', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.2), 1);
|
|
|
|
|
changeCss('.app__body .post.current--user .post__body, .app__body .post.post--comment.other--root.current--user .post-comment, .app__body pre, .app__body .post-right__container .post.post--root', 'background:' + changeOpacity(theme.centerChannelColor, 0.07), 1);
|
|
|
|
|
changeCss('.app__body .post.current--user .post__body, .app__body .post.post--comment.other--root.current--user .post-comment, .app__body .post.same--root.post--comment .post__body, .app__body .more-modal__list .more-modal__row, .app__body .member-div:first-child, .app__body .member-div, .app__body .access-history__table .access__report, .app__body .activity-log__table', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.1), 2);
|
|
|
|
|
changeCss('@media(max-width: 1800px){.app__body .inner-wrap.move--left .post.post--comment.same--root', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.07), 2);
|
|
|
|
|
changeCss('.app__body .post:hover, .app__body .more-modal__list .more-modal__row:hover, .app__body .modal .settings-modal .settings-table .settings-content .section-min:hover', 'background:' + changeOpacity(theme.centerChannelColor, 0.07), 1);
|
|
|
|
|
changeCss('.app__body .date-separator.hovered--before:after, .app__body .date-separator.hovered--after:before, .app__body .new-separator.hovered--after:before, .app__body .new-separator.hovered--before:after', 'background:' + changeOpacity(theme.centerChannelColor, 0.07), 1);
|
|
|
|
|
changeCss('.app__body .suggestion-list__content .command:hover, .app__body .mentions__name:hover, .app__body .suggestion--selected, .app__body .dropdown-menu>li>a:focus, .app__body .dropdown-menu>li>a:hover, .app__body .bot-indicator', 'background:' + changeOpacity(theme.centerChannelColor, 0.15), 1);
|
2016-04-08 17:52:34 +05:00
|
|
|
changeCss('code, .app__body .form-control[disabled], .app__body .form-control[readonly], .app__body fieldset[disabled] .form-control', 'background:' + changeOpacity(theme.centerChannelColor, 0.1), 1);
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('@media(min-width: 960px){.app__body .post.current--user:hover .post__body ', 'background: none;', 1);
|
|
|
|
|
changeCss('.app__body .sidebar--right', 'color:' + theme.centerChannelColor, 2);
|
|
|
|
|
changeCss('.app__body .search-help-popover .search-autocomplete__item:hover, .app__body .modal .settings-modal .settings-table .settings-content .appearance-section .theme-elements__body', 'background:' + changeOpacity(theme.centerChannelColor, 0.05), 1);
|
|
|
|
|
changeCss('.app__body .search-help-popover .search-autocomplete__item.selected', 'background:' + changeOpacity(theme.centerChannelColor, 0.15), 1);
|
2016-03-08 15:07:43 +05:00
|
|
|
changeCss('::-webkit-scrollbar-thumb', 'background:' + changeOpacity(theme.centerChannelColor, 0.4), 1);
|
|
|
|
|
changeCss('body', 'scrollbar-arrow-color:' + theme.centerChannelColor, 4);
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .modal .about-modal .about-modal__logo svg, .app__body .post .post__img svg', 'fill:' + theme.centerChannelColor, 1);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
2015-09-25 22:44:36 +05:00
|
|
|
if (theme.newMessageSeparator) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .new-separator .separator__text', 'color:' + theme.newMessageSeparator, 1);
|
|
|
|
|
changeCss('.app__body .new-separator .separator__hr', 'border-color:' + changeOpacity(theme.newMessageSeparator, 0.5), 1);
|
2015-09-25 22:44:36 +05:00
|
|
|
}
|
|
|
|
|
|
2015-09-23 10:12:40 -04:00
|
|
|
if (theme.linkColor) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body a, .app__body a:focus, .app__body a:hover, .app__body .btn, .app__body .btn:focus, .app__body .btn:hover', 'color:' + theme.linkColor, 1);
|
|
|
|
|
changeCss('.app__body .post .comment-icon__container, .app__body .post .post__reply', 'fill:' + theme.linkColor, 1);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme.buttonBg) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .btn.btn-primary, .app__body .tutorial__circles .circle.active', 'background:' + theme.buttonBg, 1);
|
|
|
|
|
changeCss('.app__body .btn.btn-primary:hover, .app__body .btn.btn-primary:active, .app__body .btn.btn-primary:focus', 'background:' + changeColor(theme.buttonBg, -0.25), 1);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme.buttonColor) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .btn.btn-primary', 'color:' + theme.buttonColor, 2);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
2015-10-06 10:04:39 +05:00
|
|
|
|
|
|
|
|
if (theme.mentionHighlightBg) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .mention--highlight, .app__body .search-highlight', 'background:' + theme.mentionHighlightBg, 1);
|
2015-12-04 13:21:40 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme.mentionHighlightBg) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .post.post--highlight', 'background:' + changeOpacity(theme.mentionHighlightBg, 0.5), 1);
|
2015-10-06 10:04:39 +05:00
|
|
|
}
|
2015-10-07 14:41:24 +05:00
|
|
|
|
|
|
|
|
if (theme.mentionHighlightLink) {
|
2016-04-06 23:19:55 +05:00
|
|
|
changeCss('.app__body .mention--highlight .mention-link', 'color:' + theme.mentionHighlightLink, 1);
|
2015-10-07 14:41:24 +05:00
|
|
|
}
|
2015-11-04 13:49:39 -08:00
|
|
|
|
|
|
|
|
if (!theme.codeTheme) {
|
|
|
|
|
theme.codeTheme = Constants.DEFAULT_CODE_THEME;
|
|
|
|
|
}
|
|
|
|
|
updateCodeTheme(theme.codeTheme);
|
2015-09-23 10:12:40 -04:00
|
|
|
}
|
2015-11-28 02:54:04 +01:00
|
|
|
|
2016-03-30 09:30:33 -04:00
|
|
|
export function resetTheme() {
|
|
|
|
|
applyTheme(Constants.THEMES.default);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-28 02:54:04 +01:00
|
|
|
export function applyFont(fontName) {
|
2015-12-03 16:30:45 -05:00
|
|
|
const body = $('body');
|
|
|
|
|
|
|
|
|
|
for (const key of Reflect.ownKeys(Constants.FONTS)) {
|
|
|
|
|
const className = Constants.FONTS[key];
|
|
|
|
|
|
|
|
|
|
if (fontName === key) {
|
|
|
|
|
if (!body.hasClass(className)) {
|
|
|
|
|
body.addClass(className);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
body.removeClass(className);
|
2015-11-28 02:54:04 +01:00
|
|
|
}
|
2015-12-03 16:30:45 -05:00
|
|
|
}
|
2015-11-28 02:54:04 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-23 10:12:40 -04:00
|
|
|
export function changeCss(className, classValue, classRepeat) {
|
2015-06-14 23:53:32 -08:00
|
|
|
// we need invisible container to store additional css definitions
|
|
|
|
|
var cssMainContainer = $('#css-modifier-container');
|
2015-08-18 09:43:22 -04:00
|
|
|
if (cssMainContainer.length === 0) {
|
2015-08-20 08:41:45 -04:00
|
|
|
cssMainContainer = $('<div id="css-modifier-container"></div>');
|
|
|
|
|
cssMainContainer.hide();
|
|
|
|
|
cssMainContainer.appendTo($('body'));
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// and we need one div for each class
|
2015-09-23 10:12:40 -04:00
|
|
|
var classContainer = cssMainContainer.find('div[data-class="' + className + classRepeat + '"]');
|
2015-08-18 09:43:22 -04:00
|
|
|
if (classContainer.length === 0) {
|
2015-09-23 10:12:40 -04:00
|
|
|
classContainer = $('<div data-class="' + className + classRepeat + '"></div>');
|
2015-06-14 23:53:32 -08:00
|
|
|
classContainer.appendTo(cssMainContainer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// append additional style
|
|
|
|
|
classContainer.html('<style>' + className + ' {' + classValue + '}</style>');
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function rgb2hex(rgbIn) {
|
2015-08-18 09:43:22 -04:00
|
|
|
if (/^#[0-9A-F]{6}$/i.test(rgbIn)) {
|
|
|
|
|
return rgbIn;
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
var rgb = rgbIn.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
|
2015-06-14 23:53:32 -08:00
|
|
|
function hex(x) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return ('0' + parseInt(x, 10).toString(16)).slice(-2);
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
2015-08-18 09:43:22 -04:00
|
|
|
return '#' + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2016-03-14 08:50:46 -04:00
|
|
|
export function updateCodeTheme(userTheme) {
|
|
|
|
|
let cssPath = '';
|
|
|
|
|
Constants.THEME_ELEMENTS.forEach((element) => {
|
|
|
|
|
if (element.id === 'codeTheme') {
|
|
|
|
|
element.themes.forEach((theme) => {
|
|
|
|
|
if (userTheme === theme.id) {
|
|
|
|
|
cssPath = theme.cssURL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-10-24 15:50:20 +02:00
|
|
|
const $link = $('link.code_theme');
|
2016-03-14 08:50:46 -04:00
|
|
|
if (cssPath !== $link.attr('href')) {
|
2015-10-24 15:50:20 +02:00
|
|
|
changeCss('code.hljs', 'visibility: hidden');
|
|
|
|
|
var xmlHTTP = new XMLHttpRequest();
|
2016-03-14 08:50:46 -04:00
|
|
|
xmlHTTP.open('GET', cssPath, true);
|
2015-10-24 15:50:20 +02:00
|
|
|
xmlHTTP.onload = function onLoad() {
|
2016-03-14 08:50:46 -04:00
|
|
|
$link.attr('href', cssPath);
|
2015-10-24 15:50:20 +02:00
|
|
|
if (isBrowserFirefox()) {
|
|
|
|
|
$link.one('load', () => {
|
|
|
|
|
changeCss('code.hljs', 'visibility: visible');
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
changeCss('code.hljs', 'visibility: visible');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
xmlHTTP.send();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function placeCaretAtEnd(el) {
|
2015-06-14 23:53:32 -08:00
|
|
|
el.focus();
|
2015-11-16 12:08:05 -05:00
|
|
|
el.selectionStart = el.value.length;
|
|
|
|
|
el.selectionEnd = el.value.length;
|
|
|
|
|
|
|
|
|
|
return;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getCaretPosition(el) {
|
2015-06-14 23:53:32 -08:00
|
|
|
if (el.selectionStart) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return el.selectionStart;
|
2015-06-14 23:53:32 -08:00
|
|
|
} else if (document.selection) {
|
2015-08-18 09:43:22 -04:00
|
|
|
el.focus();
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
var r = document.selection.createRange();
|
|
|
|
|
if (r == null) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
var re = el.createTextRange();
|
|
|
|
|
var rc = re.duplicate();
|
|
|
|
|
re.moveToBookmark(r.getBookmark());
|
|
|
|
|
rc.setEndPoint('EndToStart', re);
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
return rc.text.length;
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
return 0;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function setSelectionRange(input, selectionStart, selectionEnd) {
|
2015-08-18 09:43:22 -04:00
|
|
|
if (input.setSelectionRange) {
|
|
|
|
|
input.focus();
|
|
|
|
|
input.setSelectionRange(selectionStart, selectionEnd);
|
|
|
|
|
} else if (input.createTextRange) {
|
|
|
|
|
var range = input.createTextRange();
|
|
|
|
|
range.collapse(true);
|
|
|
|
|
range.moveEnd('character', selectionEnd);
|
|
|
|
|
range.moveStart('character', selectionStart);
|
|
|
|
|
range.select();
|
|
|
|
|
}
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function setCaretPosition(input, pos) {
|
|
|
|
|
setSelectionRange(input, pos, pos);
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getSelectedText(input) {
|
2015-08-18 09:43:22 -04:00
|
|
|
var selectedText;
|
|
|
|
|
if (typeof document.selection !== 'undefined') {
|
|
|
|
|
input.focus();
|
|
|
|
|
var sel = document.selection.createRange();
|
|
|
|
|
selectedText = sel.text;
|
|
|
|
|
} else if (typeof input.selectionStart !== 'undefined') {
|
|
|
|
|
var startPos = input.selectionStart;
|
|
|
|
|
var endPos = input.selectionEnd;
|
|
|
|
|
selectedText = input.value.substring(startPos, endPos);
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
return selectedText;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function isValidUsername(name) {
|
2015-08-18 09:43:22 -04:00
|
|
|
var error = '';
|
|
|
|
|
if (!name) {
|
|
|
|
|
error = 'This field is required';
|
2016-01-19 12:39:51 -08:00
|
|
|
} else if (name.length < Constants.MIN_USERNAME_LENGTH || name.length > Constants.MAX_USERNAME_LENGTH) {
|
|
|
|
|
error = 'Must be between ' + Constants.MIN_USERNAME_LENGTH + ' and ' + Constants.MAX_USERNAME_LENGTH + ' characters';
|
2015-08-18 09:43:22 -04:00
|
|
|
} else if (!(/^[a-z0-9\.\-\_]+$/).test(name)) {
|
2015-09-14 15:15:48 +01:00
|
|
|
error = "Must contain only letters, numbers, and the symbols '.', '-', and '_'.";
|
2015-10-05 09:58:42 -04:00
|
|
|
} else if (!(/[a-z]/).test(name.charAt(0))) { //eslint-disable-line no-negated-condition
|
2015-08-18 09:43:22 -04:00
|
|
|
error = 'First character must be a letter.';
|
|
|
|
|
} else {
|
|
|
|
|
for (var i = 0; i < Constants.RESERVED_USERNAMES.length; i++) {
|
2015-09-14 16:10:31 +01:00
|
|
|
if (name === Constants.RESERVED_USERNAMES[i]) {
|
2015-08-18 09:43:22 -04:00
|
|
|
error = 'Cannot use a reserved word as a username.';
|
2015-06-14 23:53:32 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return error;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-08-18 09:43:22 -04:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function isMobile() {
|
2015-08-18 09:43:22 -04:00
|
|
|
return screen.width <= 768;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function isComment(post) {
|
2015-06-14 23:53:32 -08:00
|
|
|
if ('root_id' in post) {
|
2015-11-30 14:15:28 -05:00
|
|
|
return post.root_id !== '' && post.root_id != null;
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
return false;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getDirectTeammate(channelId) {
|
2015-08-18 09:43:22 -04:00
|
|
|
var userIds = ChannelStore.get(channelId).name.split('__');
|
2015-07-02 09:32:31 -04:00
|
|
|
var curUserId = UserStore.getCurrentId();
|
|
|
|
|
var teammate = {};
|
2015-07-01 12:41:36 -07:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
if (userIds.length !== 2 || userIds.indexOf(curUserId) === -1) {
|
2015-07-02 09:32:31 -04:00
|
|
|
return teammate;
|
|
|
|
|
}
|
2015-07-01 12:41:36 -07:00
|
|
|
|
2015-07-02 09:34:57 -04:00
|
|
|
for (var idx in userIds) {
|
2015-08-18 09:43:22 -04:00
|
|
|
if (userIds[idx] !== curUserId) {
|
2015-07-02 09:32:31 -04:00
|
|
|
teammate = UserStore.getProfile(userIds[idx]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-01 12:41:36 -07:00
|
|
|
|
2015-07-02 09:32:31 -04:00
|
|
|
return teammate;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-07-01 12:41:36 -07:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
Image.prototype.load = function imageLoad(url, progressCallback) {
|
2015-08-18 09:43:22 -04:00
|
|
|
var self = this;
|
2015-06-14 23:53:32 -08:00
|
|
|
var xmlHTTP = new XMLHttpRequest();
|
|
|
|
|
xmlHTTP.open('GET', url, true);
|
|
|
|
|
xmlHTTP.responseType = 'arraybuffer';
|
2015-08-18 09:43:22 -04:00
|
|
|
xmlHTTP.onload = function onLoad() {
|
|
|
|
|
var h = xmlHTTP.getAllResponseHeaders();
|
|
|
|
|
var m = h.match(/^Content-Type\:\s*(.*?)$/mi);
|
|
|
|
|
var mimeType = m[1] || 'image/png';
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
var blob = new Blob([this.response], {type: mimeType});
|
|
|
|
|
self.src = window.URL.createObjectURL(blob);
|
2015-06-14 23:53:32 -08:00
|
|
|
};
|
2015-08-18 09:43:22 -04:00
|
|
|
xmlHTTP.onprogress = function onprogress(e) {
|
|
|
|
|
parseInt(self.completedPercentage = (e.loaded / e.total) * 100, 10);
|
|
|
|
|
if (progressCallback) {
|
|
|
|
|
progressCallback();
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
};
|
2015-08-18 09:43:22 -04:00
|
|
|
xmlHTTP.onloadstart = function onloadstart() {
|
|
|
|
|
self.completedPercentage = 0;
|
2015-06-14 23:53:32 -08:00
|
|
|
};
|
|
|
|
|
xmlHTTP.send();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Image.prototype.completedPercentage = 0;
|
2015-06-16 15:35:34 -04:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function changeColor(colourIn, amt) {
|
2015-09-23 10:12:40 -04:00
|
|
|
var hex = colourIn;
|
|
|
|
|
var lum = amt;
|
2015-07-11 08:32:02 -07:00
|
|
|
|
2015-09-23 10:12:40 -04:00
|
|
|
// validate hex string
|
|
|
|
|
hex = String(hex).replace(/[^0-9a-f]/gi, '');
|
|
|
|
|
if (hex.length < 6) {
|
|
|
|
|
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
2015-07-11 08:32:02 -07:00
|
|
|
}
|
2015-09-23 10:12:40 -04:00
|
|
|
lum = lum || 0;
|
2015-07-11 08:32:02 -07:00
|
|
|
|
2015-09-23 10:12:40 -04:00
|
|
|
// convert to decimal and change luminosity
|
|
|
|
|
var rgb = '#';
|
|
|
|
|
var c;
|
|
|
|
|
var i;
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
|
c = parseInt(hex.substr(i * 2, 2), 16);
|
|
|
|
|
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
|
|
|
|
|
rgb += ('00' + c).substr(c.length);
|
2015-08-18 09:43:22 -04:00
|
|
|
}
|
2015-07-11 08:32:02 -07:00
|
|
|
|
2015-09-23 10:12:40 -04:00
|
|
|
return rgb;
|
|
|
|
|
}
|
2015-08-18 09:43:22 -04:00
|
|
|
|
2015-09-23 10:12:40 -04:00
|
|
|
export function changeOpacity(oldColor, opacity) {
|
|
|
|
|
var color = oldColor;
|
|
|
|
|
if (color[0] === '#') {
|
|
|
|
|
color = color.slice(1);
|
2015-08-18 09:43:22 -04:00
|
|
|
}
|
2015-07-11 08:32:02 -07:00
|
|
|
|
2015-09-23 10:12:40 -04:00
|
|
|
if (color.length === 3) {
|
|
|
|
|
const tempColor = color;
|
|
|
|
|
color = '';
|
2015-08-18 11:58:15 +05:00
|
|
|
|
2015-09-23 10:12:40 -04:00
|
|
|
color += tempColor[0] + tempColor[0];
|
|
|
|
|
color += tempColor[1] + tempColor[1];
|
|
|
|
|
color += tempColor[2] + tempColor[2];
|
2015-08-18 11:58:15 +05:00
|
|
|
}
|
|
|
|
|
|
2015-09-23 10:12:40 -04:00
|
|
|
var r = parseInt(color.substring(0, 2), 16);
|
|
|
|
|
var g = parseInt(color.substring(2, 4), 16);
|
|
|
|
|
var b = parseInt(color.substring(4, 6), 16);
|
2015-08-18 11:58:15 +05:00
|
|
|
|
|
|
|
|
return 'rgba(' + r + ',' + g + ',' + b + ',' + opacity + ')';
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-08-18 11:58:15 +05:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getFullName(user) {
|
2015-07-14 17:07:19 -04:00
|
|
|
if (user.first_name && user.last_name) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return user.first_name + ' ' + user.last_name;
|
2015-07-14 17:07:19 -04:00
|
|
|
} else if (user.first_name) {
|
|
|
|
|
return user.first_name;
|
|
|
|
|
} else if (user.last_name) {
|
|
|
|
|
return user.last_name;
|
|
|
|
|
}
|
2015-08-18 09:43:22 -04:00
|
|
|
|
|
|
|
|
return '';
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-07-14 17:07:19 -04:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getDisplayName(user) {
|
2015-07-13 17:47:57 -04:00
|
|
|
if (user.nickname && user.nickname.trim().length > 0) {
|
|
|
|
|
return user.nickname;
|
2015-08-18 09:43:22 -04:00
|
|
|
}
|
2015-09-02 10:42:26 -04:00
|
|
|
var fullName = getFullName(user);
|
2015-07-14 17:07:19 -04:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
if (fullName) {
|
|
|
|
|
return fullName;
|
2015-07-13 17:47:57 -04:00
|
|
|
}
|
2015-08-18 09:43:22 -04:00
|
|
|
|
|
|
|
|
return user.username;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-07-24 14:13:19 -07:00
|
|
|
|
2015-11-01 01:08:18 +02:00
|
|
|
export function displayUsername(userId) {
|
|
|
|
|
const user = UserStore.getProfile(userId);
|
2015-12-15 11:36:14 -05:00
|
|
|
const nameFormat = PreferenceStore.get(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'name_format', 'false');
|
2015-11-01 01:08:18 +02:00
|
|
|
|
2015-11-02 17:45:51 +02:00
|
|
|
let username = '';
|
2015-11-23 17:14:13 -08:00
|
|
|
if (user) {
|
2016-03-01 16:28:47 -05:00
|
|
|
if (nameFormat === Constants.Preferences.DISPLAY_PREFER_NICKNAME) {
|
2015-11-23 17:14:13 -08:00
|
|
|
username = user.nickname || getFullName(user);
|
2016-03-01 16:28:47 -05:00
|
|
|
} else if (nameFormat === Constants.Preferences.DISPLAY_PREFER_FULL_NAME) {
|
2015-11-23 17:14:13 -08:00
|
|
|
username = getFullName(user);
|
|
|
|
|
}
|
|
|
|
|
if (!username.trim().length) {
|
|
|
|
|
username = user.username;
|
|
|
|
|
}
|
2015-11-01 01:08:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return username;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-24 14:13:19 -07:00
|
|
|
//IE10 does not set window.location.origin automatically so this must be called instead when using it
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getWindowLocationOrigin() {
|
2015-07-27 13:21:50 -07:00
|
|
|
var windowLocationOrigin = window.location.origin;
|
|
|
|
|
if (!windowLocationOrigin) {
|
2015-08-18 09:43:22 -04:00
|
|
|
windowLocationOrigin = window.location.protocol + '//' + window.location.hostname;
|
|
|
|
|
if (window.location.port) {
|
|
|
|
|
windowLocationOrigin += ':' + window.location.port;
|
|
|
|
|
}
|
2015-07-24 14:13:19 -07:00
|
|
|
}
|
2015-07-27 13:21:50 -07:00
|
|
|
return windowLocationOrigin;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-07-22 17:18:33 -04:00
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
// Converts a file size in bytes into a human-readable string of the form '123MB'.
|
2015-09-02 10:42:26 -04:00
|
|
|
export function fileSizeToString(bytes) {
|
2015-07-22 17:18:33 -04:00
|
|
|
// it's unlikely that we'll have files bigger than this
|
|
|
|
|
if (bytes > 1024 * 1024 * 1024 * 1024) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return Math.floor(bytes / (1024 * 1024 * 1024 * 1024)) + 'TB';
|
2015-07-22 17:18:33 -04:00
|
|
|
} else if (bytes > 1024 * 1024 * 1024) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return Math.floor(bytes / (1024 * 1024 * 1024)) + 'GB';
|
2015-07-22 17:18:33 -04:00
|
|
|
} else if (bytes > 1024 * 1024) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return Math.floor(bytes / (1024 * 1024)) + 'MB';
|
2015-07-22 17:18:33 -04:00
|
|
|
} else if (bytes > 1024) {
|
2015-08-18 09:43:22 -04:00
|
|
|
return Math.floor(bytes / 1024) + 'KB';
|
2015-07-22 17:18:33 -04:00
|
|
|
}
|
2015-08-18 09:43:22 -04:00
|
|
|
|
|
|
|
|
return bytes + 'B';
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-07-28 11:30:22 -04:00
|
|
|
|
|
|
|
|
// Converts a filename (like those attached to Post objects) to a url that can be used to retrieve attachments from the server.
|
2016-01-21 13:55:47 -05:00
|
|
|
export function getFileUrl(filename, isDownload) {
|
2016-02-08 07:26:10 -05:00
|
|
|
const downloadParam = isDownload ? '?download=1' : '';
|
|
|
|
|
return getWindowLocationOrigin() + '/api/v1/files/get' + filename + downloadParam;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-07-28 16:41:57 -04:00
|
|
|
|
|
|
|
|
// Gets the name of a file (including extension) from a given url or file path.
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getFileName(path) {
|
2015-07-28 16:41:57 -04:00
|
|
|
var split = path.split('/');
|
|
|
|
|
return split[split.length - 1];
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-08-10 12:05:45 -04:00
|
|
|
|
2016-01-19 19:41:39 +01:00
|
|
|
// Gets the websocket port to use. Configurable on the server.
|
|
|
|
|
export function getWebsocketPort(protocol) {
|
2016-01-20 01:03:17 +01:00
|
|
|
if ((/^wss:/).test(protocol)) { // wss://
|
|
|
|
|
return ':' + global.window.mm_config.WebsocketSecurePort;
|
|
|
|
|
}
|
|
|
|
|
if ((/^ws:/).test(protocol)) {
|
|
|
|
|
return ':' + global.window.mm_config.WebsocketPort;
|
|
|
|
|
}
|
|
|
|
|
return '';
|
2016-01-19 19:41:39 +01:00
|
|
|
}
|
|
|
|
|
|
2015-08-10 12:05:45 -04:00
|
|
|
// Generates a RFC-4122 version 4 compliant globally unique identifier.
|
2015-09-02 10:42:26 -04:00
|
|
|
export function generateId() {
|
2015-08-10 12:05:45 -04:00
|
|
|
// implementation taken from http://stackoverflow.com/a/2117523
|
|
|
|
|
var id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
|
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
id = id.replace(/[xy]/g, function replaceRandom(c) {
|
2015-08-10 12:05:45 -04:00
|
|
|
var r = Math.floor(Math.random() * 16);
|
|
|
|
|
|
|
|
|
|
var v;
|
|
|
|
|
if (c === 'x') {
|
|
|
|
|
v = r;
|
|
|
|
|
} else {
|
|
|
|
|
v = r & 0x3 | 0x8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return v.toString(16);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return id;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-08-14 14:21:41 -07:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function isBrowserFirefox() {
|
2015-08-17 08:10:49 -07:00
|
|
|
return navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-08-14 18:26:09 -07:00
|
|
|
|
2015-08-25 12:47:18 -07:00
|
|
|
// Checks if browser is IE10 or IE11
|
2015-09-02 10:42:26 -04:00
|
|
|
export function isBrowserIE() {
|
2015-08-25 12:47:18 -07:00
|
|
|
if (window.navigator && window.navigator.userAgent) {
|
|
|
|
|
var ua = window.navigator.userAgent;
|
|
|
|
|
|
|
|
|
|
return ua.indexOf('Trident/7.0') > 0 || ua.indexOf('Trident/6.0') > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-08-25 12:47:18 -07:00
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function isBrowserEdge() {
|
2015-11-01 18:30:20 -05:00
|
|
|
return window.navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('edge') > -1;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-08-25 12:47:18 -07:00
|
|
|
|
2015-10-14 16:57:03 -04:00
|
|
|
export function getDirectChannelName(id, otherId) {
|
|
|
|
|
let handle;
|
|
|
|
|
|
|
|
|
|
if (otherId > id) {
|
|
|
|
|
handle = id + '__' + otherId;
|
|
|
|
|
} else {
|
|
|
|
|
handle = otherId + '__' + id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-14 18:26:09 -07:00
|
|
|
// Used to get the id of the other user from a DM channel
|
2015-09-02 10:42:26 -04:00
|
|
|
export function getUserIdFromChannelName(channel) {
|
2015-08-14 18:26:09 -07:00
|
|
|
var ids = channel.name.split('__');
|
|
|
|
|
var otherUserId = '';
|
|
|
|
|
if (ids[0] === UserStore.getCurrentId()) {
|
|
|
|
|
otherUserId = ids[1];
|
|
|
|
|
} else {
|
|
|
|
|
otherUserId = ids[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return otherUserId;
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-07-07 09:16:13 -04:00
|
|
|
|
2015-12-08 09:45:21 -05:00
|
|
|
// Returns true if the given channel is a direct channel between the current user and the given one
|
|
|
|
|
export function isDirectChannelForUser(otherUserId, channel) {
|
|
|
|
|
return channel.type === Constants.DM_CHANNEL && getUserIdFromChannelName(channel) === otherUserId;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 10:42:26 -04:00
|
|
|
export function importSlack(file, success, error) {
|
2015-08-18 09:43:22 -04:00
|
|
|
var formData = new FormData();
|
|
|
|
|
formData.append('file', file, file.name);
|
|
|
|
|
formData.append('filesize', file.size);
|
2015-07-07 09:16:13 -04:00
|
|
|
formData.append('importFrom', 'slack');
|
|
|
|
|
|
2015-08-18 09:43:22 -04:00
|
|
|
client.importSlack(formData, success, error);
|
2015-09-02 10:42:26 -04:00
|
|
|
}
|
2015-09-14 13:56:58 -04:00
|
|
|
|
|
|
|
|
export function getTeamURLFromAddressBar() {
|
2016-03-24 20:04:40 -04:00
|
|
|
return window.location.origin + '/' + window.location.pathname.split('/')[1];
|
2015-09-14 13:56:58 -04:00
|
|
|
}
|
|
|
|
|
|
2016-04-04 11:09:59 -04:00
|
|
|
export function getTeamURLNoOriginFromAddressBar() {
|
|
|
|
|
return '/' + window.location.pathname.split('/')[1];
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-14 13:56:58 -04:00
|
|
|
export function getShortenedTeamURL() {
|
|
|
|
|
const teamURL = getTeamURLFromAddressBar();
|
2015-09-22 11:21:28 +05:00
|
|
|
if (teamURL.length > 35) {
|
2015-09-15 08:11:00 -04:00
|
|
|
return teamURL.substring(0, 10) + '...' + teamURL.substring(teamURL.length - 12, teamURL.length) + '/';
|
2015-09-14 13:56:58 -04:00
|
|
|
}
|
2015-09-22 11:21:28 +05:00
|
|
|
return teamURL + '/';
|
2015-09-14 13:56:58 -04:00
|
|
|
}
|
2015-10-16 12:32:19 +03:00
|
|
|
|
|
|
|
|
export function windowWidth() {
|
|
|
|
|
return $(window).width();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function windowHeight() {
|
|
|
|
|
return $(window).height();
|
|
|
|
|
}
|
2015-10-26 23:29:55 +01:00
|
|
|
|
|
|
|
|
export function openDirectChannelToUser(user, successCb, errorCb) {
|
2016-03-30 09:55:32 -04:00
|
|
|
AsyncClient.savePreference(
|
|
|
|
|
Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW,
|
|
|
|
|
user.id,
|
|
|
|
|
'true'
|
|
|
|
|
);
|
|
|
|
|
|
2015-10-26 23:29:55 +01:00
|
|
|
const channelName = this.getDirectChannelName(UserStore.getCurrentId(), user.id);
|
|
|
|
|
let channel = ChannelStore.getByName(channelName);
|
|
|
|
|
|
|
|
|
|
if (channel) {
|
|
|
|
|
if ($.isFunction(successCb)) {
|
|
|
|
|
successCb(channel, true);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
channel = {
|
|
|
|
|
name: channelName,
|
|
|
|
|
last_post_at: 0,
|
|
|
|
|
total_msg_count: 0,
|
|
|
|
|
type: 'D',
|
|
|
|
|
display_name: user.username,
|
|
|
|
|
teammate_id: user.id,
|
|
|
|
|
status: UserStore.getStatus(user.id)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Client.createDirectChannel(
|
|
|
|
|
channel,
|
|
|
|
|
user.id,
|
|
|
|
|
(data) => {
|
2016-04-04 11:09:59 -04:00
|
|
|
Client.getChannel(
|
|
|
|
|
data.id,
|
|
|
|
|
(data2, textStatus, xhr) => {
|
|
|
|
|
if (xhr.status === 304 || !data2) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppDispatcher.handleServerAction({
|
|
|
|
|
type: ActionTypes.RECEIVED_CHANNEL,
|
|
|
|
|
channel: data2.channel,
|
|
|
|
|
member: data2.member
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if ($.isFunction(successCb)) {
|
|
|
|
|
successCb(data2.channel, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
2015-10-26 23:29:55 +01:00
|
|
|
},
|
|
|
|
|
() => {
|
2016-03-24 11:05:13 -04:00
|
|
|
browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/' + channelName);
|
2015-10-26 23:29:55 +01:00
|
|
|
if ($.isFunction(errorCb)) {
|
|
|
|
|
errorCb();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-02 16:04:14 -08:00
|
|
|
|
|
|
|
|
// Use when sorting multiple channels or teams by their `display_name` field
|
|
|
|
|
export function sortByDisplayName(a, b) {
|
|
|
|
|
let aDisplayName = '';
|
|
|
|
|
let bDisplayName = '';
|
|
|
|
|
|
|
|
|
|
if (a && a.display_name) {
|
|
|
|
|
aDisplayName = a.display_name.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
if (b && b.display_name) {
|
|
|
|
|
bDisplayName = b.display_name.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aDisplayName < bDisplayName) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (aDisplayName > bDisplayName) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-11-05 13:32:06 -05:00
|
|
|
|
|
|
|
|
export function getChannelTerm(channelType) {
|
|
|
|
|
let channelTerm = 'Channel';
|
|
|
|
|
if (channelType === Constants.PRIVATE_CHANNEL) {
|
|
|
|
|
channelTerm = 'Group';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return channelTerm;
|
|
|
|
|
}
|
2015-11-13 12:20:33 -05:00
|
|
|
|
|
|
|
|
export function getPostTerm(post) {
|
|
|
|
|
let postTerm = 'Post';
|
|
|
|
|
if (post.root_id) {
|
|
|
|
|
postTerm = 'Comment';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return postTerm;
|
|
|
|
|
}
|
2015-11-13 03:15:33 +01:00
|
|
|
|
2015-11-27 23:16:56 +01:00
|
|
|
export function isFeatureEnabled(feature) {
|
2015-12-15 11:36:14 -05:00
|
|
|
return PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, Constants.FeatureTogglePrefix + feature.label);
|
2015-12-03 16:30:45 -05:00
|
|
|
}
|
2015-12-04 02:07:47 +01:00
|
|
|
|
|
|
|
|
export function isSystemMessage(post) {
|
|
|
|
|
return post.type && (post.type.lastIndexOf(Constants.SYSTEM_MESSAGE_PREFIX) === 0);
|
2015-12-09 12:24:34 -05:00
|
|
|
}
|
2016-01-04 12:23:46 -05:00
|
|
|
|
|
|
|
|
export function fillArray(value, length) {
|
|
|
|
|
const arr = [];
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
|
arr.push(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
2016-01-06 14:18:05 -08:00
|
|
|
|
|
|
|
|
// 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) {
|
2016-01-08 14:26:16 -08:00
|
|
|
if (isBrowserIE()) {
|
|
|
|
|
return files.types != null && files.types.contains('Files');
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 14:18:05 -08:00
|
|
|
return files.types != null && (files.types.indexOf ? files.types.indexOf('Files') !== -1 : files.types.contains('application/x-moz-file'));
|
|
|
|
|
}
|
2016-01-04 12:44:22 -05:00
|
|
|
|
|
|
|
|
export function clearFileInput(elm) {
|
|
|
|
|
// clear file input for all modern browsers
|
|
|
|
|
try {
|
|
|
|
|
elm.value = '';
|
|
|
|
|
if (elm.value) {
|
|
|
|
|
elm.type = 'text';
|
|
|
|
|
elm.type = 'file';
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// Do nothing
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-22 09:10:08 -06:00
|
|
|
|
2016-02-03 12:12:10 -05:00
|
|
|
export function isPostEphemeral(post) {
|
|
|
|
|
return post.type === Constants.POST_TYPE_EPHEMERAL || post.state === Constants.POST_DELETED;
|
|
|
|
|
}
|
2016-02-23 11:09:59 -05:00
|
|
|
|
|
|
|
|
export function getRootId(post) {
|
|
|
|
|
return post.root_id === '' ? post.id : post.root_id;
|
|
|
|
|
}
|
2016-02-08 07:26:10 -05:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2016-04-01 11:53:49 -04:00
|
|
|
|
|
|
|
|
export function getProfilePicSrcForPost(post, timestamp) {
|
|
|
|
|
let src = '/api/v1/users/' + post.user_id + '/image?time=' + timestamp;
|
|
|
|
|
if (post.props && post.props.from_webhook && global.window.mm_config.EnablePostIconOverride === 'true') {
|
|
|
|
|
if (post.props.override_icon_url) {
|
|
|
|
|
src = post.props.override_icon_url;
|
|
|
|
|
} else {
|
|
|
|
|
src = Constants.DEFAULT_WEBHOOK_LOGO;
|
|
|
|
|
}
|
|
|
|
|
} else if (isSystemMessage(post)) {
|
|
|
|
|
src = Constants.SYSTEM_MESSAGE_PROFILE_IMAGE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return src;
|
|
|
|
|
}
|