Skip to content

Commit

Permalink
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131)
Browse files Browse the repository at this point in the history
* Move rocketchat settings to specific package

* WIP: Move models from rocketchat-lib to a specific package (server)

* Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models

* Move client models from rocketchat:lib to rocketchat:models

* Fix lint

* Move rocketchat.info from lib to utils

* Remove directly dependency between lib and migrations

* Move statistics Model to rocketchat:models

* Create rocketchat:metrics to be able to depacking rocketchat callbacks

* Move  callbacks to specific package

* Remove unused dependency

* Move rocketchat-notifications to a specific package

* Move rocketchat-promises to a specific package

* remove directly dependency from metrics and models

* Move CachedCollection from lib to models

* Move ui models/collections from ui to models

* Move authorization client/ui models to rocketchat:models to be able to remove lib dependency

* Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz

* Move some common functions to rocketchat:utils

* Change imports to dynamic imports to avoid directly dependency between some packages

* Move authz models to rocketchat:models

* Remove directly dependency between rocketchat:authz and rocketchat:lib

* Move some functions from rocketchat:lib to rocketchat:utils

* Add functions to settings package

* Convert rocketchat:file-upload to main module structure

* Import FileUpload where it is being used

* Remove FileUpload and fileUploadHandler from globals eslintrc

* Move some  functions to rocketchat:ui-utils

* Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils

* Remove dependency between lazy-load and lib

* Change imports of renderMessageBody from ui-message to ui-utils

* Add import of main ready from ui-utils

* Convert rocketchat-ui-sidenav to main module structure

* Add imports of toolbarSearch from ui-sidenav

* Remove toolbarSearch from eslintrc globals

* Move CachedCollection to a specific package

* Change imports of CachedCollection to new package

* Move some functions to rocketchat:ui-utils

* Remove directly dependency between tooltip and lib

*  Remove directly dependency between settings and metrics

* Move some settings client function from lib to settings

* Convert rocketchat-ui-master to main module structure

* Remove directly dependency between rocketchat:e2e and rocketchat:lib

* Fix wrong import and lint

* Convert rocketchat-webrtc to main module structure

* Fix missing export

* Remove directly dependency between rocketchat:emoji and lib

* Add emoji dependencies inside RocketChat namespace

* Merge branch 'develop' into globals/move-rocketchat-callbacks

* Move some functions to utils

* Fix lint

* Move some ui functions to ui-utils

* Fix import missed objects inside RocketChat namespace

* Fix lint

* Remove rocketchat:ui package dependency of RocketChat namespace

* Remove lib dependency in rocketchat:ui-sidenav

* Remove dependency between lib and ui-vrecord

* Add logger dependency in file-upload

* Revert commented test file
  • Loading branch information
MarcosSpessatto authored and rodrigok committed Jan 15, 2019
1 parent af96bd9 commit fb54664
Show file tree
Hide file tree
Showing 32 changed files with 227 additions and 268 deletions.
1 change: 1 addition & 0 deletions packages/rocketchat-file-upload/package.js
Expand Up @@ -20,6 +20,7 @@ Package.onUse(function(api) {
'rocketchat:settings',
'rocketchat:callbacks',
'rocketchat:authorization',
'rocketchat:logger',
'random',
'accounts-base',
'tracker',
Expand Down
7 changes: 7 additions & 0 deletions packages/rocketchat-lib/client/lib/ui-buttons.js
@@ -0,0 +1,7 @@
import { Login, Button, animationSupport, animeBack, preLoadImgs } from 'meteor/rocketchat:ui';

RocketChat.Login = Login;
RocketChat.Button = Button;
RocketChat.animationSupport = animationSupport;
RocketChat.animeBack = animeBack;
RocketChat.preLoadImgs = preLoadImgs;
2 changes: 2 additions & 0 deletions packages/rocketchat-lib/package.js
Expand Up @@ -34,6 +34,7 @@ Package.onUse(function(api) {
api.use('rocketchat:ui-utils');
api.use('rocketchat:tooltip');
api.use('rocketchat:emoji');
api.use('rocketchat:ui');
api.use('rocketchat:accounts');
api.use('modules');
api.use('rocketchat:i18n');
Expand Down Expand Up @@ -240,6 +241,7 @@ Package.onUse(function(api) {
api.addFiles('client/lib/authorization.js', 'client');
api.addFiles('client/lib/tooltip.js', 'client');
api.addFiles('client/lib/EmojiPicker.js', 'client');
api.addFiles('client/lib/ui-buttons.js', 'client');

// CLIENT LIB STARTUP
api.addFiles('client/lib/startup/commands.js', 'client');
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-ui-sidenav/package.js
Expand Up @@ -14,7 +14,6 @@ Package.onUse(function(api) {
api.use([
'ecmascript',
'templating',
'rocketchat:lib',
'rocketchat:callbacks',
'rocketchat:authorization',
'rocketchat:settings',
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-ui-utils/client/lib/RoomManager.js
Expand Up @@ -31,7 +31,6 @@ const onDeleteMessageBulkStream = ({ rid, ts, excludePinned, users }) => {

export const RoomManager = new function() {
const openedRooms = {};
let openedRoom = undefined; //eslint-disable-line
const msgStream = new Meteor.Streamer('room-messages');
const onlineUsers = new ReactiveVar({});
const Dep = new Tracker.Dependency();
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-ui-vrecord/package.js
Expand Up @@ -11,7 +11,8 @@ Package.onUse(function(api) {
'ecmascript',
'templating',
'tracker',
'rocketchat:lib',
'rocketchat:settings',
'rocketchat:ui',
]);
api.addFiles('client/vrecord.css', 'client');
api.mainModule('server/index.js', 'server');
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-ui-vrecord/server/settings.js
@@ -1,6 +1,6 @@
import { RocketChat } from 'meteor/rocketchat:lib';
import { settings } from 'meteor/rocketchat:settings';

RocketChat.settings.addGroup('Message', function() {
settings.addGroup('Message', function() {
this.add('Message_VideoRecorderEnabled', true, {
type: 'boolean',
public: true,
Expand Down
29 changes: 16 additions & 13 deletions packages/rocketchat-ui/client/components/header/header.js
@@ -1,11 +1,14 @@
import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
import { Template } from 'meteor/templating';
import { t } from 'meteor/rocketchat:utils';
import { t, roomTypes, handleError } from 'meteor/rocketchat:utils';
import { TabBar, fireGlobalEvent } from 'meteor/rocketchat:ui-utils';
import { ChatSubscription, Rooms } from 'meteor/rocketchat:models';
import { settings } from 'meteor/rocketchat:settings';

const isSubscribed = (_id) => ChatSubscription.find({ rid: _id }).count() > 0;

const favoritesEnabled = () => RocketChat.settings.get('Favorite_Rooms');
const favoritesEnabled = () => settings.get('Favorite_Rooms');

Template.header.helpers({
back() {
Expand All @@ -14,15 +17,15 @@ Template.header.helpers({
avatarBackground() {
const roomData = Session.get(`roomData${ this._id }`);
if (!roomData) { return ''; }
return RocketChat.roomTypes.getSecondaryRoomName(roomData.t, roomData) || RocketChat.roomTypes.getRoomName(roomData.t, roomData);
return roomTypes.getSecondaryRoomName(roomData.t, roomData) || roomTypes.getRoomName(roomData.t, roomData);
},
buttons() {
return RocketChat.TabBar.getButtons();
return TabBar.getButtons();
},

isTranslated() {
const sub = ChatSubscription.findOne({ rid: this._id }, { fields: { autoTranslate: 1, autoTranslateLanguage: 1 } });
return RocketChat.settings.get('AutoTranslate_Enabled') && ((sub != null ? sub.autoTranslate : undefined) === true) && (sub.autoTranslateLanguage != null);
return settings.get('AutoTranslate_Enabled') && ((sub != null ? sub.autoTranslate : undefined) === true) && (sub.autoTranslateLanguage != null);
},

state() {
Expand All @@ -38,21 +41,21 @@ Template.header.helpers({
},

isDirect() {
return RocketChat.models.Rooms.findOne(this._id).t === 'd';
return Rooms.findOne(this._id).t === 'd';
},

roomName() {
const roomData = Session.get(`roomData${ this._id }`);
if (!roomData) { return ''; }

return RocketChat.roomTypes.getRoomName(roomData.t, roomData);
return roomTypes.getRoomName(roomData.t, roomData);
},

secondaryName() {
const roomData = Session.get(`roomData${ this._id }`);
if (!roomData) { return ''; }

return RocketChat.roomTypes.getSecondaryRoomName(roomData.t, roomData);
return roomTypes.getSecondaryRoomName(roomData.t, roomData);
},

roomTopic() {
Expand All @@ -62,7 +65,7 @@ Template.header.helpers({
},

channelIcon() {
const roomType = RocketChat.models.Rooms.findOne(this._id).t;
const roomType = Rooms.findOne(this._id).t;
switch (roomType) {
case 'd':
return 'at';
Expand All @@ -73,15 +76,15 @@ Template.header.helpers({
case 'l':
return 'livechat';
default:
return RocketChat.roomTypes.getIcon(roomType);
return roomTypes.getIcon(roomType);
}
},

roomIcon() {
const roomData = Session.get(`roomData${ this._id }`);
if (!(roomData != null ? roomData.t : undefined)) { return ''; }

return RocketChat.roomTypes.getIcon(roomData != null ? roomData.t : undefined);
return roomTypes.getIcon(roomData != null ? roomData.t : undefined);
},

encryptedChannel() {
Expand All @@ -91,7 +94,7 @@ Template.header.helpers({

userStatus() {
const roomData = Session.get(`roomData${ this._id }`);
return RocketChat.roomTypes.getUserStatus(roomData.t, this._id) || t('offline');
return roomTypes.getUserStatus(roomData.t, this._id) || t('offline');
},

showToggleFavorite() {
Expand Down Expand Up @@ -146,5 +149,5 @@ Template.header.events({
});

Template.header.onCreated(function() {
this.currentChannel = (this.data && this.data._id && RocketChat.models.Rooms.findOne(this.data._id)) || undefined;
this.currentChannel = (this.data && this.data._id && Rooms.findOne(this.data._id)) || undefined;
});
3 changes: 2 additions & 1 deletion packages/rocketchat-ui/client/components/popupList.js
@@ -1,4 +1,5 @@
import { Template } from 'meteor/templating';
import { settings } from 'meteor/rocketchat:settings';

Template.popupList.helpers({
config() {
Expand Down Expand Up @@ -34,6 +35,6 @@ Template.popupList_default.helpers({

Template.popupList_item_default.helpers({
showRealNames() {
return RocketChat.settings.get('UI_Use_Real_Name');
return settings.get('UI_Use_Real_Name');
},
});
1 change: 1 addition & 0 deletions packages/rocketchat-ui/client/index.js
@@ -0,0 +1 @@
export { Button, Login, animationSupport, animeBack, preLoadImgs } from './lib/rocket';
53 changes: 30 additions & 23 deletions packages/rocketchat-ui/client/lib/chatMessages.js
Expand Up @@ -5,7 +5,14 @@ import { Tracker } from 'meteor/tracker';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Session } from 'meteor/session';
import { TAPi18n } from 'meteor/tap:i18n';
import { t } from 'meteor/rocketchat:utils';
import { t, getUserPreference, slashCommands, handleError } from 'meteor/rocketchat:utils';
import { MessageAction, messageProperties, MessageTypes, readMessage, modal } from 'meteor/rocketchat:ui-utils';
import { settings } from 'meteor/rocketchat:settings';
import { callbacks } from 'meteor/rocketchat:callbacks';
import { promises } from 'meteor/rocketchat:promises';
import { hasAtLeastOnePermission } from 'meteor/rocketchat:authorization';
import { Messages, Rooms, ChatMessage } from 'meteor/rocketchat:models';
import { emoji } from 'meteor/rocketchat:emoji';
import _ from 'underscore';
import s from 'underscore.string';
import moment from 'moment';
Expand All @@ -16,7 +23,7 @@ let sendOnEnter = '';
Meteor.startup(() => {
Tracker.autorun(function() {
const user = Meteor.userId();
sendOnEnter = RocketChat.getUserPreference(user, 'sendOnEnter');
sendOnEnter = getUserPreference(user, 'sendOnEnter');
});
});

Expand All @@ -32,7 +39,7 @@ ChatMessages = class ChatMessages {
init(node) {
this.editing = {};
this.records = {};
this.messageMaxSize = RocketChat.settings.get('Message_MaxAllowedSize');
this.messageMaxSize = settings.get('Message_MaxAllowedSize');
this.wrapper = $(node).find('.wrapper');
this.input = this.input || $(node).find('.js-input-message').get(0);
this.$input = $(this.input);
Expand Down Expand Up @@ -120,14 +127,14 @@ ChatMessages = class ChatMessages {

const message = this.getMessageById(element.getAttribute('id'));

const hasPermission = RocketChat.authz.hasAtLeastOnePermission('edit-message', message.rid);
const editAllowed = RocketChat.settings.get('Message_AllowEditing');
const hasPermission = hasAtLeastOnePermission('edit-message', message.rid);
const editAllowed = settings.get('Message_AllowEditing');
const editOwn = message && message.u && message.u._id === Meteor.userId();

if (!hasPermission && (!editAllowed || !editOwn)) { return; }
if (element.classList.contains('system')) { return; }

const blockEditInMinutes = RocketChat.settings.get('Message_AllowEditing_BlockEditInMinutes');
const blockEditInMinutes = settings.get('Message_AllowEditing_BlockEditInMinutes');
if (blockEditInMinutes && blockEditInMinutes !== 0) {
let currentTsDiff;
let msgTs;
Expand Down Expand Up @@ -211,8 +218,8 @@ ChatMessages = class ChatMessages {
const mentionUser = $(input).data('mention-user') || false;

if (reply !== undefined) {
msg = `[ ](${ await RocketChat.MessageAction.getPermaLink(reply._id) }) `;
const roomInfo = RocketChat.models.Rooms.findOne(reply.rid, { fields: { t: 1 } });
msg = `[ ](${ await MessageAction.getPermaLink(reply._id) }) `;
const roomInfo = Rooms.findOne(reply.rid, { fields: { t: 1 } });
if (roomInfo.t !== 'd' && reply.u.username !== Meteor.user().username && mentionUser) {
msg += `@${ reply.u.username } `;
}
Expand All @@ -225,7 +232,7 @@ ChatMessages = class ChatMessages {

if (msg.slice(0, 2) === '+:') {
const reaction = msg.slice(1).trim();
if (RocketChat.emoji.list[reaction]) {
if (emoji.list[reaction]) {
const lastMessage = ChatMessage.findOne({ rid }, { fields: { ts: 1 }, sort: { ts: -1 } });
Meteor.call('setReaction', reaction, lastMessage._id);
input.value = '';
Expand All @@ -235,7 +242,7 @@ ChatMessages = class ChatMessages {
}

// Run to allow local encryption, and maybe other client specific actions to be run before send
const msgObject = await RocketChat.promises.run('onClientBeforeSendMessage', { _id: Random.id(), rid, msg });
const msgObject = await promises.run('onClientBeforeSendMessage', { _id: Random.id(), rid, msg });

// checks for the final msgObject.msg size before actually sending the message
if (this.isMessageTooLong(msgObject.msg)) {
Expand Down Expand Up @@ -290,12 +297,12 @@ ChatMessages = class ChatMessages {
const match = msgObject.msg.match(/^\/([^\s]+)(?:\s+(.*))?$/m);
if (match) {
let command;
if (RocketChat.slashCommands.commands[match[1]]) {
const commandOptions = RocketChat.slashCommands.commands[match[1]];
if (slashCommands.commands[match[1]]) {
const commandOptions = slashCommands.commands[match[1]];
command = match[1];
const param = match[2] || '';

if (!commandOptions.permission || RocketChat.authz.hasAtLeastOnePermission(commandOptions.permission, Session.get('openedRoom'))) {
if (!commandOptions.permission || hasAtLeastOnePermission(commandOptions.permission, Session.get('openedRoom'))) {
if (commandOptions.clientOnly) {
commandOptions.callback(command, param, msgObject);
} else {
Expand All @@ -306,14 +313,14 @@ ChatMessages = class ChatMessages {
}
}

if (!RocketChat.settings.get('Message_AllowUnrecognizedSlashCommand')) {
if (!settings.get('Message_AllowUnrecognizedSlashCommand')) {
const invalidCommandMsg = {
_id: Random.id(),
rid: msgObject.rid,
ts: new Date,
msg: TAPi18n.__('No_such_command', { command: match[1] }),
u: {
username: RocketChat.settings.get('InternalHubot_Username'),
username: settings.get('InternalHubot_Username'),
},
private: true,
};
Expand All @@ -328,7 +335,7 @@ ChatMessages = class ChatMessages {
}

confirmDeleteMsg(message, done = function() {}) {
if (RocketChat.MessageTypes.isSystemMessage(message)) { return; }
if (MessageTypes.isSystemMessage(message)) { return; }
modal.open({
title: t('Are_you_sure'),
text: t('You_will_not_be_able_to_recover'),
Expand Down Expand Up @@ -358,8 +365,8 @@ ChatMessages = class ChatMessages {
}

deleteMsg(message) {
const forceDelete = RocketChat.authz.hasAtLeastOnePermission('force-delete-message', message.rid);
const blockDeleteInMinutes = RocketChat.settings.get('Message_AllowDeleting_BlockDeleteInMinutes');
const forceDelete = hasAtLeastOnePermission('force-delete-message', message.rid);
const blockDeleteInMinutes = settings.get('Message_AllowDeleting_BlockDeleteInMinutes');
if (blockDeleteInMinutes && forceDelete === false) {
let msgTs;
if (message.ts != null) { msgTs = moment(message.ts); }
Expand Down Expand Up @@ -460,7 +467,7 @@ ChatMessages = class ChatMessages {
if (!msgId) {
return;
}
const message = RocketChat.models.Messages.findOne(msgId);
const message = Messages.findOne(msgId);
if (message) {
return this.$input.data('reply', message).trigger('dataChange');
}
Expand Down Expand Up @@ -594,8 +601,8 @@ ChatMessages = class ChatMessages {
}

isMessageTooLong(message) {
const adjustedMessage = RocketChat.messageProperties.messageWithoutEmojiShortnames(message);
return RocketChat.messageProperties.length(adjustedMessage) > this.messageMaxSize && message;
const adjustedMessage = messageProperties.messageWithoutEmojiShortnames(message);
return messageProperties.length(adjustedMessage) > this.messageMaxSize && message;
}

isEmpty() {
Expand All @@ -604,10 +611,10 @@ ChatMessages = class ChatMessages {
};


RocketChat.callbacks.add('afterLogoutCleanUp', () => {
callbacks.add('afterLogoutCleanUp', () => {
Object.keys(localStorage).forEach((item) => {
if (item.indexOf('messagebox_') === 0) {
localStorage.removeItem(item);
}
});
}, RocketChat.callbacks.priority.MEDIUM, 'chatMessages-after-logout-cleanup');
}, callbacks.priority.MEDIUM, 'chatMessages-after-logout-cleanup');
3 changes: 2 additions & 1 deletion packages/rocketchat-ui/client/lib/collections.js
@@ -1,5 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { settings } from 'meteor/rocketchat:settings';
import {
ChatMessage as chatMessage,
CachedChatRoom as cachedChatRoom,
Expand Down Expand Up @@ -27,7 +28,7 @@ this.CachedUserList = cachedUserList;

Meteor.startup(() => {
Tracker.autorun(() => {
if (!Meteor.userId() && RocketChat.settings.get('Accounts_AllowAnonymousRead') === true) {
if (!Meteor.userId() && settings.get('Accounts_AllowAnonymousRead') === true) {
CachedChatRoom.init();
CachedChatSubscription.ready.set(true);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-ui/client/lib/cordova/push.js
Expand Up @@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Push } from 'meteor/rocketchat:push';
import { settings } from 'meteor/rocketchat:settings';

if (Meteor.isCordova) {
// Push.addListener 'token', (token) ->
Expand Down Expand Up @@ -72,7 +73,7 @@ if (Meteor.isCordova) {

Meteor.startup(() =>
Tracker.autorun(() => {
if (RocketChat.settings.get('Push_enable') === true) {
if (settings.get('Push_enable') === true) {

Push.Configure({
android: {
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-ui/client/lib/cordova/user-state.js
@@ -1,5 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { UserPresence } from 'meteor/konecty:user-presence';
import { readMessage } from 'meteor/rocketchat:ui-utils';
import _ from 'underscore';

let timer = undefined;
Expand Down

0 comments on commit fb54664

Please sign in to comment.