The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rocket.Chat/server/startup/migrations/v103.js

88 lines
3.3 KiB

const majorColors = {
'content-background-color': '#FFFFFF',
'primary-background-color': '#04436A',
'primary-font-color': '#444444',
'primary-action-color': '#13679A', // was action-buttons-color
'secondary-background-color': '#F4F4F4',
'secondary-font-color': '#A0A0A0',
'secondary-action-color': '#DDDDDD',
'component-color': '#EAEAEA',
'success-color': '#4dff4d',
'pending-color': '#FCB316',
'error-color': '#BC2031',
'selection-color': '#02ACEC',
'attention-color': '#9C27B0'
};
// Minor colours implement major colours by default, but can be overruled
8 years ago
// const minorColors = {
// 'tertiary-background-color': '@component-color',
// 'tertiary-font-color': '@transparent-lightest',
// 'link-font-color': '@primary-action-color',
// 'info-font-color': '@secondary-font-color',
// 'custom-scrollbar-color': '@transparent-darker',
// 'status-online': '@success-color',
// 'status-away': '@pending-color',
// 'status-busy': '@error-color',
// 'status-offline': '@transparent-darker'
// };
const newvariables = {
8 years ago
'content-background-color': 'rc-color-primary-lightest',
'primary-background-color': 'rc-color-primary',
'success-color': 'rc-color-success',
'pending-color': 'rc-color-alert',
'error-color': 'rc-color-error',
'status-online': 'rc-color-success',
'status-away': 'rc-color-alert',
'status-busy': 'rc-color-error',
'status-offline': 'rc-color-primary-darkest'
};
8 years ago
function lightenDarkenColor(col, amt) {
8 years ago
let usePound = false;
8 years ago
if (col[0] === '#') {
8 years ago
col = col.slice(1);
usePound = true;
}
8 years ago
const num = parseInt(col, 16);
8 years ago
let r = (num >> 16) + amt;
8 years ago
if (r > 255) { r = 255; } else if (r < 0) { r = 0; }
8 years ago
let b = ((num >> 8) & 0x00FF) + amt;
8 years ago
if (b > 255) { b = 255; } else if (b < 0) { b = 0; }
8 years ago
let g = (num & 0x0000FF) + amt;
8 years ago
if (g > 255) { g = 255; } else if (g < 0) { g = 0; }
8 years ago
8 years ago
return (usePound ? '#' : '') + (g | (b << 8) | (r << 16)).toString(16);
8 years ago
}
RocketChat.Migrations.add({
version: 103,
up() {
8 years ago
Object.keys(majorColors).forEach(function(_id) {
const color = RocketChat.models.Settings.findOne({_id: `theme-color-${ _id }`});
const key = newvariables[_id];
8 years ago
if (color && color.value !== majorColors[_id] && key) {
if (/^@.+/.test(color.value)) {
color.value = newvariables[color.value.replace('@', '')];
}
const id = `theme-color-${ key }`;
RocketChat.models.Settings.update({_id: id}, {$set: { value : color.value, editor: /^#.+/.test(color.value) ? 'color' : 'expression' }});
8 years ago
if (key === 'rc-color-primary') {
RocketChat.models.Settings.update({_id: 'theme-color-rc-color-primary-darkest'}, {$set: {editor: 'color', value: lightenDarkenColor(color.value, -16)}});
RocketChat.models.Settings.update({_id: 'theme-color-rc-color-primary-dark'}, {$set: {editor: 'color', value: lightenDarkenColor(color.value, 18)}});
RocketChat.models.Settings.update({_id: 'theme-color-rc-color-primary-light'}, {$set: {editor: 'color', value: lightenDarkenColor(color.value, 110)}});
RocketChat.models.Settings.update({_id: 'theme-color-rc-color-primary-light-medium'}, {$set: {editor: 'color', value: lightenDarkenColor(color.value, 156)}});
RocketChat.models.Settings.update({_id: 'theme-color-rc-color-primary-lightest'}, {$set: {editor: 'color', value: lightenDarkenColor(color.value, 200)}});
}
}
8 years ago
});
}
});