diff --git a/packages/rocketchat-livechat/imports/server/rest/departments.js b/packages/rocketchat-livechat/imports/server/rest/departments.js
index 635f89b32de1..c4c8abce1d9f 100644
--- a/packages/rocketchat-livechat/imports/server/rest/departments.js
+++ b/packages/rocketchat-livechat/imports/server/rest/departments.js
@@ -1,12 +1,12 @@
import { check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
import { API } from 'meteor/rocketchat:api';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { LivechatDepartment, LivechatDepartmentAgents } from '../../../server/models';
import { Livechat } from '../../../server/lib/Livechat';
API.v1.addRoute('livechat/department', { authRequired: true }, {
get() {
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return API.v1.unauthorized();
}
@@ -15,7 +15,7 @@ API.v1.addRoute('livechat/department', { authRequired: true }, {
});
},
post() {
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return API.v1.unauthorized();
}
@@ -43,7 +43,7 @@ API.v1.addRoute('livechat/department', { authRequired: true }, {
API.v1.addRoute('livechat/department/:_id', { authRequired: true }, {
get() {
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return API.v1.unauthorized();
}
@@ -61,7 +61,7 @@ API.v1.addRoute('livechat/department/:_id', { authRequired: true }, {
}
},
put() {
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return API.v1.unauthorized();
}
@@ -88,7 +88,7 @@ API.v1.addRoute('livechat/department/:_id', { authRequired: true }, {
}
},
delete() {
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return API.v1.unauthorized();
}
diff --git a/packages/rocketchat-livechat/imports/server/rest/facebook.js b/packages/rocketchat-livechat/imports/server/rest/facebook.js
index d10c0664be23..a74b4cdf14f8 100644
--- a/packages/rocketchat-livechat/imports/server/rest/facebook.js
+++ b/packages/rocketchat-livechat/imports/server/rest/facebook.js
@@ -1,8 +1,8 @@
import crypto from 'crypto';
import { Random } from 'meteor/random';
-import { RocketChat } from 'meteor/rocketchat:lib';
import { API } from 'meteor/rocketchat:api';
-
+import { Rooms, Users } from 'meteor/rocketchat:models';
+import { settings } from 'meteor/rocketchat:settings';
import LivechatVisitors from '../../../server/models/LivechatVisitors';
import { Livechat } from '../../../server/lib/Livechat';
@@ -33,7 +33,7 @@ API.v1.addRoute('livechat/facebook', {
};
}
- if (!RocketChat.settings.get('Livechat_Facebook_Enabled')) {
+ if (!settings.get('Livechat_Facebook_Enabled')) {
return {
success: false,
error: 'Integration disabled',
@@ -41,7 +41,7 @@ API.v1.addRoute('livechat/facebook', {
}
// validate if request come from omni
- const signature = crypto.createHmac('sha1', RocketChat.settings.get('Livechat_Facebook_API_Secret')).update(JSON.stringify(this.request.body)).digest('hex');
+ const signature = crypto.createHmac('sha1', settings.get('Livechat_Facebook_API_Secret')).update(JSON.stringify(this.request.body)).digest('hex');
if (this.request.headers['x-hub-signature'] !== `sha1=${ signature }`) {
return {
success: false,
@@ -61,7 +61,7 @@ API.v1.addRoute('livechat/facebook', {
};
let visitor = LivechatVisitors.getVisitorByToken(this.bodyParams.token);
if (visitor) {
- const rooms = RocketChat.models.Rooms.findOpenByVisitorToken(visitor.token).fetch();
+ const rooms = Rooms.findOpenByVisitorToken(visitor.token).fetch();
if (rooms && rooms.length > 0) {
sendMessage.message.rid = rooms[0]._id;
} else {
@@ -77,7 +77,7 @@ API.v1.addRoute('livechat/facebook', {
name: `${ this.bodyParams.first_name } ${ this.bodyParams.last_name }`,
});
- visitor = RocketChat.models.Users.findOneById(userId);
+ visitor = Users.findOneById(userId);
}
sendMessage.message.msg = this.bodyParams.text;
diff --git a/packages/rocketchat-livechat/imports/server/rest/sms.js b/packages/rocketchat-livechat/imports/server/rest/sms.js
index 8b7861fcd600..328267d00a01 100644
--- a/packages/rocketchat-livechat/imports/server/rest/sms.js
+++ b/packages/rocketchat-livechat/imports/server/rest/sms.js
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Rooms } from 'meteor/rocketchat:models';
import { API } from 'meteor/rocketchat:api';
import { SMS } from 'meteor/rocketchat:sms';
import LivechatVisitors from '../../../server/models/LivechatVisitors';
@@ -26,7 +26,7 @@ API.v1.addRoute('livechat/sms-incoming/:service', {
};
if (visitor) {
- const rooms = RocketChat.models.Rooms.findOpenByVisitorToken(visitor.token).fetch();
+ const rooms = Rooms.findOpenByVisitorToken(visitor.token).fetch();
if (rooms && rooms.length > 0) {
sendMessage.message.rid = rooms[0]._id;
diff --git a/packages/rocketchat-livechat/imports/server/rest/upload.js b/packages/rocketchat-livechat/imports/server/rest/upload.js
index 61dd1438bb5f..808eb1a232af 100644
--- a/packages/rocketchat-livechat/imports/server/rest/upload.js
+++ b/packages/rocketchat-livechat/imports/server/rest/upload.js
@@ -1,5 +1,7 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings } from 'meteor/rocketchat:settings';
+import { Settings, Rooms } from 'meteor/rocketchat:models';
+import { fileUploadIsValidContentType } from 'meteor/rocketchat:utils';
import { FileUpload } from 'meteor/rocketchat:file-upload';
import { API } from 'meteor/rocketchat:api';
import Busboy from 'busboy';
@@ -7,11 +9,11 @@ import filesize from 'filesize';
import LivechatVisitors from '../../../server/models/LivechatVisitors';
let maxFileSize;
-RocketChat.settings.get('FileUpload_MaxFileSize', function(key, value) {
+settings.get('FileUpload_MaxFileSize', function(key, value) {
try {
maxFileSize = parseInt(value);
} catch (e) {
- maxFileSize = RocketChat.models.Settings.findOneById('FileUpload_MaxFileSize').packageValue;
+ maxFileSize = Settings.findOneById('FileUpload_MaxFileSize').packageValue;
}
});
@@ -28,7 +30,7 @@ API.v1.addRoute('livechat/upload/:rid', {
return API.v1.unauthorized();
}
- const room = RocketChat.models.Rooms.findOneOpenByRoomIdAndVisitorToken(this.urlParams.rid, visitorToken);
+ const room = Rooms.findOneOpenByRoomIdAndVisitorToken(this.urlParams.rid, visitorToken);
if (!room) {
return API.v1.unauthorized();
}
@@ -68,7 +70,7 @@ API.v1.addRoute('livechat/upload/:rid', {
const file = files[0];
- if (!RocketChat.fileUploadIsValidContentType(file.mimetype)) {
+ if (!fileUploadIsValidContentType(file.mimetype)) {
return API.v1.failure({
reason: 'error-type-not-allowed',
});
diff --git a/packages/rocketchat-livechat/imports/server/rest/users.js b/packages/rocketchat-livechat/imports/server/rest/users.js
index e8df87995b43..494fd226be73 100644
--- a/packages/rocketchat-livechat/imports/server/rest/users.js
+++ b/packages/rocketchat-livechat/imports/server/rest/users.js
@@ -1,12 +1,13 @@
import { check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission, getUsersInRole } from 'meteor/rocketchat:authorization';
import { API } from 'meteor/rocketchat:api';
+import { Users } from 'meteor/rocketchat:models';
import { Livechat } from '../../../server/lib/Livechat';
import _ from 'underscore';
API.v1.addRoute('livechat/users/:type', { authRequired: true }, {
get() {
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return API.v1.unauthorized();
}
@@ -24,7 +25,7 @@ API.v1.addRoute('livechat/users/:type', { authRequired: true }, {
throw 'Invalid type';
}
- const users = RocketChat.authz.getUsersInRole(role);
+ const users = getUsersInRole(role);
return API.v1.success({
users: users.fetch().map((user) => _.pick(user, '_id', 'username', 'name', 'status', 'statusLivechat')),
@@ -34,7 +35,7 @@ API.v1.addRoute('livechat/users/:type', { authRequired: true }, {
}
},
post() {
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return API.v1.unauthorized();
}
try {
@@ -69,7 +70,7 @@ API.v1.addRoute('livechat/users/:type', { authRequired: true }, {
API.v1.addRoute('livechat/users/:type/:_id', { authRequired: true }, {
get() {
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return API.v1.unauthorized();
}
@@ -79,7 +80,7 @@ API.v1.addRoute('livechat/users/:type/:_id', { authRequired: true }, {
_id: String,
});
- const user = RocketChat.models.Users.findOneById(this.urlParams._id);
+ const user = Users.findOneById(this.urlParams._id);
if (!user) {
return API.v1.failure('User not found');
@@ -109,7 +110,7 @@ API.v1.addRoute('livechat/users/:type/:_id', { authRequired: true }, {
}
},
delete() {
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return API.v1.unauthorized();
}
@@ -119,7 +120,7 @@ API.v1.addRoute('livechat/users/:type/:_id', { authRequired: true }, {
_id: String,
});
- const user = RocketChat.models.Users.findOneById(this.urlParams._id);
+ const user = Users.findOneById(this.urlParams._id);
if (!user) {
return API.v1.failure();
diff --git a/packages/rocketchat-livechat/lib/LivechatRoomType.js b/packages/rocketchat-livechat/lib/LivechatRoomType.js
index 8a9d25171a36..a2a09784f581 100644
--- a/packages/rocketchat-livechat/lib/LivechatRoomType.js
+++ b/packages/rocketchat-livechat/lib/LivechatRoomType.js
@@ -1,6 +1,9 @@
import { Session } from 'meteor/session';
-import { ChatRoom } from 'meteor/rocketchat:ui';
-import { RocketChat, RoomSettingsEnum, RoomTypeConfig, RoomTypeRouteConfig, UiTextContext, openRoom } from 'meteor/rocketchat:lib';
+import { ChatRoom } from 'meteor/rocketchat:models';
+import { settings } from 'meteor/rocketchat:settings';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { openRoom } from 'meteor/rocketchat:ui-utils';
+import { RoomSettingsEnum, UiTextContext, RoomTypeRouteConfig, RoomTypeConfig } from 'meteor/rocketchat:utils';
import { LivechatInquiry } from './LivechatInquiry';
class LivechatRoomRoute extends RoomTypeRouteConfig {
@@ -46,7 +49,7 @@ export default class LivechatRoomType extends RoomTypeConfig {
}
condition() {
- return RocketChat.settings.get('Livechat_enabled') && RocketChat.authz.hasPermission('view-l-room');
+ return settings.get('Livechat_enabled') && hasPermission('view-l-room');
}
canSendMessage(roomId) {
diff --git a/packages/rocketchat-livechat/lib/messageTypes.js b/packages/rocketchat-livechat/lib/messageTypes.js
index ae0f7763045a..c1455b498164 100644
--- a/packages/rocketchat-livechat/lib/messageTypes.js
+++ b/packages/rocketchat-livechat/lib/messageTypes.js
@@ -1,9 +1,13 @@
import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/tap:i18n';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { MessageTypes } from 'meteor/rocketchat:ui-utils';
+import { actionLinks } from 'meteor/rocketchat:action-links';
+import { Notifications } from 'meteor/rocketchat:notifications';
+import { Messages, Rooms } from 'meteor/rocketchat:models';
+import { settings } from 'meteor/rocketchat:settings';
import { Livechat } from 'meteor/rocketchat:livechat';
-RocketChat.MessageTypes.registerType({
+MessageTypes.registerType({
id: 'livechat_navigation_history',
system: true,
message: 'New_visitor_navigation',
@@ -17,34 +21,34 @@ RocketChat.MessageTypes.registerType({
},
});
-RocketChat.MessageTypes.registerType({
+MessageTypes.registerType({
id: 'livechat_video_call',
system: true,
message: 'New_videocall_request',
});
-RocketChat.actionLinks.register('createLivechatCall', function(message, params, instance) {
+actionLinks.register('createLivechatCall', function(message, params, instance) {
if (Meteor.isClient) {
instance.tabBar.open('video');
}
});
-RocketChat.actionLinks.register('denyLivechatCall', function(message/* , params*/) {
+actionLinks.register('denyLivechatCall', function(message/* , params*/) {
if (Meteor.isServer) {
const user = Meteor.user();
- RocketChat.models.Messages.createWithTypeRoomIdMessageAndUser('command', message.rid, 'endCall', user);
- RocketChat.Notifications.notifyRoom(message.rid, 'deleteMessage', { _id: message._id });
+ Messages.createWithTypeRoomIdMessageAndUser('command', message.rid, 'endCall', user);
+ Notifications.notifyRoom(message.rid, 'deleteMessage', { _id: message._id });
- const language = user.language || RocketChat.settings.get('Language') || 'en';
+ const language = user.language || settings.get('Language') || 'en';
Livechat.closeRoom({
user,
- room: RocketChat.models.Rooms.findOneById(message.rid),
+ room: Rooms.findOneById(message.rid),
comment: TAPi18n.__('Videocall_declined', { lng: language }),
});
Meteor.defer(() => {
- RocketChat.models.Messages.setHiddenById(message._id);
+ Messages.setHiddenById(message._id);
});
}
});
diff --git a/packages/rocketchat-livechat/package.js b/packages/rocketchat-livechat/package.js
index b78f63442d48..fdd14ae623de 100644
--- a/packages/rocketchat-livechat/package.js
+++ b/packages/rocketchat-livechat/package.js
@@ -26,8 +26,10 @@ Package.onUse(function(api) {
'webapp',
'autoupdate',
'rocketchat:utils',
+ 'rocketchat:action-links',
'rocketchat:ui-utils',
'rocketchat:settings',
+ 'rocketchat:callbacks',
'rocketchat:models',
'rocketchat:lib',
'rocketchat:authorization',
diff --git a/packages/rocketchat-livechat/server/agentStatus.js b/packages/rocketchat-livechat/server/agentStatus.js
index 04628283dec1..6cf9a3bfde14 100644
--- a/packages/rocketchat-livechat/server/agentStatus.js
+++ b/packages/rocketchat-livechat/server/agentStatus.js
@@ -1,9 +1,9 @@
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasRole } from 'meteor/rocketchat:authorization';
import { UserPresenceMonitor } from 'meteor/konecty:user-presence';
import { Livechat } from './lib/Livechat';
UserPresenceMonitor.onSetUserStatus((user, status) => {
- if (RocketChat.authz.hasRole(user._id, 'livechat-manager') || RocketChat.authz.hasRole(user._id, 'livechat-agent')) {
+ if (hasRole(user._id, 'livechat-manager') || hasRole(user._id, 'livechat-agent')) {
Livechat.notifyAgentStatusChanged(user._id, status);
}
});
diff --git a/packages/rocketchat-livechat/server/api/lib/livechat.js b/packages/rocketchat-livechat/server/api/lib/livechat.js
index 03b55517b42c..a679c2b688d9 100644
--- a/packages/rocketchat-livechat/server/api/lib/livechat.js
+++ b/packages/rocketchat-livechat/server/api/lib/livechat.js
@@ -1,13 +1,13 @@
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Users, Rooms } from 'meteor/rocketchat:models';
import { LivechatDepartment, LivechatTrigger } from '../../models';
import _ from 'underscore';
import LivechatVisitors from '../../models/LivechatVisitors';
import { Livechat } from '../../lib/Livechat';
export function online() {
- return RocketChat.models.Users.findOnlineAgents().count() > 0;
+ return Users.findOnlineAgents().count() > 0;
}
export function findTriggers() {
@@ -38,10 +38,10 @@ export function findRoom(token, rid) {
};
if (!rid) {
- return RocketChat.models.Rooms.findLivechatByVisitorToken(token, fields);
+ return Rooms.findLivechatByVisitorToken(token, fields);
}
- return RocketChat.models.Rooms.findLivechatByIdAndVisitorToken(rid, token, fields);
+ return Rooms.findLivechatByIdAndVisitorToken(rid, token, fields);
}
export function findOpenRoom(token, departmentId) {
@@ -54,7 +54,7 @@ export function findOpenRoom(token, departmentId) {
};
let room;
- const rooms = departmentId ? RocketChat.models.Rooms.findOpenByVisitorTokenAndDepartmentId(token, departmentId, options).fetch() : RocketChat.models.Rooms.findOpenByVisitorToken(token, options).fetch();
+ const rooms = departmentId ? Rooms.findOpenByVisitorTokenAndDepartmentId(token, departmentId, options).fetch() : Rooms.findOpenByVisitorToken(token, options).fetch();
if (rooms && rooms.length > 0) {
room = rooms[0];
}
@@ -77,7 +77,7 @@ export function getRoom(guest, rid, roomInfo) {
}
export function findAgent(agentId) {
- return RocketChat.models.Users.getAgentInfo(agentId);
+ return Users.getAgentInfo(agentId);
}
export function settings() {
diff --git a/packages/rocketchat-livechat/server/api/v1/config.js b/packages/rocketchat-livechat/server/api/v1/config.js
index 03e86c76128d..99aaf7131904 100644
--- a/packages/rocketchat-livechat/server/api/v1/config.js
+++ b/packages/rocketchat-livechat/server/api/v1/config.js
@@ -1,4 +1,4 @@
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Users } from 'meteor/rocketchat:models';
import { API } from 'meteor/rocketchat:api';
import { findGuest, settings, online, findOpenRoom } from '../lib/livechat';
import { Match, check } from 'meteor/check';
@@ -26,7 +26,7 @@ API.v1.addRoute('livechat/config', {
if (token) {
guest = findGuest(token);
room = findOpenRoom(token);
- agent = room && room.servedBy && RocketChat.models.Users.getAgentInfo(room.servedBy._id);
+ agent = room && room.servedBy && Users.getAgentInfo(room.servedBy._id);
}
Object.assign(config, { online: status, guest, room, agent });
diff --git a/packages/rocketchat-livechat/server/api/v1/message.js b/packages/rocketchat-livechat/server/api/v1/message.js
index a988bbb9d4bd..c8432efd69b7 100644
--- a/packages/rocketchat-livechat/server/api/v1/message.js
+++ b/packages/rocketchat-livechat/server/api/v1/message.js
@@ -1,8 +1,10 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { Random } from 'meteor/random';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Messages, Rooms } from 'meteor/rocketchat:models';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { API } from 'meteor/rocketchat:api';
+import { loadMessageHistory } from 'meteor/rocketchat:lib';
import LivechatVisitors from '../../../server/models/LivechatVisitors';
import { findGuest, findRoom } from '../lib/livechat';
import { Livechat } from '../../lib/Livechat';
@@ -85,7 +87,7 @@ API.v1.addRoute('livechat/message/:_id', {
throw new Meteor.Error('invalid-room');
}
- const msg = RocketChat.models.Messages.findOneById(_id);
+ const msg = Messages.findOneById(_id);
if (!msg) {
throw new Meteor.Error('invalid-message');
}
@@ -94,7 +96,7 @@ API.v1.addRoute('livechat/message/:_id', {
const result = Livechat.updateMessage({ guest, message });
if (result) {
- const data = RocketChat.models.Messages.findOneById(_id);
+ const data = Messages.findOneById(_id);
return API.v1.success({
message: { _id: data._id, rid: data.rid, msg: data.msg, u: data.u, ts: data.ts },
});
@@ -129,7 +131,7 @@ API.v1.addRoute('livechat/message/:_id', {
throw new Meteor.Error('invalid-room');
}
- const message = RocketChat.models.Messages.findOneById(_id);
+ const message = Messages.findOneById(_id);
if (!message) {
throw new Meteor.Error('invalid-message');
}
@@ -190,7 +192,7 @@ API.v1.addRoute('livechat/messages.history/:rid', {
limit = parseInt(this.queryParams.limit);
}
- const messages = RocketChat.loadMessageHistory({ userId: guest._id, rid, end, limit, ls });
+ const messages = loadMessageHistory({ userId: guest._id, rid, end, limit, ls });
return API.v1.success(messages);
} catch (e) {
return API.v1.failure(e.error);
@@ -200,7 +202,7 @@ API.v1.addRoute('livechat/messages.history/:rid', {
API.v1.addRoute('livechat/messages', { authRequired: true }, {
post() {
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return API.v1.unauthorized();
}
@@ -225,7 +227,7 @@ API.v1.addRoute('livechat/messages', { authRequired: true }, {
let visitor = LivechatVisitors.getVisitorByToken(visitorToken);
let rid;
if (visitor) {
- const rooms = RocketChat.models.Rooms.findOpenByVisitorToken(visitorToken).fetch();
+ const rooms = Rooms.findOpenByVisitorToken(visitorToken).fetch();
if (rooms && rooms.length > 0) {
rid = rooms[0]._id;
} else {
diff --git a/packages/rocketchat-livechat/server/api/v1/room.js b/packages/rocketchat-livechat/server/api/v1/room.js
index 3a6161222c61..8ea1d8ce6e35 100644
--- a/packages/rocketchat-livechat/server/api/v1/room.js
+++ b/packages/rocketchat-livechat/server/api/v1/room.js
@@ -2,7 +2,8 @@ import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { Random } from 'meteor/random';
import { TAPi18n } from 'meteor/tap:i18n';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings as rcSettings } from 'meteor/rocketchat:settings';
+import { Messages, Rooms } from 'meteor/rocketchat:models';
import { API } from 'meteor/rocketchat:api';
import { findGuest, findRoom, getRoom, settings } from '../lib/livechat';
import { Livechat } from '../../lib/Livechat';
@@ -55,7 +56,7 @@ API.v1.addRoute('livechat/room.close', {
throw new Meteor.Error('room-closed');
}
- const language = RocketChat.settings.get('Language') || 'en';
+ const language = rcSettings.get('Language') || 'en';
const comment = TAPi18n.__('Closed_by_visitor', { lng: language });
if (!Livechat.closeRoom({ visitor, room, comment })) {
@@ -91,7 +92,7 @@ API.v1.addRoute('livechat/room.transfer', {
}
// update visited page history to not expire
- RocketChat.models.Messages.keepHistoryForToken(token);
+ Messages.keepHistoryForToken(token);
if (!Livechat.transfer(room, guest, { roomId: rid, departmentId: department })) {
return API.v1.failure();
@@ -145,7 +146,7 @@ API.v1.addRoute('livechat/room.survey', {
throw new Meteor.Error('invalid-data');
}
- if (!RocketChat.models.Rooms.updateSurveyFeedbackById(room._id, updateData)) {
+ if (!Rooms.updateSurveyFeedbackById(room._id, updateData)) {
return API.v1.failure();
}
diff --git a/packages/rocketchat-livechat/server/api/v1/videoCall.js b/packages/rocketchat-livechat/server/api/v1/videoCall.js
index aaa7e0521d3f..1ecb196944a2 100644
--- a/packages/rocketchat-livechat/server/api/v1/videoCall.js
+++ b/packages/rocketchat-livechat/server/api/v1/videoCall.js
@@ -1,7 +1,8 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { Random } from 'meteor/random';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Messages } from 'meteor/rocketchat:models';
+import { settings as rcSettings } from 'meteor/rocketchat:settings';
import { API } from 'meteor/rocketchat:api';
import { findGuest, getRoom, settings } from '../lib/livechat';
@@ -30,15 +31,15 @@ API.v1.addRoute('livechat/video.call/:token', {
throw new Meteor.Error('invalid-livechat-config');
}
- RocketChat.models.Messages.createWithTypeRoomIdMessageAndUser('livechat_video_call', room._id, '', guest, {
+ Messages.createWithTypeRoomIdMessageAndUser('livechat_video_call', room._id, '', guest, {
actionLinks: config.theme.actionLinks,
});
const videoCall = {
rid,
- domain: RocketChat.settings.get('Jitsi_Domain'),
+ domain: rcSettings.get('Jitsi_Domain'),
provider: 'jitsi',
- room: RocketChat.settings.get('Jitsi_URL_Room_Prefix') + RocketChat.settings.get('uniqueID') + rid,
+ room: rcSettings.get('Jitsi_URL_Room_Prefix') + rcSettings.get('uniqueID') + rid,
timeout: new Date(Date.now() + 3600 * 1000),
};
diff --git a/packages/rocketchat-livechat/server/api/v1/visitor.js b/packages/rocketchat-livechat/server/api/v1/visitor.js
index d0c3b08fc472..658879441061 100644
--- a/packages/rocketchat-livechat/server/api/v1/visitor.js
+++ b/packages/rocketchat-livechat/server/api/v1/visitor.js
@@ -1,6 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Rooms } from 'meteor/rocketchat:models';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { API } from 'meteor/rocketchat:api';
import LivechatVisitors from '../../../server/models/LivechatVisitors';
import { findGuest } from '../lib/livechat';
@@ -39,7 +40,7 @@ API.v1.addRoute('livechat/visitor', {
let visitor = LivechatVisitors.getVisitorByToken(token);
// If it's updating an existing visitor, it must also update the roomInfo
- const cursor = RocketChat.models.Rooms.findOpenByVisitorToken(token);
+ const cursor = Rooms.findOpenByVisitorToken(token);
cursor.forEach((room) => {
Livechat.saveRoomInfo(room, visitor);
});
@@ -109,11 +110,11 @@ API.v1.addRoute('livechat/visitor/:token', {
API.v1.addRoute('livechat/visitor/:token/room', { authRequired: true }, {
get() {
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return API.v1.unauthorized();
}
- const rooms = RocketChat.models.Rooms.findOpenByVisitorToken(this.urlParams.token, {
+ const rooms = Rooms.findOpenByVisitorToken(this.urlParams.token, {
fields: {
name: 1,
t: 1,
diff --git a/packages/rocketchat-livechat/server/config.js b/packages/rocketchat-livechat/server/config.js
index bb14dad38f38..8baec635c61b 100644
--- a/packages/rocketchat-livechat/server/config.js
+++ b/packages/rocketchat-livechat/server/config.js
@@ -1,13 +1,13 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings } from 'meteor/rocketchat:settings';
Meteor.startup(function() {
- RocketChat.settings.addGroup('Livechat');
+ settings.addGroup('Livechat');
- RocketChat.settings.add('Livechat_enabled', false, { type: 'boolean', group: 'Livechat', public: true });
+ settings.add('Livechat_enabled', false, { type: 'boolean', group: 'Livechat', public: true });
- RocketChat.settings.add('Livechat_title', 'Rocket.Chat', { type: 'string', group: 'Livechat', public: true });
- RocketChat.settings.add('Livechat_title_color', '#C1272D', {
+ settings.add('Livechat_title', 'Rocket.Chat', { type: 'string', group: 'Livechat', public: true });
+ settings.add('Livechat_title_color', '#C1272D', {
type: 'color',
editor: 'color',
allowedTypes: ['color', 'expression'],
@@ -15,7 +15,7 @@ Meteor.startup(function() {
public: true,
});
- RocketChat.settings.add('Livechat_display_offline_form', true, {
+ settings.add('Livechat_display_offline_form', true, {
type: 'boolean',
group: 'Livechat',
public: true,
@@ -23,7 +23,7 @@ Meteor.startup(function() {
i18nLabel: 'Display_offline_form',
});
- RocketChat.settings.add('Livechat_validate_offline_email', true, {
+ settings.add('Livechat_validate_offline_email', true, {
type: 'boolean',
group: 'Livechat',
public: true,
@@ -31,7 +31,7 @@ Meteor.startup(function() {
i18nLabel: 'Validate_email_address',
});
- RocketChat.settings.add('Livechat_offline_form_unavailable', '', {
+ settings.add('Livechat_offline_form_unavailable', '', {
type: 'string',
group: 'Livechat',
public: true,
@@ -39,14 +39,14 @@ Meteor.startup(function() {
i18nLabel: 'Offline_form_unavailable_message',
});
- RocketChat.settings.add('Livechat_offline_title', 'Leave a message', {
+ settings.add('Livechat_offline_title', 'Leave a message', {
type: 'string',
group: 'Livechat',
public: true,
section: 'Offline',
i18nLabel: 'Title',
});
- RocketChat.settings.add('Livechat_offline_title_color', '#666666', {
+ settings.add('Livechat_offline_title_color', '#666666', {
type: 'color',
editor: 'color',
allowedTypes: ['color', 'expression'],
@@ -55,7 +55,7 @@ Meteor.startup(function() {
section: 'Offline',
i18nLabel: 'Color',
});
- RocketChat.settings.add('Livechat_offline_message', '', {
+ settings.add('Livechat_offline_message', '', {
type: 'string',
group: 'Livechat',
public: true,
@@ -63,13 +63,13 @@ Meteor.startup(function() {
i18nLabel: 'Instructions',
i18nDescription: 'Instructions_to_your_visitor_fill_the_form_to_send_a_message',
});
- RocketChat.settings.add('Livechat_offline_email', '', {
+ settings.add('Livechat_offline_email', '', {
type: 'string',
group: 'Livechat',
i18nLabel: 'Email_address_to_send_offline_messages',
section: 'Offline',
});
- RocketChat.settings.add('Livechat_offline_success_message', '', {
+ settings.add('Livechat_offline_success_message', '', {
type: 'string',
group: 'Livechat',
public: true,
@@ -77,46 +77,46 @@ Meteor.startup(function() {
i18nLabel: 'Offline_success_message',
});
- RocketChat.settings.add('Livechat_allow_switching_departments', true, { type: 'boolean', group: 'Livechat', public: true, i18nLabel: 'Allow_switching_departments' });
- RocketChat.settings.add('Livechat_show_agent_email', true, { type: 'boolean', group: 'Livechat', public: true, i18nLabel: 'Show_agent_email' });
+ settings.add('Livechat_allow_switching_departments', true, { type: 'boolean', group: 'Livechat', public: true, i18nLabel: 'Allow_switching_departments' });
+ settings.add('Livechat_show_agent_email', true, { type: 'boolean', group: 'Livechat', public: true, i18nLabel: 'Show_agent_email' });
- RocketChat.settings.add('Livechat_conversation_finished_message', '', {
+ settings.add('Livechat_conversation_finished_message', '', {
type: 'string',
group: 'Livechat',
public: true,
i18nLabel: 'Conversation_finished_message',
});
- RocketChat.settings.add('Livechat_registration_form', true, {
+ settings.add('Livechat_registration_form', true, {
type: 'boolean',
group: 'Livechat',
public: true,
i18nLabel: 'Show_preregistration_form',
});
- RocketChat.settings.add('Livechat_name_field_registration_form', true, {
+ settings.add('Livechat_name_field_registration_form', true, {
type: 'boolean',
group: 'Livechat',
public: true,
i18nLabel: 'Show_name_field',
});
- RocketChat.settings.add('Livechat_email_field_registration_form', true, {
+ settings.add('Livechat_email_field_registration_form', true, {
type: 'boolean',
group: 'Livechat',
public: true,
i18nLabel: 'Show_email_field',
});
- RocketChat.settings.add('Livechat_guest_count', 1, { type: 'int', group: 'Livechat' });
+ settings.add('Livechat_guest_count', 1, { type: 'int', group: 'Livechat' });
- RocketChat.settings.add('Livechat_Room_Count', 1, {
+ settings.add('Livechat_Room_Count', 1, {
type: 'int',
group: 'Livechat',
i18nLabel: 'Livechat_room_count',
});
- RocketChat.settings.add('Livechat_agent_leave_action', 'none', {
+ settings.add('Livechat_agent_leave_action', 'none', {
type: 'select',
group: 'Livechat',
values: [
@@ -127,7 +127,7 @@ Meteor.startup(function() {
i18nLabel: 'How_to_handle_open_sessions_when_agent_goes_offline',
});
- RocketChat.settings.add('Livechat_agent_leave_action_timeout', 60, {
+ settings.add('Livechat_agent_leave_action_timeout', 60, {
type: 'int',
group: 'Livechat',
enableQuery: { _id: 'Livechat_agent_leave_action', value: { $ne: 'none' } },
@@ -135,56 +135,56 @@ Meteor.startup(function() {
i18nDescription: 'Time_in_seconds',
});
- RocketChat.settings.add('Livechat_agent_leave_comment', '', {
+ settings.add('Livechat_agent_leave_comment', '', {
type: 'string',
group: 'Livechat',
enableQuery: { _id: 'Livechat_agent_leave_action', value: 'close' },
i18nLabel: 'Comment_to_leave_on_closing_session',
});
- RocketChat.settings.add('Livechat_webhookUrl', false, {
+ settings.add('Livechat_webhookUrl', false, {
type: 'string',
group: 'Livechat',
section: 'CRM_Integration',
i18nLabel: 'Webhook_URL',
});
- RocketChat.settings.add('Livechat_secret_token', false, {
+ settings.add('Livechat_secret_token', false, {
type: 'string',
group: 'Livechat',
section: 'CRM_Integration',
i18nLabel: 'Secret_token',
});
- RocketChat.settings.add('Livechat_webhook_on_close', false, {
+ settings.add('Livechat_webhook_on_close', false, {
type: 'boolean',
group: 'Livechat',
section: 'CRM_Integration',
i18nLabel: 'Send_request_on_chat_close',
});
- RocketChat.settings.add('Livechat_webhook_on_offline_msg', false, {
+ settings.add('Livechat_webhook_on_offline_msg', false, {
type: 'boolean',
group: 'Livechat',
section: 'CRM_Integration',
i18nLabel: 'Send_request_on_offline_messages',
});
- RocketChat.settings.add('Livechat_webhook_on_visitor_message', false, {
+ settings.add('Livechat_webhook_on_visitor_message', false, {
type: 'boolean',
group: 'Livechat',
section: 'CRM_Integration',
i18nLabel: 'Send_request_on_visitor_message',
});
- RocketChat.settings.add('Livechat_webhook_on_agent_message', false, {
+ settings.add('Livechat_webhook_on_agent_message', false, {
type: 'boolean',
group: 'Livechat',
section: 'CRM_Integration',
i18nLabel: 'Send_request_on_agent_message',
});
- RocketChat.settings.add('Send_visitor_navigation_history_livechat_webhook_request', false, {
+ settings.add('Send_visitor_navigation_history_livechat_webhook_request', false, {
type: 'boolean',
group: 'Livechat',
section: 'CRM_Integration',
@@ -193,28 +193,28 @@ Meteor.startup(function() {
enableQuery: { _id: 'Livechat_Visitor_navigation_as_a_message', value: true },
});
- RocketChat.settings.add('Livechat_webhook_on_capture', false, {
+ settings.add('Livechat_webhook_on_capture', false, {
type: 'boolean',
group: 'Livechat',
section: 'CRM_Integration',
i18nLabel: 'Send_request_on_lead_capture',
});
- RocketChat.settings.add('Livechat_lead_email_regex', '\\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\\.)+[A-Z]{2,4}\\b', {
+ settings.add('Livechat_lead_email_regex', '\\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\\.)+[A-Z]{2,4}\\b', {
type: 'string',
group: 'Livechat',
section: 'CRM_Integration',
i18nLabel: 'Lead_capture_email_regex',
});
- RocketChat.settings.add('Livechat_lead_phone_regex', '((?:\\([0-9]{1,3}\\)|[0-9]{2})[ \\-]*?[0-9]{4,5}(?:[\\-\\s\\_]{1,2})?[0-9]{4}(?:(?=[^0-9])|$)|[0-9]{4,5}(?:[\\-\\s\\_]{1,2})?[0-9]{4}(?:(?=[^0-9])|$))', {
+ settings.add('Livechat_lead_phone_regex', '((?:\\([0-9]{1,3}\\)|[0-9]{2})[ \\-]*?[0-9]{4,5}(?:[\\-\\s\\_]{1,2})?[0-9]{4}(?:(?=[^0-9])|$)|[0-9]{4,5}(?:[\\-\\s\\_]{1,2})?[0-9]{4}(?:(?=[^0-9])|$))', {
type: 'string',
group: 'Livechat',
section: 'CRM_Integration',
i18nLabel: 'Lead_capture_phone_regex',
});
- RocketChat.settings.add('Livechat_Knowledge_Enabled', false, {
+ settings.add('Livechat_Knowledge_Enabled', false, {
type: 'boolean',
group: 'Livechat',
section: 'Knowledge_Base',
@@ -222,7 +222,7 @@ Meteor.startup(function() {
i18nLabel: 'Enabled',
});
- RocketChat.settings.add('Livechat_Knowledge_Apiai_Key', '', {
+ settings.add('Livechat_Knowledge_Apiai_Key', '', {
type: 'string',
group: 'Livechat',
section: 'Knowledge_Base',
@@ -230,7 +230,7 @@ Meteor.startup(function() {
i18nLabel: 'Apiai_Key',
});
- RocketChat.settings.add('Livechat_Knowledge_Apiai_Language', 'en', {
+ settings.add('Livechat_Knowledge_Apiai_Language', 'en', {
type: 'string',
group: 'Livechat',
section: 'Knowledge_Base',
@@ -238,7 +238,7 @@ Meteor.startup(function() {
i18nLabel: 'Apiai_Language',
});
- RocketChat.settings.add('Livechat_history_monitor_type', 'url', {
+ settings.add('Livechat_history_monitor_type', 'url', {
type: 'select',
group: 'Livechat',
i18nLabel: 'Monitor_history_for_changes_on',
@@ -248,28 +248,28 @@ Meteor.startup(function() {
],
});
- RocketChat.settings.add('Livechat_Visitor_navigation_as_a_message', false, {
+ settings.add('Livechat_Visitor_navigation_as_a_message', false, {
type: 'boolean',
group: 'Livechat',
public: true,
i18nLabel: 'Send_Visitor_navigation_history_as_a_message',
});
- RocketChat.settings.add('Livechat_enable_office_hours', false, {
+ settings.add('Livechat_enable_office_hours', false, {
type: 'boolean',
group: 'Livechat',
public: true,
i18nLabel: 'Office_hours_enabled',
});
- RocketChat.settings.add('Livechat_continuous_sound_notification_new_livechat_room', false, {
+ settings.add('Livechat_continuous_sound_notification_new_livechat_room', false, {
type: 'boolean',
group: 'Livechat',
public: true,
i18nLabel: 'Continuous_sound_notifications_for_new_livechat_room',
});
- RocketChat.settings.add('Livechat_videocall_enabled', false, {
+ settings.add('Livechat_videocall_enabled', false, {
type: 'boolean',
group: 'Livechat',
public: true,
@@ -278,7 +278,7 @@ Meteor.startup(function() {
enableQuery: { _id: 'Jitsi_Enabled', value: true },
});
- RocketChat.settings.add('Livechat_fileupload_enabled', true, {
+ settings.add('Livechat_fileupload_enabled', true, {
type: 'boolean',
group: 'Livechat',
public: true,
@@ -286,14 +286,14 @@ Meteor.startup(function() {
enableQuery: { _id: 'FileUpload_Enabled', value: true },
});
- RocketChat.settings.add('Livechat_enable_transcript', false, {
+ settings.add('Livechat_enable_transcript', false, {
type: 'boolean',
group: 'Livechat',
public: true,
i18nLabel: 'Transcript_Enabled',
});
- RocketChat.settings.add('Livechat_transcript_message', '', {
+ settings.add('Livechat_transcript_message', '', {
type: 'string',
group: 'Livechat',
public: true,
@@ -301,14 +301,14 @@ Meteor.startup(function() {
enableQuery: { _id: 'Livechat_enable_transcript', value: true },
});
- RocketChat.settings.add('Livechat_registration_form_message', '', {
+ settings.add('Livechat_registration_form_message', '', {
type: 'string',
group: 'Livechat',
public: true,
i18nLabel: 'Livechat_registration_form_message',
});
- RocketChat.settings.add('Livechat_open_inquiery_show_connecting', false, {
+ settings.add('Livechat_open_inquiery_show_connecting', false, {
type: 'boolean',
group: 'Livechat',
public: true,
@@ -316,7 +316,7 @@ Meteor.startup(function() {
enableQuery: { _id: 'Livechat_Routing_Method', value: 'Guest_Pool' },
});
- RocketChat.settings.add('Livechat_AllowedDomainsList', '', {
+ settings.add('Livechat_AllowedDomainsList', '', {
type: 'string',
group: 'Livechat',
public: true,
@@ -324,27 +324,27 @@ Meteor.startup(function() {
i18nDescription: 'Domains_allowed_to_embed_the_livechat_widget',
});
- RocketChat.settings.add('Livechat_Facebook_Enabled', false, {
+ settings.add('Livechat_Facebook_Enabled', false, {
type: 'boolean',
group: 'Livechat',
section: 'Facebook',
});
- RocketChat.settings.add('Livechat_Facebook_API_Key', '', {
+ settings.add('Livechat_Facebook_API_Key', '', {
type: 'string',
group: 'Livechat',
section: 'Facebook',
i18nDescription: 'If_you_dont_have_one_send_an_email_to_omni_rocketchat_to_get_yours',
});
- RocketChat.settings.add('Livechat_Facebook_API_Secret', '', {
+ settings.add('Livechat_Facebook_API_Secret', '', {
type: 'string',
group: 'Livechat',
section: 'Facebook',
i18nDescription: 'If_you_dont_have_one_send_an_email_to_omni_rocketchat_to_get_yours',
});
- RocketChat.settings.add('Livechat_RDStation_Token', '', {
+ settings.add('Livechat_RDStation_Token', '', {
type: 'string',
group: 'Livechat',
public: false,
@@ -352,7 +352,7 @@ Meteor.startup(function() {
i18nLabel: 'RDStation_Token',
});
- RocketChat.settings.add('Livechat_Routing_Method', 'Least_Amount', {
+ settings.add('Livechat_Routing_Method', 'Least_Amount', {
type: 'select',
group: 'Livechat',
public: true,
@@ -364,7 +364,7 @@ Meteor.startup(function() {
],
});
- RocketChat.settings.add('Livechat_guest_pool_with_no_agents', false, {
+ settings.add('Livechat_guest_pool_with_no_agents', false, {
type: 'boolean',
group: 'Livechat',
section: 'Routing',
@@ -373,7 +373,7 @@ Meteor.startup(function() {
enableQuery: { _id: 'Livechat_Routing_Method', value: 'Guest_Pool' },
});
- RocketChat.settings.add('Livechat_show_queue_list_link', false, {
+ settings.add('Livechat_show_queue_list_link', false, {
type: 'boolean',
group: 'Livechat',
public: true,
@@ -382,7 +382,7 @@ Meteor.startup(function() {
enableQuery: { _id: 'Livechat_Routing_Method', value: { $ne: 'External' } },
});
- RocketChat.settings.add('Livechat_External_Queue_URL', '', {
+ settings.add('Livechat_External_Queue_URL', '', {
type: 'string',
group: 'Livechat',
public: false,
@@ -392,7 +392,7 @@ Meteor.startup(function() {
enableQuery: { _id: 'Livechat_Routing_Method', value: 'External' },
});
- RocketChat.settings.add('Livechat_External_Queue_Token', '', {
+ settings.add('Livechat_External_Queue_Token', '', {
type: 'string',
group: 'Livechat',
public: false,
@@ -401,7 +401,7 @@ Meteor.startup(function() {
enableQuery: { _id: 'Livechat_Routing_Method', value: 'External' },
});
- RocketChat.settings.add('Livechat_Allow_collect_and_store_HTTP_header_informations', false, {
+ settings.add('Livechat_Allow_collect_and_store_HTTP_header_informations', false, {
type: 'boolean',
group: 'Livechat',
public: true,
@@ -409,7 +409,7 @@ Meteor.startup(function() {
i18nDescription: 'Allow_collect_and_store_HTTP_header_informations_description',
});
- RocketChat.settings.add('Livechat_force_accept_data_processing_consent', false, {
+ settings.add('Livechat_force_accept_data_processing_consent', false, {
type: 'boolean',
group: 'Livechat',
public: true,
@@ -418,7 +418,7 @@ Meteor.startup(function() {
i18nDescription: 'Force_visitor_to_accept_data_processing_consent_description',
});
- RocketChat.settings.add('Livechat_data_processing_consent_text', '', {
+ settings.add('Livechat_data_processing_consent_text', '', {
type: 'string',
multiline: true,
group: 'Livechat',
diff --git a/packages/rocketchat-livechat/server/hooks/RDStation.js b/packages/rocketchat-livechat/server/hooks/RDStation.js
index 5e04f5e5a8ba..34dbbe3d74a3 100644
--- a/packages/rocketchat-livechat/server/hooks/RDStation.js
+++ b/packages/rocketchat-livechat/server/hooks/RDStation.js
@@ -1,9 +1,10 @@
import { HTTP } from 'meteor/http';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings } from 'meteor/rocketchat:settings';
+import { callbacks } from 'meteor/rocketchat:callbacks';
import { Livechat } from '../lib/Livechat';
function sendToRDStation(room) {
- if (!RocketChat.settings.get('Livechat_RDStation_Token')) {
+ if (!settings.get('Livechat_RDStation_Token')) {
return room;
}
@@ -20,7 +21,7 @@ function sendToRDStation(room) {
'Content-Type': 'application/json',
},
data: {
- token_rdstation: RocketChat.settings.get('Livechat_RDStation_Token'),
+ token_rdstation: settings.get('Livechat_RDStation_Token'),
identificador: 'rocketchat-livechat',
client_id: livechatData.visitor._id,
email,
@@ -54,6 +55,6 @@ function sendToRDStation(room) {
return room;
}
-RocketChat.callbacks.add('livechat.closeRoom', sendToRDStation, RocketChat.callbacks.priority.MEDIUM, 'livechat-rd-station-close-room');
+callbacks.add('livechat.closeRoom', sendToRDStation, callbacks.priority.MEDIUM, 'livechat-rd-station-close-room');
-RocketChat.callbacks.add('livechat.saveInfo', sendToRDStation, RocketChat.callbacks.priority.MEDIUM, 'livechat-rd-station-save-info');
+callbacks.add('livechat.saveInfo', sendToRDStation, callbacks.priority.MEDIUM, 'livechat-rd-station-save-info');
diff --git a/packages/rocketchat-livechat/server/hooks/externalMessage.js b/packages/rocketchat-livechat/server/hooks/externalMessage.js
index 71bf0e9a1d8b..f94954b9c584 100644
--- a/packages/rocketchat-livechat/server/hooks/externalMessage.js
+++ b/packages/rocketchat-livechat/server/hooks/externalMessage.js
@@ -1,5 +1,6 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings } from 'meteor/rocketchat:settings';
+import { callbacks } from 'meteor/rocketchat:callbacks';
import { SystemLogger } from 'meteor/rocketchat:logger';
import { HTTP } from 'meteor/http';
import { LivechatExternalMessage } from '../../lib/LivechatExternalMessage';
@@ -8,17 +9,17 @@ import _ from 'underscore';
let knowledgeEnabled = false;
let apiaiKey = '';
let apiaiLanguage = 'en';
-RocketChat.settings.get('Livechat_Knowledge_Enabled', function(key, value) {
+settings.get('Livechat_Knowledge_Enabled', function(key, value) {
knowledgeEnabled = value;
});
-RocketChat.settings.get('Livechat_Knowledge_Apiai_Key', function(key, value) {
+settings.get('Livechat_Knowledge_Apiai_Key', function(key, value) {
apiaiKey = value;
});
-RocketChat.settings.get('Livechat_Knowledge_Apiai_Language', function(key, value) {
+settings.get('Livechat_Knowledge_Apiai_Language', function(key, value) {
apiaiLanguage = value;
});
-RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
+callbacks.add('afterSaveMessage', function(message, room) {
// skips this callback if the message was edited
if (!message || message.editedAt) {
return message;
@@ -65,4 +66,4 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
});
return message;
-}, RocketChat.callbacks.priority.LOW, 'externalWebHook');
+}, callbacks.priority.LOW, 'externalWebHook');
diff --git a/packages/rocketchat-livechat/server/hooks/leadCapture.js b/packages/rocketchat-livechat/server/hooks/leadCapture.js
index 2c9087fe3831..d909dbcd0471 100644
--- a/packages/rocketchat-livechat/server/hooks/leadCapture.js
+++ b/packages/rocketchat-livechat/server/hooks/leadCapture.js
@@ -1,4 +1,5 @@
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { callbacks } from 'meteor/rocketchat:callbacks';
+import { settings } from 'meteor/rocketchat:settings';
import LivechatVisitors from '../../server/models/LivechatVisitors';
function validateMessage(message, room) {
@@ -25,22 +26,22 @@ function validateMessage(message, room) {
return true;
}
-RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
+callbacks.add('afterSaveMessage', function(message, room) {
if (!validateMessage(message, room)) {
return message;
}
- const phoneRegexp = new RegExp(RocketChat.settings.get('Livechat_lead_phone_regex'), 'g');
+ const phoneRegexp = new RegExp(settings.get('Livechat_lead_phone_regex'), 'g');
const msgPhones = message.msg.match(phoneRegexp);
- const emailRegexp = new RegExp(RocketChat.settings.get('Livechat_lead_email_regex'), 'gi');
+ const emailRegexp = new RegExp(settings.get('Livechat_lead_email_regex'), 'gi');
const msgEmails = message.msg.match(emailRegexp);
if (msgEmails || msgPhones) {
LivechatVisitors.saveGuestEmailPhoneById(room.v._id, msgEmails, msgPhones);
- RocketChat.callbacks.run('livechat.leadCapture', room);
+ callbacks.run('livechat.leadCapture', room);
}
return message;
-}, RocketChat.callbacks.priority.LOW, 'leadCapture');
+}, callbacks.priority.LOW, 'leadCapture');
diff --git a/packages/rocketchat-livechat/server/hooks/markRoomResponded.js b/packages/rocketchat-livechat/server/hooks/markRoomResponded.js
index 3e6d8d933423..15249388c372 100644
--- a/packages/rocketchat-livechat/server/hooks/markRoomResponded.js
+++ b/packages/rocketchat-livechat/server/hooks/markRoomResponded.js
@@ -1,7 +1,8 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { callbacks } from 'meteor/rocketchat:callbacks';
+import { Rooms } from 'meteor/rocketchat:models';
-RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
+callbacks.add('afterSaveMessage', function(message, room) {
// skips this callback if the message was edited
if (!message || message.editedAt) {
return message;
@@ -18,7 +19,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
}
Meteor.defer(() => {
- RocketChat.models.Rooms.setResponseByRoomId(room._id, {
+ Rooms.setResponseByRoomId(room._id, {
user: {
_id: message.u._id,
username: message.u.username,
@@ -27,4 +28,4 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
});
return message;
-}, RocketChat.callbacks.priority.LOW, 'markRoomResponded');
+}, callbacks.priority.LOW, 'markRoomResponded');
diff --git a/packages/rocketchat-livechat/server/hooks/offlineMessage.js b/packages/rocketchat-livechat/server/hooks/offlineMessage.js
index 31a916e13aec..bf73c650ed45 100644
--- a/packages/rocketchat-livechat/server/hooks/offlineMessage.js
+++ b/packages/rocketchat-livechat/server/hooks/offlineMessage.js
@@ -1,8 +1,9 @@
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { callbacks } from 'meteor/rocketchat:callbacks';
+import { settings } from 'meteor/rocketchat:settings';
import { Livechat } from '../lib/Livechat';
-RocketChat.callbacks.add('livechat.offlineMessage', (data) => {
- if (!RocketChat.settings.get('Livechat_webhook_on_offline_msg')) {
+callbacks.add('livechat.offlineMessage', (data) => {
+ if (!settings.get('Livechat_webhook_on_offline_msg')) {
return data;
}
@@ -17,4 +18,4 @@ RocketChat.callbacks.add('livechat.offlineMessage', (data) => {
};
Livechat.sendRequest(postData);
-}, RocketChat.callbacks.priority.MEDIUM, 'livechat-send-email-offline-message');
+}, callbacks.priority.MEDIUM, 'livechat-send-email-offline-message');
diff --git a/packages/rocketchat-livechat/server/hooks/saveAnalyticsData.js b/packages/rocketchat-livechat/server/hooks/saveAnalyticsData.js
index 31b178fede11..4e516d5c421c 100644
--- a/packages/rocketchat-livechat/server/hooks/saveAnalyticsData.js
+++ b/packages/rocketchat-livechat/server/hooks/saveAnalyticsData.js
@@ -1,7 +1,8 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { callbacks } from 'meteor/rocketchat:callbacks';
+import { Rooms } from 'meteor/rocketchat:models';
-RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
+callbacks.add('afterSaveMessage', function(message, room) {
// skips this callback if the message was edited
if (!message || message.editedAt) {
return message;
@@ -58,8 +59,8 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
} // ignore, its continuing response
}
- RocketChat.models.Rooms.saveAnalyticsDataByRoomId(room, message, analyticsData);
+ Rooms.saveAnalyticsDataByRoomId(room, message, analyticsData);
});
return message;
-}, RocketChat.callbacks.priority.LOW, 'saveAnalyticsData');
+}, callbacks.priority.LOW, 'saveAnalyticsData');
diff --git a/packages/rocketchat-livechat/server/hooks/sendToCRM.js b/packages/rocketchat-livechat/server/hooks/sendToCRM.js
index 301b61988eaa..a22fd6f71bda 100644
--- a/packages/rocketchat-livechat/server/hooks/sendToCRM.js
+++ b/packages/rocketchat-livechat/server/hooks/sendToCRM.js
@@ -1,16 +1,18 @@
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings } from 'meteor/rocketchat:settings';
+import { callbacks } from 'meteor/rocketchat:callbacks';
+import { Messages, Rooms } from 'meteor/rocketchat:models';
import { Livechat } from '../lib/Livechat';
const msgNavType = 'livechat_navigation_history';
const crmEnabled = () => {
- const secretToken = RocketChat.settings.get('Livechat_secret_token');
- const webhookUrl = RocketChat.settings.get('Livechat_webhookUrl');
+ const secretToken = settings.get('Livechat_secret_token');
+ const webhookUrl = settings.get('Livechat_webhookUrl');
return secretToken !== '' && secretToken !== undefined && webhookUrl !== '' && webhookUrl !== undefined;
};
const sendMessageType = (msgType) => {
- const sendNavHistory = RocketChat.settings.get('Livechat_Visitor_navigation_as_a_message') && RocketChat.settings.get('Send_visitor_navigation_history_livechat_webhook_request');
+ const sendNavHistory = settings.get('Livechat_Visitor_navigation_as_a_message') && settings.get('Send_visitor_navigation_history_livechat_webhook_request');
return sendNavHistory && msgType === msgNavType;
};
@@ -28,7 +30,7 @@ function sendToCRM(type, room, includeMessages = true) {
let messages;
if (typeof includeMessages === 'boolean' && includeMessages) {
- messages = RocketChat.models.Messages.findVisibleByRoomId(room._id, { sort: { ts: 1 } });
+ messages = Messages.findVisibleByRoomId(room._id, { sort: { ts: 1 } });
} else if (includeMessages instanceof Array) {
messages = includeMessages;
}
@@ -61,30 +63,30 @@ function sendToCRM(type, room, includeMessages = true) {
const response = Livechat.sendRequest(postData);
if (response && response.data && response.data.data) {
- RocketChat.models.Rooms.saveCRMDataByRoomId(room._id, response.data.data);
+ Rooms.saveCRMDataByRoomId(room._id, response.data.data);
}
return room;
}
-RocketChat.callbacks.add('livechat.closeRoom', (room) => {
- if (!RocketChat.settings.get('Livechat_webhook_on_close')) {
+callbacks.add('livechat.closeRoom', (room) => {
+ if (!settings.get('Livechat_webhook_on_close')) {
return room;
}
return sendToCRM('LivechatSession', room);
-}, RocketChat.callbacks.priority.MEDIUM, 'livechat-send-crm-close-room');
+}, callbacks.priority.MEDIUM, 'livechat-send-crm-close-room');
-RocketChat.callbacks.add('livechat.saveInfo', (room) => {
+callbacks.add('livechat.saveInfo', (room) => {
// Do not send to CRM if the chat is still open
if (room.open) {
return room;
}
return sendToCRM('LivechatEdit', room);
-}, RocketChat.callbacks.priority.MEDIUM, 'livechat-send-crm-save-info');
+}, callbacks.priority.MEDIUM, 'livechat-send-crm-save-info');
-RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
+callbacks.add('afterSaveMessage', function(message, room) {
// only call webhook if it is a livechat room
if (room.t !== 'l' || room.v == null || room.v.token == null) {
return message;
@@ -93,10 +95,10 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
// if the message has a token, it was sent from the visitor
// if not, it was sent from the agent
if (message.token) {
- if (!RocketChat.settings.get('Livechat_webhook_on_visitor_message')) {
+ if (!settings.get('Livechat_webhook_on_visitor_message')) {
return message;
}
- } else if (!RocketChat.settings.get('Livechat_webhook_on_agent_message')) {
+ } else if (!settings.get('Livechat_webhook_on_agent_message')) {
return message;
}
// if the message has a type means it is a special message (like the closing comment), so skips
@@ -107,11 +109,11 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
sendToCRM('Message', room, [message]);
return message;
-}, RocketChat.callbacks.priority.MEDIUM, 'livechat-send-crm-message');
+}, callbacks.priority.MEDIUM, 'livechat-send-crm-message');
-RocketChat.callbacks.add('livechat.leadCapture', (room) => {
- if (!RocketChat.settings.get('Livechat_webhook_on_capture')) {
+callbacks.add('livechat.leadCapture', (room) => {
+ if (!settings.get('Livechat_webhook_on_capture')) {
return room;
}
return sendToCRM('LeadCapture', room, false);
-}, RocketChat.callbacks.priority.MEDIUM, 'livechat-send-crm-lead-capture');
+}, callbacks.priority.MEDIUM, 'livechat-send-crm-lead-capture');
diff --git a/packages/rocketchat-livechat/server/hooks/sendToFacebook.js b/packages/rocketchat-livechat/server/hooks/sendToFacebook.js
index 0526f1e16ed8..2325c15acdac 100644
--- a/packages/rocketchat-livechat/server/hooks/sendToFacebook.js
+++ b/packages/rocketchat-livechat/server/hooks/sendToFacebook.js
@@ -1,13 +1,14 @@
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { callbacks } from 'meteor/rocketchat:callbacks';
+import { settings } from 'meteor/rocketchat:settings';
import OmniChannel from '../lib/OmniChannel';
-RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
+callbacks.add('afterSaveMessage', function(message, room) {
// skips this callback if the message was edited
if (message.editedAt) {
return message;
}
- if (!RocketChat.settings.get('Livechat_Facebook_Enabled') || !RocketChat.settings.get('Livechat_Facebook_API_Key')) {
+ if (!settings.get('Livechat_Facebook_Enabled') || !settings.get('Livechat_Facebook_API_Key')) {
return message;
}
@@ -34,4 +35,4 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
return message;
-}, RocketChat.callbacks.priority.LOW, 'sendMessageToFacebook');
+}, callbacks.priority.LOW, 'sendMessageToFacebook');
diff --git a/packages/rocketchat-livechat/server/lib/Analytics.js b/packages/rocketchat-livechat/server/lib/Analytics.js
index b70301f6b424..75d0903cf900 100644
--- a/packages/rocketchat-livechat/server/lib/Analytics.js
+++ b/packages/rocketchat-livechat/server/lib/Analytics.js
@@ -1,4 +1,4 @@
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Rooms } from 'meteor/rocketchat:models';
import moment from 'moment';
/**
@@ -119,14 +119,14 @@ export const Analytics = {
* @returns {Integer}
*/
Total_conversations(date) {
- return RocketChat.models.Rooms.getTotalConversationsBetweenDate('l', date);
+ return Rooms.getTotalConversationsBetweenDate('l', date);
},
Avg_chat_duration(date) {
let total = 0;
let count = 0;
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({ metrics }) => {
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({ metrics }) => {
if (metrics && metrics.chatDuration) {
total += metrics.chatDuration;
count++;
@@ -140,7 +140,7 @@ export const Analytics = {
Total_messages(date) {
let total = 0;
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({ msgs }) => {
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({ msgs }) => {
if (msgs) {
total += msgs;
}
@@ -158,7 +158,7 @@ export const Analytics = {
Avg_first_response_time(date) {
let frt = 0;
let count = 0;
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({ metrics }) => {
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({ metrics }) => {
if (metrics && metrics.response && metrics.response.ft) {
frt += metrics.response.ft;
count++;
@@ -178,7 +178,7 @@ export const Analytics = {
Best_first_response_time(date) {
let maxFrt;
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({ metrics }) => {
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({ metrics }) => {
if (metrics && metrics.response && metrics.response.ft) {
maxFrt = (maxFrt) ? Math.min(maxFrt, metrics.response.ft) : metrics.response.ft;
}
@@ -198,7 +198,7 @@ export const Analytics = {
Avg_response_time(date) {
let art = 0;
let count = 0;
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({ metrics }) => {
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({ metrics }) => {
if (metrics && metrics.response && metrics.response.avg) {
art += metrics.response.avg;
count++;
@@ -219,7 +219,7 @@ export const Analytics = {
Avg_reaction_time(date) {
let arnt = 0;
let count = 0;
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({ metrics }) => {
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({ metrics }) => {
if (metrics && metrics.reaction && metrics.reaction.ft) {
arnt += metrics.reaction.ft;
count++;
@@ -284,7 +284,7 @@ export const Analytics = {
lt: moment(m).add(1, 'days'),
};
- const result = RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date);
+ const result = Rooms.getAnalyticsMetricsBetweenDate('l', date);
totalConversations += result.count();
result.forEach(summarize(m));
@@ -302,7 +302,7 @@ export const Analytics = {
lt: moment(h).add(1, 'hours'),
};
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
msgs,
}) => {
const dayHour = h.format('H'); // @int : 0, 1, ... 23
@@ -354,7 +354,7 @@ export const Analytics = {
lt: to.add(1, 'days'),
};
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
metrics,
}) => {
if (metrics && metrics.response && metrics.reaction) {
@@ -436,7 +436,7 @@ export const Analytics = {
data: [],
};
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
servedBy,
}) => {
if (servedBy) {
@@ -486,7 +486,7 @@ export const Analytics = {
data: [],
};
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
metrics,
servedBy,
}) => {
@@ -546,7 +546,7 @@ export const Analytics = {
data: [],
};
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
servedBy,
msgs,
}) => {
@@ -590,7 +590,7 @@ export const Analytics = {
data: [],
};
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
metrics,
servedBy,
}) => {
@@ -650,7 +650,7 @@ export const Analytics = {
data: [],
};
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
metrics,
servedBy,
}) => {
@@ -702,7 +702,7 @@ export const Analytics = {
data: [],
};
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
metrics,
servedBy,
}) => {
@@ -762,7 +762,7 @@ export const Analytics = {
data: [],
};
- RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
+ Rooms.getAnalyticsMetricsBetweenDate('l', date).forEach(({
metrics,
servedBy,
}) => {
diff --git a/packages/rocketchat-livechat/server/lib/Livechat.js b/packages/rocketchat-livechat/server/lib/Livechat.js
index c8f3522de3e3..94697be0bfe9 100644
--- a/packages/rocketchat-livechat/server/lib/Livechat.js
+++ b/packages/rocketchat-livechat/server/lib/Livechat.js
@@ -3,8 +3,12 @@ import { Match, check } from 'meteor/check';
import { Random } from 'meteor/random';
import { TAPi18n } from 'meteor/tap:i18n';
import { HTTP } from 'meteor/http';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings } from 'meteor/rocketchat:settings';
+import { callbacks } from 'meteor/rocketchat:callbacks';
+import { Users, Rooms, Messages, Subscriptions, Settings } from 'meteor/rocketchat:models';
import { Logger } from 'meteor/rocketchat:logger';
+import { sendMessage, deleteMessage, updateMessage } from 'meteor/rocketchat:lib';
+import { addUserRoles, removeUserFromRoles } from 'meteor/rocketchat:authorization';
import _ from 'underscore';
import s from 'underscore.string';
import moment from 'moment';
@@ -13,7 +17,7 @@ import UAParser from 'ua-parser-js';
import * as Mailer from 'meteor/rocketchat:mailer';
import { LivechatDepartmentAgents, LivechatDepartment, LivechatCustomField } from '../models';
import { LivechatInquiry } from '../../lib/LivechatInquiry';
-
+import { QueueMethods } from './QueueMethods';
import LivechatVisitors from '../models/LivechatVisitors';
import { Analytics } from './Analytics';
@@ -28,20 +32,20 @@ export const Livechat = {
}),
getNextAgent(department) {
- if (RocketChat.settings.get('Livechat_Routing_Method') === 'External') {
+ if (settings.get('Livechat_Routing_Method') === 'External') {
for (let i = 0; i < 10; i++) {
try {
const queryString = department ? `?departmentId=${ department }` : '';
- const result = HTTP.call('GET', `${ RocketChat.settings.get('Livechat_External_Queue_URL') }${ queryString }`, {
+ const result = HTTP.call('GET', `${ settings.get('Livechat_External_Queue_URL') }${ queryString }`, {
headers: {
'User-Agent': 'RocketChat Server',
Accept: 'application/json',
- 'X-RocketChat-Secret-Token': RocketChat.settings.get('Livechat_External_Queue_Token'),
+ 'X-RocketChat-Secret-Token': settings.get('Livechat_External_Queue_Token'),
},
});
if (result && result.data && result.data.username) {
- const agent = RocketChat.models.Users.findOneOnlineAgentByUsername(result.data.username);
+ const agent = Users.findOneOnlineAgentByUsername(result.data.username);
if (agent) {
return {
@@ -59,19 +63,19 @@ export const Livechat = {
} else if (department) {
return LivechatDepartmentAgents.getNextAgentForDepartment(department);
}
- return RocketChat.models.Users.getNextAgent();
+ return Users.getNextAgent();
},
getAgents(department) {
if (department) {
return LivechatDepartmentAgents.findByDepartmentId(department);
}
- return RocketChat.models.Users.findAgents();
+ return Users.findAgents();
},
getOnlineAgents(department) {
if (department) {
return LivechatDepartmentAgents.getOnlineForDepartment(department);
}
- return RocketChat.models.Users.findOnlineAgents();
+ return Users.findOnlineAgents();
},
getRequiredDepartment(onlineRequired = true) {
const departments = LivechatDepartment.findEnabledWithAgents();
@@ -88,7 +92,7 @@ export const Livechat = {
});
},
getRoom(guest, message, roomInfo, agent) {
- let room = RocketChat.models.Rooms.findOneById(message.rid);
+ let room = Rooms.findOneById(message.rid);
let newRoom = false;
if (room && !room.open) {
@@ -107,8 +111,8 @@ export const Livechat = {
}
// delegate room creation to QueueMethods
- const routingMethod = RocketChat.settings.get('Livechat_Routing_Method');
- room = RocketChat.QueueMethods[routingMethod](guest, message, roomInfo, agent);
+ const routingMethod = settings.get('Livechat_Routing_Method');
+ room = QueueMethods[routingMethod](guest, message, roomInfo, agent);
newRoom = true;
}
@@ -118,7 +122,7 @@ export const Livechat = {
}
if (newRoom) {
- RocketChat.models.Messages.setRoomIdByToken(guest.token, room._id);
+ Messages.setRoomIdByToken(guest.token, room._id);
}
return { room, newRoom };
@@ -131,25 +135,25 @@ export const Livechat = {
}
// return messages;
- return _.extend(RocketChat.sendMessage(guest, message, room), { newRoom, showConnecting: this.showConnecting() });
+ return _.extend(sendMessage(guest, message, room), { newRoom, showConnecting: this.showConnecting() });
},
updateMessage({ guest, message }) {
check(message, Match.ObjectIncluding({ _id: String }));
- const originalMessage = RocketChat.models.Messages.findOneById(message._id);
+ const originalMessage = Messages.findOneById(message._id);
if (!originalMessage || !originalMessage._id) {
return;
}
- const editAllowed = RocketChat.settings.get('Message_AllowEditing');
+ const editAllowed = settings.get('Message_AllowEditing');
const editOwn = originalMessage.u && originalMessage.u._id === guest._id;
if (!editAllowed || !editOwn) {
throw new Meteor.Error('error-action-not-allowed', 'Message editing not allowed', { method: 'livechatUpdateMessage' });
}
- RocketChat.updateMessage(message, guest);
+ updateMessage(message, guest);
return true;
},
@@ -157,19 +161,19 @@ export const Livechat = {
deleteMessage({ guest, message }) {
check(message, Match.ObjectIncluding({ _id: String }));
- const msg = RocketChat.models.Messages.findOneById(message._id);
+ const msg = Messages.findOneById(message._id);
if (!msg || !msg._id) {
return;
}
- const deleteAllowed = RocketChat.settings.get('Message_AllowDeleting');
+ const deleteAllowed = settings.get('Message_AllowDeleting');
const editOwn = msg.u && msg.u._id === guest._id;
if (!deleteAllowed || !editOwn) {
throw new Meteor.Error('error-action-not-allowed', 'Message deleting not allowed', { method: 'livechatDeleteMessage' });
}
- RocketChat.deleteMessage(message, guest);
+ deleteMessage(message, guest);
return true;
},
@@ -202,7 +206,7 @@ export const Livechat = {
username,
};
- const storeHttpHeaderData = RocketChat.settings.get('Livechat_Allow_collect_and_store_HTTP_header_informations');
+ const storeHttpHeaderData = settings.get('Livechat_Allow_collect_and_store_HTTP_header_informations');
if (this.connection && storeHttpHeaderData) {
userData.userAgent = this.connection.httpHeaders['user-agent'];
@@ -271,7 +275,7 @@ export const Livechat = {
const ret = LivechatVisitors.saveGuestById(_id, updateData);
Meteor.defer(() => {
- RocketChat.callbacks.run('livechat.saveGuest', updateData);
+ callbacks.run('livechat.saveGuest', updateData);
});
return ret;
@@ -303,7 +307,7 @@ export const Livechat = {
};
}
- RocketChat.models.Rooms.closeByRoomId(room._id, closeData);
+ Rooms.closeByRoomId(room._id, closeData);
LivechatInquiry.closeByRoomId(room._id, closeData);
const message = {
@@ -312,15 +316,15 @@ export const Livechat = {
groupable: false,
};
- RocketChat.sendMessage(user, message, room);
+ sendMessage(user, message, room);
if (room.servedBy) {
- RocketChat.models.Subscriptions.hideByRoomIdAndUserId(room._id, room.servedBy._id);
+ Subscriptions.hideByRoomIdAndUserId(room._id, room.servedBy._id);
}
- RocketChat.models.Messages.createCommandWithRoomIdAndUser('promptTranscript', room._id, closeData.closedBy);
+ Messages.createCommandWithRoomIdAndUser('promptTranscript', room._id, closeData.closedBy);
Meteor.defer(() => {
- RocketChat.callbacks.run('livechat.closeRoom', room);
+ callbacks.run('livechat.closeRoom', room);
});
return true;
@@ -338,16 +342,16 @@ export const Livechat = {
}
if (customField.scope === 'room') {
- return RocketChat.models.Rooms.updateLivechatDataByToken(token, key, value, overwrite);
+ return Rooms.updateLivechatDataByToken(token, key, value, overwrite);
} else {
return LivechatVisitors.updateLivechatDataByToken(token, key, value, overwrite);
}
},
getInitSettings() {
- const settings = {};
+ const rcSettings = {};
- RocketChat.models.Settings.findNotHiddenPublic([
+ Settings.findNotHiddenPublic([
'Livechat_title',
'Livechat_title_color',
'Livechat_enabled',
@@ -373,41 +377,41 @@ export const Livechat = {
'Livechat_force_accept_data_processing_consent',
'Livechat_data_processing_consent_text',
]).forEach((setting) => {
- settings[setting._id] = setting.value;
+ rcSettings[setting._id] = setting.value;
});
- RocketChat.settings.get('Livechat_history_monitor_type', (key, value) => {
- settings[key] = value;
+ settings.get('Livechat_history_monitor_type', (key, value) => {
+ rcSettings[key] = value;
});
- settings.Livechat_Show_Connecting = this.showConnecting();
+ rcSettings.Livechat_Show_Connecting = this.showConnecting();
- return settings;
+ return rcSettings;
},
saveRoomInfo(roomData, guestData) {
- if ((roomData.topic != null || roomData.tags != null) && !RocketChat.models.Rooms.setTopicAndTagsById(roomData._id, roomData.topic, roomData.tags)) {
+ if ((roomData.topic != null || roomData.tags != null) && !Rooms.setTopicAndTagsById(roomData._id, roomData.topic, roomData.tags)) {
return false;
}
Meteor.defer(() => {
- RocketChat.callbacks.run('livechat.saveRoom', roomData);
+ callbacks.run('livechat.saveRoom', roomData);
});
if (!_.isEmpty(guestData.name)) {
- return RocketChat.models.Rooms.setFnameById(roomData._id, guestData.name) && RocketChat.models.Subscriptions.updateDisplayNameByRoomId(roomData._id, guestData.name);
+ return Rooms.setFnameById(roomData._id, guestData.name) && Subscriptions.updateDisplayNameByRoomId(roomData._id, guestData.name);
}
},
closeOpenChats(userId, comment) {
- const user = RocketChat.models.Users.findOneById(userId);
- RocketChat.models.Rooms.findOpenByAgent(userId).forEach((room) => {
+ const user = Users.findOneById(userId);
+ Rooms.findOpenByAgent(userId).forEach((room) => {
this.closeRoom({ user, room, comment });
});
},
forwardOpenChats(userId) {
- RocketChat.models.Rooms.findOpenByAgent(userId).forEach((room) => {
+ Rooms.findOpenByAgent(userId).forEach((room) => {
const guest = LivechatVisitors.findOneById(room.v._id);
this.transfer(room, guest, { departmentId: guest.department });
});
@@ -416,7 +420,7 @@ export const Livechat = {
savePageHistory(token, roomId, pageInfo) {
if (pageInfo.change === Livechat.historyMonitorType) {
- const user = RocketChat.models.Users.findOneById('rocket.cat');
+ const user = Users.findOneById('rocket.cat');
const pageTitle = pageInfo.title;
const pageUrl = pageInfo.location.href;
@@ -433,11 +437,11 @@ export const Livechat = {
extraData.expireAt = new Date().getTime() + keepHistoryMiliseconds;
}
- if (!RocketChat.settings.get('Livechat_Visitor_navigation_as_a_message')) {
+ if (!settings.get('Livechat_Visitor_navigation_as_a_message')) {
extraData._hidden = true;
}
- return RocketChat.models.Messages.createNavigationHistoryWithRoomIdMessageAndUser(roomId, `${ pageTitle } - ${ pageUrl }`, user, extraData);
+ return Messages.createNavigationHistoryWithRoomIdMessageAndUser(roomId, `${ pageTitle } - ${ pageUrl }`, user, extraData);
}
return;
@@ -447,14 +451,14 @@ export const Livechat = {
let agent;
if (transferData.userId) {
- const user = RocketChat.models.Users.findOneOnlineAgentById(transferData.userId);
+ const user = Users.findOneOnlineAgentById(transferData.userId);
if (!user) {
return false;
}
const { _id: agentId, username } = user;
agent = Object.assign({}, { agentId, username });
- } else if (RocketChat.settings.get('Livechat_Routing_Method') !== 'Guest_Pool') {
+ } else if (settings.get('Livechat_Routing_Method') !== 'Guest_Pool') {
agent = Livechat.getNextAgent(transferData.departmentId);
} else {
return Livechat.returnRoomAsInquiry(room._id, transferData.departmentId);
@@ -463,10 +467,10 @@ export const Livechat = {
const { servedBy } = room;
if (agent && agent.agentId !== servedBy._id) {
- RocketChat.models.Rooms.changeAgentByRoomId(room._id, agent);
+ Rooms.changeAgentByRoomId(room._id, agent);
if (transferData.departmentId) {
- RocketChat.models.Rooms.changeDepartmentIdByRoomId(room._id, transferData.departmentId);
+ Rooms.changeDepartmentIdByRoomId(room._id, transferData.departmentId);
}
const subscriptionData = {
@@ -486,13 +490,13 @@ export const Livechat = {
mobilePushNotifications: 'all',
emailNotifications: 'all',
};
- RocketChat.models.Subscriptions.removeByRoomIdAndUserId(room._id, servedBy._id);
+ Subscriptions.removeByRoomIdAndUserId(room._id, servedBy._id);
- RocketChat.models.Subscriptions.insert(subscriptionData);
- RocketChat.models.Rooms.incUsersCountById(room._id);
+ Subscriptions.insert(subscriptionData);
+ Rooms.incUsersCountById(room._id);
- RocketChat.models.Messages.createUserLeaveWithRoomIdAndUser(room._id, { _id: servedBy._id, username: servedBy.username });
- RocketChat.models.Messages.createUserJoinWithRoomIdAndUser(room._id, { _id: agent.agentId, username: agent.username });
+ Messages.createUserLeaveWithRoomIdAndUser(room._id, { _id: servedBy._id, username: servedBy.username });
+ Messages.createUserJoinWithRoomIdAndUser(room._id, { _id: agent.agentId, username: agent.username });
const guestData = {
token: guest.token,
@@ -500,7 +504,7 @@ export const Livechat = {
};
this.setDepartmentForGuest(guestData);
- const data = RocketChat.models.Users.getAgentInfo(agent.agentId);
+ const data = Users.getAgentInfo(agent.agentId);
Livechat.stream.emit(room._id, {
type: 'agentData',
@@ -514,7 +518,7 @@ export const Livechat = {
},
returnRoomAsInquiry(rid, departmentId) {
- const room = RocketChat.models.Rooms.findOneById(rid);
+ const room = Rooms.findOneById(rid);
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'livechat:returnRoomAsInquiry' });
}
@@ -523,7 +527,7 @@ export const Livechat = {
return false;
}
- const user = RocketChat.models.Users.findOne(room.servedBy._id);
+ const user = Users.findOne(room.servedBy._id);
if (!user || !user._id) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'livechat:returnRoomAsInquiry' });
}
@@ -533,7 +537,7 @@ export const Livechat = {
if (departmentId) {
let agents = Livechat.getOnlineAgents(departmentId);
- if (agents.count() === 0 && RocketChat.settings.get('Livechat_guest_pool_with_no_agents')) {
+ if (agents.count() === 0 && settings.get('Livechat_guest_pool_with_no_agents')) {
agents = Livechat.getAgents(departmentId);
}
@@ -545,14 +549,14 @@ export const Livechat = {
agentIds.push(agent.agentId);
});
- RocketChat.models.Rooms.changeDepartmentIdByRoomId(room._id, departmentId);
+ Rooms.changeDepartmentIdByRoomId(room._id, departmentId);
}
// delete agent and room subscription
- RocketChat.models.Subscriptions.removeByRoomId(rid);
+ Subscriptions.removeByRoomId(rid);
// remove agent from room
- RocketChat.models.Rooms.removeAgentByRoomId(rid);
+ Rooms.removeAgentByRoomId(rid);
// find inquiry corresponding to room
const inquiry = LivechatInquiry.findOne({ rid });
@@ -569,7 +573,7 @@ export const Livechat = {
}
if (openInq) {
- RocketChat.models.Messages.createUserLeaveWithRoomIdAndUser(rid, { _id: room.servedBy._id, username: room.servedBy.username });
+ Messages.createUserLeaveWithRoomIdAndUser(rid, { _id: room.servedBy._id, username: room.servedBy.username });
Livechat.stream.emit(rid, {
type: 'agentData',
@@ -584,11 +588,11 @@ export const Livechat = {
try {
const options = {
headers: {
- 'X-RocketChat-Livechat-Token': RocketChat.settings.get('Livechat_secret_token'),
+ 'X-RocketChat-Livechat-Token': settings.get('Livechat_secret_token'),
},
data: postData,
};
- return HTTP.post(RocketChat.settings.get('Livechat_webhookUrl'), options);
+ return HTTP.post(settings.get('Livechat_webhookUrl'), options);
} catch (e) {
Livechat.logger.webhook.error(`Response error on ${ trying } try ->`, e);
// try 10 times after 10 seconds each
@@ -604,7 +608,7 @@ export const Livechat = {
getLivechatRoomGuestInfo(room) {
const visitor = LivechatVisitors.findOneById(room.v._id);
- const agent = RocketChat.models.Users.findOneById(room.servedBy && room.servedBy._id);
+ const agent = Users.findOneById(room.servedBy && room.servedBy._id);
const ua = new UAParser();
ua.setUA(visitor.userAgent);
@@ -662,15 +666,15 @@ export const Livechat = {
addAgent(username) {
check(username, String);
- const user = RocketChat.models.Users.findOneByUsername(username, { fields: { _id: 1, username: 1 } });
+ const user = Users.findOneByUsername(username, { fields: { _id: 1, username: 1 } });
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'livechat:addAgent' });
}
- if (RocketChat.authz.addUserRoles(user._id, 'livechat-agent')) {
- RocketChat.models.Users.setOperator(user._id, true);
- RocketChat.models.Users.setLivechatStatus(user._id, 'available');
+ if (addUserRoles(user._id, 'livechat-agent')) {
+ Users.setOperator(user._id, true);
+ Users.setLivechatStatus(user._id, 'available');
return user;
}
@@ -680,13 +684,13 @@ export const Livechat = {
addManager(username) {
check(username, String);
- const user = RocketChat.models.Users.findOneByUsername(username, { fields: { _id: 1, username: 1 } });
+ const user = Users.findOneByUsername(username, { fields: { _id: 1, username: 1 } });
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'livechat:addManager' });
}
- if (RocketChat.authz.addUserRoles(user._id, 'livechat-manager')) {
+ if (addUserRoles(user._id, 'livechat-manager')) {
return user;
}
@@ -696,15 +700,15 @@ export const Livechat = {
removeAgent(username) {
check(username, String);
- const user = RocketChat.models.Users.findOneByUsername(username, { fields: { _id: 1 } });
+ const user = Users.findOneByUsername(username, { fields: { _id: 1 } });
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'livechat:removeAgent' });
}
- if (RocketChat.authz.removeUserFromRoles(user._id, 'livechat-agent')) {
- RocketChat.models.Users.setOperator(user._id, false);
- RocketChat.models.Users.setLivechatStatus(user._id, 'not-available');
+ if (removeUserFromRoles(user._id, 'livechat-agent')) {
+ Users.setOperator(user._id, false);
+ Users.setLivechatStatus(user._id, 'not-available');
return true;
}
@@ -714,13 +718,13 @@ export const Livechat = {
removeManager(username) {
check(username, String);
- const user = RocketChat.models.Users.findOneByUsername(username, { fields: { _id: 1 } });
+ const user = Users.findOneByUsername(username, { fields: { _id: 1 } });
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'livechat:removeManager' });
}
- return RocketChat.authz.removeUserFromRoles(user._id, 'livechat-manager');
+ return removeUserFromRoles(user._id, 'livechat-manager');
},
removeGuest(_id) {
@@ -743,13 +747,13 @@ export const Livechat = {
const { token } = guest;
- RocketChat.models.Rooms.findByVisitorToken(token).forEach((room) => {
- RocketChat.models.Messages.removeFilesByRoomId(room._id);
- RocketChat.models.Messages.removeByRoomId(room._id);
+ Rooms.findByVisitorToken(token).forEach((room) => {
+ Messages.removeFilesByRoomId(room._id);
+ Messages.removeByRoomId(room._id);
});
- RocketChat.models.Subscriptions.removeByVisitorToken(token);
- RocketChat.models.Rooms.removeByVisitorToken(token);
+ Subscriptions.removeByVisitorToken(token);
+ Rooms.removeByVisitorToken(token);
},
saveDepartment(_id, departmentData, departmentAgents) {
@@ -792,8 +796,8 @@ export const Livechat = {
},
showConnecting() {
- if (RocketChat.settings.get('Livechat_Routing_Method') === 'Guest_Pool') {
- return RocketChat.settings.get('Livechat_open_inquiery_show_connecting');
+ if (settings.get('Livechat_Routing_Method') === 'Guest_Pool') {
+ return settings.get('Livechat_open_inquiery_show_connecting');
} else {
return false;
}
@@ -813,17 +817,17 @@ export const Livechat = {
check(rid, String);
check(email, String);
- const room = RocketChat.models.Rooms.findOneById(rid);
+ const room = Rooms.findOneById(rid);
const visitor = LivechatVisitors.getVisitorByToken(token);
- const userLanguage = (visitor && visitor.language) || RocketChat.settings.get('Language') || 'en';
+ const userLanguage = (visitor && visitor.language) || settings.get('Language') || 'en';
// allow to only user to send transcripts from their own chats
if (!room || room.t !== 'l' || !room.v || room.v.token !== token) {
throw new Meteor.Error('error-invalid-room', 'Invalid room');
}
- const messages = RocketChat.models.Messages.findVisibleByRoomIdNotContainingTypes(rid, ['livechat_navigation_history'], { sort: { ts: 1 } });
+ const messages = Messages.findVisibleByRoomIdNotContainingTypes(rid, ['livechat_navigation_history'], { sort: { ts: 1 } });
let html = '
';
messages.forEach((message) => {
@@ -848,12 +852,12 @@ export const Livechat = {
html = `${ html }`;
- let fromEmail = RocketChat.settings.get('From_Email').match(/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i);
+ let fromEmail = settings.get('From_Email').match(/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i);
if (fromEmail) {
fromEmail = fromEmail[0];
} else {
- fromEmail = RocketChat.settings.get('From_Email');
+ fromEmail = settings.get('From_Email');
}
const subject = TAPi18n.__('Transcript_of_your_livechat_conversation', { lng: userLanguage });
@@ -861,7 +865,7 @@ export const Livechat = {
this.sendEmail(fromEmail, email, fromEmail, subject, html);
Meteor.defer(() => {
- RocketChat.callbacks.run('livechat.sendTranscript', messages, email);
+ callbacks.run('livechat.sendTranscript', messages, email);
});
return true;
@@ -869,11 +873,11 @@ export const Livechat = {
notifyGuestStatusChanged(token, status) {
LivechatInquiry.updateVisitorStatus(token, status);
- RocketChat.models.Rooms.updateVisitorStatus(token, status);
+ Rooms.updateVisitorStatus(token, status);
},
sendOfflineMessage(data = {}) {
- if (!RocketChat.settings.get('Livechat_display_offline_form')) {
+ if (!settings.get('Livechat_display_offline_form')) {
return false;
}
@@ -885,15 +889,15 @@ export const Livechat = {
Visitor email: ${ data.email }
Message:
${ message }
`;
- let fromEmail = RocketChat.settings.get('From_Email').match(/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i);
+ let fromEmail = settings.get('From_Email').match(/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i);
if (fromEmail) {
fromEmail = fromEmail[0];
} else {
- fromEmail = RocketChat.settings.get('From_Email');
+ fromEmail = settings.get('From_Email');
}
- if (RocketChat.settings.get('Livechat_validate_offline_email')) {
+ if (settings.get('Livechat_validate_offline_email')) {
const emailDomain = data.email.substr(data.email.lastIndexOf('@') + 1);
try {
@@ -903,7 +907,7 @@ export const Livechat = {
}
}
- const to = RocketChat.settings.get('Livechat_offline_email');
+ const to = settings.get('Livechat_offline_email');
const from = `${ data.name } - ${ data.email } <${ fromEmail }>`;
const replyTo = `${ data.name } <${ data.email }>`;
const subject = `Livechat offline message from ${ data.name }: ${ (`${ data.message }`).substring(0, 20) }`;
@@ -911,14 +915,14 @@ export const Livechat = {
this.sendEmail(from, to, replyTo, subject, html);
Meteor.defer(() => {
- RocketChat.callbacks.run('livechat.offlineMessage', data);
+ callbacks.run('livechat.offlineMessage', data);
});
return true;
},
notifyAgentStatusChanged(userId, status) {
- RocketChat.models.Rooms.findOpenByAgent(userId).forEach((room) => {
+ Rooms.findOpenByAgent(userId).forEach((room) => {
Livechat.stream.emit(room._id, {
type: 'agentStatus',
status,
@@ -930,7 +934,7 @@ export const Livechat = {
Livechat.stream = new Meteor.Streamer('livechat-room');
Livechat.stream.allowRead((roomId, extraData) => {
- const room = RocketChat.models.Rooms.findOneById(roomId);
+ const room = Rooms.findOneById(roomId);
if (!room) {
console.warn(`Invalid eventName: "${ roomId }"`);
@@ -943,6 +947,6 @@ Livechat.stream.allowRead((roomId, extraData) => {
return false;
});
-RocketChat.settings.get('Livechat_history_monitor_type', (key, value) => {
+settings.get('Livechat_history_monitor_type', (key, value) => {
Livechat.historyMonitorType = value;
});
diff --git a/packages/rocketchat-livechat/server/lib/OfficeClock.js b/packages/rocketchat-livechat/server/lib/OfficeClock.js
index 317fc500ff6c..8590efae7780 100644
--- a/packages/rocketchat-livechat/server/lib/OfficeClock.js
+++ b/packages/rocketchat-livechat/server/lib/OfficeClock.js
@@ -1,14 +1,15 @@
// Every minute check if office closed
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings } from 'meteor/rocketchat:settings';
+import { Users } from 'meteor/rocketchat:models';
import { LivechatOfficeHour } from '../models';
Meteor.setInterval(function() {
- if (RocketChat.settings.get('Livechat_enable_office_hours')) {
+ if (settings.get('Livechat_enable_office_hours')) {
if (LivechatOfficeHour.isOpeningTime()) {
- RocketChat.models.Users.openOffice();
+ Users.openOffice();
} else if (LivechatOfficeHour.isClosingTime()) {
- RocketChat.models.Users.closeOffice();
+ Users.closeOffice();
}
}
}, 60000);
diff --git a/packages/rocketchat-livechat/server/lib/OmniChannel.js b/packages/rocketchat-livechat/server/lib/OmniChannel.js
index 80698e255722..6469599c6696 100644
--- a/packages/rocketchat-livechat/server/lib/OmniChannel.js
+++ b/packages/rocketchat-livechat/server/lib/OmniChannel.js
@@ -1,5 +1,5 @@
import { HTTP } from 'meteor/http';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings } from 'meteor/rocketchat:settings';
const gatewayURL = 'https://omni.rocket.chat';
@@ -7,11 +7,11 @@ export default {
enable() {
const result = HTTP.call('POST', `${ gatewayURL }/facebook/enable`, {
headers: {
- authorization: `Bearer ${ RocketChat.settings.get('Livechat_Facebook_API_Key') }`,
+ authorization: `Bearer ${ settings.get('Livechat_Facebook_API_Key') }`,
'content-type': 'application/json',
},
data: {
- url: RocketChat.settings.get('Site_Url'),
+ url: settings.get('Site_Url'),
},
});
return result.data;
@@ -20,7 +20,7 @@ export default {
disable() {
const result = HTTP.call('DELETE', `${ gatewayURL }/facebook/enable`, {
headers: {
- authorization: `Bearer ${ RocketChat.settings.get('Livechat_Facebook_API_Key') }`,
+ authorization: `Bearer ${ settings.get('Livechat_Facebook_API_Key') }`,
'content-type': 'application/json',
},
});
@@ -30,7 +30,7 @@ export default {
listPages() {
const result = HTTP.call('GET', `${ gatewayURL }/facebook/pages`, {
headers: {
- authorization: `Bearer ${ RocketChat.settings.get('Livechat_Facebook_API_Key') }`,
+ authorization: `Bearer ${ settings.get('Livechat_Facebook_API_Key') }`,
},
});
return result.data;
@@ -39,7 +39,7 @@ export default {
subscribe(pageId) {
const result = HTTP.call('POST', `${ gatewayURL }/facebook/page/${ pageId }/subscribe`, {
headers: {
- authorization: `Bearer ${ RocketChat.settings.get('Livechat_Facebook_API_Key') }`,
+ authorization: `Bearer ${ settings.get('Livechat_Facebook_API_Key') }`,
},
});
return result.data;
@@ -48,7 +48,7 @@ export default {
unsubscribe(pageId) {
const result = HTTP.call('DELETE', `${ gatewayURL }/facebook/page/${ pageId }/subscribe`, {
headers: {
- authorization: `Bearer ${ RocketChat.settings.get('Livechat_Facebook_API_Key') }`,
+ authorization: `Bearer ${ settings.get('Livechat_Facebook_API_Key') }`,
},
});
return result.data;
@@ -57,7 +57,7 @@ export default {
reply({ page, token, text }) {
return HTTP.call('POST', `${ gatewayURL }/facebook/reply`, {
headers: {
- authorization: `Bearer ${ RocketChat.settings.get('Livechat_Facebook_API_Key') }`,
+ authorization: `Bearer ${ settings.get('Livechat_Facebook_API_Key') }`,
},
data: {
page,
diff --git a/packages/rocketchat-livechat/server/lib/QueueMethods.js b/packages/rocketchat-livechat/server/lib/QueueMethods.js
index bcea885b4822..e79b7807b2dd 100644
--- a/packages/rocketchat-livechat/server/lib/QueueMethods.js
+++ b/packages/rocketchat-livechat/server/lib/QueueMethods.js
@@ -1,12 +1,13 @@
import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/tap:i18n';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Rooms, Subscriptions, Users } from 'meteor/rocketchat:models';
+import { settings } from 'meteor/rocketchat:settings';
import _ from 'underscore';
import { sendNotification } from 'meteor/rocketchat:lib';
import { LivechatInquiry } from '../../lib/LivechatInquiry';
import { Livechat } from './Livechat';
-RocketChat.QueueMethods = {
+export const QueueMethods = {
/* Least Amount Queuing method:
*
* default method where the agent with the least number
@@ -20,7 +21,7 @@ RocketChat.QueueMethods = {
}
}
- RocketChat.models.Rooms.updateLivechatRoomCount();
+ Rooms.updateLivechatRoomCount();
const room = _.extend({
_id: message.rid,
@@ -69,13 +70,13 @@ RocketChat.QueueMethods = {
room.departmentId = guest.department;
}
- RocketChat.models.Rooms.insert(room);
+ Rooms.insert(room);
- RocketChat.models.Subscriptions.insert(subscriptionData);
+ Subscriptions.insert(subscriptionData);
Livechat.stream.emit(room._id, {
type: 'agentData',
- data: RocketChat.models.Users.getAgentInfo(agent.agentId),
+ data: Users.getAgentInfo(agent.agentId),
});
return room;
@@ -92,7 +93,7 @@ RocketChat.QueueMethods = {
'Guest_Pool'(guest, message, roomInfo) {
let agents = Livechat.getOnlineAgents(guest.department);
- if (agents.count() === 0 && RocketChat.settings.get('Livechat_guest_pool_with_no_agents')) {
+ if (agents.count() === 0 && settings.get('Livechat_guest_pool_with_no_agents')) {
agents = Livechat.getAgents(guest.department);
}
@@ -100,7 +101,7 @@ RocketChat.QueueMethods = {
throw new Meteor.Error('no-agent-online', 'Sorry, no online agents');
}
- RocketChat.models.Rooms.updateLivechatRoomCount();
+ Rooms.updateLivechatRoomCount();
const agentIds = [];
@@ -154,7 +155,7 @@ RocketChat.QueueMethods = {
}
LivechatInquiry.insert(inquiry);
- RocketChat.models.Rooms.insert(room);
+ Rooms.insert(room);
// Alert the agents of the queued request
agentIds.forEach((agentId) => {
diff --git a/packages/rocketchat-livechat/server/livechat.js b/packages/rocketchat-livechat/server/livechat.js
index b944278813d8..2f2f51969f1a 100644
--- a/packages/rocketchat-livechat/server/livechat.js
+++ b/packages/rocketchat-livechat/server/livechat.js
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings } from 'meteor/rocketchat:settings';
import _ from 'underscore';
import url from 'url';
@@ -13,7 +13,7 @@ WebApp.connectHandlers.use('/livechat', Meteor.bindEnvironment((req, res, next)
}
res.setHeader('content-type', 'text/html; charset=utf-8');
- let domainWhiteList = RocketChat.settings.get('Livechat_AllowedDomainsList');
+ let domainWhiteList = settings.get('Livechat_AllowedDomainsList');
if (req.headers.referer && !_.isEmpty(domainWhiteList.trim())) {
domainWhiteList = _.map(domainWhiteList.split(','), function(domain) {
return domain.trim();
diff --git a/packages/rocketchat-livechat/server/methods/addAgent.js b/packages/rocketchat-livechat/server/methods/addAgent.js
index b9a7cc01baa5..38a945df1933 100644
--- a/packages/rocketchat-livechat/server/methods/addAgent.js
+++ b/packages/rocketchat-livechat/server/methods/addAgent.js
@@ -1,10 +1,10 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:addAgent'(username) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:addAgent' });
}
diff --git a/packages/rocketchat-livechat/server/methods/addManager.js b/packages/rocketchat-livechat/server/methods/addManager.js
index a83ce7bfa3db..3fba85835c4b 100644
--- a/packages/rocketchat-livechat/server/methods/addManager.js
+++ b/packages/rocketchat-livechat/server/methods/addManager.js
@@ -1,10 +1,10 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:addManager'(username) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:addManager' });
}
diff --git a/packages/rocketchat-livechat/server/methods/changeLivechatStatus.js b/packages/rocketchat-livechat/server/methods/changeLivechatStatus.js
index 06e08f59b8bb..0f92b1cd7d23 100644
--- a/packages/rocketchat-livechat/server/methods/changeLivechatStatus.js
+++ b/packages/rocketchat-livechat/server/methods/changeLivechatStatus.js
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Users } from 'meteor/rocketchat:models';
Meteor.methods({
'livechat:changeLivechatStatus'() {
@@ -11,6 +11,6 @@ Meteor.methods({
const newStatus = user.statusLivechat === 'available' ? 'not-available' : 'available';
- return RocketChat.models.Users.setLivechatStatus(user._id, newStatus);
+ return Users.setLivechatStatus(user._id, newStatus);
},
});
diff --git a/packages/rocketchat-livechat/server/methods/closeByVisitor.js b/packages/rocketchat-livechat/server/methods/closeByVisitor.js
index 5acee57cb3f1..a5a014f54560 100644
--- a/packages/rocketchat-livechat/server/methods/closeByVisitor.js
+++ b/packages/rocketchat-livechat/server/methods/closeByVisitor.js
@@ -1,6 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/tap:i18n';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings } from 'meteor/rocketchat:settings';
+import { Rooms } from 'meteor/rocketchat:models';
import LivechatVisitors from '../models/LivechatVisitors';
import { Livechat } from '../lib/Livechat';
@@ -8,11 +9,11 @@ Meteor.methods({
'livechat:closeByVisitor'({ roomId, token }) {
const visitor = LivechatVisitors.getVisitorByToken(token);
- const language = (visitor && visitor.language) || RocketChat.settings.get('Language') || 'en';
+ const language = (visitor && visitor.language) || settings.get('Language') || 'en';
return Livechat.closeRoom({
visitor,
- room: RocketChat.models.Rooms.findOneOpenByRoomIdAndVisitorToken(roomId, token),
+ room: Rooms.findOneOpenByRoomIdAndVisitorToken(roomId, token),
comment: TAPi18n.__('Closed_by_visitor', { lng: language }),
});
},
diff --git a/packages/rocketchat-livechat/server/methods/closeRoom.js b/packages/rocketchat-livechat/server/methods/closeRoom.js
index 5f9b558dc781..8f586e9585e5 100644
--- a/packages/rocketchat-livechat/server/methods/closeRoom.js
+++ b/packages/rocketchat-livechat/server/methods/closeRoom.js
@@ -1,24 +1,25 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { Subscriptions, Rooms } from 'meteor/rocketchat:models';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:closeRoom'(roomId, comment) {
const userId = Meteor.userId();
- if (!userId || !RocketChat.authz.hasPermission(userId, 'close-livechat-room')) {
+ if (!userId || !hasPermission(userId, 'close-livechat-room')) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'livechat:closeRoom' });
}
const user = Meteor.user();
- const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(roomId, user._id, { _id: 1 });
- if (!subscription && !RocketChat.authz.hasPermission(userId, 'close-others-livechat-room')) {
+ const subscription = Subscriptions.findOneByRoomIdAndUserId(roomId, user._id, { _id: 1 });
+ if (!subscription && !hasPermission(userId, 'close-others-livechat-room')) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'livechat:closeRoom' });
}
return Livechat.closeRoom({
user,
- room: RocketChat.models.Rooms.findOneById(roomId),
+ room: Rooms.findOneById(roomId),
comment,
});
},
diff --git a/packages/rocketchat-livechat/server/methods/facebook.js b/packages/rocketchat-livechat/server/methods/facebook.js
index b3fd3fe48dab..b804b72ea301 100644
--- a/packages/rocketchat-livechat/server/methods/facebook.js
+++ b/packages/rocketchat-livechat/server/methods/facebook.js
@@ -1,10 +1,11 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { settings } from 'meteor/rocketchat:settings';
import OmniChannel from '../lib/OmniChannel';
Meteor.methods({
'livechat:facebook'(options) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:addAgent' });
}
@@ -12,8 +13,8 @@ Meteor.methods({
switch (options.action) {
case 'initialState': {
return {
- enabled: RocketChat.settings.get('Livechat_Facebook_Enabled'),
- hasToken: !!RocketChat.settings.get('Livechat_Facebook_API_Key'),
+ enabled: settings.get('Livechat_Facebook_Enabled'),
+ hasToken: !!settings.get('Livechat_Facebook_API_Key'),
};
}
@@ -24,13 +25,13 @@ Meteor.methods({
return result;
}
- return RocketChat.settings.updateById('Livechat_Facebook_Enabled', true);
+ return settings.updateById('Livechat_Facebook_Enabled', true);
}
case 'disable': {
OmniChannel.disable();
- return RocketChat.settings.updateById('Livechat_Facebook_Enabled', false);
+ return settings.updateById('Livechat_Facebook_Enabled', false);
}
case 'list-pages': {
diff --git a/packages/rocketchat-livechat/server/methods/getAgentData.js b/packages/rocketchat-livechat/server/methods/getAgentData.js
index f9bef1adf071..c9ec165842a4 100644
--- a/packages/rocketchat-livechat/server/methods/getAgentData.js
+++ b/packages/rocketchat-livechat/server/methods/getAgentData.js
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Users, Rooms } from 'meteor/rocketchat:models';
import LivechatVisitors from '../models/LivechatVisitors';
Meteor.methods({
@@ -8,7 +8,7 @@ Meteor.methods({
check(roomId, String);
check(token, String);
- const room = RocketChat.models.Rooms.findOneById(roomId);
+ const room = Rooms.findOneById(roomId);
const visitor = LivechatVisitors.getVisitorByToken(token);
if (!room || room.t !== 'l' || !room.v || room.v.token !== visitor.token) {
@@ -19,6 +19,6 @@ Meteor.methods({
return;
}
- return RocketChat.models.Users.getAgentInfo(room.servedBy._id);
+ return Users.getAgentInfo(room.servedBy._id);
},
});
diff --git a/packages/rocketchat-livechat/server/methods/getAgentOverviewData.js b/packages/rocketchat-livechat/server/methods/getAgentOverviewData.js
index 3a9ef3142534..25858f8a3f04 100644
--- a/packages/rocketchat-livechat/server/methods/getAgentOverviewData.js
+++ b/packages/rocketchat-livechat/server/methods/getAgentOverviewData.js
@@ -1,10 +1,10 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:getAgentOverviewData'(options) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'livechat:getAgentOverviewData',
});
diff --git a/packages/rocketchat-livechat/server/methods/getAnalyticsChartData.js b/packages/rocketchat-livechat/server/methods/getAnalyticsChartData.js
index 13d426971450..63cb49c580ef 100644
--- a/packages/rocketchat-livechat/server/methods/getAnalyticsChartData.js
+++ b/packages/rocketchat-livechat/server/methods/getAnalyticsChartData.js
@@ -1,10 +1,10 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:getAnalyticsChartData'(options) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'livechat:getAnalyticsChartData',
});
diff --git a/packages/rocketchat-livechat/server/methods/getAnalyticsOverviewData.js b/packages/rocketchat-livechat/server/methods/getAnalyticsOverviewData.js
index aacae224b0ce..0ec4df5f471a 100644
--- a/packages/rocketchat-livechat/server/methods/getAnalyticsOverviewData.js
+++ b/packages/rocketchat-livechat/server/methods/getAnalyticsOverviewData.js
@@ -1,10 +1,10 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:getAnalyticsOverviewData'(options) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'livechat:getAnalyticsOverviewData',
});
diff --git a/packages/rocketchat-livechat/server/methods/getInitialData.js b/packages/rocketchat-livechat/server/methods/getInitialData.js
index 5112786cf2fa..583205adcc5f 100644
--- a/packages/rocketchat-livechat/server/methods/getInitialData.js
+++ b/packages/rocketchat-livechat/server/methods/getInitialData.js
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Rooms, Users } from 'meteor/rocketchat:models';
import _ from 'underscore';
import { LivechatDepartment, LivechatTrigger } from '../models';
import LivechatVisitors from '../models/LivechatVisitors';
@@ -43,7 +43,7 @@ Meteor.methods({
departmentId: 1,
},
};
- const room = (departmentId) ? RocketChat.models.Rooms.findOpenByVisitorTokenAndDepartmentId(visitorToken, departmentId, options).fetch() : RocketChat.models.Rooms.findOpenByVisitorToken(visitorToken, options).fetch();
+ const room = (departmentId) ? Rooms.findOpenByVisitorTokenAndDepartmentId(visitorToken, departmentId, options).fetch() : Rooms.findOpenByVisitorToken(visitorToken, options).fetch();
if (room && room.length > 0) {
info.room = room[0];
}
@@ -83,7 +83,7 @@ Meteor.methods({
info.emailFieldRegistrationForm = initSettings.Livechat_email_field_registration_form;
info.registrationFormMessage = initSettings.Livechat_registration_form_message;
- info.agentData = room && room[0] && room[0].servedBy && RocketChat.models.Users.getAgentInfo(room[0].servedBy._id);
+ info.agentData = room && room[0] && room[0].servedBy && Users.getAgentInfo(room[0].servedBy._id);
LivechatTrigger.findEnabled().forEach((trigger) => {
info.triggers.push(_.pick(trigger, '_id', 'actions', 'conditions', 'runOnce'));
@@ -94,7 +94,7 @@ Meteor.methods({
});
info.allowSwitchingDepartments = initSettings.Livechat_allow_switching_departments;
- info.online = RocketChat.models.Users.findOnlineAgents().count() > 0;
+ info.online = Users.findOnlineAgents().count() > 0;
return info;
},
});
diff --git a/packages/rocketchat-livechat/server/methods/getNextAgent.js b/packages/rocketchat-livechat/server/methods/getNextAgent.js
index 5e6792c41ac4..c303f183bcb7 100644
--- a/packages/rocketchat-livechat/server/methods/getNextAgent.js
+++ b/packages/rocketchat-livechat/server/methods/getNextAgent.js
@@ -1,13 +1,13 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Rooms, Users } from 'meteor/rocketchat:models';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:getNextAgent'({ token, department }) {
check(token, String);
- const room = RocketChat.models.Rooms.findOpenByVisitorToken(token).fetch();
+ const room = Rooms.findOpenByVisitorToken(token).fetch();
if (room && room.length > 0) {
return;
@@ -25,6 +25,6 @@ Meteor.methods({
return;
}
- return RocketChat.models.Users.getAgentInfo(agent.agentId);
+ return Users.getAgentInfo(agent.agentId);
},
});
diff --git a/packages/rocketchat-livechat/server/methods/loadHistory.js b/packages/rocketchat-livechat/server/methods/loadHistory.js
index 1e2f63be96d3..fc5d124e978d 100644
--- a/packages/rocketchat-livechat/server/methods/loadHistory.js
+++ b/packages/rocketchat-livechat/server/methods/loadHistory.js
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { loadMessageHistory } from 'meteor/rocketchat:lib';
import LivechatVisitors from '../models/LivechatVisitors';
Meteor.methods({
@@ -10,6 +10,6 @@ Meteor.methods({
return;
}
- return RocketChat.loadMessageHistory({ userId: visitor._id, rid, end, limit, ls });
+ return loadMessageHistory({ userId: visitor._id, rid, end, limit, ls });
},
});
diff --git a/packages/rocketchat-livechat/server/methods/registerGuest.js b/packages/rocketchat-livechat/server/methods/registerGuest.js
index a743fbad85f3..75e78858d021 100644
--- a/packages/rocketchat-livechat/server/methods/registerGuest.js
+++ b/packages/rocketchat-livechat/server/methods/registerGuest.js
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Messages, Rooms } from 'meteor/rocketchat:models';
import LivechatVisitors from '../models/LivechatVisitors';
import { Livechat } from '../lib/Livechat';
@@ -13,7 +13,7 @@ Meteor.methods({
});
// update visited page history to not expire
- RocketChat.models.Messages.keepHistoryForToken(token);
+ Messages.keepHistoryForToken(token);
const visitor = LivechatVisitors.getVisitorByToken(token, {
fields: {
@@ -26,7 +26,7 @@ Meteor.methods({
});
// If it's updating an existing visitor, it must also update the roomInfo
- const cursor = RocketChat.models.Rooms.findOpenByVisitorToken(token);
+ const cursor = Rooms.findOpenByVisitorToken(token);
cursor.forEach((room) => {
Livechat.saveRoomInfo(room, visitor);
});
diff --git a/packages/rocketchat-livechat/server/methods/removeAgent.js b/packages/rocketchat-livechat/server/methods/removeAgent.js
index a1b28a619c66..0896a68328c2 100644
--- a/packages/rocketchat-livechat/server/methods/removeAgent.js
+++ b/packages/rocketchat-livechat/server/methods/removeAgent.js
@@ -1,10 +1,10 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:removeAgent'(username) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeAgent' });
}
diff --git a/packages/rocketchat-livechat/server/methods/removeCustomField.js b/packages/rocketchat-livechat/server/methods/removeCustomField.js
index 35251d971b80..536962bf73c5 100644
--- a/packages/rocketchat-livechat/server/methods/removeCustomField.js
+++ b/packages/rocketchat-livechat/server/methods/removeCustomField.js
@@ -1,11 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { LivechatCustomField } from '../models';
Meteor.methods({
'livechat:removeCustomField'(_id) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeCustomField' });
}
diff --git a/packages/rocketchat-livechat/server/methods/removeDepartment.js b/packages/rocketchat-livechat/server/methods/removeDepartment.js
index 40ad21fa2939..95f70fc7fa86 100644
--- a/packages/rocketchat-livechat/server/methods/removeDepartment.js
+++ b/packages/rocketchat-livechat/server/methods/removeDepartment.js
@@ -1,10 +1,10 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:removeDepartment'(_id) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeDepartment' });
}
diff --git a/packages/rocketchat-livechat/server/methods/removeManager.js b/packages/rocketchat-livechat/server/methods/removeManager.js
index 549f50b85554..9ec5a9caa456 100644
--- a/packages/rocketchat-livechat/server/methods/removeManager.js
+++ b/packages/rocketchat-livechat/server/methods/removeManager.js
@@ -1,10 +1,10 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:removeManager'(username) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeManager' });
}
diff --git a/packages/rocketchat-livechat/server/methods/removeRoom.js b/packages/rocketchat-livechat/server/methods/removeRoom.js
index e18f2092e550..529eb5bf0610 100644
--- a/packages/rocketchat-livechat/server/methods/removeRoom.js
+++ b/packages/rocketchat-livechat/server/methods/removeRoom.js
@@ -1,13 +1,14 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { Rooms, Messages, Subscriptions } from 'meteor/rocketchat:models';
Meteor.methods({
'livechat:removeRoom'(rid) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'remove-closed-livechat-rooms')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'remove-closed-livechat-rooms')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeRoom' });
}
- const room = RocketChat.models.Rooms.findOneById(rid);
+ const room = Rooms.findOneById(rid);
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', {
@@ -27,8 +28,8 @@ Meteor.methods({
});
}
- RocketChat.models.Messages.removeByRoomId(rid);
- RocketChat.models.Subscriptions.removeByRoomId(rid);
- return RocketChat.models.Rooms.removeById(rid);
+ Messages.removeByRoomId(rid);
+ Subscriptions.removeByRoomId(rid);
+ return Rooms.removeById(rid);
},
});
diff --git a/packages/rocketchat-livechat/server/methods/removeTrigger.js b/packages/rocketchat-livechat/server/methods/removeTrigger.js
index 4001e866734a..9af9bf73342d 100644
--- a/packages/rocketchat-livechat/server/methods/removeTrigger.js
+++ b/packages/rocketchat-livechat/server/methods/removeTrigger.js
@@ -1,11 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { LivechatTrigger } from '../models';
Meteor.methods({
'livechat:removeTrigger'(triggerId) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeTrigger' });
}
diff --git a/packages/rocketchat-livechat/server/methods/returnAsInquiry.js b/packages/rocketchat-livechat/server/methods/returnAsInquiry.js
index 59c127fea288..9c08c381408b 100644
--- a/packages/rocketchat-livechat/server/methods/returnAsInquiry.js
+++ b/packages/rocketchat-livechat/server/methods/returnAsInquiry.js
@@ -1,10 +1,10 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:returnAsInquiry'(rid, departmentId) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-l-room')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-l-room')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveDepartment' });
}
diff --git a/packages/rocketchat-livechat/server/methods/saveAppearance.js b/packages/rocketchat-livechat/server/methods/saveAppearance.js
index 368863bf2bf8..c1110701ef8a 100644
--- a/packages/rocketchat-livechat/server/methods/saveAppearance.js
+++ b/packages/rocketchat-livechat/server/methods/saveAppearance.js
@@ -1,9 +1,9 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
Meteor.methods({
'livechat:saveAppearance'(settings) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveAppearance' });
}
@@ -32,7 +32,7 @@ Meteor.methods({
}
settings.forEach((setting) => {
- RocketChat.settings.updateById(setting._id, setting.value);
+ settings.updateById(setting._id, setting.value);
});
return;
diff --git a/packages/rocketchat-livechat/server/methods/saveCustomField.js b/packages/rocketchat-livechat/server/methods/saveCustomField.js
index 59802826703d..167d86c297f8 100644
--- a/packages/rocketchat-livechat/server/methods/saveCustomField.js
+++ b/packages/rocketchat-livechat/server/methods/saveCustomField.js
@@ -1,11 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { LivechatCustomField } from '../models';
Meteor.methods({
'livechat:saveCustomField'(_id, customFieldData) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveCustomField' });
}
diff --git a/packages/rocketchat-livechat/server/methods/saveDepartment.js b/packages/rocketchat-livechat/server/methods/saveDepartment.js
index ce400a0e456b..59a1ea310a79 100644
--- a/packages/rocketchat-livechat/server/methods/saveDepartment.js
+++ b/packages/rocketchat-livechat/server/methods/saveDepartment.js
@@ -1,10 +1,10 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:saveDepartment'(_id, departmentData, departmentAgents) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveDepartment' });
}
diff --git a/packages/rocketchat-livechat/server/methods/saveInfo.js b/packages/rocketchat-livechat/server/methods/saveInfo.js
index 6bfb27794414..4d198aac713a 100644
--- a/packages/rocketchat-livechat/server/methods/saveInfo.js
+++ b/packages/rocketchat-livechat/server/methods/saveInfo.js
@@ -1,11 +1,13 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { Rooms } from 'meteor/rocketchat:models';
+import { callbacks } from 'meteor/rocketchat:callbacks';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:saveInfo'(guestData, roomData) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-l-room')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-l-room')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveInfo' });
}
@@ -22,20 +24,20 @@ Meteor.methods({
tags: Match.Optional(String),
}));
- const room = RocketChat.models.Rooms.findOneById(roomData._id, { fields: { t: 1, servedBy: 1 } });
+ const room = Rooms.findOneById(roomData._id, { fields: { t: 1, servedBy: 1 } });
if (room == null || room.t !== 'l') {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'livechat:saveInfo' });
}
- if ((!room.servedBy || room.servedBy._id !== Meteor.userId()) && !RocketChat.authz.hasPermission(Meteor.userId(), 'save-others-livechat-room-info')) {
+ if ((!room.servedBy || room.servedBy._id !== Meteor.userId()) && !hasPermission(Meteor.userId(), 'save-others-livechat-room-info')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveInfo' });
}
const ret = Livechat.saveGuest(guestData) && Livechat.saveRoomInfo(roomData, guestData);
Meteor.defer(() => {
- RocketChat.callbacks.run('livechat.saveInfo', RocketChat.models.Rooms.findOneById(roomData._id));
+ callbacks.run('livechat.saveInfo', Rooms.findOneById(roomData._id));
});
return ret;
diff --git a/packages/rocketchat-livechat/server/methods/saveIntegration.js b/packages/rocketchat-livechat/server/methods/saveIntegration.js
index ff601d48c33e..6306a9133392 100644
--- a/packages/rocketchat-livechat/server/methods/saveIntegration.js
+++ b/packages/rocketchat-livechat/server/methods/saveIntegration.js
@@ -1,35 +1,36 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { settings } from 'meteor/rocketchat:settings';
import s from 'underscore.string';
Meteor.methods({
'livechat:saveIntegration'(values) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveIntegration' });
}
if (typeof values.Livechat_webhookUrl !== 'undefined') {
- RocketChat.settings.updateById('Livechat_webhookUrl', s.trim(values.Livechat_webhookUrl));
+ settings.updateById('Livechat_webhookUrl', s.trim(values.Livechat_webhookUrl));
}
if (typeof values.Livechat_secret_token !== 'undefined') {
- RocketChat.settings.updateById('Livechat_secret_token', s.trim(values.Livechat_secret_token));
+ settings.updateById('Livechat_secret_token', s.trim(values.Livechat_secret_token));
}
if (typeof values.Livechat_webhook_on_close !== 'undefined') {
- RocketChat.settings.updateById('Livechat_webhook_on_close', !!values.Livechat_webhook_on_close);
+ settings.updateById('Livechat_webhook_on_close', !!values.Livechat_webhook_on_close);
}
if (typeof values.Livechat_webhook_on_offline_msg !== 'undefined') {
- RocketChat.settings.updateById('Livechat_webhook_on_offline_msg', !!values.Livechat_webhook_on_offline_msg);
+ settings.updateById('Livechat_webhook_on_offline_msg', !!values.Livechat_webhook_on_offline_msg);
}
if (typeof values.Livechat_webhook_on_visitor_message !== 'undefined') {
- RocketChat.settings.updateById('Livechat_webhook_on_visitor_message', !!values.Livechat_webhook_on_visitor_message);
+ settings.updateById('Livechat_webhook_on_visitor_message', !!values.Livechat_webhook_on_visitor_message);
}
if (typeof values.Livechat_webhook_on_agent_message !== 'undefined') {
- RocketChat.settings.updateById('Livechat_webhook_on_agent_message', !!values.Livechat_webhook_on_agent_message);
+ settings.updateById('Livechat_webhook_on_agent_message', !!values.Livechat_webhook_on_agent_message);
}
return;
diff --git a/packages/rocketchat-livechat/server/methods/saveSurveyFeedback.js b/packages/rocketchat-livechat/server/methods/saveSurveyFeedback.js
index 4636a42a7a4b..224cfa736e02 100644
--- a/packages/rocketchat-livechat/server/methods/saveSurveyFeedback.js
+++ b/packages/rocketchat-livechat/server/methods/saveSurveyFeedback.js
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Rooms } from 'meteor/rocketchat:models';
import LivechatVisitors from '../models/LivechatVisitors';
import _ from 'underscore';
@@ -11,7 +11,7 @@ Meteor.methods({
check(formData, [Match.ObjectIncluding({ name: String, value: String })]);
const visitor = LivechatVisitors.getVisitorByToken(visitorToken);
- const room = RocketChat.models.Rooms.findOneById(visitorRoom);
+ const room = Rooms.findOneById(visitorRoom);
if (visitor !== undefined && room !== undefined && room.v !== undefined && room.v.token === visitor.token) {
const updateData = {};
@@ -23,7 +23,7 @@ Meteor.methods({
}
}
if (!_.isEmpty(updateData)) {
- return RocketChat.models.Rooms.updateSurveyFeedbackById(room._id, updateData);
+ return Rooms.updateSurveyFeedbackById(room._id, updateData);
}
}
},
diff --git a/packages/rocketchat-livechat/server/methods/saveTrigger.js b/packages/rocketchat-livechat/server/methods/saveTrigger.js
index 2bf033d637bd..3d2801e1ccd8 100644
--- a/packages/rocketchat-livechat/server/methods/saveTrigger.js
+++ b/packages/rocketchat-livechat/server/methods/saveTrigger.js
@@ -1,11 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { LivechatTrigger } from '../models';
Meteor.methods({
'livechat:saveTrigger'(trigger) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveTrigger' });
}
diff --git a/packages/rocketchat-livechat/server/methods/searchAgent.js b/packages/rocketchat-livechat/server/methods/searchAgent.js
index 2c7db1618d34..bc7d99e81de8 100644
--- a/packages/rocketchat-livechat/server/methods/searchAgent.js
+++ b/packages/rocketchat-livechat/server/methods/searchAgent.js
@@ -1,10 +1,11 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { Users } from 'meteor/rocketchat:models';
import _ from 'underscore';
Meteor.methods({
'livechat:searchAgent'(username) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-livechat-manager')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:searchAgent' });
}
@@ -12,7 +13,7 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-arguments', 'Invalid arguments', { method: 'livechat:searchAgent' });
}
- const user = RocketChat.models.Users.findOneByUsername(username, { fields: { _id: 1, username: 1 } });
+ const user = Users.findOneByUsername(username, { fields: { _id: 1, username: 1 } });
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'livechat:searchAgent' });
diff --git a/packages/rocketchat-livechat/server/methods/sendFileLivechatMessage.js b/packages/rocketchat-livechat/server/methods/sendFileLivechatMessage.js
index 187b4e5c0da3..f81677e87887 100644
--- a/packages/rocketchat-livechat/server/methods/sendFileLivechatMessage.js
+++ b/packages/rocketchat-livechat/server/methods/sendFileLivechatMessage.js
@@ -1,7 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { Random } from 'meteor/random';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Rooms } from 'meteor/rocketchat:models';
import { FileUpload } from 'meteor/rocketchat:file-upload';
import LivechatVisitors from '../models/LivechatVisitors';
@@ -13,7 +13,7 @@ Meteor.methods({
return false;
}
- const room = RocketChat.models.Rooms.findOneOpenByRoomIdAndVisitorToken(roomId, visitorToken);
+ const room = Rooms.findOneOpenByRoomIdAndVisitorToken(roomId, visitorToken);
if (!room) {
return false;
diff --git a/packages/rocketchat-livechat/server/methods/setCustomField.js b/packages/rocketchat-livechat/server/methods/setCustomField.js
index 98bc2443fb81..59abe289fd6c 100644
--- a/packages/rocketchat-livechat/server/methods/setCustomField.js
+++ b/packages/rocketchat-livechat/server/methods/setCustomField.js
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Rooms } from 'meteor/rocketchat:models';
import LivechatVisitors from '../models/LivechatVisitors';
import { LivechatCustomField } from '../models';
@@ -8,7 +8,7 @@ Meteor.methods({
const customField = LivechatCustomField.findOneById(key);
if (customField) {
if (customField.scope === 'room') {
- return RocketChat.models.Rooms.updateLivechatDataByToken(token, key, value, overwrite);
+ return Rooms.updateLivechatDataByToken(token, key, value, overwrite);
} else {
// Save in user
return LivechatVisitors.updateLivechatDataByToken(token, key, value, overwrite);
diff --git a/packages/rocketchat-livechat/server/methods/setDepartmentForVisitor.js b/packages/rocketchat-livechat/server/methods/setDepartmentForVisitor.js
index 551a2f29bc56..cd9b9e8a965b 100644
--- a/packages/rocketchat-livechat/server/methods/setDepartmentForVisitor.js
+++ b/packages/rocketchat-livechat/server/methods/setDepartmentForVisitor.js
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Rooms, Messages } from 'meteor/rocketchat:models';
import LivechatVisitors from '../models/LivechatVisitors';
import { Livechat } from '../lib/Livechat';
@@ -10,7 +10,7 @@ Meteor.methods({
check(visitorToken, String);
check(departmentId, String);
- const room = RocketChat.models.Rooms.findOneById(roomId);
+ const room = Rooms.findOneById(roomId);
const visitor = LivechatVisitors.getVisitorByToken(visitorToken);
if (!room || room.t !== 'l' || !room.v || room.v.token !== visitor.token) {
@@ -18,7 +18,7 @@ Meteor.methods({
}
// update visited page history to not expire
- RocketChat.models.Messages.keepHistoryForToken(visitorToken);
+ Messages.keepHistoryForToken(visitorToken);
const transferData = {
roomId,
diff --git a/packages/rocketchat-livechat/server/methods/startVideoCall.js b/packages/rocketchat-livechat/server/methods/startVideoCall.js
index b9a384f3f83f..874646e9890e 100644
--- a/packages/rocketchat-livechat/server/methods/startVideoCall.js
+++ b/packages/rocketchat-livechat/server/methods/startVideoCall.js
@@ -1,6 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Messages } from 'meteor/rocketchat:models';
+import { settings } from 'meteor/rocketchat:settings';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
@@ -21,7 +22,7 @@ Meteor.methods({
const { room } = Livechat.getRoom(guest, message, { jitsiTimeout: new Date(Date.now() + 3600 * 1000) });
message.rid = room._id;
- RocketChat.models.Messages.createWithTypeRoomIdMessageAndUser('livechat_video_call', room._id, '', guest, {
+ Messages.createWithTypeRoomIdMessageAndUser('livechat_video_call', room._id, '', guest, {
actionLinks: [
{ icon: 'icon-videocam', i18nLabel: 'Accept', method_id: 'createLivechatCall', params: '' },
{ icon: 'icon-cancel', i18nLabel: 'Decline', method_id: 'denyLivechatCall', params: '' },
@@ -30,8 +31,8 @@ Meteor.methods({
return {
roomId: room._id,
- domain: RocketChat.settings.get('Jitsi_Domain'),
- jitsiRoom: RocketChat.settings.get('Jitsi_URL_Room_Prefix') + RocketChat.settings.get('uniqueID') + roomId,
+ domain: settings.get('Jitsi_Domain'),
+ jitsiRoom: settings.get('Jitsi_URL_Room_Prefix') + settings.get('uniqueID') + roomId,
};
},
});
diff --git a/packages/rocketchat-livechat/server/methods/takeInquiry.js b/packages/rocketchat-livechat/server/methods/takeInquiry.js
index 49cbf2f888fe..8184795c8c1e 100644
--- a/packages/rocketchat-livechat/server/methods/takeInquiry.js
+++ b/packages/rocketchat-livechat/server/methods/takeInquiry.js
@@ -1,11 +1,12 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { Users, Rooms, Subscriptions, Messages } from 'meteor/rocketchat:models';
import { LivechatInquiry } from '../../lib/LivechatInquiry';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:takeInquiry'(inquiryId) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-l-room')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-l-room')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:takeInquiry' });
}
@@ -15,7 +16,7 @@ Meteor.methods({
throw new Meteor.Error('error-not-allowed', 'Inquiry already taken', { method: 'livechat:takeInquiry' });
}
- const user = RocketChat.models.Users.findOneById(Meteor.userId());
+ const user = Users.findOneById(Meteor.userId());
const agent = {
agentId: user._id,
@@ -42,13 +43,13 @@ Meteor.methods({
emailNotifications: 'all',
};
- RocketChat.models.Subscriptions.insert(subscriptionData);
- RocketChat.models.Rooms.incUsersCountById(inquiry.rid);
+ Subscriptions.insert(subscriptionData);
+ Rooms.incUsersCountById(inquiry.rid);
// update room
- const room = RocketChat.models.Rooms.findOneById(inquiry.rid);
+ const room = Rooms.findOneById(inquiry.rid);
- RocketChat.models.Rooms.changeAgentByRoomId(inquiry.rid, agent);
+ Rooms.changeAgentByRoomId(inquiry.rid, agent);
room.servedBy = {
_id: agent.agentId,
@@ -62,11 +63,11 @@ Meteor.methods({
// remove sending message from guest widget
// dont check if setting is true, because if settingwas switched off inbetween guest entered pool,
// and inquiry being taken, message would not be switched off.
- RocketChat.models.Messages.createCommandWithRoomIdAndUser('connected', room._id, user);
+ Messages.createCommandWithRoomIdAndUser('connected', room._id, user);
Livechat.stream.emit(room._id, {
type: 'agentData',
- data: RocketChat.models.Users.getAgentInfo(agent.agentId),
+ data: Users.getAgentInfo(agent.agentId),
});
// return inquiry (for redirecting agent to the room route)
diff --git a/packages/rocketchat-livechat/server/methods/transfer.js b/packages/rocketchat-livechat/server/methods/transfer.js
index bd101c136800..faec98ab1964 100644
--- a/packages/rocketchat-livechat/server/methods/transfer.js
+++ b/packages/rocketchat-livechat/server/methods/transfer.js
@@ -1,12 +1,13 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission, hasRole } from 'meteor/rocketchat:authorization';
+import { Rooms, Subscriptions } from 'meteor/rocketchat:models';
import LivechatVisitors from '../models/LivechatVisitors';
import { Livechat } from '../lib/Livechat';
Meteor.methods({
'livechat:transfer'(transferData) {
- if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-l-room')) {
+ if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-l-room')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:transfer' });
}
@@ -16,13 +17,13 @@ Meteor.methods({
departmentId: Match.Optional(String),
});
- const room = RocketChat.models.Rooms.findOneById(transferData.roomId);
+ const room = Rooms.findOneById(transferData.roomId);
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'livechat:transfer' });
}
- const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(room._id, Meteor.userId(), { fields: { _id: 1 } });
- if (!subscription && !RocketChat.authz.hasRole(Meteor.userId(), 'livechat-manager')) {
+ const subscription = Subscriptions.findOneByRoomIdAndUserId(room._id, Meteor.userId(), { fields: { _id: 1 } });
+ if (!subscription && !hasRole(Meteor.userId(), 'livechat-manager')) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'livechat:transfer' });
}
diff --git a/packages/rocketchat-livechat/server/methods/webhookTest.js b/packages/rocketchat-livechat/server/methods/webhookTest.js
index eb8221d51fd3..9da8eb07d730 100644
--- a/packages/rocketchat-livechat/server/methods/webhookTest.js
+++ b/packages/rocketchat-livechat/server/methods/webhookTest.js
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings } from 'meteor/rocketchat:settings';
import { HTTP } from 'meteor/http';
const postCatchError = Meteor.wrapAsync(function(url, options, resolve) {
@@ -65,12 +65,12 @@ Meteor.methods({
const options = {
headers: {
- 'X-RocketChat-Livechat-Token': RocketChat.settings.get('Livechat_secret_token'),
+ 'X-RocketChat-Livechat-Token': settings.get('Livechat_secret_token'),
},
data: sampleData,
};
- const response = postCatchError(RocketChat.settings.get('Livechat_webhookUrl'), options);
+ const response = postCatchError(settings.get('Livechat_webhookUrl'), options);
console.log('response ->', response);
diff --git a/packages/rocketchat-livechat/server/models/LivechatCustomField.js b/packages/rocketchat-livechat/server/models/LivechatCustomField.js
index 27a70f6199ba..ab4a8b58192b 100644
--- a/packages/rocketchat-livechat/server/models/LivechatCustomField.js
+++ b/packages/rocketchat-livechat/server/models/LivechatCustomField.js
@@ -44,4 +44,3 @@ class LivechatCustomFieldClass extends Base {
}
export const LivechatCustomField = new LivechatCustomFieldClass();
-RocketChat.models.LivechatCustomField = LivechatCustomField;
diff --git a/packages/rocketchat-livechat/server/models/LivechatOfficeHour.js b/packages/rocketchat-livechat/server/models/LivechatOfficeHour.js
index 7f7b31224bc3..05a113513017 100644
--- a/packages/rocketchat-livechat/server/models/LivechatOfficeHour.js
+++ b/packages/rocketchat-livechat/server/models/LivechatOfficeHour.js
@@ -108,4 +108,3 @@ class LivechatOfficeHourClass extends Base {
}
}
export const LivechatOfficeHour = new LivechatOfficeHourClass();
-RocketChat.models.LivechatOfficeHour = LivechatOfficeHour;
diff --git a/packages/rocketchat-livechat/server/models/LivechatTrigger.js b/packages/rocketchat-livechat/server/models/LivechatTrigger.js
index 77abc29280ea..e52734f362a2 100644
--- a/packages/rocketchat-livechat/server/models/LivechatTrigger.js
+++ b/packages/rocketchat-livechat/server/models/LivechatTrigger.js
@@ -29,4 +29,3 @@ class LivechatTriggerClass extends Base {
}
}
export const LivechatTrigger = new LivechatTriggerClass();
-RocketChat.models.LivechatTrigger = LivechatTrigger;
diff --git a/packages/rocketchat-livechat/server/permissions.js b/packages/rocketchat-livechat/server/permissions.js
index 5f84b4e97f53..05239e634338 100644
--- a/packages/rocketchat-livechat/server/permissions.js
+++ b/packages/rocketchat-livechat/server/permissions.js
@@ -1,26 +1,26 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Roles, Permissions } from 'meteor/rocketchat:models';
import _ from 'underscore';
Meteor.startup(() => {
- const roles = _.pluck(RocketChat.models.Roles.find().fetch(), 'name');
+ const roles = _.pluck(Roles.find().fetch(), 'name');
if (roles.indexOf('livechat-agent') === -1) {
- RocketChat.models.Roles.createOrUpdate('livechat-agent');
+ Roles.createOrUpdate('livechat-agent');
}
if (roles.indexOf('livechat-manager') === -1) {
- RocketChat.models.Roles.createOrUpdate('livechat-manager');
+ Roles.createOrUpdate('livechat-manager');
}
if (roles.indexOf('livechat-guest') === -1) {
- RocketChat.models.Roles.createOrUpdate('livechat-guest');
+ Roles.createOrUpdate('livechat-guest');
}
- if (RocketChat.models && RocketChat.models.Permissions) {
- RocketChat.models.Permissions.createOrUpdate('view-l-room', ['livechat-agent', 'livechat-manager', 'admin']);
- RocketChat.models.Permissions.createOrUpdate('view-livechat-manager', ['livechat-manager', 'admin']);
- RocketChat.models.Permissions.createOrUpdate('view-livechat-rooms', ['livechat-manager', 'admin']);
- RocketChat.models.Permissions.createOrUpdate('close-livechat-room', ['livechat-agent', 'livechat-manager', 'admin']);
- RocketChat.models.Permissions.createOrUpdate('close-others-livechat-room', ['livechat-manager', 'admin']);
- RocketChat.models.Permissions.createOrUpdate('save-others-livechat-room-info', ['livechat-manager']);
- RocketChat.models.Permissions.createOrUpdate('remove-closed-livechat-rooms', ['livechat-manager', 'admin']);
- RocketChat.models.Permissions.createOrUpdate('view-livechat-analytics', ['livechat-manager', 'admin']);
+ if (Permissions) {
+ Permissions.createOrUpdate('view-l-room', ['livechat-agent', 'livechat-manager', 'admin']);
+ Permissions.createOrUpdate('view-livechat-manager', ['livechat-manager', 'admin']);
+ Permissions.createOrUpdate('view-livechat-rooms', ['livechat-manager', 'admin']);
+ Permissions.createOrUpdate('close-livechat-room', ['livechat-agent', 'livechat-manager', 'admin']);
+ Permissions.createOrUpdate('close-others-livechat-room', ['livechat-manager', 'admin']);
+ Permissions.createOrUpdate('save-others-livechat-room-info', ['livechat-manager']);
+ Permissions.createOrUpdate('remove-closed-livechat-rooms', ['livechat-manager', 'admin']);
+ Permissions.createOrUpdate('view-livechat-analytics', ['livechat-manager', 'admin']);
}
});
diff --git a/packages/rocketchat-livechat/server/publications/customFields.js b/packages/rocketchat-livechat/server/publications/customFields.js
index 3d778d703898..616517caddb0 100644
--- a/packages/rocketchat-livechat/server/publications/customFields.js
+++ b/packages/rocketchat-livechat/server/publications/customFields.js
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { LivechatCustomField } from '../models';
import s from 'underscore.string';
@@ -8,7 +8,7 @@ Meteor.publish('livechat:customFields', function(_id) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:customFields' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) {
+ if (!hasPermission(this.userId, 'view-l-room')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:customFields' }));
}
diff --git a/packages/rocketchat-livechat/server/publications/departmentAgents.js b/packages/rocketchat-livechat/server/publications/departmentAgents.js
index 69af2003bef6..e99e015ec09c 100644
--- a/packages/rocketchat-livechat/server/publications/departmentAgents.js
+++ b/packages/rocketchat-livechat/server/publications/departmentAgents.js
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { LivechatDepartmentAgents } from '../models';
Meteor.publish('livechat:departmentAgents', function(departmentId) {
@@ -7,7 +7,7 @@ Meteor.publish('livechat:departmentAgents', function(departmentId) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:departmentAgents' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-rooms')) {
+ if (!hasPermission(this.userId, 'view-livechat-rooms')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:departmentAgents' }));
}
diff --git a/packages/rocketchat-livechat/server/publications/livechatAgents.js b/packages/rocketchat-livechat/server/publications/livechatAgents.js
index c5d333039c1f..31d026b283e6 100644
--- a/packages/rocketchat-livechat/server/publications/livechatAgents.js
+++ b/packages/rocketchat-livechat/server/publications/livechatAgents.js
@@ -1,18 +1,18 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission, getUsersInRole } from 'meteor/rocketchat:authorization';
Meteor.publish('livechat:agents', function() {
if (!this.userId) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:agents' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) {
+ if (!hasPermission(this.userId, 'view-l-room')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:agents' }));
}
const self = this;
- const handle = RocketChat.authz.getUsersInRole('livechat-agent').observeChanges({
+ const handle = getUsersInRole('livechat-agent').observeChanges({
added(id, fields) {
self.added('agentUsers', id, fields);
},
diff --git a/packages/rocketchat-livechat/server/publications/livechatAppearance.js b/packages/rocketchat-livechat/server/publications/livechatAppearance.js
index ae46dc9797c1..2e08b44fb0bb 100644
--- a/packages/rocketchat-livechat/server/publications/livechatAppearance.js
+++ b/packages/rocketchat-livechat/server/publications/livechatAppearance.js
@@ -1,12 +1,13 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { Settings } from 'meteor/rocketchat:models';
Meteor.publish('livechat:appearance', function() {
if (!this.userId) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:appearance' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:appearance' }));
}
@@ -34,7 +35,7 @@ Meteor.publish('livechat:appearance', function() {
const self = this;
- const handle = RocketChat.models.Settings.find(query).observeChanges({
+ const handle = Settings.find(query).observeChanges({
added(id, fields) {
self.added('livechatAppearance', id, fields);
},
diff --git a/packages/rocketchat-livechat/server/publications/livechatDepartments.js b/packages/rocketchat-livechat/server/publications/livechatDepartments.js
index dc45a31e0201..1e987bbf0f13 100644
--- a/packages/rocketchat-livechat/server/publications/livechatDepartments.js
+++ b/packages/rocketchat-livechat/server/publications/livechatDepartments.js
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { LivechatDepartment } from '../models';
Meteor.publish('livechat:departments', function(_id) {
@@ -7,7 +7,7 @@ Meteor.publish('livechat:departments', function(_id) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:agents' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) {
+ if (!hasPermission(this.userId, 'view-l-room')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:agents' }));
}
diff --git a/packages/rocketchat-livechat/server/publications/livechatInquiries.js b/packages/rocketchat-livechat/server/publications/livechatInquiries.js
index 3eb7893c13da..f1e4aaa61517 100644
--- a/packages/rocketchat-livechat/server/publications/livechatInquiries.js
+++ b/packages/rocketchat-livechat/server/publications/livechatInquiries.js
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { LivechatInquiry } from '../../lib/LivechatInquiry';
Meteor.publish('livechat:inquiry', function() {
@@ -7,7 +7,7 @@ Meteor.publish('livechat:inquiry', function() {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:inquiry' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) {
+ if (!hasPermission(this.userId, 'view-l-room')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:inquiry' }));
}
diff --git a/packages/rocketchat-livechat/server/publications/livechatIntegration.js b/packages/rocketchat-livechat/server/publications/livechatIntegration.js
index 4eaeb694e24e..521573b4b4dd 100644
--- a/packages/rocketchat-livechat/server/publications/livechatIntegration.js
+++ b/packages/rocketchat-livechat/server/publications/livechatIntegration.js
@@ -1,18 +1,19 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { Settings } from 'meteor/rocketchat:models';
Meteor.publish('livechat:integration', function() {
if (!this.userId) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:integration' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:integration' }));
}
const self = this;
- const handle = RocketChat.models.Settings.findByIds(['Livechat_webhookUrl', 'Livechat_secret_token', 'Livechat_webhook_on_close', 'Livechat_webhook_on_offline_msg', 'Livechat_webhook_on_visitor_message', 'Livechat_webhook_on_agent_message']).observeChanges({
+ const handle = Settings.findByIds(['Livechat_webhookUrl', 'Livechat_secret_token', 'Livechat_webhook_on_close', 'Livechat_webhook_on_offline_msg', 'Livechat_webhook_on_visitor_message', 'Livechat_webhook_on_agent_message']).observeChanges({
added(id, fields) {
self.added('livechatIntegration', id, fields);
},
diff --git a/packages/rocketchat-livechat/server/publications/livechatManagers.js b/packages/rocketchat-livechat/server/publications/livechatManagers.js
index 6f9aa3dec657..21b9070dad58 100644
--- a/packages/rocketchat-livechat/server/publications/livechatManagers.js
+++ b/packages/rocketchat-livechat/server/publications/livechatManagers.js
@@ -1,18 +1,18 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission, getUsersInRole } from 'meteor/rocketchat:authorization';
Meteor.publish('livechat:managers', function() {
if (!this.userId) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:managers' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-rooms')) {
+ if (!hasPermission(this.userId, 'view-livechat-rooms')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:managers' }));
}
const self = this;
- const handle = RocketChat.authz.getUsersInRole('livechat-manager').observeChanges({
+ const handle = getUsersInRole('livechat-manager').observeChanges({
added(id, fields) {
self.added('managerUsers', id, fields);
},
diff --git a/packages/rocketchat-livechat/server/publications/livechatMonitoring.js b/packages/rocketchat-livechat/server/publications/livechatMonitoring.js
index 99707fc23324..a120eb01aaeb 100644
--- a/packages/rocketchat-livechat/server/publications/livechatMonitoring.js
+++ b/packages/rocketchat-livechat/server/publications/livechatMonitoring.js
@@ -1,13 +1,14 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { Rooms } from 'meteor/rocketchat:models';
Meteor.publish('livechat:monitoring', function(date) {
if (!this.userId) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:monitoring' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:monitoring' }));
}
@@ -21,7 +22,7 @@ Meteor.publish('livechat:monitoring', function(date) {
const self = this;
- const handle = RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).observeChanges({
+ const handle = Rooms.getAnalyticsMetricsBetweenDate('l', date).observeChanges({
added(id, fields) {
self.added('livechatMonitoring', id, fields);
},
diff --git a/packages/rocketchat-livechat/server/publications/livechatOfficeHours.js b/packages/rocketchat-livechat/server/publications/livechatOfficeHours.js
index 754217ef3e38..da8d795f6fef 100644
--- a/packages/rocketchat-livechat/server/publications/livechatOfficeHours.js
+++ b/packages/rocketchat-livechat/server/publications/livechatOfficeHours.js
@@ -1,9 +1,9 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { LivechatOfficeHour } from '../models';
Meteor.publish('livechat:officeHour', function() {
- if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) {
+ if (!hasPermission(this.userId, 'view-l-room')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:agents' }));
}
diff --git a/packages/rocketchat-livechat/server/publications/livechatQueue.js b/packages/rocketchat-livechat/server/publications/livechatQueue.js
index 94df8ba2c8fb..8230848f4600 100644
--- a/packages/rocketchat-livechat/server/publications/livechatQueue.js
+++ b/packages/rocketchat-livechat/server/publications/livechatQueue.js
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { LivechatDepartmentAgents } from '../models';
Meteor.publish('livechat:queue', function() {
@@ -7,7 +7,7 @@ Meteor.publish('livechat:queue', function() {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:queue' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) {
+ if (!hasPermission(this.userId, 'view-l-room')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:queue' }));
}
diff --git a/packages/rocketchat-livechat/server/publications/livechatRooms.js b/packages/rocketchat-livechat/server/publications/livechatRooms.js
index 0a5cb4f5354a..c0586e4dc80f 100644
--- a/packages/rocketchat-livechat/server/publications/livechatRooms.js
+++ b/packages/rocketchat-livechat/server/publications/livechatRooms.js
@@ -1,13 +1,14 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { Rooms } from 'meteor/rocketchat:models';
Meteor.publish('livechat:rooms', function(filter = {}, offset = 0, limit = 20) {
if (!this.userId) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:rooms' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-rooms')) {
+ if (!hasPermission(this.userId, 'view-livechat-rooms')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:rooms' }));
}
@@ -50,7 +51,7 @@ Meteor.publish('livechat:rooms', function(filter = {}, offset = 0, limit = 20) {
const self = this;
- const handle = RocketChat.models.Rooms.findLivechat(query, offset, limit).observeChanges({
+ const handle = Rooms.findLivechat(query, offset, limit).observeChanges({
added(id, fields) {
self.added('livechatRoom', id, fields);
},
diff --git a/packages/rocketchat-livechat/server/publications/livechatTriggers.js b/packages/rocketchat-livechat/server/publications/livechatTriggers.js
index eaf10f591d75..9d20679d5f93 100644
--- a/packages/rocketchat-livechat/server/publications/livechatTriggers.js
+++ b/packages/rocketchat-livechat/server/publications/livechatTriggers.js
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import { LivechatTrigger } from '../models';
Meteor.publish('livechat:triggers', function(_id) {
@@ -7,7 +7,7 @@ Meteor.publish('livechat:triggers', function(_id) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:triggers' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:triggers' }));
}
diff --git a/packages/rocketchat-livechat/server/publications/livechatVisitors.js b/packages/rocketchat-livechat/server/publications/livechatVisitors.js
index b71b4888d55b..e7137ed45beb 100644
--- a/packages/rocketchat-livechat/server/publications/livechatVisitors.js
+++ b/packages/rocketchat-livechat/server/publications/livechatVisitors.js
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
import LivechatVisitors from '../models/LivechatVisitors';
Meteor.publish('livechat:visitors', function(date) {
@@ -8,7 +8,7 @@ Meteor.publish('livechat:visitors', function(date) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitors' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
+ if (!hasPermission(this.userId, 'view-livechat-manager')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitors' }));
}
diff --git a/packages/rocketchat-livechat/server/publications/visitorHistory.js b/packages/rocketchat-livechat/server/publications/visitorHistory.js
index 77b0405430ba..d826639bb18b 100644
--- a/packages/rocketchat-livechat/server/publications/visitorHistory.js
+++ b/packages/rocketchat-livechat/server/publications/visitorHistory.js
@@ -1,18 +1,19 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { Rooms, Subscriptions } from 'meteor/rocketchat:models';
Meteor.publish('livechat:visitorHistory', function({ rid: roomId }) {
if (!this.userId) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorHistory' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) {
+ if (!hasPermission(this.userId, 'view-l-room')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorHistory' }));
}
- const room = RocketChat.models.Rooms.findOneById(roomId);
+ const room = Rooms.findOneById(roomId);
- const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(room._id, this.userId, { fields: { _id: 1 } });
+ const subscription = Subscriptions.findOneByRoomIdAndUserId(room._id, this.userId, { fields: { _id: 1 } });
if (!subscription) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorHistory' }));
}
@@ -20,7 +21,7 @@ Meteor.publish('livechat:visitorHistory', function({ rid: roomId }) {
const self = this;
if (room && room.v && room.v._id) {
- const handle = RocketChat.models.Rooms.findByVisitorId(room.v._id).observeChanges({
+ const handle = Rooms.findByVisitorId(room.v._id).observeChanges({
added(id, fields) {
self.added('visitor_history', id, fields);
},
diff --git a/packages/rocketchat-livechat/server/publications/visitorInfo.js b/packages/rocketchat-livechat/server/publications/visitorInfo.js
index a5ba86542cef..fafa5120ade9 100644
--- a/packages/rocketchat-livechat/server/publications/visitorInfo.js
+++ b/packages/rocketchat-livechat/server/publications/visitorInfo.js
@@ -1,5 +1,6 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { Rooms } from 'meteor/rocketchat:models';
import LivechatVisitors from '../models/LivechatVisitors';
Meteor.publish('livechat:visitorInfo', function({ rid: roomId }) {
@@ -7,11 +8,11 @@ Meteor.publish('livechat:visitorInfo', function({ rid: roomId }) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorInfo' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) {
+ if (!hasPermission(this.userId, 'view-l-room')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorInfo' }));
}
- const room = RocketChat.models.Rooms.findOneById(roomId);
+ const room = Rooms.findOneById(roomId);
if (room && room.v && room.v._id) {
return LivechatVisitors.findById(room.v._id);
diff --git a/packages/rocketchat-livechat/server/publications/visitorPageVisited.js b/packages/rocketchat-livechat/server/publications/visitorPageVisited.js
index 039e36fcf82d..739949b266a9 100644
--- a/packages/rocketchat-livechat/server/publications/visitorPageVisited.js
+++ b/packages/rocketchat-livechat/server/publications/visitorPageVisited.js
@@ -1,5 +1,6 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { hasPermission } from 'meteor/rocketchat:authorization';
+import { Rooms, Messages } from 'meteor/rocketchat:models';
Meteor.publish('livechat:visitorPageVisited', function({ rid: roomId }) {
@@ -7,15 +8,15 @@ Meteor.publish('livechat:visitorPageVisited', function({ rid: roomId }) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorPageVisited' }));
}
- if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) {
+ if (!hasPermission(this.userId, 'view-l-room')) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorPageVisited' }));
}
const self = this;
- const room = RocketChat.models.Rooms.findOneById(roomId);
+ const room = Rooms.findOneById(roomId);
if (room) {
- const handle = RocketChat.models.Messages.findByRoomIdAndType(room._id, 'livechat_navigation_history').observeChanges({
+ const handle = Messages.findByRoomIdAndType(room._id, 'livechat_navigation_history').observeChanges({
added(id, fields) {
self.added('visitor_navigation_history', id, fields);
},
diff --git a/packages/rocketchat-livechat/server/roomType.js b/packages/rocketchat-livechat/server/roomType.js
index d9721271bea4..6fef98cc409d 100644
--- a/packages/rocketchat-livechat/server/roomType.js
+++ b/packages/rocketchat-livechat/server/roomType.js
@@ -1,4 +1,5 @@
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { Rooms } from 'meteor/rocketchat:models';
+import { roomTypes } from 'meteor/rocketchat:utils';
import LivechatRoomType from '../lib/LivechatRoomType';
import LivechatVisitors from './models/LivechatVisitors';
@@ -23,8 +24,8 @@ class LivechatRoomTypeServer extends LivechatRoomType {
}
canAccessUploadedFile({ rc_token, rc_rid } = {}) {
- return rc_token && rc_rid && RocketChat.models.Rooms.findOneOpenByRoomIdAndVisitorToken(rc_rid, rc_token);
+ return rc_token && rc_rid && Rooms.findOneOpenByRoomIdAndVisitorToken(rc_rid, rc_token);
}
}
-RocketChat.roomTypes.add(new LivechatRoomTypeServer());
+roomTypes.add(new LivechatRoomTypeServer());
diff --git a/packages/rocketchat-livechat/server/sendMessageBySMS.js b/packages/rocketchat-livechat/server/sendMessageBySMS.js
index a1957f85fe8f..36180f95b420 100644
--- a/packages/rocketchat-livechat/server/sendMessageBySMS.js
+++ b/packages/rocketchat-livechat/server/sendMessageBySMS.js
@@ -1,8 +1,9 @@
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { callbacks } from 'meteor/rocketchat:callbacks';
+import { settings } from 'meteor/rocketchat:settings';
import { SMS } from 'meteor/rocketchat:sms';
import LivechatVisitors from './models/LivechatVisitors';
-RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
+callbacks.add('afterSaveMessage', function(message, room) {
// skips this callback if the message was edited
if (message.editedAt) {
return message;
@@ -27,7 +28,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
return message;
}
- const SMSService = SMS.getService(RocketChat.settings.get('SMS_Service'));
+ const SMSService = SMS.getService(settings.get('SMS_Service'));
if (!SMSService) {
return message;
@@ -43,4 +44,4 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
return message;
-}, RocketChat.callbacks.priority.LOW, 'sendMessageBySms');
+}, callbacks.priority.LOW, 'sendMessageBySms');
diff --git a/packages/rocketchat-livechat/server/startup.js b/packages/rocketchat-livechat/server/startup.js
index ea7b0f02239b..b038ffc17548 100644
--- a/packages/rocketchat-livechat/server/startup.js
+++ b/packages/rocketchat-livechat/server/startup.js
@@ -1,27 +1,31 @@
import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/tap:i18n';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { roomTypes } from 'meteor/rocketchat:utils';
+import { Rooms } from 'meteor/rocketchat:models';
+import { hasPermission, addRoomAccessValidator } from 'meteor/rocketchat:authorization';
+import { callbacks } from 'meteor/rocketchat:callbacks';
+import { settings } from 'meteor/rocketchat:settings';
Meteor.startup(() => {
- RocketChat.roomTypes.setRoomFind('l', (_id) => RocketChat.models.Rooms.findLivechatById(_id).fetch());
+ roomTypes.setRoomFind('l', (_id) => Rooms.findLivechatById(_id).fetch());
- RocketChat.authz.addRoomAccessValidator(function(room, user) {
- return room && room.t === 'l' && user && RocketChat.authz.hasPermission(user._id, 'view-livechat-rooms');
+ addRoomAccessValidator(function(room, user) {
+ return room && room.t === 'l' && user && hasPermission(user._id, 'view-livechat-rooms');
});
- RocketChat.authz.addRoomAccessValidator(function(room, user, extraData) {
+ addRoomAccessValidator(function(room, user, extraData) {
if (!room && extraData && extraData.rid) {
- room = RocketChat.models.Rooms.findOneById(extraData.rid);
+ room = Rooms.findOneById(extraData.rid);
}
return room && room.t === 'l' && extraData && extraData.visitorToken && room.v && room.v.token === extraData.visitorToken;
});
- RocketChat.callbacks.add('beforeLeaveRoom', function(user, room) {
+ callbacks.add('beforeLeaveRoom', function(user, room) {
if (room.t !== 'l') {
return user;
}
throw new Meteor.Error(TAPi18n.__('You_cant_leave_a_livechat_room_Please_use_the_close_button', {
- lng: user.language || RocketChat.settings.get('Language') || 'en',
+ lng: user.language || settings.get('Language') || 'en',
}));
- }, RocketChat.callbacks.priority.LOW, 'cant-leave-room');
+ }, callbacks.priority.LOW, 'cant-leave-room');
});
diff --git a/packages/rocketchat-livechat/server/unclosedLivechats.js b/packages/rocketchat-livechat/server/unclosedLivechats.js
index 76d73427a61d..9a65a7c55b47 100644
--- a/packages/rocketchat-livechat/server/unclosedLivechats.js
+++ b/packages/rocketchat-livechat/server/unclosedLivechats.js
@@ -1,6 +1,8 @@
import { Meteor } from 'meteor/meteor';
-import { RocketChat } from 'meteor/rocketchat:lib';
+import { settings } from 'meteor/rocketchat:settings';
+import { Users } from 'meteor/rocketchat:models';
import { UserPresenceMonitor } from 'meteor/konecty:user-presence';
+import { Livechat } from './lib/Livechat';
let agentsHandler;
let monitorAgents = false;
@@ -36,23 +38,23 @@ const onlineAgents = {
};
function runAgentLeaveAction(userId) {
- const action = RocketChat.settings.get('Livechat_agent_leave_action');
+ const action = settings.get('Livechat_agent_leave_action');
if (action === 'close') {
- return RocketChat.Livechat.closeOpenChats(userId, RocketChat.settings.get('Livechat_agent_leave_comment'));
+ return Livechat.closeOpenChats(userId, settings.get('Livechat_agent_leave_comment'));
} else if (action === 'forward') {
- return RocketChat.Livechat.forwardOpenChats(userId);
+ return Livechat.forwardOpenChats(userId);
}
}
-RocketChat.settings.get('Livechat_agent_leave_action_timeout', function(key, value) {
+settings.get('Livechat_agent_leave_action_timeout', function(key, value) {
actionTimeout = value * 1000;
});
-RocketChat.settings.get('Livechat_agent_leave_action', function(key, value) {
+settings.get('Livechat_agent_leave_action', function(key, value) {
monitorAgents = value;
if (value !== 'none') {
if (!agentsHandler) {
- agentsHandler = RocketChat.models.Users.findOnlineAgents().observeChanges({
+ agentsHandler = Users.findOnlineAgents().observeChanges({
added(id) {
onlineAgents.add(id);
},