Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency of RC namespace in rc-theme #13234

Merged
merged 31 commits into from Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6f749bc
Move integrations models to rc-models
MarcosSpessatto Jan 21, 2019
5dec8ce
Move composeMessage function to rc-utils
MarcosSpessatto Jan 21, 2019
583cb87
Move PushNotifications class to push-notifications package
MarcosSpessatto Jan 21, 2019
039e7cd
Import variables to remove dependency of RC namespace
MarcosSpessatto Jan 21, 2019
d49540b
Import variables to remove RC namespace dependency inside rc-lib/serv…
MarcosSpessatto Jan 22, 2019
4cede2e
Import variables to remove RC namespace inside rc-lib/server/methods
MarcosSpessatto Jan 22, 2019
5ecc7b8
Import variables to remove dependency with RC namespace
MarcosSpessatto Jan 22, 2019
f3280a6
Remove duplicated server settings located in rc-lib
MarcosSpessatto Jan 22, 2019
f526680
Merge remote-tracking branch 'origin/depackaging' into globals/rc-lib…
rodrigok Jan 22, 2019
8d4c70f
Merge branch 'globals/rc-lib-wave-5' into globals/rc-lib-wave-6
MarcosSpessatto Jan 22, 2019
fb7666d
Merge branch 'globals/rc-lib-wave-6' into globals/lib-settings
MarcosSpessatto Jan 22, 2019
f457877
Export function and lib function of rc-lib but keep it inside RC name…
MarcosSpessatto Jan 22, 2019
3b6ffa6
Import variables from functions and lib to remove RC namespace depend…
MarcosSpessatto Jan 22, 2019
27043cb
Merge remote-tracking branch 'origin/depackaging' into globals/lib-fu…
rodrigok Jan 22, 2019
6ab7f28
Remove dependency of RC namespace in rc-sandstorm
MarcosSpessatto Jan 22, 2019
f00a322
Merge branch 'globals/lib-functions' into globals/lib-functions-import
MarcosSpessatto Jan 22, 2019
6043a3d
Merge branch 'globals/lib-functions-import' into globals/lib-x-sandstorm
MarcosSpessatto Jan 22, 2019
568ed1f
Remove dependency of RC namespace in chatpal-search
MarcosSpessatto Jan 23, 2019
36c17f2
Merge remote-tracking branch 'origin/depackaging' into globals/lib-fu…
rodrigok Jan 23, 2019
08d8bd1
Merge remote-tracking branch 'origin/globals/lib-functions-import' in…
rodrigok Jan 23, 2019
06a780f
Merge remote-tracking branch 'origin/depackaging' into globals/lib-x-…
rodrigok Jan 23, 2019
5d60447
Move CreadentialTokens model to rc-models
MarcosSpessatto Jan 23, 2019
dd9303f
Move getUsernameSuggestion function and method from server/ to rc-lib
MarcosSpessatto Jan 23, 2019
842a519
Remove dependency of RC namespace in meteor saml
MarcosSpessatto Jan 23, 2019
76b17c8
Merge branch 'globals/lib-x-sandstorm' into globals/lib-x-chatpal-search
rodrigok Jan 23, 2019
9645e02
Merge remote-tracking branch 'origin/depackaging' into globals/lib-x-…
rodrigok Jan 23, 2019
ba81c02
Remove dependency of RC namespace in rc-theme
MarcosSpessatto Jan 23, 2019
c32491e
Merge branch 'globals/lib-x-chatpal-search' into globals/rc-x-saml
rodrigok Jan 23, 2019
df3c3f8
Merge remote-tracking branch 'origin/depackaging' into globals/rc-x-saml
rodrigok Jan 23, 2019
9a4ee66
Merge branch 'globals/rc-x-saml' into globals/rc-x-theme
MarcosSpessatto Jan 23, 2019
025eb99
Merge remote-tracking branch 'origin/depackaging' into globals/rc-x-t…
rodrigok Jan 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rocketchat_theme/package.js
Expand Up @@ -10,7 +10,7 @@ Package.onUse(function(api) {
'less',
'webapp',
'webapp-hashing',
'rocketchat:lib',
'rocketchat:settings',
'rocketchat:logger',
'rocketchat:assets',
'templating',
Expand Down
101 changes: 51 additions & 50 deletions packages/rocketchat_theme/server/server.js
@@ -1,6 +1,6 @@
import { WebApp } from 'meteor/webapp';
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { settings } from 'meteor/rocketchat:settings';
import { Logger } from 'meteor/rocketchat:logger';
import { WebAppHashing } from 'meteor/webapp-hashing';
import _ from 'underscore';
Expand All @@ -16,54 +16,15 @@ const logger = new Logger('rocketchat:theme', {
},
});

WebApp.rawConnectHandlers.use(function(req, res, next) {
const path = req.url.split('?')[0];
const prefix = __meteor_runtime_config__.ROOT_URL_PATH_PREFIX || '';
if (path === `${ prefix }/theme.css`) {
const css = RocketChat.theme.getCss();
const hash = crypto.createHash('sha1').update(css).digest('hex');
res.setHeader('Content-Type', 'text/css; charset=UTF-8');
res.setHeader('ETag', `"${ hash }"`);
res.write(css);
return res.end();
} else {
return next();
}
});

const { calculateClientHash } = WebAppHashing;

WebAppHashing.calculateClientHash = function(manifest, includeFilter, runtimeConfigOverride) {
const css = RocketChat.theme.getCss();
if (css.trim() !== '') {
const hash = crypto.createHash('sha1').update(css).digest('hex');
let themeManifestItem = _.find(manifest, function(item) {
return item.path === 'app/theme.css';
});
if (themeManifestItem == null) {
themeManifestItem = {};
manifest.push(themeManifestItem);
}
themeManifestItem.path = 'app/theme.css';
themeManifestItem.type = 'css';
themeManifestItem.cacheable = true;
themeManifestItem.where = 'client';
themeManifestItem.url = `/theme.css?${ hash }`;
themeManifestItem.size = css.length;
themeManifestItem.hash = hash;
}
return calculateClientHash.call(this, manifest, includeFilter, runtimeConfigOverride);
};

RocketChat.theme = new class {
export const theme = new class {
constructor() {
this.variables = {};
this.packageCallbacks = [];
this.files = ['server/colors.less'];
this.customCSS = '';
RocketChat.settings.add('css', '');
RocketChat.settings.addGroup('Layout');
RocketChat.settings.onload('css', Meteor.bindEnvironment((key, value, initialLoad) => {
settings.add('css', '');
settings.addGroup('Layout');
settings.onload('css', Meteor.bindEnvironment((key, value, initialLoad) => {
if (!initialLoad) {
Meteor.startup(function() {
process.emit('message', {
Expand All @@ -74,8 +35,8 @@ RocketChat.theme = new class {
}));
this.compileDelayed = _.debounce(Meteor.bindEnvironment(this.compile.bind(this)), 100);
Meteor.startup(() => {
RocketChat.settings.onAfterInitialLoad(() => {
RocketChat.settings.get(/^theme-./, Meteor.bindEnvironment((key, value) => {
settings.onAfterInitialLoad(() => {
settings.get(/^theme-./, Meteor.bindEnvironment((key, value) => {
if (key === 'theme-custom-css' && value != null) {
this.customCSS = value;
} else {
Expand Down Expand Up @@ -110,7 +71,7 @@ RocketChat.theme = new class {
if (err != null) {
return console.log(err);
}
RocketChat.settings.updateById('css', data.css);
settings.updateById('css', data.css);
return Meteor.startup(function() {
return Meteor.setTimeout(function() {
return process.emit('message', {
Expand All @@ -131,7 +92,7 @@ RocketChat.theme = new class {
section,
};

return RocketChat.settings.add(`theme-color-${ name }`, value, config);
return settings.add(`theme-color-${ name }`, value, config);
}

addVariable(type, name, value, section, persist = true, editor, allowedTypes, property) {
Expand All @@ -149,7 +110,7 @@ RocketChat.theme = new class {
allowedTypes,
property,
};
return RocketChat.settings.add(`theme-${ type }-${ name }`, value, config);
return settings.add(`theme-${ type }-${ name }`, value, config);
}

}
Expand Down Expand Up @@ -182,7 +143,47 @@ RocketChat.theme = new class {
}

getCss() {
return RocketChat.settings.get('css') || '';
return settings.get('css') || '';
}

};


WebApp.rawConnectHandlers.use(function(req, res, next) {
const path = req.url.split('?')[0];
const prefix = __meteor_runtime_config__.ROOT_URL_PATH_PREFIX || '';
if (path === `${ prefix }/theme.css`) {
const css = theme.getCss();
const hash = crypto.createHash('sha1').update(css).digest('hex');
res.setHeader('Content-Type', 'text/css; charset=UTF-8');
res.setHeader('ETag', `"${ hash }"`);
res.write(css);
return res.end();
} else {
return next();
}
});

const { calculateClientHash } = WebAppHashing;

WebAppHashing.calculateClientHash = function(manifest, includeFilter, runtimeConfigOverride) {
const css = theme.getCss();
if (css.trim() !== '') {
const hash = crypto.createHash('sha1').update(css).digest('hex');
let themeManifestItem = _.find(manifest, function(item) {
return item.path === 'app/theme.css';
});
if (themeManifestItem == null) {
themeManifestItem = {};
manifest.push(themeManifestItem);
}
themeManifestItem.path = 'app/theme.css';
themeManifestItem.type = 'css';
themeManifestItem.cacheable = true;
themeManifestItem.where = 'client';
themeManifestItem.url = `/theme.css?${ hash }`;
themeManifestItem.size = css.length;
themeManifestItem.hash = hash;
}
return calculateClientHash.call(this, manifest, includeFilter, runtimeConfigOverride);
};
15 changes: 8 additions & 7 deletions packages/rocketchat_theme/server/variables.js
@@ -1,4 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';
import { settings } from 'meteor/rocketchat:settings';
import { theme } from './server';
// TODO: Define registers/getters/setters for packages to work with established
// heirarchy of colors instead of making duplicate definitions
// TODO: Settings pages to show simple separation of major/minor/addon colors
Expand All @@ -21,9 +22,9 @@ const colors = [...Assets.getText('client/imports/general/variables.css').match(
colors.forEach(([key, color]) => {
if (/var/.test(color)) {
const [, value] = color.match(/var\(--(.*?)\)/i);
return RocketChat.theme.addPublicColor(key, value, 'Colors', 'expression');
return theme.addPublicColor(key, value, 'Colors', 'expression');
}
RocketChat.theme.addPublicColor(key, color, 'Colors');
theme.addPublicColor(key, color, 'Colors');
});

const majorColors = {
Expand Down Expand Up @@ -58,17 +59,17 @@ const minorColors = {
// Bulk-add settings for color scheme
Object.keys(majorColors).forEach((key) => {
const value = majorColors[key];
RocketChat.theme.addPublicColor(key, value, 'Old Colors');
theme.addPublicColor(key, value, 'Old Colors');
});

Object.keys(minorColors).forEach((key) => {
const value = minorColors[key];
RocketChat.theme.addPublicColor(key, value, 'Old Colors (minor)', 'expression');
theme.addPublicColor(key, value, 'Old Colors (minor)', 'expression');
});

RocketChat.theme.addPublicFont('body-font-family', '-apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen, Ubuntu, Cantarell, \'Helvetica Neue\', \'Apple Color Emoji\', \'Segoe UI Emoji\', \'Segoe UI Symbol\', \'Meiryo UI\', Arial, sans-serif');
theme.addPublicFont('body-font-family', '-apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen, Ubuntu, Cantarell, \'Helvetica Neue\', \'Apple Color Emoji\', \'Segoe UI Emoji\', \'Segoe UI Symbol\', \'Meiryo UI\', Arial, sans-serif');

RocketChat.settings.add('theme-custom-css', '', {
settings.add('theme-custom-css', '', {
group: 'Layout',
type: 'code',
code: 'text/css',
Expand Down