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 some dependencies inside rocketchat-lib/lib #13212

Merged
merged 4 commits into from
Jan 21, 2019
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
5 changes: 2 additions & 3 deletions packages/rocketchat-grant/server/grant.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { RocketChat } from 'meteor/rocketchat:lib';

import { hostname } from 'meteor/rocketchat:lib';
import Providers from './providers';
import Settings from './settings';
import { path, generateCallback, generateAppCallback } from './routes';
Expand Down Expand Up @@ -38,7 +37,7 @@ const config = {};
export function generateConfig() {
config.server = {
protocol: 'http',
host: RocketChat.hostname,
host: hostname,
path,
state: true,
};
Expand Down
103 changes: 2 additions & 101 deletions packages/rocketchat-lib/client/lib/openRoom.js
Original file line number Diff line number Diff line change
@@ -1,102 +1,3 @@
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import { Session } from 'meteor/session';
import { RoomManager, fireGlobalEvent, readMessage, RoomHistoryManager, Layout } from 'meteor/rocketchat:ui-utils';
import { ChatSubscription, Rooms } from 'meteor/rocketchat:models';
import { settings } from 'meteor/rocketchat:settings';
import { callbacks } from 'meteor/rocketchat:callbacks';
import { roomTypes, handleError } from 'meteor/rocketchat:utils';
import _ from 'underscore';
import { openRoom as _openRoom } from 'meteor/rocketchat:ui-utils';

export let currentTracker = undefined;

openRoom = function(type, name) {
Session.set('openedRoom', null);

return Meteor.defer(() =>
currentTracker = Tracker.autorun(function(c) {
const user = Meteor.user();
if ((user && user.username == null) || (user == null && settings.get('Accounts_AllowAnonymousRead') === false)) {
BlazeLayout.render('main');
return;
}

if (RoomManager.open(type + name).ready() !== true) {
BlazeLayout.render('main', { modal: Layout.isEmbedded(), center: 'loading' });
return;
}
if (currentTracker) {
currentTracker = undefined;
}
c.stop();

const room = roomTypes.findRoom(type, name, user);
if (room == null) {
if (type === 'd') {
Meteor.call('createDirectMessage', name, function(error) {
if (!error) {
RoomManager.close(type + name);
return openRoom('d', name);
} else {
Session.set('roomNotFound', { type, name, error });
BlazeLayout.render('main', { center: 'roomNotFound' });
return;
}
});
} else {
Meteor.call('getRoomByTypeAndName', type, name, function(error, record) {
if (error) {
Session.set('roomNotFound', { type, name, error });
return BlazeLayout.render('main', { center: 'roomNotFound' });
} else {
Rooms.upsert({ _id: record._id }, _.omit(record, '_id'));
RoomManager.close(type + name);
return openRoom(type, name);
}
});
}
return;
}

const mainNode = document.querySelector('.main-content');
if (mainNode) {
for (const child of Array.from(mainNode.children)) {
if (child) { mainNode.removeChild(child); }
}
const roomDom = RoomManager.getDomOfRoom(type + name, room._id);
mainNode.appendChild(roomDom);
if (roomDom.classList.contains('room-container')) {
roomDom.querySelector('.messages-box > .wrapper').scrollTop = roomDom.oldScrollTop;
}
}

Session.set('openedRoom', room._id);
RoomManager.openedRoom = room._id;

fireGlobalEvent('room-opened', _.omit(room, 'usernames'));

Session.set('editRoomTitle', false);
RoomManager.updateMentionsMarksOfRoom(type + name);
Meteor.setTimeout(() => readMessage.readNow(), 2000);
// KonchatNotification.removeRoomNotification(params._id)
// update user's room subscription
const sub = ChatSubscription.findOne({ rid: room._id });
if (sub && sub.open === false) {
Meteor.call('openRoom', room._id, function(err) {
if (err) {
return handleError(err);
}
});
}

if (FlowRouter.getQueryParam('msg')) {
const msg = { _id: FlowRouter.getQueryParam('msg'), rid: room._id };
RoomHistoryManager.getSurroundingMessages(msg);
}

return callbacks.run('enter-room', sub);
})
);
};
openRoom = _openRoom;
2 changes: 1 addition & 1 deletion packages/rocketchat-lib/client/lib/roomExit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Blaze } from 'meteor/blaze';
import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import { callbacks } from 'meteor/rocketchat:callbacks';
import { currentTracker } from './openRoom';
import { currentTracker } from 'meteor/rocketchat:ui-utils';

this.roomExit = function() {
// 7370 - Close flex-tab when opening a room on mobile UI
Expand Down
33 changes: 2 additions & 31 deletions packages/rocketchat-lib/lib/Message.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,3 @@
import { TAPi18n } from 'meteor/tap:i18n';
import s from 'underscore.string';
import { Message } from 'meteor/rocketchat:ui-utils';

RocketChat.Message = {
parse(msg, language) {
const messageType = RocketChat.MessageTypes.getType(msg);
if (messageType) {
if (messageType.render) {
return messageType.render(msg);
} else if (messageType.template) {
// Render message
return;
} else if (messageType.message) {
if (!language && typeof localStorage !== 'undefined') {
language = localStorage.getItem('userLanguage');
}
const data = (typeof messageType.data === 'function' && messageType.data(msg)) || {};
return TAPi18n.__(messageType.message, data, language);
}
}
if (msg.u && msg.u.username === RocketChat.settings.get('Chatops_Username')) {
msg.html = msg.msg;
return msg.html;
}
msg.html = msg.msg;
if (s.trim(msg.html) !== '') {
msg.html = s.escapeHTML(msg.html);
}
msg.html = msg.html.replace(/\n/gm, '<br/>');
return msg.html;
},
};
RocketChat.Message = Message;
31 changes: 16 additions & 15 deletions packages/rocketchat-lib/lib/MessageTypes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { MessageTypes } from 'meteor/rocketchat:ui-utils';
import { callbacks } from 'meteor/rocketchat:callbacks';

RocketChat.MessageTypes = MessageTypes;

Meteor.startup(function() {
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'r',
system: true,
message: 'Room_name_changed',
Expand All @@ -15,7 +16,7 @@ Meteor.startup(function() {
};
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'au',
system: true,
message: 'User_added_by',
Expand All @@ -26,7 +27,7 @@ Meteor.startup(function() {
};
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'ru',
system: true,
message: 'User_removed_by',
Expand All @@ -37,7 +38,7 @@ Meteor.startup(function() {
};
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'ul',
system: true,
message: 'User_left',
Expand All @@ -47,7 +48,7 @@ Meteor.startup(function() {
};
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'uj',
system: true,
message: 'User_joined_channel',
Expand All @@ -57,7 +58,7 @@ Meteor.startup(function() {
};
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'wm',
system: true,
message: 'Welcome',
Expand All @@ -67,7 +68,7 @@ Meteor.startup(function() {
};
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'rm',
system: true,
message: 'Message_removed',
Expand All @@ -77,13 +78,13 @@ Meteor.startup(function() {
};
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'rtc',
render(message) {
return RocketChat.callbacks.run('renderRtcMessage', message);
return callbacks.run('renderRtcMessage', message);
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'user-muted',
system: true,
message: 'User_muted_by',
Expand All @@ -94,7 +95,7 @@ Meteor.startup(function() {
};
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'user-unmuted',
system: true,
message: 'User_unmuted_by',
Expand All @@ -105,7 +106,7 @@ Meteor.startup(function() {
};
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'subscription-role-added',
system: true,
message: '__username__was_set__role__by__user_by_',
Expand All @@ -117,7 +118,7 @@ Meteor.startup(function() {
};
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'subscription-role-removed',
system: true,
message: '__username__is_no_longer__role__defined_by__user_by_',
Expand All @@ -129,7 +130,7 @@ Meteor.startup(function() {
};
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'room-archived',
system: true,
message: 'This_room_has_been_archived_by__username_',
Expand All @@ -139,7 +140,7 @@ Meteor.startup(function() {
};
},
});
RocketChat.MessageTypes.registerType({
MessageTypes.registerType({
id: 'room-unarchived',
system: true,
message: 'This_room_has_been_unarchived_by__username_',
Expand Down
3 changes: 1 addition & 2 deletions packages/rocketchat-lib/lib/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import EventEmitter from 'wolfy87-eventemitter';
RocketChat = new EventEmitter();
RocketChat = {};
/*
* Kick off the global namespace for RocketChat.
* @namespace RocketChat
Expand Down
6 changes: 2 additions & 4 deletions packages/rocketchat-lib/lib/getAvatarColor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const colors = ['#F44336', '#E91E63', '#9C27B0', '#673AB7', '#3F51B5', '#2196F3', '#03A9F4', '#00BCD4', '#009688', '#4CAF50', '#8BC34A', '#CDDC39', '#FFC107', '#FF9800', '#FF5722', '#795548', '#9E9E9E', '#607D8B'];
import { getAvatarColor } from 'meteor/rocketchat:utils';

RocketChat.getAvatarColor = function(name) {
return colors[name.length % colors.length];
};
RocketChat.getAvatarColor = getAvatarColor;
22 changes: 2 additions & 20 deletions packages/rocketchat-lib/lib/getURL.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
import { Meteor } from 'meteor/meteor';
import s from 'underscore.string';
import { getURL } from 'meteor/rocketchat:utils';

RocketChat.getURL = (path, { cdn = true, full = false } = {}) => {
const cdnPrefix = s.rtrim(s.trim(RocketChat.settings.get('CDN_PREFIX') || ''), '/');
const pathPrefix = s.rtrim(s.trim(__meteor_runtime_config__.ROOT_URL_PATH_PREFIX || ''), '/');

let basePath;

const finalPath = s.ltrim(s.trim(path), '/');

if (cdn && cdnPrefix !== '') {
basePath = cdnPrefix + pathPrefix;
} else if (full) {
return Meteor.absoluteUrl(finalPath);
} else {
basePath = pathPrefix;
}

return `${ basePath }/${ finalPath }`;
};
RocketChat.getURL = getURL;
50 changes: 2 additions & 48 deletions packages/rocketchat-lib/lib/getValidRoomName.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,3 @@
import { Meteor } from 'meteor/meteor';
import s from 'underscore.string';
import { getValidRoomName } from 'meteor/rocketchat:utils';

RocketChat.getValidRoomName = function getValidRoomName(displayName, rid = '') {
let slugifiedName = displayName;

if (RocketChat.settings.get('UI_Allow_room_names_with_special_chars')) {
const room = RocketChat.models.Rooms.findOneByDisplayName(displayName);
if (room && room._id !== rid) {
if (room.archived) {
throw new Meteor.Error('error-archived-duplicate-name', `There's an archived channel with name ${ displayName }`, { function: 'RocketChat.getValidRoomName', channel_name: displayName });
} else {
throw new Meteor.Error('error-duplicate-channel-name', `A channel with name '${ displayName }' exists`, { function: 'RocketChat.getValidRoomName', channel_name: displayName });
}
}
slugifiedName = s.slugify(displayName);
}

let nameValidation;
try {
nameValidation = new RegExp(`^${ RocketChat.settings.get('UTF8_Names_Validation') }$`);
} catch (error) {
nameValidation = new RegExp('^[0-9a-zA-Z-_.]+$');
}
if (!nameValidation.test(slugifiedName)) {
throw new Meteor.Error('error-invalid-room-name', `${ slugifiedName } is not a valid room name.`, {
function: 'RocketChat.getValidRoomName',
channel_name: slugifiedName,
});
}

const room = RocketChat.models.Rooms.findOneByName(slugifiedName);
if (room && room._id !== rid) {
if (RocketChat.settings.get('UI_Allow_room_names_with_special_chars')) {
let tmpName = slugifiedName;
let next = 0;
while (RocketChat.models.Rooms.findOneByNameAndNotId(tmpName, rid)) {
tmpName = `${ slugifiedName }-${ ++next }`;
}
slugifiedName = tmpName;
} else if (room.archived) {
throw new Meteor.Error('error-archived-duplicate-name', `There's an archived channel with name ${ slugifiedName }`, { function: 'RocketChat.getValidRoomName', channel_name: slugifiedName });
} else {
throw new Meteor.Error('error-duplicate-channel-name', `A channel with name '${ slugifiedName }' exists`, { function: 'RocketChat.getValidRoomName', channel_name: slugifiedName });
}
}

return slugifiedName;
};
RocketChat.getValidRoomName = getValidRoomName;
Loading