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

Convert rocketchat-emoji-custom to main module structure #12604

Merged
merged 6 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ReactiveVar } from 'meteor/reactive-var';
import { RocketChatTabBar } from 'meteor/rocketchat:lib';
import { RocketChat, RocketChatTabBar } from 'meteor/rocketchat:lib';
import { Tracker } from 'meteor/tracker';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Template } from 'meteor/templating';
import { SideNav } from 'meteor/rocketchat:ui';
import s from 'underscore.string';

Template.adminEmoji.helpers({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { TAPi18n } from 'meteor/tap:i18n';
import { handleError } from 'meteor/rocketchat:lib';
import { t } from 'meteor/rocketchat:ui';
import toastr from 'toastr';
import s from 'underscore.string';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { Template } from 'meteor/templating';
import { handleError } from 'meteor/rocketchat:lib';
import { t, modal } from 'meteor/rocketchat:ui';

Template.emojiInfo.helpers({
name() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

RocketChat.AdminBox.addOption({
href: 'emoji-custom',
i18nLabel: 'Custom_Emoji',
Expand Down
16 changes: 16 additions & 0 deletions packages/rocketchat-emoji-custom/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import '../assets/stylesheets/emojiCustomAdmin.css';
import './models/EmojiCustom';
import './lib/emojiCustom';
import './notifications/deleteEmojiCustom';
import './notifications/updateEmojiCustom';
import './admin/startup';
import './admin/adminEmoji.html';
import './admin/adminEmoji';
import './admin/adminEmojiEdit.html';
import './admin/adminEmojiInfo.html';
import './admin/emojiEdit.html';
import './admin/emojiEdit';
import './admin/emojiInfo.html';
import './admin/emojiInfo';
import './admin/emojiPreview.html';
import './admin/route';
74 changes: 37 additions & 37 deletions packages/rocketchat-emoji-custom/client/lib/emojiCustom.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,11 @@
/* globals getEmojiUrlFromName:true, updateEmojiCustom:true, deleteEmojiCustom:true, isSetNotNull */
import { Meteor } from 'meteor/meteor';
import { Blaze } from 'meteor/blaze';
import { Session } from 'meteor/session';
import { RocketChat } from 'meteor/rocketchat:lib';
import { isSetNotNull } from '../lib/function-isSet';
import { RoomManager } from 'meteor/rocketchat:ui';

RocketChat.emoji.packages.emojiCustom = {
emojiCategories: { rocket: 'Custom' },
toneList: {},
list: [],

render(html) {
const regShortNames = new RegExp(`<object[^>]*>.*?<\/object>|<span[^>]*>.*?<\/span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|(${ RocketChat.emoji.packages.emojiCustom.list.join('|') })`, 'gi');

// replace regular shortnames first
html = html.replace(regShortNames, function(shortname) {
// console.log('shortname (preif) ->', shortname, html);
if ((typeof shortname === 'undefined') || (shortname === '') || (RocketChat.emoji.packages.emojiCustom.list.indexOf(shortname) === -1)) {
// if the shortname doesnt exist just return the entire match
return shortname;
} else {
let emojiAlias = shortname.replace(/:/g, '');

let dataCheck = RocketChat.emoji.list[shortname];
if (dataCheck.hasOwnProperty('aliasOf')) {
emojiAlias = dataCheck.aliasOf;
dataCheck = RocketChat.emoji.list[`:${ emojiAlias }:`];
}

return `<span class="emoji" style="background-image:url(${ getEmojiUrlFromName(emojiAlias, dataCheck.extension) });" data-emoji="${ emojiAlias }" title="${ shortname }">${ shortname }</span>`;
}
});

return html;
},
};

getEmojiUrlFromName = function(name, extension) {
export const getEmojiUrlFromName = function(name, extension) {
Session.get;

const key = `emoji_random_${ name }`;
Expand All @@ -53,7 +24,7 @@ getEmojiUrlFromName = function(name, extension) {

Blaze.registerHelper('emojiUrlFromName', getEmojiUrlFromName);

deleteEmojiCustom = function(emojiData) {
export const deleteEmojiCustom = function(emojiData) {
delete RocketChat.emoji.list[`:${ emojiData.name }:`];
const arrayIndex = RocketChat.emoji.packages.emojiCustom.emojisByCategory.rocket.indexOf(emojiData.name);
if (arrayIndex !== -1) {
Expand All @@ -75,7 +46,7 @@ deleteEmojiCustom = function(emojiData) {
RocketChat.EmojiPicker.updateRecent();
};

updateEmojiCustom = function(emojiData) {
export const updateEmojiCustom = function(emojiData) {
let key = `emoji_random_${ emojiData.name }`;
Session.set(key, Math.round(Math.random() * 1000));

Expand Down Expand Up @@ -151,6 +122,37 @@ updateEmojiCustom = function(emojiData) {
RocketChat.EmojiPicker.updateRecent();
};

RocketChat.emoji.packages.emojiCustom = {
emojiCategories: { rocket: 'Custom' },
toneList: {},
list: [],

render(html) {
const regShortNames = new RegExp(`<object[^>]*>.*?<\/object>|<span[^>]*>.*?<\/span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|(${ RocketChat.emoji.packages.emojiCustom.list.join('|') })`, 'gi');

// replace regular shortnames first
html = html.replace(regShortNames, function(shortname) {
// console.log('shortname (preif) ->', shortname, html);
if ((typeof shortname === 'undefined') || (shortname === '') || (RocketChat.emoji.packages.emojiCustom.list.indexOf(shortname) === -1)) {
// if the shortname doesnt exist just return the entire match
return shortname;
} else {
let emojiAlias = shortname.replace(/:/g, '');

let dataCheck = RocketChat.emoji.list[shortname];
if (dataCheck.hasOwnProperty('aliasOf')) {
emojiAlias = dataCheck.aliasOf;
dataCheck = RocketChat.emoji.list[`:${ emojiAlias }:`];
}

return `<span class="emoji" style="background-image:url(${ getEmojiUrlFromName(emojiAlias, dataCheck.extension) });" data-emoji="${ emojiAlias }" title="${ shortname }">${ shortname }</span>`;
}
});

return html;
},
};

Meteor.startup(() =>
RocketChat.CachedCollectionManager.onLogin(() => {
Meteor.call('listEmojiCustom', (error, result) => {
Expand All @@ -171,5 +173,3 @@ Meteor.startup(() =>
});
})
);

/* exported getEmojiUrlFromName, updateEmojiCustom, deleteEmojiCustom */
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* globals isSet:true, isSetNotNull:true */
// http://stackoverflow.com/a/26990347 function isSet() from Gajus
isSet = function(fn) {
export const isSet = function(fn) {
let value;
try {
value = fn();
Expand All @@ -11,7 +10,7 @@ isSet = function(fn) {
}
};

isSetNotNull = function(fn) {
export const isSetNotNull = function(fn) {
let value;
try {
value = fn();
Expand All @@ -21,5 +20,3 @@ isSetNotNull = function(fn) {
return value !== null && value !== undefined;
}
};

/* exported isSet, isSetNotNull */
2 changes: 2 additions & 0 deletions packages/rocketchat-emoji-custom/client/models/EmojiCustom.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

class EmojiCustom extends RocketChat.models._Base {
constructor() {
super();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* globals deleteEmojiCustom */
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { deleteEmojiCustom } from '../lib/emojiCustom';

Meteor.startup(() =>
RocketChat.Notifications.onLogged('deleteEmojiCustom', (data) => deleteEmojiCustom(data.emojiData))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* globals updateEmojiCustom */
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { updateEmojiCustom } from '../lib/emojiCustom';

Meteor.startup(() =>
RocketChat.Notifications.onLogged('updateEmojiCustom', (data) => updateEmojiCustom(data.emojiData))
Expand Down
44 changes: 4 additions & 40 deletions packages/rocketchat-emoji-custom/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,10 @@ Package.onUse(function(api) {
'rocketchat:lib',
'templating',
'webapp',
'kadira:flow-router',
'kadira:blaze-layout',
]);

api.use('kadira:flow-router', 'client');
api.use('kadira:blaze-layout', 'client');

api.addFiles('function-isSet.js');

api.addFiles('server/startup/emoji-custom.js', 'server');
api.addFiles('server/startup/settings.js', 'server');

api.addFiles('server/models/EmojiCustom.js', 'server');
api.addFiles('server/publications/fullEmojiData.js', 'server');

api.addFiles([
'server/methods/listEmojiCustom.js',
'server/methods/deleteEmojiCustom.js',
'server/methods/insertOrUpdateEmoji.js',
'server/methods/uploadEmojiCustom.js',
], 'server');

api.addFiles('assets/stylesheets/emojiCustomAdmin.css', 'client');

api.addFiles([
'admin/startup.js',
'admin/adminEmoji.html',
'admin/adminEmoji.js',
'admin/adminEmojiEdit.html',
'admin/adminEmojiInfo.html',
'admin/emojiPreview.html',
'admin/emojiEdit.html',
'admin/emojiEdit.js',
'admin/emojiInfo.html',
'admin/emojiInfo.js',
'admin/route.js',
], 'client');

api.addFiles([
'client/lib/emojiCustom.js',
'client/models/EmojiCustom.js',
'client/notifications/updateEmojiCustom.js',
'client/notifications/deleteEmojiCustom.js',
], 'client');
api.mainModule('client/index.js', 'client');
api.mainModule('server/index.js', 'server');
});
8 changes: 8 additions & 0 deletions packages/rocketchat-emoji-custom/server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import './startup/emoji-custom';
import './startup/settings';
import './models/EmojiCustom';
import './publications/fullEmojiData';
import './methods/listEmojiCustom';
import './methods/deleteEmojiCustom';
import './methods/insertOrUpdateEmoji';
import './methods/uploadEmojiCustom';
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* globals RocketChatFileEmojiCustomInstance */
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { RocketChatFileEmojiCustomInstance } from '../startup/emoji-custom';

Meteor.methods({
deleteEmojiCustom(emojiID) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* globals RocketChatFileEmojiCustomInstance */
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { RocketChatFileEmojiCustomInstance } from '../startup/emoji-custom';
import _ from 'underscore';
import s from 'underscore.string';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';

Meteor.methods({
listEmojiCustom() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* globals RocketChatFileEmojiCustomInstance */
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { RocketChatFile } from 'meteor/rocketchat:file';
import { RocketChatFileEmojiCustomInstance } from '../startup/emoji-custom';

Meteor.methods({
uploadEmojiCustom(binaryContent, contentType, emojiData) {
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-emoji-custom/server/models/EmojiCustom.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

class EmojiCustom extends RocketChat.models._Base {
constructor() {
super('custom_emoji');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import s from 'underscore.string';

Meteor.publish('fullEmojiData', function(filter, limit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* globals RocketChatFileEmojiCustomInstance */
import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
import { RocketChat } from 'meteor/rocketchat:lib';
import { RocketChatFile } from 'meteor/rocketchat:file';
import _ from 'underscore';

export let RocketChatFileEmojiCustomInstance;

Meteor.startup(function() {
let storeType = 'GridFS';

Expand All @@ -25,11 +28,12 @@ Meteor.startup(function() {
}
}

this.RocketChatFileEmojiCustomInstance = new RocketChatStore({
RocketChatFileEmojiCustomInstance = new RocketChatStore({
name: 'custom_emoji',
absolutePath: path,
});


return WebApp.connectHandlers.use('/emoji-custom/', Meteor.bindEnvironment(function(req, res/* , next*/) {
const params =
{ emoji: decodeURIComponent(req.url.replace(/^\//, '').replace(/\?.*$/, '')) };
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-emoji-custom/server/startup/settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

RocketChat.settings.addGroup('EmojiCustomFilesystem', function() {
this.add('EmojiUpload_Storage_Type', 'GridFS', {
type: 'select',
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-ui/client/lib/RoomManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ Tracker.autorun(function() {
}
});

export { RoomManager };
RocketChat.callbacks.add('afterLogoutCleanUp', () => RoomManager.closeAllRooms(), RocketChat.callbacks.priority.MEDIUM, 'roommanager-after-logout-cleanup');

RocketChat.CachedCollectionManager.onLogin(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-ui/client/lib/sideNav.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Session } from 'meteor/session';

this.SideNav = new class {
SideNav = new class { //eslint-disable-line
constructor() {
this.initiated = false;
this.sideNav = {};
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-ui/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Package.onUse(function(api) {
api.export('ChatRoom', 'client');
api.export('ChatSubscription', 'client');
api.export('RoomRoles', 'client');
api.export('SideNav', 'client');
api.export('ChatMessages', 'client');
api.export('RoomManager', 'client');
});