From 9caf0cddbfbff329da5b83cfb675892ab9ed0d36 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 8 Jun 2017 17:33:03 -0300 Subject: [PATCH 01/16] Do not use users collection for visitors --- packages/rocketchat-lib/package.js | 1 + .../server/functions/loadMessageHistory.js | 86 ++++++++++ .../server/lib/sendNotificationsOnMessage.js | 5 + .../app/client/lib/CustomFields.js | 4 +- .../app/client/lib/LivechatVideoCall.js | 1 + .../app/client/lib/_livechat.js | 6 +- .../app/client/lib/chatMessages.js | 15 +- .../app/client/lib/commands.js | 3 + .../app/client/lib/fromApp/Notifications.js | 12 +- .../client/lib/fromApp/RoomHistoryManager.js | 5 +- .../app/client/lib/hooks.js | 2 + .../app/client/lib/msgTyping.js | 4 +- .../app/client/lib/triggers.js | 4 +- .../app/client/methods/sendMessageExternal.js | 4 +- .../app/client/routes/router.js | 2 + .../app/client/startup/visitor.js | 13 +- .../app/client/views/avatar.js | 1 + .../app/client/views/livechatWindow.js | 3 +- .../app/client/views/message.js | 4 +- .../app/client/views/messages.js | 12 +- .../app/client/views/options.js | 1 + .../app/client/views/register.js | 9 +- .../app/client/views/survey.js | 2 + .../app/client/views/switchDepartment.js | 1 + .../_visitor.js => imports/client/visitor.js} | 33 ++-- .../imports/server/rest/sms.js | 8 +- packages/rocketchat-livechat/package.js | 1 + .../server/lib/Livechat.js | 85 +++++----- .../server/methods/getAgentData.js | 9 +- .../server/methods/loadHistory.js | 13 ++ .../server/methods/loginByToken.js | 38 +++-- .../server/methods/registerGuest.js | 10 +- .../server/methods/saveSurveyFeedback.js | 5 +- .../server/methods/sendMessageLivechat.js | 31 +++- .../server/methods/sendTranscript.js | 2 +- .../server/methods/setCustomField.js | 4 +- .../server/models/LivechatVisitors.js | 148 ++++++++++++++++++ .../server/models/Users.js | 139 ---------------- .../rocketchat-livechat/server/rest/sms.js | 8 +- .../server/sendMessageBySMS.js | 4 +- server/methods/loadHistory.js | 85 +--------- server/stream/messages.js | 32 ++-- 42 files changed, 475 insertions(+), 380 deletions(-) create mode 100644 packages/rocketchat-lib/server/functions/loadMessageHistory.js rename packages/rocketchat-livechat/app/{client/lib/_visitor.js => imports/client/visitor.js} (76%) create mode 100644 packages/rocketchat-livechat/server/methods/loadHistory.js create mode 100644 packages/rocketchat-livechat/server/models/LivechatVisitors.js diff --git a/packages/rocketchat-lib/package.js b/packages/rocketchat-lib/package.js index b4e0168c2664..ad418fe2264d 100644 --- a/packages/rocketchat-lib/package.js +++ b/packages/rocketchat-lib/package.js @@ -78,6 +78,7 @@ Package.onUse(function(api) { api.addFiles('server/functions/deleteUser.js', 'server'); api.addFiles('server/functions/getFullUserData.js', 'server'); api.addFiles('server/functions/getRoomByNameOrIdWithOptionToJoin.js', 'server'); + api.addFiles('server/functions/loadMessageHistory.js', 'server'); api.addFiles('server/functions/removeUserFromRoom.js', 'server'); api.addFiles('server/functions/saveUser.js', 'server'); api.addFiles('server/functions/saveCustomFields.js', 'server'); diff --git a/packages/rocketchat-lib/server/functions/loadMessageHistory.js b/packages/rocketchat-lib/server/functions/loadMessageHistory.js new file mode 100644 index 000000000000..f98ba1efe977 --- /dev/null +++ b/packages/rocketchat-lib/server/functions/loadMessageHistory.js @@ -0,0 +1,86 @@ +const hideMessagesOfType = []; + +RocketChat.settings.get(/Message_HideType_.+/, function(key, value) { + const type = key.replace('Message_HideType_', ''); + const types = type === 'mute_unmute' ? ['user-muted', 'user-unmuted'] : [type]; + + return types.forEach((type) => { + const index = hideMessagesOfType.indexOf(type); + + if (value === true && index === -1) { + return hideMessagesOfType.push(type); + } + + if (index > -1) { + return hideMessagesOfType.splice(index, 1); + } + }); +}); + +RocketChat.loadMessageHistory = function loadMessageHistory({ userId, rid, end, limit = 20, ls }) { + const options = { + sort: { + ts: -1 + }, + limit + }; + + if (!RocketChat.settings.get('Message_ShowEditedStatus')) { + options.fields = { + editedAt: 0 + }; + } + + let records; + if (end != null) { + records = RocketChat.models.Messages.findVisibleByRoomIdBeforeTimestampNotContainingTypes(rid, end, hideMessagesOfType, options).fetch(); + } else { + records = RocketChat.models.Messages.findVisibleByRoomIdNotContainingTypes(rid, hideMessagesOfType, options).fetch(); + } + + const UI_Use_Real_Name = RocketChat.settings.get('UI_Use_Real_Name') === true; + + const messages = records.map((message) => { + message.starred = _.findWhere(message.starred, { + _id: userId + }); + if (message.u && message.u._id && UI_Use_Real_Name) { + const user = RocketChat.models.Users.findOneById(message.u._id); + message.u.name = user && user.name; + } + if (message.mentions && message.mentions.length && UI_Use_Real_Name) { + message.mentions.forEach((mention) => { + const user = RocketChat.models.Users.findOneById(mention._id); + mention.name = user && user.name; + }); + } + return message; + }); + + let unreadNotLoaded = 0; + let firstUnread; + + if (ls != null) { + const firstMessage = messages[messages.length - 1]; + + if ((firstMessage != null ? firstMessage.ts : undefined) > ls) { + delete options.limit; + + const unreadMessages = RocketChat.models.Messages.findVisibleByRoomIdBetweenTimestampsNotContainingTypes(rid, ls, firstMessage.ts, hideMessagesOfType, { + limit: 1, + sort: { + ts: 1 + } + }); + + firstUnread = unreadMessages.fetch()[0]; + unreadNotLoaded = unreadMessages.count(); + } + } + + return { + messages, + firstUnread, + unreadNotLoaded + }; +}; diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index 7beab8fdfcfa..f30e58de8383 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -96,6 +96,11 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { const user = RocketChat.models.Users.findOneById(message.u._id); + // @TODO maybe a livechat visitor + if (!user) { + return message; + } + /* Increment unread couter if direct messages */ diff --git a/packages/rocketchat-livechat/app/client/lib/CustomFields.js b/packages/rocketchat-livechat/app/client/lib/CustomFields.js index 4f984139c7db..36132c9aa714 100644 --- a/packages/rocketchat-livechat/app/client/lib/CustomFields.js +++ b/packages/rocketchat-livechat/app/client/lib/CustomFields.js @@ -1,3 +1,5 @@ +import visitor from '../../imports/client/visitor'; + this.CustomFields = (function() { let queue = {}; let initiated = false; @@ -13,7 +15,7 @@ this.CustomFields = (function() { const init = function() { Tracker.autorun(function() { - if (Meteor.userId()) { + if (visitor.getId()) { initiated = true; Object.keys(queue).forEach((key) => { setCustomField.call(this, queue[key].token, key, queue[key].value, queue[key].overwrite); diff --git a/packages/rocketchat-livechat/app/client/lib/LivechatVideoCall.js b/packages/rocketchat-livechat/app/client/lib/LivechatVideoCall.js index 88bdd62e0f2c..e31490bb45f0 100644 --- a/packages/rocketchat-livechat/app/client/lib/LivechatVideoCall.js +++ b/packages/rocketchat-livechat/app/client/lib/LivechatVideoCall.js @@ -1,4 +1,5 @@ /* globals LivechatVideoCall, cordova, JitsiMeetExternalAPI */ +import visitor from '../../imports/client/visitor'; LivechatVideoCall = new (class LivechatVideoCall { constructor() { diff --git a/packages/rocketchat-livechat/app/client/lib/_livechat.js b/packages/rocketchat-livechat/app/client/lib/_livechat.js index eb94f7b84974..d1a04ec71600 100644 --- a/packages/rocketchat-livechat/app/client/lib/_livechat.js +++ b/packages/rocketchat-livechat/app/client/lib/_livechat.js @@ -1,3 +1,5 @@ +import visitor from '../../imports/client/visitor'; + this.Livechat = new (class Livechat { constructor() { this._online = new ReactiveVar(null); @@ -30,12 +32,12 @@ this.Livechat = new (class Livechat { this.stream = new Meteor.Streamer('livechat-room'); Tracker.autorun(() => { - if (this._room.get() && Meteor.userId()) { + if (this._room.get() && visitor.getId()) { RoomHistoryManager.getMoreIfIsEmpty(this._room.get()); visitor.subscribeToRoom(this._room.get()); visitor.setRoom(this._room.get()); - Meteor.call('livechat:getAgentData', this._room.get(), (error, result) => { + Meteor.call('livechat:getAgentData', { roomId: this._room.get(), token: visitor.getToken() }, (error, result) => { if (!error) { this._agent.set(result); } diff --git a/packages/rocketchat-livechat/app/client/lib/chatMessages.js b/packages/rocketchat-livechat/app/client/lib/chatMessages.js index 2649809fd286..5f9c6e6fb6c5 100644 --- a/packages/rocketchat-livechat/app/client/lib/chatMessages.js +++ b/packages/rocketchat-livechat/app/client/lib/chatMessages.js @@ -1,5 +1,6 @@ /* globals MsgTyping, showError, Livechat */ import toastr from 'toastr'; +import visitor from '../../imports/client/visitor'; this.ChatMessages = class ChatMessages { init(node) { @@ -61,7 +62,7 @@ this.ChatMessages = class ChatMessages { } this.clearEditing(); const id = element.getAttribute('id'); - const message = ChatMessage.findOne({ _id: id, 'u._id': Meteor.userId() }); + const message = ChatMessage.findOne({ _id: id, 'u._id': visitor.getId() }); this.input.value = message.msg; this.editing.element = element; this.editing.index = index || this.getEditingIndex(element); @@ -125,7 +126,7 @@ this.ChatMessages = class ChatMessages { }); }; - if (!Meteor.userId()) { + if (!visitor.getId()) { const guest = { token: visitor.getToken() }; @@ -139,13 +140,8 @@ this.ChatMessages = class ChatMessages { return showError(error.reason); } - Meteor.loginWithToken(result.token, (error) => { - if (error) { - return showError(error.reason); - } - - sendMessage(); - }); + visitor.setId(result._id); + sendMessage(); }); } else { sendMessage(); @@ -194,6 +190,7 @@ this.ChatMessages = class ChatMessages { const re = new RegExp(value, 'i'); + // @TODO verify if used const user = Meteor.users.findOne({ username: re }, { fields: { username: 1 } }); if (user) { input.value = input.value.replace(value, `@${ user.username } `); diff --git a/packages/rocketchat-livechat/app/client/lib/commands.js b/packages/rocketchat-livechat/app/client/lib/commands.js index f215fdad0c96..23e10d3b9812 100644 --- a/packages/rocketchat-livechat/app/client/lib/commands.js +++ b/packages/rocketchat-livechat/app/client/lib/commands.js @@ -1,4 +1,6 @@ /* globals LivechatVideoCall, Livechat */ +import visitor from '../../imports/client/visitor'; + // Functions to call on messages of type 'command' this.Commands = { survey() { @@ -13,6 +15,7 @@ this.Commands = { promptTranscript() { if (Livechat.transcript) { + // @TODO get visitor email const user = Meteor.user(); const email = user.visitorEmails && user.visitorEmails.length > 0 ? user.visitorEmails[0].address : ''; diff --git a/packages/rocketchat-livechat/app/client/lib/fromApp/Notifications.js b/packages/rocketchat-livechat/app/client/lib/fromApp/Notifications.js index d33705486995..836f9388e489 100644 --- a/packages/rocketchat-livechat/app/client/lib/fromApp/Notifications.js +++ b/packages/rocketchat-livechat/app/client/lib/fromApp/Notifications.js @@ -1,12 +1,14 @@ +import visitor from '../../../imports/client/visitor'; + this.Notifications = new class { constructor() { - this.logged = Meteor.userId() !== null; + this.logged = visitor.getId() !== null; this.loginCb = []; Tracker.autorun(() => { - if (Meteor.userId() !== null && this.logged === false) { + if (visitor.getId() !== null && this.logged === false) { this.loginCb.forEach(cb => cb()); } - return this.logged = Meteor.userId() !== null; + return this.logged = visitor.getId() !== null; }); this.debug = false; this.streamAll = new Meteor.Streamer('notify-all'); @@ -61,7 +63,7 @@ this.Notifications = new class { return this.streamRoom.on(`${ room }/${ eventName }`, callback); } onUser(eventName, callback) { - return this.streamUser.on(`${ Meteor.userId() }/${ eventName }`, callback); + return this.streamUser.on(`${ visitor.getId() }/${ eventName }`, callback); } unAll(callback) { return this.streamAll.removeListener('notify', callback); @@ -73,7 +75,7 @@ this.Notifications = new class { return this.streamRoom.removeListener(`${ room }/${ eventName }`, callback); } unUser(callback) { - return this.streamUser.removeListener(Meteor.userId(), callback); + return this.streamUser.removeListener(visitor.getId(), callback); } }; diff --git a/packages/rocketchat-livechat/app/client/lib/fromApp/RoomHistoryManager.js b/packages/rocketchat-livechat/app/client/lib/fromApp/RoomHistoryManager.js index 2f94b4d1c5b4..648eb78fd371 100644 --- a/packages/rocketchat-livechat/app/client/lib/fromApp/RoomHistoryManager.js +++ b/packages/rocketchat-livechat/app/client/lib/fromApp/RoomHistoryManager.js @@ -1,4 +1,7 @@ /* globals readMessage UserRoles RoomRoles*/ + +import visitor from '../../../imports/client/visitor'; + export const RoomHistoryManager = new class { constructor() { this.defaultLimit = 50; @@ -40,7 +43,7 @@ export const RoomHistoryManager = new class { ts = new Date(); } - Meteor.call('loadHistory', rid, ts, limit, undefined, (err, result) => { + Meteor.call('livechat:loadHistory', { token: visitor.getToken(), rid, ts, limit }, (err, result) => { if (err) { return; } diff --git a/packages/rocketchat-livechat/app/client/lib/hooks.js b/packages/rocketchat-livechat/app/client/lib/hooks.js index eb7a2e34c56c..3a525c34cf5d 100644 --- a/packages/rocketchat-livechat/app/client/lib/hooks.js +++ b/packages/rocketchat-livechat/app/client/lib/hooks.js @@ -1,4 +1,6 @@ /* globals CustomFields, Livechat */ +import visitor from '../../imports/client/visitor'; + const api = { pageVisited(info) { if (info.change === 'url') { diff --git a/packages/rocketchat-livechat/app/client/lib/msgTyping.js b/packages/rocketchat-livechat/app/client/lib/msgTyping.js index 1d387f744e06..c120f01ae2ed 100644 --- a/packages/rocketchat-livechat/app/client/lib/msgTyping.js +++ b/packages/rocketchat-livechat/app/client/lib/msgTyping.js @@ -1,4 +1,6 @@ /* globals Notifications */ +import visitor from '../../imports/client/visitor'; + export const MsgTyping = (function() { const timeout = 15000; const timeouts = {}; @@ -34,7 +36,7 @@ export const MsgTyping = (function() { }; Tracker.autorun(() => { - if (visitor.getRoom() && Meteor.userId()) { + if (visitor.getRoom() && visitor.getId()) { addStream(visitor.getRoom()); } }); diff --git a/packages/rocketchat-livechat/app/client/lib/triggers.js b/packages/rocketchat-livechat/app/client/lib/triggers.js index e303ef110937..72f68df99294 100644 --- a/packages/rocketchat-livechat/app/client/lib/triggers.js +++ b/packages/rocketchat-livechat/app/client/lib/triggers.js @@ -1,3 +1,5 @@ +import visitor from '../../imports/client/visitor'; + this.Triggers = (function() { let triggers = []; let initiated = false; @@ -5,7 +7,7 @@ this.Triggers = (function() { let enabled = true; const fire = function(trigger) { - if (!enabled || Meteor.userId()) { + if (!enabled || visitor.getId()) { return; } trigger.actions.forEach(function(action) { diff --git a/packages/rocketchat-livechat/app/client/methods/sendMessageExternal.js b/packages/rocketchat-livechat/app/client/methods/sendMessageExternal.js index 35c8844fa881..89b0f0e7a720 100644 --- a/packages/rocketchat-livechat/app/client/methods/sendMessageExternal.js +++ b/packages/rocketchat-livechat/app/client/methods/sendMessageExternal.js @@ -1,3 +1,5 @@ +import visitor from '../../imports/client/visitor'; + Meteor.methods({ sendMessageLivechat(message) { if (s.trim(message.msg) !== '') { @@ -10,7 +12,7 @@ Meteor.methods({ const user = Meteor.user(); message.u = { - _id: Meteor.userId(), + _id: visitor.getId(), username: user && user.username || 'visitor' }; diff --git a/packages/rocketchat-livechat/app/client/routes/router.js b/packages/rocketchat-livechat/app/client/routes/router.js index 6762a019a5e2..9b6e69af2952 100644 --- a/packages/rocketchat-livechat/app/client/routes/router.js +++ b/packages/rocketchat-livechat/app/client/routes/router.js @@ -1,3 +1,5 @@ +import visitor from '../../imports/client/visitor'; + BlazeLayout.setRoot('body'); FlowRouter.route('/livechat', { diff --git a/packages/rocketchat-livechat/app/client/startup/visitor.js b/packages/rocketchat-livechat/app/client/startup/visitor.js index bd27d17e99af..c9aae1ecac63 100644 --- a/packages/rocketchat-livechat/app/client/startup/visitor.js +++ b/packages/rocketchat-livechat/app/client/startup/visitor.js @@ -1,21 +1,18 @@ -this.visitorId = new ReactiveVar(null); +import visitor from '../../imports/client/visitor'; Meteor.startup(() => { if (!localStorage.getItem('rocketChatLivechat')) { localStorage.setItem('rocketChatLivechat', Random.id()); } else { Tracker.autorun(c => { - if (!Meteor.userId() && visitor.getToken()) { + if (!visitor.getId() && visitor.getToken()) { Meteor.call('livechat:loginByToken', visitor.getToken(), (err, result) => { - if (result && result.token) { - Meteor.loginWithToken(result.token, () => { - c.stop(); - }); + if (result && result._id) { + visitor.setId(result._id); + c.stop(); } }); } }); } - - this.visitorId.set(localStorage.getItem('rocketChatLivechat')); }); diff --git a/packages/rocketchat-livechat/app/client/views/avatar.js b/packages/rocketchat-livechat/app/client/views/avatar.js index 5ab46c366a45..e863c6ba45aa 100644 --- a/packages/rocketchat-livechat/app/client/views/avatar.js +++ b/packages/rocketchat-livechat/app/client/views/avatar.js @@ -6,6 +6,7 @@ Template.avatar.helpers({ username = user && user.username; } + // @TODO get visitor username const currentUser = Meteor.users.findOne(Meteor.userId(), { fields: { username: 1 }}); if (!username || (currentUser && currentUser.username === username)) { return; diff --git a/packages/rocketchat-livechat/app/client/views/livechatWindow.js b/packages/rocketchat-livechat/app/client/views/livechatWindow.js index fcbe88f9587d..0d56c2561c2c 100644 --- a/packages/rocketchat-livechat/app/client/views/livechatWindow.js +++ b/packages/rocketchat-livechat/app/client/views/livechatWindow.js @@ -1,4 +1,5 @@ /* globals Department, Livechat, LivechatVideoCall */ +import visitor from '../../imports/client/visitor'; Template.livechatWindow.helpers({ title() { @@ -17,7 +18,7 @@ Template.livechatWindow.helpers({ return Session.get('sound'); }, showRegisterForm() { - if (Session.get('triggered') || Meteor.userId()) { + if (Session.get('triggered') || visitor.getId()) { return false; } return Livechat.registrationForm; diff --git a/packages/rocketchat-livechat/app/client/views/message.js b/packages/rocketchat-livechat/app/client/views/message.js index 86c64ed26e79..880fb0edbca7 100644 --- a/packages/rocketchat-livechat/app/client/views/message.js +++ b/packages/rocketchat-livechat/app/client/views/message.js @@ -1,9 +1,11 @@ /* globals Livechat, t, tr, livechatAutolinker */ import moment from 'moment'; +import visitor from '../../imports/client/visitor'; Template.message.helpers({ own() { - if (this.u && this.u._id === Meteor.userId()) { + console.log(this.u._id, visitor.getId()); + if (this.u && this.u._id === visitor.getId()) { return 'own'; } }, diff --git a/packages/rocketchat-livechat/app/client/views/messages.js b/packages/rocketchat-livechat/app/client/views/messages.js index 9c0fe36b43e9..c6523802f77a 100644 --- a/packages/rocketchat-livechat/app/client/views/messages.js +++ b/packages/rocketchat-livechat/app/client/views/messages.js @@ -1,4 +1,5 @@ /* globals Livechat, LivechatVideoCall, MsgTyping */ +import visitor from '../../imports/client/visitor'; Template.messages.helpers({ messages() { @@ -114,19 +115,14 @@ Template.messages.events({ 'click .video-button'(event) { event.preventDefault(); - if (!Meteor.userId()) { + if (!visitor.getId()) { Meteor.call('livechat:registerGuest', { token: visitor.getToken() }, (error, result) => { if (error) { return console.log(error.reason); } - Meteor.loginWithToken(result.token, (error) => { - if (error) { - return console.log(error.reason); - } - - LivechatVideoCall.request(); - }); + visitor.setId(result._id); + LivechatVideoCall.request(); }); } else { LivechatVideoCall.request(); diff --git a/packages/rocketchat-livechat/app/client/views/options.js b/packages/rocketchat-livechat/app/client/views/options.js index 0329f6c73f63..ec5bc787377f 100644 --- a/packages/rocketchat-livechat/app/client/views/options.js +++ b/packages/rocketchat-livechat/app/client/views/options.js @@ -1,4 +1,5 @@ /* globals Department, Livechat */ +import visitor from '../../imports/client/visitor'; Template.options.helpers({ showDepartments() { diff --git a/packages/rocketchat-livechat/app/client/views/register.js b/packages/rocketchat-livechat/app/client/views/register.js index 607d2e57c768..e26e1ee68ef8 100644 --- a/packages/rocketchat-livechat/app/client/views/register.js +++ b/packages/rocketchat-livechat/app/client/views/register.js @@ -1,4 +1,5 @@ /* globals Department, Livechat, LivechatVideoCall */ +import visitor from '../../imports/client/visitor'; Template.register.helpers({ error() { @@ -56,12 +57,8 @@ Template.register.events({ return instance.showError(error.reason); } parentCall('callback', ['pre-chat-form-submit', _.omit(guest, 'token')]); - Meteor.loginWithToken(result.token, function(error) { - if (error) { - return instance.showError(error.reason); - } - start(); - }); + visitor.setId(result._id); + start(); }); } }, diff --git a/packages/rocketchat-livechat/app/client/views/survey.js b/packages/rocketchat-livechat/app/client/views/survey.js index 51d3928cd668..fb53137c9cee 100644 --- a/packages/rocketchat-livechat/app/client/views/survey.js +++ b/packages/rocketchat-livechat/app/client/views/survey.js @@ -1,3 +1,5 @@ +import visitor from '../../imports/client/visitor'; + Template.survey.events({ 'click button.skip'(e, instance) { instance.$('#survey').remove(); diff --git a/packages/rocketchat-livechat/app/client/views/switchDepartment.js b/packages/rocketchat-livechat/app/client/views/switchDepartment.js index 70ce6893d17b..803ec46d442d 100644 --- a/packages/rocketchat-livechat/app/client/views/switchDepartment.js +++ b/packages/rocketchat-livechat/app/client/views/switchDepartment.js @@ -1,4 +1,5 @@ /* globals Department, Livechat */ +import visitor from '../../imports/client/visitor'; Template.switchDepartment.helpers({ departments() { diff --git a/packages/rocketchat-livechat/app/client/lib/_visitor.js b/packages/rocketchat-livechat/app/imports/client/visitor.js similarity index 76% rename from packages/rocketchat-livechat/app/client/lib/_visitor.js rename to packages/rocketchat-livechat/app/imports/client/visitor.js index 21080388f652..ccc0937d4270 100644 --- a/packages/rocketchat-livechat/app/client/lib/_visitor.js +++ b/packages/rocketchat-livechat/app/imports/client/visitor.js @@ -1,13 +1,12 @@ /* globals Commands */ const msgStream = new Meteor.Streamer('room-messages'); -this.visitor = new class { - constructor() { - this.token = new ReactiveVar(null); - this.room = new ReactiveVar(null); - this.roomToSubscribe = new ReactiveVar(null); - this.roomSubscribed = null; - } +export default { + id: new ReactiveVar(null), + token: new ReactiveVar(null), + room: new ReactiveVar(null), + roomToSubscribe: new ReactiveVar(null), + roomSubscribed: null, register() { if (!localStorage.getItem('visitorToken')) { @@ -15,15 +14,23 @@ this.visitor = new class { } this.token.set(localStorage.getItem('visitorToken')); - } + }, + + getId() { + return this.id.get(); + }, + + setId(id) { + return this.id.set(id); + }, getToken() { return this.token.get(); - } + }, setRoom(rid) { this.room.set(rid); - } + }, getRoom(createOnEmpty = false) { let roomId = this.room.get(); @@ -33,11 +40,11 @@ this.visitor = new class { } return roomId; - } + }, isSubscribed(roomId) { return this.roomSubscribed === roomId; - } + }, subscribeToRoom(roomId) { if (this.roomSubscribed && this.roomSubscribed === roomId) { @@ -57,7 +64,7 @@ this.visitor = new class { } // notification sound - if (Session.equals('sound', true) && msg.u._id !== Meteor.userId()) { + if (Session.equals('sound', true) && msg.u._id !== this.getId()) { $('#chatAudioNotification')[0].play(); } } diff --git a/packages/rocketchat-livechat/imports/server/rest/sms.js b/packages/rocketchat-livechat/imports/server/rest/sms.js index c01a1b34fb06..31d5b4e13df7 100644 --- a/packages/rocketchat-livechat/imports/server/rest/sms.js +++ b/packages/rocketchat-livechat/imports/server/rest/sms.js @@ -1,10 +1,12 @@ +import LivechatVisitors from '../../../server/models/LivechatVisitors'; + RocketChat.API.v1.addRoute('livechat/sms-incoming/:service', { post() { const SMSService = RocketChat.SMS.getService(this.urlParams.service); const sms = SMSService.parse(this.bodyParams); - let visitor = RocketChat.models.Users.findOneVisitorByPhone(sms.from); + let visitor = LivechatVisitors.findOneVisitorByPhone(sms.from); const sendMessage = { message: { @@ -18,14 +20,14 @@ RocketChat.API.v1.addRoute('livechat/sms-incoming/:service', { }; if (visitor) { - const rooms = RocketChat.models.Rooms.findOpenByVisitorToken(visitor.profile.token).fetch(); + const rooms = RocketChat.models.Rooms.findOpenByVisitorToken(visitor.token).fetch(); if (rooms && rooms.length > 0) { sendMessage.message.rid = rooms[0]._id; } else { sendMessage.message.rid = Random.id(); } - sendMessage.message.token = visitor.profile.token; + sendMessage.message.token = visitor.token; } else { sendMessage.message.rid = Random.id(); sendMessage.message.token = Random.id(); diff --git a/packages/rocketchat-livechat/package.js b/packages/rocketchat-livechat/package.js index 26451fc650ac..7f162cbb2c63 100644 --- a/packages/rocketchat-livechat/package.js +++ b/packages/rocketchat-livechat/package.js @@ -138,6 +138,7 @@ Package.onUse(function(api) { api.addFiles('server/methods/getCustomFields.js', 'server'); api.addFiles('server/methods/getAgentData.js', 'server'); api.addFiles('server/methods/getInitialData.js', 'server'); + api.addFiles('server/methods/loadHistory.js', 'server'); api.addFiles('server/methods/loginByToken.js', 'server'); api.addFiles('server/methods/pageVisited.js', 'server'); api.addFiles('server/methods/registerGuest.js', 'server'); diff --git a/packages/rocketchat-livechat/server/lib/Livechat.js b/packages/rocketchat-livechat/server/lib/Livechat.js index aa9200a1ac9c..778906758862 100644 --- a/packages/rocketchat-livechat/server/lib/Livechat.js +++ b/packages/rocketchat-livechat/server/lib/Livechat.js @@ -1,5 +1,6 @@ /* globals HTTP */ import UAParser from 'ua-parser-js'; +import LivechatVisitors from '../models/LivechatVisitors'; RocketChat.Livechat = { historyMonitorType: 'url', @@ -58,11 +59,12 @@ RocketChat.Livechat = { room = RocketChat.QueueMethods[routingMethod](guest, message, roomInfo); newRoom = true; - } else { - room = Meteor.call('canAccessRoom', message.rid, guest._id); } - if (!room) { - throw new Meteor.Error('cannot-acess-room'); + console.log('getRoom.room ->', room); + console.log('getRoom.guest ->', guest); + + if (room.v.token !== guest.token) { + throw new Meteor.Error('cannot-access-room'); } return { room, newRoom }; @@ -76,53 +78,49 @@ RocketChat.Livechat = { // return messages; return _.extend(RocketChat.sendMessage(guest, message, room), { newRoom, showConnecting: this.showConnecting() }); }, - registerGuest({ token, name, email, department, phone, loginToken, username } = {}) { + registerGuest({ token, name, email, department, phone, username } = {}) { check(token, String); let userId; const updateUser = { $set: { - profile: { - guest: true, - token - } + token } }; - const user = RocketChat.models.Users.getVisitorByToken(token, { fields: { _id: 1 } }); + const user = LivechatVisitors.getVisitorByToken(token, { fields: { _id: 1 } }); if (user) { userId = user._id; - if (loginToken) { - if (!updateUser.$addToSet) { - updateUser.$addToSet = {}; - } - updateUser.$addToSet['services.resume.loginTokens'] = loginToken; - } + // if (loginToken) { + // if (!updateUser.$addToSet) { + // updateUser.$addToSet = {}; + // } + // updateUser.$addToSet['services.resume.loginTokens'] = loginToken; + // } } else { if (!username) { - username = RocketChat.models.Users.getNextVisitorUsername(); + username = LivechatVisitors.getNextVisitorUsername(); } let existingUser = null; - if (s.trim(email) !== '' && (existingUser = RocketChat.models.Users.findOneGuestByEmailAddress(email))) { - if (loginToken) { - if (!updateUser.$addToSet) { - updateUser.$addToSet = {}; - } - updateUser.$addToSet['services.resume.loginTokens'] = loginToken; - } + if (s.trim(email) !== '' && (existingUser = LivechatVisitors.findOneGuestByEmailAddress(email))) { + // if (loginToken) { + // if (!updateUser.$addToSet) { + // updateUser.$addToSet = {}; + // } + // updateUser.$addToSet['services.resume.loginTokens'] = loginToken; + // } userId = existingUser._id; } else { - const userData = { username, - globalRoles: ['livechat-guest'], - department, - type: 'visitor', - joinDefaultChannels: false + // globalRoles: ['livechat-guest'], + department + // type: 'visitor', + // joinDefaultChannels: false }; if (this.connection) { @@ -131,15 +129,16 @@ RocketChat.Livechat = { userData.host = this.connection.httpHeaders.host; } - userId = Accounts.insertUserDoc({}, userData); + // userId = Accounts.insertUserDoc({}, userData); - if (loginToken) { - updateUser.$set.services = { - resume: { - loginTokens: [ loginToken ] - } - }; - } + // if (loginToken) { + // updateUser.$set.services = { + // resume: { + // loginTokens: [ loginToken ] + // } + // }; + // } + userId = LivechatVisitors.insert(userData); } } @@ -156,10 +155,10 @@ RocketChat.Livechat = { } if (name) { - RocketChat._setRealName(userId, name); + updateUser.$set.name = name; } - Meteor.users.update(userId, updateUser); + LivechatVisitors.updateById(userId, updateUser); return userId; }, @@ -172,7 +171,7 @@ RocketChat.Livechat = { } }; - const user = RocketChat.models.Users.getVisitorByToken(token, { fields: { _id: 1 } }); + const user = LivechatVisitors.getVisitorByToken(token, { fields: { _id: 1 } }); if (user) { return Meteor.users.update(user._id, updateUser); } @@ -190,7 +189,7 @@ RocketChat.Livechat = { if (phone) { updateData.phone = phone; } - const ret = RocketChat.models.Users.saveGuestById(_id, updateData); + const ret = LivechatVisitors.saveGuestById(_id, updateData); Meteor.defer(() => { RocketChat.callbacks.run('livechat.saveGuest', updateData); @@ -534,7 +533,9 @@ RocketChat.Livechat = { }; RocketChat.Livechat.stream = new Meteor.Streamer('livechat-room'); -RocketChat.Livechat.stream.allowRead('logged'); + +// @TODO create a allow function +RocketChat.Livechat.stream.allowRead('all'); RocketChat.settings.get('Livechat_history_monitor_type', (key, value) => { RocketChat.Livechat.historyMonitorType = value; diff --git a/packages/rocketchat-livechat/server/methods/getAgentData.js b/packages/rocketchat-livechat/server/methods/getAgentData.js index 98f8e2808ae8..75a6981abb51 100644 --- a/packages/rocketchat-livechat/server/methods/getAgentData.js +++ b/packages/rocketchat-livechat/server/methods/getAgentData.js @@ -1,12 +1,15 @@ +import LivechatVisitors from '../models/LivechatVisitors'; + Meteor.methods({ - 'livechat:getAgentData'(roomId) { + 'livechat:getAgentData'({ roomId, token }) { check(roomId, String); + check(token, String); const room = RocketChat.models.Rooms.findOneById(roomId); - const user = Meteor.user(); + const visitor = LivechatVisitors.getVisitorByToken(token); // allow to only user to send transcripts from their own chats - if (!room || room.t !== 'l' || !room.v || !user.profile || room.v.token !== user.profile.token) { + if (!room || room.t !== 'l' || !room.v || room.v.token !== visitor.token) { throw new Meteor.Error('error-invalid-room', 'Invalid room'); } diff --git a/packages/rocketchat-livechat/server/methods/loadHistory.js b/packages/rocketchat-livechat/server/methods/loadHistory.js new file mode 100644 index 000000000000..fdbab8bcc23c --- /dev/null +++ b/packages/rocketchat-livechat/server/methods/loadHistory.js @@ -0,0 +1,13 @@ +import LivechatVisitors from '../models/LivechatVisitors'; + +Meteor.methods({ + 'livechat:loadHistory'({ token, rid, end, limit = 20, ls}) { + const visitor = LivechatVisitors.getVisitorByToken(token, { fields: { _id: 1 } }); + + if (!visitor) { + return; + } + + return RocketChat.loadMessageHistory({ userId: visitor._id, rid, end, limit, ls }); + } +}); diff --git a/packages/rocketchat-livechat/server/methods/loginByToken.js b/packages/rocketchat-livechat/server/methods/loginByToken.js index 78c08a4d454f..264e97caaa7a 100644 --- a/packages/rocketchat-livechat/server/methods/loginByToken.js +++ b/packages/rocketchat-livechat/server/methods/loginByToken.js @@ -1,28 +1,34 @@ +import LivechatVisitors from '../models/LivechatVisitors'; + Meteor.methods({ 'livechat:loginByToken'(token) { - const user = RocketChat.models.Users.getVisitorByToken(token, { fields: { _id: 1 } }); + const user = LivechatVisitors.getVisitorByToken(token, { fields: { _id: 1 } }); if (!user) { return; } - const stampedToken = Accounts._generateStampedLoginToken(); - const hashStampedToken = Accounts._hashStampedToken(stampedToken); - - const updateUser = { - $set: { - services: { - resume: { - loginTokens: [ hashStampedToken ] - } - } - } + return { + _id: user._id }; - Meteor.users.update(user._id, updateUser); + // const stampedToken = Accounts._generateStampedLoginToken(); + // const hashStampedToken = Accounts._hashStampedToken(stampedToken); - return { - token: stampedToken.token - }; + // const updateUser = { + // $set: { + // services: { + // resume: { + // loginTokens: [ hashStampedToken ] + // } + // } + // } + // }; + + // Meteor.users.update(user._id, updateUser); + + // return { + // token: stampedToken.token + // }; } }); diff --git a/packages/rocketchat-livechat/server/methods/registerGuest.js b/packages/rocketchat-livechat/server/methods/registerGuest.js index 9dcc0b9082cd..303fd58a9075 100644 --- a/packages/rocketchat-livechat/server/methods/registerGuest.js +++ b/packages/rocketchat-livechat/server/methods/registerGuest.js @@ -1,22 +1,20 @@ Meteor.methods({ 'livechat:registerGuest'({ token, name, email, department } = {}) { - const stampedToken = Accounts._generateStampedLoginToken(); - const hashStampedToken = Accounts._hashStampedToken(stampedToken); + // const stampedToken = Accounts._generateStampedLoginToken(); + // const hashStampedToken = Accounts._hashStampedToken(stampedToken); const userId = RocketChat.Livechat.registerGuest.call(this, { token, name, email, - department, - loginToken: hashStampedToken + department }); // update visited page history to not expire RocketChat.models.LivechatPageVisited.keepHistoryForToken(token); return { - userId, - token: stampedToken.token + userId }; } }); diff --git a/packages/rocketchat-livechat/server/methods/saveSurveyFeedback.js b/packages/rocketchat-livechat/server/methods/saveSurveyFeedback.js index 4d04b268f051..bf313234f7d2 100644 --- a/packages/rocketchat-livechat/server/methods/saveSurveyFeedback.js +++ b/packages/rocketchat-livechat/server/methods/saveSurveyFeedback.js @@ -1,4 +1,5 @@ /* eslint new-cap: [2, {"capIsNewExceptions": ["Match.ObjectIncluding"]}] */ +import LivechatVisitors from '../models/LivechatVisitors'; Meteor.methods({ 'livechat:saveSurveyFeedback'(visitorToken, visitorRoom, formData) { @@ -6,10 +7,10 @@ Meteor.methods({ check(visitorRoom, String); check(formData, [Match.ObjectIncluding({ name: String, value: String })]); - const visitor = RocketChat.models.Users.getVisitorByToken(visitorToken); + const visitor = LivechatVisitors.getVisitorByToken(visitorToken); const room = RocketChat.models.Rooms.findOneById(visitorRoom); - if (visitor !== undefined && room !== undefined && room.v !== undefined && visitor.profile !== undefined && room.v.token === visitor.profile.token) { + if (visitor !== undefined && room !== undefined && room.v !== undefined && room.v.token === visitor.token) { const updateData = {}; for (const item of formData) { if (_.contains(['satisfaction', 'agentKnowledge', 'agentResposiveness', 'agentFriendliness'], item.name) && _.contains(['1', '2', '3', '4', '5'], item.value)) { diff --git a/packages/rocketchat-livechat/server/methods/sendMessageLivechat.js b/packages/rocketchat-livechat/server/methods/sendMessageLivechat.js index b34c80019d98..4dabd29c07cf 100644 --- a/packages/rocketchat-livechat/server/methods/sendMessageLivechat.js +++ b/packages/rocketchat-livechat/server/methods/sendMessageLivechat.js @@ -1,16 +1,35 @@ +import LivechatVisitors from '../models/LivechatVisitors'; + Meteor.methods({ - sendMessageLivechat(message) { - check(message.rid, String); - check(message.token, String); + sendMessageLivechat({ token, _id, rid, msg }) { + check(token, String); + check(_id, String); + check(rid, String); + check(msg, String); - const guest = Meteor.users.findOne(Meteor.userId(), { + const guest = LivechatVisitors.getVisitorByToken(token, { fields: { name: 1, username: 1, - department: 1 + department: 1, + token: 1 } }); - return RocketChat.Livechat.sendMessage({ guest, message }); + console.log('guest ->', guest); + + if (!guest) { + throw new Meteor.Error('invalid-token'); + } + + return RocketChat.Livechat.sendMessage({ + guest, + message: { + _id, + rid, + msg, + token + } + }); } }); diff --git a/packages/rocketchat-livechat/server/methods/sendTranscript.js b/packages/rocketchat-livechat/server/methods/sendTranscript.js index a37a874a9c4f..2b5474718e8c 100644 --- a/packages/rocketchat-livechat/server/methods/sendTranscript.js +++ b/packages/rocketchat-livechat/server/methods/sendTranscript.js @@ -12,7 +12,7 @@ Meteor.methods({ const userLanguage = user.language || RocketChat.settings.get('language') || 'en'; // allow to only user to send transcripts from their own chats - if (!room || room.t !== 'l' || !room.v || !user.profile || room.v.token !== user.profile.token) { + if (!room || room.t !== 'l' || !room.v || room.v.token !== user.token) { throw new Meteor.Error('error-invalid-room', 'Invalid room'); } diff --git a/packages/rocketchat-livechat/server/methods/setCustomField.js b/packages/rocketchat-livechat/server/methods/setCustomField.js index 5187cedde36e..1ff16847a5a0 100644 --- a/packages/rocketchat-livechat/server/methods/setCustomField.js +++ b/packages/rocketchat-livechat/server/methods/setCustomField.js @@ -1,3 +1,5 @@ +import LivechatVisitors from '../models/LivechatVisitors'; + Meteor.methods({ 'livechat:setCustomField'(token, key, value, overwrite = true) { const customField = RocketChat.models.LivechatCustomField.findOneById(key); @@ -6,7 +8,7 @@ Meteor.methods({ return RocketChat.models.Rooms.updateLivechatDataByToken(token, key, value, overwrite); } else { // Save in user - return RocketChat.models.Users.updateLivechatDataByToken(token, key, value, overwrite); + return LivechatVisitors.updateLivechatDataByToken(token, key, value, overwrite); } } diff --git a/packages/rocketchat-livechat/server/models/LivechatVisitors.js b/packages/rocketchat-livechat/server/models/LivechatVisitors.js new file mode 100644 index 000000000000..13881cbcf0ef --- /dev/null +++ b/packages/rocketchat-livechat/server/models/LivechatVisitors.js @@ -0,0 +1,148 @@ +class LivechatVisitors extends RocketChat.models._Base { + constructor() { + super('livechat_visitor'); + } + + /** + * Gets visitor by token + * @param {string} token - Visitor token + */ + getVisitorByToken(token, options) { + const query = { + token + }; + + return this.findOne(query, options); + } + + /** + * Gets visitor by token + * @param {string} token - Visitor token + */ + findVisitorByToken(token) { + const query = { + token + }; + + return this.find(query); + } + + updateLivechatDataByToken(token, key, value, overwrite = true) { + const query = { + token + }; + + if (!overwrite) { + const user = this.findOne(query, { fields: { livechatData: 1 } }); + if (user.livechatData && typeof user.livechatData[key] !== 'undefined') { + return true; + } + } + + const update = { + $set: { + [`livechatData.${ key }`]: value + } + }; + + return this.update(query, update); + } + + /** + * Find a visitor by their phone number + * @return {object} User from db + */ + findOneVisitorByPhone(phone) { + const query = { + 'phone.phoneNumber': phone + }; + + return this.findOne(query); + } + + /** + * Get the next visitor name + * @return {string} The next visitor name + */ + getNextVisitorUsername() { + const settingsRaw = RocketChat.models.Settings.model.rawCollection(); + const findAndModify = Meteor.wrapAsync(settingsRaw.findAndModify, settingsRaw); + + const query = { + _id: 'Livechat_guest_count' + }; + + const update = { + $inc: { + value: 1 + } + }; + + const livechatCount = findAndModify(query, null, update); + + return `guest-${ livechatCount.value.value + 1 }`; + } + + updateById(_id, update) { + return this.update({ _id }, update); + } + + saveGuestById(_id, data) { + const setData = {}; + const unsetData = {}; + + if (data.name) { + if (!_.isEmpty(s.trim(data.name))) { + setData.name = s.trim(data.name); + } else { + unsetData.name = 1; + } + } + + if (data.email) { + if (!_.isEmpty(s.trim(data.email))) { + setData.visitorEmails = [ + { address: s.trim(data.email) } + ]; + } else { + unsetData.visitorEmails = 1; + } + } + + if (data.phone) { + if (!_.isEmpty(s.trim(data.phone))) { + setData.phone = [ + { phoneNumber: s.trim(data.phone) } + ]; + } else { + unsetData.phone = 1; + } + } + + const update = {}; + + if (!_.isEmpty(setData)) { + update.$set = setData; + } + + if (!_.isEmpty(unsetData)) { + update.$unset = unsetData; + } + + if (_.isEmpty(update)) { + return true; + } + + return this.update({ _id }, update); + } + + findOneGuestByEmailAddress(emailAddress) { + const query = { + 'visitorEmails.address': new RegExp(`^${ s.escapeRegExp(emailAddress) }$`, 'i') + }; + + return this.findOne(query); + } +} + +export default new LivechatVisitors(); diff --git a/packages/rocketchat-livechat/server/models/Users.js b/packages/rocketchat-livechat/server/models/Users.js index 75cd14114d79..0c341d635216 100644 --- a/packages/rocketchat-livechat/server/models/Users.js +++ b/packages/rocketchat-livechat/server/models/Users.js @@ -102,32 +102,6 @@ RocketChat.models.Users.getNextAgent = function() { } }; -/** - * Gets visitor by token - * @param {string} token - Visitor token - */ -RocketChat.models.Users.getVisitorByToken = function(token, options) { - const query = { - 'profile.guest': true, - 'profile.token': token - }; - - return this.findOne(query, options); -}; - -/** - * Gets visitor by token - * @param {string} token - Visitor token - */ -RocketChat.models.Users.findVisitorByToken = function(token) { - const query = { - 'profile.guest': true, - 'profile.token': token - }; - - return this.find(query); -}; - /** * Change user's livechat status * @param {string} token - Visitor token @@ -166,119 +140,6 @@ RocketChat.models.Users.openOffice = function() { }); }; -RocketChat.models.Users.updateLivechatDataByToken = function(token, key, value, overwrite = true) { - const query = { - 'profile.token': token - }; - - if (!overwrite) { - const user = this.findOne(query, { fields: { livechatData: 1 } }); - if (user.livechatData && typeof user.livechatData[key] !== 'undefined') { - return true; - } - } - - const update = { - $set: { - [`livechatData.${ key }`]: value - } - }; - - return this.update(query, update); -}; - -/** - * Find a visitor by their phone number - * @return {object} User from db - */ -RocketChat.models.Users.findOneVisitorByPhone = function(phone) { - const query = { - 'phone.phoneNumber': phone - }; - - return this.findOne(query); -}; - -/** - * Get the next visitor name - * @return {string} The next visitor name - */ -RocketChat.models.Users.getNextVisitorUsername = function() { - const settingsRaw = RocketChat.models.Settings.model.rawCollection(); - const findAndModify = Meteor.wrapAsync(settingsRaw.findAndModify, settingsRaw); - - const query = { - _id: 'Livechat_guest_count' - }; - - const update = { - $inc: { - value: 1 - } - }; - - const livechatCount = findAndModify(query, null, update); - - return `guest-${ livechatCount.value.value + 1 }`; -}; - -RocketChat.models.Users.saveGuestById = function(_id, data) { - const setData = {}; - const unsetData = {}; - - if (data.name) { - if (!_.isEmpty(s.trim(data.name))) { - setData.name = s.trim(data.name); - } else { - unsetData.name = 1; - } - } - - if (data.email) { - if (!_.isEmpty(s.trim(data.email))) { - setData.visitorEmails = [ - { address: s.trim(data.email) } - ]; - } else { - unsetData.visitorEmails = 1; - } - } - - if (data.phone) { - if (!_.isEmpty(s.trim(data.phone))) { - setData.phone = [ - { phoneNumber: s.trim(data.phone) } - ]; - } else { - unsetData.phone = 1; - } - } - - const update = {}; - - if (!_.isEmpty(setData)) { - update.$set = setData; - } - - if (!_.isEmpty(unsetData)) { - update.$unset = unsetData; - } - - if (_.isEmpty(update)) { - return true; - } - - return this.update({ _id }, update); -}; - -RocketChat.models.Users.findOneGuestByEmailAddress = function(emailAddress) { - const query = { - 'visitorEmails.address': new RegExp(`^${ s.escapeRegExp(emailAddress) }$`, 'i') - }; - - return this.findOne(query); -}; - RocketChat.models.Users.getAgentInfo = function(agentId) { const query = { _id: agentId diff --git a/packages/rocketchat-livechat/server/rest/sms.js b/packages/rocketchat-livechat/server/rest/sms.js index c01a1b34fb06..6bb7d63fead1 100644 --- a/packages/rocketchat-livechat/server/rest/sms.js +++ b/packages/rocketchat-livechat/server/rest/sms.js @@ -1,10 +1,12 @@ +import LivechatVisitors from '../models/LivechatVisitors'; + RocketChat.API.v1.addRoute('livechat/sms-incoming/:service', { post() { const SMSService = RocketChat.SMS.getService(this.urlParams.service); const sms = SMSService.parse(this.bodyParams); - let visitor = RocketChat.models.Users.findOneVisitorByPhone(sms.from); + let visitor = LivechatVisitors.findOneVisitorByPhone(sms.from); const sendMessage = { message: { @@ -18,14 +20,14 @@ RocketChat.API.v1.addRoute('livechat/sms-incoming/:service', { }; if (visitor) { - const rooms = RocketChat.models.Rooms.findOpenByVisitorToken(visitor.profile.token).fetch(); + const rooms = RocketChat.models.Rooms.findOpenByVisitorToken(visitor.token).fetch(); if (rooms && rooms.length > 0) { sendMessage.message.rid = rooms[0]._id; } else { sendMessage.message.rid = Random.id(); } - sendMessage.message.token = visitor.profile.token; + sendMessage.message.token = visitor.token; } else { sendMessage.message.rid = Random.id(); sendMessage.message.token = Random.id(); diff --git a/packages/rocketchat-livechat/server/sendMessageBySMS.js b/packages/rocketchat-livechat/server/sendMessageBySMS.js index fc849bc9be9c..313d3ce6370f 100644 --- a/packages/rocketchat-livechat/server/sendMessageBySMS.js +++ b/packages/rocketchat-livechat/server/sendMessageBySMS.js @@ -1,3 +1,5 @@ +import LivechatVisitors from './models/LivechatVisitors'; + RocketChat.callbacks.add('afterSaveMessage', function(message, room) { // skips this callback if the message was edited if (message.editedAt) { @@ -29,7 +31,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { return message; } - const visitor = RocketChat.models.Users.getVisitorByToken(room.v.token); + const visitor = LivechatVisitors.getVisitorByToken(room.v.token); if (!visitor || !visitor.profile || !visitor.phone || visitor.phone.length === 0) { return message; diff --git a/server/methods/loadHistory.js b/server/methods/loadHistory.js index 31858c9aa821..0e7472870ed1 100644 --- a/server/methods/loadHistory.js +++ b/server/methods/loadHistory.js @@ -1,22 +1,3 @@ -const hideMessagesOfType = []; - -RocketChat.settings.get(/Message_HideType_.+/, function(key, value) { - const type = key.replace('Message_HideType_', ''); - const types = type === 'mute_unmute' ? ['user-muted', 'user-unmuted'] : [type]; - - return types.forEach((type) => { - const index = hideMessagesOfType.indexOf(type); - - if (value === true && index === -1) { - return hideMessagesOfType.push(type); - } - - if (index > -1) { - return hideMessagesOfType.splice(index, 1); - } - }); -}); - Meteor.methods({ loadHistory(rid, end, limit = 20, ls) { check(rid, String); @@ -40,70 +21,6 @@ Meteor.methods({ return false; } - const options = { - sort: { - ts: -1 - }, - limit - }; - - if (!RocketChat.settings.get('Message_ShowEditedStatus')) { - options.fields = { - editedAt: 0 - }; - } - - let records; - if (end != null) { - records = RocketChat.models.Messages.findVisibleByRoomIdBeforeTimestampNotContainingTypes(rid, end, hideMessagesOfType, options).fetch(); - } else { - records = RocketChat.models.Messages.findVisibleByRoomIdNotContainingTypes(rid, hideMessagesOfType, options).fetch(); - } - - const UI_Use_Real_Name = RocketChat.settings.get('UI_Use_Real_Name') === true; - - const messages = records.map((message) => { - message.starred = _.findWhere(message.starred, { - _id: fromId - }); - if (message.u && message.u._id && UI_Use_Real_Name) { - const user = RocketChat.models.Users.findOneById(message.u._id); - message.u.name = user && user.name; - } - if (message.mentions && message.mentions.length && UI_Use_Real_Name) { - message.mentions.forEach((mention) => { - const user = RocketChat.models.Users.findOneById(mention._id); - mention.name = user && user.name; - }); - } - return message; - }); - - let unreadNotLoaded = 0; - let firstUnread; - - if (ls != null) { - const firstMessage = messages[messages.length - 1]; - - if ((firstMessage != null ? firstMessage.ts : undefined) > ls) { - delete options.limit; - - const unreadMessages = RocketChat.models.Messages.findVisibleByRoomIdBetweenTimestampsNotContainingTypes(rid, ls, firstMessage.ts, hideMessagesOfType, { - limit: 1, - sort: { - ts: 1 - } - }); - - firstUnread = unreadMessages.fetch()[0]; - unreadNotLoaded = unreadMessages.count(); - } - } - - return { - messages, - firstUnread, - unreadNotLoaded - }; + return RocketChat.loadMessageHistory({ userId: fromId, rid, end, limit, ls }); } }); diff --git a/server/stream/messages.js b/server/stream/messages.js index 96afa00f6bc7..94dded4a9485 100644 --- a/server/stream/messages.js +++ b/server/stream/messages.js @@ -3,24 +3,26 @@ this.msgStream = msgStream; msgStream.allowWrite('none'); -msgStream.allowRead(function(eventName) { - try { - const room = Meteor.call('canAccessRoom', eventName, this.userId); +msgStream.allowRead('all'); +// @TODO fix livechat +// msgStream.allowRead(function(eventName) { +// try { +// const room = Meteor.call('canAccessRoom', eventName, this.userId); - if (!room) { - return false; - } +// if (!room) { +// return false; +// } - if (room.t === 'c' && !RocketChat.authz.hasPermission(this.userId, 'preview-c-room') && room.usernames.indexOf(room.username) === -1) { - return false; - } +// if (room.t === 'c' && !RocketChat.authz.hasPermission(this.userId, 'preview-c-room') && room.usernames.indexOf(room.username) === -1) { +// return false; +// } - return true; - } catch (error) { - /*error*/ - return false; - } -}); +// return true; +// } catch (error) { +// /*error*/ +// return false; +// } +// }); msgStream.allowRead('__my_messages__', 'all'); From 98097d6c25ebfc266d82dd197b89b7b8df61aed7 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 9 Jun 2017 10:44:23 -0300 Subject: [PATCH 02/16] Do not show visitor avatar --- packages/rocketchat-livechat/app/client/stylesheets/main.less | 4 ++++ packages/rocketchat-livechat/app/client/views/message.js | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/rocketchat-livechat/app/client/stylesheets/main.less b/packages/rocketchat-livechat/app/client/stylesheets/main.less index afad4f334141..d4f0e14aa553 100644 --- a/packages/rocketchat-livechat/app/client/stylesheets/main.less +++ b/packages/rocketchat-livechat/app/client/stylesheets/main.less @@ -340,6 +340,10 @@ input:focus { left: inherit; } } + + .thumb { + display: none; + } } .delete-message { diff --git a/packages/rocketchat-livechat/app/client/views/message.js b/packages/rocketchat-livechat/app/client/views/message.js index 880fb0edbca7..ac8bcd2b4d12 100644 --- a/packages/rocketchat-livechat/app/client/views/message.js +++ b/packages/rocketchat-livechat/app/client/views/message.js @@ -4,7 +4,6 @@ import visitor from '../../imports/client/visitor'; Template.message.helpers({ own() { - console.log(this.u._id, visitor.getId()); if (this.u && this.u._id === visitor.getId()) { return 'own'; } From affb966b443b8f4b32e34473e2407e081a2108b7 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 9 Jun 2017 10:59:11 -0300 Subject: [PATCH 03/16] Make livechat app folder hidden This will make Meteor ignore changes on this folder which will prevent rebuilds of whole livechat package. For local development it is recommended to run the livechat app individually like on run.sh file. --- .eslintignore | 2 +- .gitignore | 2 +- .travis.yml | 4 ++-- .../{app => .app}/.meteor/.finished-upgraders | 0 packages/rocketchat-livechat/{app => .app}/.meteor/.gitignore | 0 packages/rocketchat-livechat/{app => .app}/.meteor/.id | 0 packages/rocketchat-livechat/{app => .app}/.meteor/packages | 0 packages/rocketchat-livechat/{app => .app}/.meteor/platforms | 0 packages/rocketchat-livechat/{app => .app}/.meteor/release | 0 packages/rocketchat-livechat/{app => .app}/.meteor/versions | 0 .../{app => .app}/client/components/modal.html | 0 .../{app => .app}/client/lib/CustomFields.js | 0 .../{app => .app}/client/lib/LivechatVideoCall.js | 0 .../rocketchat-livechat/{app => .app}/client/lib/_livechat.js | 0 .../{app => .app}/client/lib/autolinker.js | 0 .../{app => .app}/client/lib/chatMessages.js | 0 .../{app => .app}/client/lib/collections.js | 0 .../rocketchat-livechat/{app => .app}/client/lib/commands.js | 0 .../rocketchat-livechat/{app => .app}/client/lib/error.js | 0 .../{app => .app}/client/lib/fromApp/Notifications.js | 0 .../{app => .app}/client/lib/fromApp/RoomHistoryManager.js | 0 .../{app => .app}/client/lib/fromApp/avatar.js | 0 .../rocketchat-livechat/{app => .app}/client/lib/hooks.js | 0 .../rocketchat-livechat/{app => .app}/client/lib/msgTyping.js | 0 .../{app => .app}/client/lib/parentCall.js | 0 .../rocketchat-livechat/{app => .app}/client/lib/tapi18n.js | 0 .../rocketchat-livechat/{app => .app}/client/lib/triggers.js | 0 .../{app => .app}/client/methods/sendMessageExternal.js | 0 .../rocketchat-livechat/{app => .app}/client/routes/router.js | 0 .../{app => .app}/client/startup/customFields.js | 0 .../{app => .app}/client/startup/visitor.js | 0 .../{app => .app}/client/stylesheets/main.less | 0 .../client/stylesheets/utils/_keyframes.import.less | 0 .../client/stylesheets/utils/_loading.import.less | 0 .../{app => .app}/client/stylesheets/utils/_reset.import.less | 0 .../client/stylesheets/utils/_variables.import.less | 0 .../{app => .app}/client/views/avatar.html | 0 .../rocketchat-livechat/{app => .app}/client/views/avatar.js | 0 .../{app => .app}/client/views/livechatWindow.html | 0 .../{app => .app}/client/views/livechatWindow.js | 0 .../{app => .app}/client/views/loading.html | 0 .../rocketchat-livechat/{app => .app}/client/views/main.html | 0 .../{app => .app}/client/views/message.html | 0 .../rocketchat-livechat/{app => .app}/client/views/message.js | 0 .../{app => .app}/client/views/messages.html | 0 .../{app => .app}/client/views/messages.js | 0 .../{app => .app}/client/views/offlineForm.html | 0 .../{app => .app}/client/views/offlineForm.js | 0 .../{app => .app}/client/views/options.html | 0 .../rocketchat-livechat/{app => .app}/client/views/options.js | 0 .../{app => .app}/client/views/poweredBy.html | 0 .../{app => .app}/client/views/register.html | 0 .../{app => .app}/client/views/register.js | 0 .../{app => .app}/client/views/survey.html | 0 .../rocketchat-livechat/{app => .app}/client/views/survey.js | 0 .../{app => .app}/client/views/switchDepartment.html | 0 .../{app => .app}/client/views/switchDepartment.js | 0 .../{app => .app}/client/views/videoCall.html | 0 .../{app => .app}/client/views/videoCall.js | 0 packages/rocketchat-livechat/{app => .app}/i18n/ar.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/az.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/bg.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/ca.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/cs.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/da.i18n.json | 0 .../rocketchat-livechat/{app => .app}/i18n/de-AT.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/de.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/el.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/en.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/eo.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/es.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/fa.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/fi.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/fr.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/he.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/hr.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/hu.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/id.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/it.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/ja.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/km.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/ko.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/ku.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/lo.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/lt.i18n.json | 0 .../rocketchat-livechat/{app => .app}/i18n/ms-MY.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/nl.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/no.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/pl.i18n.json | 0 .../rocketchat-livechat/{app => .app}/i18n/pt-BR.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/pt.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/ro.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/ru.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/sq.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/sr.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/sv.i18n.json | 0 .../rocketchat-livechat/{app => .app}/i18n/ta-IN.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/tr.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/ug.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/uk.i18n.json | 0 .../rocketchat-livechat/{app => .app}/i18n/zh-HK.i18n.json | 0 .../rocketchat-livechat/{app => .app}/i18n/zh-TW.i18n.json | 0 packages/rocketchat-livechat/{app => .app}/i18n/zh.i18n.json | 0 .../{app => .app}/imports/client/visitor.js | 0 packages/rocketchat-livechat/{app => .app}/package.json | 0 packages/rocketchat-livechat/{app => .app}/run.sh | 0 packages/rocketchat-livechat/plugin/build.bat | 2 +- packages/rocketchat-livechat/plugin/build.sh | 2 +- private/node_scripts/auto-translate.js | 2 +- 109 files changed, 7 insertions(+), 7 deletions(-) rename packages/rocketchat-livechat/{app => .app}/.meteor/.finished-upgraders (100%) rename packages/rocketchat-livechat/{app => .app}/.meteor/.gitignore (100%) rename packages/rocketchat-livechat/{app => .app}/.meteor/.id (100%) rename packages/rocketchat-livechat/{app => .app}/.meteor/packages (100%) rename packages/rocketchat-livechat/{app => .app}/.meteor/platforms (100%) rename packages/rocketchat-livechat/{app => .app}/.meteor/release (100%) rename packages/rocketchat-livechat/{app => .app}/.meteor/versions (100%) rename packages/rocketchat-livechat/{app => .app}/client/components/modal.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/CustomFields.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/LivechatVideoCall.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/_livechat.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/autolinker.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/chatMessages.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/collections.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/commands.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/error.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/fromApp/Notifications.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/fromApp/RoomHistoryManager.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/fromApp/avatar.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/hooks.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/msgTyping.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/parentCall.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/tapi18n.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/lib/triggers.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/methods/sendMessageExternal.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/routes/router.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/startup/customFields.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/startup/visitor.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/stylesheets/main.less (100%) rename packages/rocketchat-livechat/{app => .app}/client/stylesheets/utils/_keyframes.import.less (100%) rename packages/rocketchat-livechat/{app => .app}/client/stylesheets/utils/_loading.import.less (100%) rename packages/rocketchat-livechat/{app => .app}/client/stylesheets/utils/_reset.import.less (100%) rename packages/rocketchat-livechat/{app => .app}/client/stylesheets/utils/_variables.import.less (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/avatar.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/avatar.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/livechatWindow.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/livechatWindow.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/loading.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/main.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/message.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/message.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/messages.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/messages.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/offlineForm.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/offlineForm.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/options.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/options.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/poweredBy.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/register.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/register.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/survey.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/survey.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/switchDepartment.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/switchDepartment.js (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/videoCall.html (100%) rename packages/rocketchat-livechat/{app => .app}/client/views/videoCall.js (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/ar.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/az.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/bg.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/ca.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/cs.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/da.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/de-AT.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/de.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/el.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/en.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/eo.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/es.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/fa.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/fi.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/fr.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/he.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/hr.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/hu.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/id.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/it.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/ja.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/km.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/ko.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/ku.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/lo.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/lt.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/ms-MY.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/nl.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/no.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/pl.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/pt-BR.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/pt.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/ro.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/ru.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/sq.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/sr.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/sv.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/ta-IN.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/tr.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/ug.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/uk.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/zh-HK.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/zh-TW.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/i18n/zh.i18n.json (100%) rename packages/rocketchat-livechat/{app => .app}/imports/client/visitor.js (100%) rename packages/rocketchat-livechat/{app => .app}/package.json (100%) rename packages/rocketchat-livechat/{app => .app}/run.sh (100%) diff --git a/.eslintignore b/.eslintignore index 03b1ad39e1a6..984ba1d5dc35 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,7 +5,7 @@ packages/meteor-timesync/ packages/rocketchat-emoji-emojione/generateEmojiIndex.js packages/rocketchat-favico/favico.js packages/rocketchat-katex/client/katex/katex.min.js -packages/rocketchat-livechat/app/node_modules +packages/rocketchat-livechat/.app/node_modules packages/rocketchat-livechat/assets/rocketchat-livechat.min.js packages/rocketchat-livechat/assets/rocket-livechat.js packages/rocketchat-migrations/ diff --git a/.gitignore b/.gitignore index 0f1c300b4d17..22a8d5865323 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,7 @@ .meteor/local* .meteor/meteorite .meteor/dev_bundle -packages/rocketchat-livechat/app/.meteor/dev_bundle +packages/rocketchat-livechat/.app/.meteor/dev_bundle packages/rocketchat-livechat/assets/rocketchat-livechat.min.js .mule .pmd diff --git a/.travis.yml b/.travis.yml index 948ec8f880c7..24ac2fb1b9a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,8 +32,8 @@ cache: - "$HOME/build/RocketChat/Rocket.Chat/node_modules" - "$HOME/build/RocketChat/Rocket.Chat/.meteor/local" - "$HOME/build/RocketChat/Rocket.Chat/packages/rocketchat-livechat/.npm" - - "$HOME/build/RocketChat/Rocket.Chat/packages/rocketchat-livechat/app/node_modules" - - "$HOME/build/RocketChat/Rocket.Chat/packages/rocketchat-livechat/app/.meteor/local" + - "$HOME/build/RocketChat/Rocket.Chat/packages/rocketchat-livechat/.app/node_modules" + - "$HOME/build/RocketChat/Rocket.Chat/packages/rocketchat-livechat/.app/.meteor/local" before_install: - if [ ! -e "$HOME/.meteor/meteor" ]; then curl https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh; fi # Start X Virtual Frame Buffer for headless testing with real browsers diff --git a/packages/rocketchat-livechat/app/.meteor/.finished-upgraders b/packages/rocketchat-livechat/.app/.meteor/.finished-upgraders similarity index 100% rename from packages/rocketchat-livechat/app/.meteor/.finished-upgraders rename to packages/rocketchat-livechat/.app/.meteor/.finished-upgraders diff --git a/packages/rocketchat-livechat/app/.meteor/.gitignore b/packages/rocketchat-livechat/.app/.meteor/.gitignore similarity index 100% rename from packages/rocketchat-livechat/app/.meteor/.gitignore rename to packages/rocketchat-livechat/.app/.meteor/.gitignore diff --git a/packages/rocketchat-livechat/app/.meteor/.id b/packages/rocketchat-livechat/.app/.meteor/.id similarity index 100% rename from packages/rocketchat-livechat/app/.meteor/.id rename to packages/rocketchat-livechat/.app/.meteor/.id diff --git a/packages/rocketchat-livechat/app/.meteor/packages b/packages/rocketchat-livechat/.app/.meteor/packages similarity index 100% rename from packages/rocketchat-livechat/app/.meteor/packages rename to packages/rocketchat-livechat/.app/.meteor/packages diff --git a/packages/rocketchat-livechat/app/.meteor/platforms b/packages/rocketchat-livechat/.app/.meteor/platforms similarity index 100% rename from packages/rocketchat-livechat/app/.meteor/platforms rename to packages/rocketchat-livechat/.app/.meteor/platforms diff --git a/packages/rocketchat-livechat/app/.meteor/release b/packages/rocketchat-livechat/.app/.meteor/release similarity index 100% rename from packages/rocketchat-livechat/app/.meteor/release rename to packages/rocketchat-livechat/.app/.meteor/release diff --git a/packages/rocketchat-livechat/app/.meteor/versions b/packages/rocketchat-livechat/.app/.meteor/versions similarity index 100% rename from packages/rocketchat-livechat/app/.meteor/versions rename to packages/rocketchat-livechat/.app/.meteor/versions diff --git a/packages/rocketchat-livechat/app/client/components/modal.html b/packages/rocketchat-livechat/.app/client/components/modal.html similarity index 100% rename from packages/rocketchat-livechat/app/client/components/modal.html rename to packages/rocketchat-livechat/.app/client/components/modal.html diff --git a/packages/rocketchat-livechat/app/client/lib/CustomFields.js b/packages/rocketchat-livechat/.app/client/lib/CustomFields.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/CustomFields.js rename to packages/rocketchat-livechat/.app/client/lib/CustomFields.js diff --git a/packages/rocketchat-livechat/app/client/lib/LivechatVideoCall.js b/packages/rocketchat-livechat/.app/client/lib/LivechatVideoCall.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/LivechatVideoCall.js rename to packages/rocketchat-livechat/.app/client/lib/LivechatVideoCall.js diff --git a/packages/rocketchat-livechat/app/client/lib/_livechat.js b/packages/rocketchat-livechat/.app/client/lib/_livechat.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/_livechat.js rename to packages/rocketchat-livechat/.app/client/lib/_livechat.js diff --git a/packages/rocketchat-livechat/app/client/lib/autolinker.js b/packages/rocketchat-livechat/.app/client/lib/autolinker.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/autolinker.js rename to packages/rocketchat-livechat/.app/client/lib/autolinker.js diff --git a/packages/rocketchat-livechat/app/client/lib/chatMessages.js b/packages/rocketchat-livechat/.app/client/lib/chatMessages.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/chatMessages.js rename to packages/rocketchat-livechat/.app/client/lib/chatMessages.js diff --git a/packages/rocketchat-livechat/app/client/lib/collections.js b/packages/rocketchat-livechat/.app/client/lib/collections.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/collections.js rename to packages/rocketchat-livechat/.app/client/lib/collections.js diff --git a/packages/rocketchat-livechat/app/client/lib/commands.js b/packages/rocketchat-livechat/.app/client/lib/commands.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/commands.js rename to packages/rocketchat-livechat/.app/client/lib/commands.js diff --git a/packages/rocketchat-livechat/app/client/lib/error.js b/packages/rocketchat-livechat/.app/client/lib/error.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/error.js rename to packages/rocketchat-livechat/.app/client/lib/error.js diff --git a/packages/rocketchat-livechat/app/client/lib/fromApp/Notifications.js b/packages/rocketchat-livechat/.app/client/lib/fromApp/Notifications.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/fromApp/Notifications.js rename to packages/rocketchat-livechat/.app/client/lib/fromApp/Notifications.js diff --git a/packages/rocketchat-livechat/app/client/lib/fromApp/RoomHistoryManager.js b/packages/rocketchat-livechat/.app/client/lib/fromApp/RoomHistoryManager.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/fromApp/RoomHistoryManager.js rename to packages/rocketchat-livechat/.app/client/lib/fromApp/RoomHistoryManager.js diff --git a/packages/rocketchat-livechat/app/client/lib/fromApp/avatar.js b/packages/rocketchat-livechat/.app/client/lib/fromApp/avatar.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/fromApp/avatar.js rename to packages/rocketchat-livechat/.app/client/lib/fromApp/avatar.js diff --git a/packages/rocketchat-livechat/app/client/lib/hooks.js b/packages/rocketchat-livechat/.app/client/lib/hooks.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/hooks.js rename to packages/rocketchat-livechat/.app/client/lib/hooks.js diff --git a/packages/rocketchat-livechat/app/client/lib/msgTyping.js b/packages/rocketchat-livechat/.app/client/lib/msgTyping.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/msgTyping.js rename to packages/rocketchat-livechat/.app/client/lib/msgTyping.js diff --git a/packages/rocketchat-livechat/app/client/lib/parentCall.js b/packages/rocketchat-livechat/.app/client/lib/parentCall.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/parentCall.js rename to packages/rocketchat-livechat/.app/client/lib/parentCall.js diff --git a/packages/rocketchat-livechat/app/client/lib/tapi18n.js b/packages/rocketchat-livechat/.app/client/lib/tapi18n.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/tapi18n.js rename to packages/rocketchat-livechat/.app/client/lib/tapi18n.js diff --git a/packages/rocketchat-livechat/app/client/lib/triggers.js b/packages/rocketchat-livechat/.app/client/lib/triggers.js similarity index 100% rename from packages/rocketchat-livechat/app/client/lib/triggers.js rename to packages/rocketchat-livechat/.app/client/lib/triggers.js diff --git a/packages/rocketchat-livechat/app/client/methods/sendMessageExternal.js b/packages/rocketchat-livechat/.app/client/methods/sendMessageExternal.js similarity index 100% rename from packages/rocketchat-livechat/app/client/methods/sendMessageExternal.js rename to packages/rocketchat-livechat/.app/client/methods/sendMessageExternal.js diff --git a/packages/rocketchat-livechat/app/client/routes/router.js b/packages/rocketchat-livechat/.app/client/routes/router.js similarity index 100% rename from packages/rocketchat-livechat/app/client/routes/router.js rename to packages/rocketchat-livechat/.app/client/routes/router.js diff --git a/packages/rocketchat-livechat/app/client/startup/customFields.js b/packages/rocketchat-livechat/.app/client/startup/customFields.js similarity index 100% rename from packages/rocketchat-livechat/app/client/startup/customFields.js rename to packages/rocketchat-livechat/.app/client/startup/customFields.js diff --git a/packages/rocketchat-livechat/app/client/startup/visitor.js b/packages/rocketchat-livechat/.app/client/startup/visitor.js similarity index 100% rename from packages/rocketchat-livechat/app/client/startup/visitor.js rename to packages/rocketchat-livechat/.app/client/startup/visitor.js diff --git a/packages/rocketchat-livechat/app/client/stylesheets/main.less b/packages/rocketchat-livechat/.app/client/stylesheets/main.less similarity index 100% rename from packages/rocketchat-livechat/app/client/stylesheets/main.less rename to packages/rocketchat-livechat/.app/client/stylesheets/main.less diff --git a/packages/rocketchat-livechat/app/client/stylesheets/utils/_keyframes.import.less b/packages/rocketchat-livechat/.app/client/stylesheets/utils/_keyframes.import.less similarity index 100% rename from packages/rocketchat-livechat/app/client/stylesheets/utils/_keyframes.import.less rename to packages/rocketchat-livechat/.app/client/stylesheets/utils/_keyframes.import.less diff --git a/packages/rocketchat-livechat/app/client/stylesheets/utils/_loading.import.less b/packages/rocketchat-livechat/.app/client/stylesheets/utils/_loading.import.less similarity index 100% rename from packages/rocketchat-livechat/app/client/stylesheets/utils/_loading.import.less rename to packages/rocketchat-livechat/.app/client/stylesheets/utils/_loading.import.less diff --git a/packages/rocketchat-livechat/app/client/stylesheets/utils/_reset.import.less b/packages/rocketchat-livechat/.app/client/stylesheets/utils/_reset.import.less similarity index 100% rename from packages/rocketchat-livechat/app/client/stylesheets/utils/_reset.import.less rename to packages/rocketchat-livechat/.app/client/stylesheets/utils/_reset.import.less diff --git a/packages/rocketchat-livechat/app/client/stylesheets/utils/_variables.import.less b/packages/rocketchat-livechat/.app/client/stylesheets/utils/_variables.import.less similarity index 100% rename from packages/rocketchat-livechat/app/client/stylesheets/utils/_variables.import.less rename to packages/rocketchat-livechat/.app/client/stylesheets/utils/_variables.import.less diff --git a/packages/rocketchat-livechat/app/client/views/avatar.html b/packages/rocketchat-livechat/.app/client/views/avatar.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/avatar.html rename to packages/rocketchat-livechat/.app/client/views/avatar.html diff --git a/packages/rocketchat-livechat/app/client/views/avatar.js b/packages/rocketchat-livechat/.app/client/views/avatar.js similarity index 100% rename from packages/rocketchat-livechat/app/client/views/avatar.js rename to packages/rocketchat-livechat/.app/client/views/avatar.js diff --git a/packages/rocketchat-livechat/app/client/views/livechatWindow.html b/packages/rocketchat-livechat/.app/client/views/livechatWindow.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/livechatWindow.html rename to packages/rocketchat-livechat/.app/client/views/livechatWindow.html diff --git a/packages/rocketchat-livechat/app/client/views/livechatWindow.js b/packages/rocketchat-livechat/.app/client/views/livechatWindow.js similarity index 100% rename from packages/rocketchat-livechat/app/client/views/livechatWindow.js rename to packages/rocketchat-livechat/.app/client/views/livechatWindow.js diff --git a/packages/rocketchat-livechat/app/client/views/loading.html b/packages/rocketchat-livechat/.app/client/views/loading.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/loading.html rename to packages/rocketchat-livechat/.app/client/views/loading.html diff --git a/packages/rocketchat-livechat/app/client/views/main.html b/packages/rocketchat-livechat/.app/client/views/main.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/main.html rename to packages/rocketchat-livechat/.app/client/views/main.html diff --git a/packages/rocketchat-livechat/app/client/views/message.html b/packages/rocketchat-livechat/.app/client/views/message.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/message.html rename to packages/rocketchat-livechat/.app/client/views/message.html diff --git a/packages/rocketchat-livechat/app/client/views/message.js b/packages/rocketchat-livechat/.app/client/views/message.js similarity index 100% rename from packages/rocketchat-livechat/app/client/views/message.js rename to packages/rocketchat-livechat/.app/client/views/message.js diff --git a/packages/rocketchat-livechat/app/client/views/messages.html b/packages/rocketchat-livechat/.app/client/views/messages.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/messages.html rename to packages/rocketchat-livechat/.app/client/views/messages.html diff --git a/packages/rocketchat-livechat/app/client/views/messages.js b/packages/rocketchat-livechat/.app/client/views/messages.js similarity index 100% rename from packages/rocketchat-livechat/app/client/views/messages.js rename to packages/rocketchat-livechat/.app/client/views/messages.js diff --git a/packages/rocketchat-livechat/app/client/views/offlineForm.html b/packages/rocketchat-livechat/.app/client/views/offlineForm.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/offlineForm.html rename to packages/rocketchat-livechat/.app/client/views/offlineForm.html diff --git a/packages/rocketchat-livechat/app/client/views/offlineForm.js b/packages/rocketchat-livechat/.app/client/views/offlineForm.js similarity index 100% rename from packages/rocketchat-livechat/app/client/views/offlineForm.js rename to packages/rocketchat-livechat/.app/client/views/offlineForm.js diff --git a/packages/rocketchat-livechat/app/client/views/options.html b/packages/rocketchat-livechat/.app/client/views/options.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/options.html rename to packages/rocketchat-livechat/.app/client/views/options.html diff --git a/packages/rocketchat-livechat/app/client/views/options.js b/packages/rocketchat-livechat/.app/client/views/options.js similarity index 100% rename from packages/rocketchat-livechat/app/client/views/options.js rename to packages/rocketchat-livechat/.app/client/views/options.js diff --git a/packages/rocketchat-livechat/app/client/views/poweredBy.html b/packages/rocketchat-livechat/.app/client/views/poweredBy.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/poweredBy.html rename to packages/rocketchat-livechat/.app/client/views/poweredBy.html diff --git a/packages/rocketchat-livechat/app/client/views/register.html b/packages/rocketchat-livechat/.app/client/views/register.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/register.html rename to packages/rocketchat-livechat/.app/client/views/register.html diff --git a/packages/rocketchat-livechat/app/client/views/register.js b/packages/rocketchat-livechat/.app/client/views/register.js similarity index 100% rename from packages/rocketchat-livechat/app/client/views/register.js rename to packages/rocketchat-livechat/.app/client/views/register.js diff --git a/packages/rocketchat-livechat/app/client/views/survey.html b/packages/rocketchat-livechat/.app/client/views/survey.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/survey.html rename to packages/rocketchat-livechat/.app/client/views/survey.html diff --git a/packages/rocketchat-livechat/app/client/views/survey.js b/packages/rocketchat-livechat/.app/client/views/survey.js similarity index 100% rename from packages/rocketchat-livechat/app/client/views/survey.js rename to packages/rocketchat-livechat/.app/client/views/survey.js diff --git a/packages/rocketchat-livechat/app/client/views/switchDepartment.html b/packages/rocketchat-livechat/.app/client/views/switchDepartment.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/switchDepartment.html rename to packages/rocketchat-livechat/.app/client/views/switchDepartment.html diff --git a/packages/rocketchat-livechat/app/client/views/switchDepartment.js b/packages/rocketchat-livechat/.app/client/views/switchDepartment.js similarity index 100% rename from packages/rocketchat-livechat/app/client/views/switchDepartment.js rename to packages/rocketchat-livechat/.app/client/views/switchDepartment.js diff --git a/packages/rocketchat-livechat/app/client/views/videoCall.html b/packages/rocketchat-livechat/.app/client/views/videoCall.html similarity index 100% rename from packages/rocketchat-livechat/app/client/views/videoCall.html rename to packages/rocketchat-livechat/.app/client/views/videoCall.html diff --git a/packages/rocketchat-livechat/app/client/views/videoCall.js b/packages/rocketchat-livechat/.app/client/views/videoCall.js similarity index 100% rename from packages/rocketchat-livechat/app/client/views/videoCall.js rename to packages/rocketchat-livechat/.app/client/views/videoCall.js diff --git a/packages/rocketchat-livechat/app/i18n/ar.i18n.json b/packages/rocketchat-livechat/.app/i18n/ar.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/ar.i18n.json rename to packages/rocketchat-livechat/.app/i18n/ar.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/az.i18n.json b/packages/rocketchat-livechat/.app/i18n/az.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/az.i18n.json rename to packages/rocketchat-livechat/.app/i18n/az.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/bg.i18n.json b/packages/rocketchat-livechat/.app/i18n/bg.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/bg.i18n.json rename to packages/rocketchat-livechat/.app/i18n/bg.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/ca.i18n.json b/packages/rocketchat-livechat/.app/i18n/ca.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/ca.i18n.json rename to packages/rocketchat-livechat/.app/i18n/ca.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/cs.i18n.json b/packages/rocketchat-livechat/.app/i18n/cs.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/cs.i18n.json rename to packages/rocketchat-livechat/.app/i18n/cs.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/da.i18n.json b/packages/rocketchat-livechat/.app/i18n/da.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/da.i18n.json rename to packages/rocketchat-livechat/.app/i18n/da.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/de-AT.i18n.json b/packages/rocketchat-livechat/.app/i18n/de-AT.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/de-AT.i18n.json rename to packages/rocketchat-livechat/.app/i18n/de-AT.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/de.i18n.json b/packages/rocketchat-livechat/.app/i18n/de.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/de.i18n.json rename to packages/rocketchat-livechat/.app/i18n/de.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/el.i18n.json b/packages/rocketchat-livechat/.app/i18n/el.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/el.i18n.json rename to packages/rocketchat-livechat/.app/i18n/el.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/en.i18n.json b/packages/rocketchat-livechat/.app/i18n/en.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/en.i18n.json rename to packages/rocketchat-livechat/.app/i18n/en.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/eo.i18n.json b/packages/rocketchat-livechat/.app/i18n/eo.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/eo.i18n.json rename to packages/rocketchat-livechat/.app/i18n/eo.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/es.i18n.json b/packages/rocketchat-livechat/.app/i18n/es.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/es.i18n.json rename to packages/rocketchat-livechat/.app/i18n/es.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/fa.i18n.json b/packages/rocketchat-livechat/.app/i18n/fa.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/fa.i18n.json rename to packages/rocketchat-livechat/.app/i18n/fa.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/fi.i18n.json b/packages/rocketchat-livechat/.app/i18n/fi.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/fi.i18n.json rename to packages/rocketchat-livechat/.app/i18n/fi.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/fr.i18n.json b/packages/rocketchat-livechat/.app/i18n/fr.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/fr.i18n.json rename to packages/rocketchat-livechat/.app/i18n/fr.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/he.i18n.json b/packages/rocketchat-livechat/.app/i18n/he.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/he.i18n.json rename to packages/rocketchat-livechat/.app/i18n/he.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/hr.i18n.json b/packages/rocketchat-livechat/.app/i18n/hr.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/hr.i18n.json rename to packages/rocketchat-livechat/.app/i18n/hr.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/hu.i18n.json b/packages/rocketchat-livechat/.app/i18n/hu.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/hu.i18n.json rename to packages/rocketchat-livechat/.app/i18n/hu.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/id.i18n.json b/packages/rocketchat-livechat/.app/i18n/id.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/id.i18n.json rename to packages/rocketchat-livechat/.app/i18n/id.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/it.i18n.json b/packages/rocketchat-livechat/.app/i18n/it.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/it.i18n.json rename to packages/rocketchat-livechat/.app/i18n/it.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/ja.i18n.json b/packages/rocketchat-livechat/.app/i18n/ja.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/ja.i18n.json rename to packages/rocketchat-livechat/.app/i18n/ja.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/km.i18n.json b/packages/rocketchat-livechat/.app/i18n/km.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/km.i18n.json rename to packages/rocketchat-livechat/.app/i18n/km.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/ko.i18n.json b/packages/rocketchat-livechat/.app/i18n/ko.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/ko.i18n.json rename to packages/rocketchat-livechat/.app/i18n/ko.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/ku.i18n.json b/packages/rocketchat-livechat/.app/i18n/ku.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/ku.i18n.json rename to packages/rocketchat-livechat/.app/i18n/ku.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/lo.i18n.json b/packages/rocketchat-livechat/.app/i18n/lo.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/lo.i18n.json rename to packages/rocketchat-livechat/.app/i18n/lo.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/lt.i18n.json b/packages/rocketchat-livechat/.app/i18n/lt.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/lt.i18n.json rename to packages/rocketchat-livechat/.app/i18n/lt.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/ms-MY.i18n.json b/packages/rocketchat-livechat/.app/i18n/ms-MY.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/ms-MY.i18n.json rename to packages/rocketchat-livechat/.app/i18n/ms-MY.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/nl.i18n.json b/packages/rocketchat-livechat/.app/i18n/nl.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/nl.i18n.json rename to packages/rocketchat-livechat/.app/i18n/nl.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/no.i18n.json b/packages/rocketchat-livechat/.app/i18n/no.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/no.i18n.json rename to packages/rocketchat-livechat/.app/i18n/no.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/pl.i18n.json b/packages/rocketchat-livechat/.app/i18n/pl.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/pl.i18n.json rename to packages/rocketchat-livechat/.app/i18n/pl.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/pt-BR.i18n.json b/packages/rocketchat-livechat/.app/i18n/pt-BR.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/pt-BR.i18n.json rename to packages/rocketchat-livechat/.app/i18n/pt-BR.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/pt.i18n.json b/packages/rocketchat-livechat/.app/i18n/pt.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/pt.i18n.json rename to packages/rocketchat-livechat/.app/i18n/pt.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/ro.i18n.json b/packages/rocketchat-livechat/.app/i18n/ro.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/ro.i18n.json rename to packages/rocketchat-livechat/.app/i18n/ro.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/ru.i18n.json b/packages/rocketchat-livechat/.app/i18n/ru.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/ru.i18n.json rename to packages/rocketchat-livechat/.app/i18n/ru.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/sq.i18n.json b/packages/rocketchat-livechat/.app/i18n/sq.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/sq.i18n.json rename to packages/rocketchat-livechat/.app/i18n/sq.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/sr.i18n.json b/packages/rocketchat-livechat/.app/i18n/sr.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/sr.i18n.json rename to packages/rocketchat-livechat/.app/i18n/sr.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/sv.i18n.json b/packages/rocketchat-livechat/.app/i18n/sv.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/sv.i18n.json rename to packages/rocketchat-livechat/.app/i18n/sv.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/ta-IN.i18n.json b/packages/rocketchat-livechat/.app/i18n/ta-IN.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/ta-IN.i18n.json rename to packages/rocketchat-livechat/.app/i18n/ta-IN.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/tr.i18n.json b/packages/rocketchat-livechat/.app/i18n/tr.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/tr.i18n.json rename to packages/rocketchat-livechat/.app/i18n/tr.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/ug.i18n.json b/packages/rocketchat-livechat/.app/i18n/ug.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/ug.i18n.json rename to packages/rocketchat-livechat/.app/i18n/ug.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/uk.i18n.json b/packages/rocketchat-livechat/.app/i18n/uk.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/uk.i18n.json rename to packages/rocketchat-livechat/.app/i18n/uk.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/zh-HK.i18n.json b/packages/rocketchat-livechat/.app/i18n/zh-HK.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/zh-HK.i18n.json rename to packages/rocketchat-livechat/.app/i18n/zh-HK.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/zh-TW.i18n.json b/packages/rocketchat-livechat/.app/i18n/zh-TW.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/zh-TW.i18n.json rename to packages/rocketchat-livechat/.app/i18n/zh-TW.i18n.json diff --git a/packages/rocketchat-livechat/app/i18n/zh.i18n.json b/packages/rocketchat-livechat/.app/i18n/zh.i18n.json similarity index 100% rename from packages/rocketchat-livechat/app/i18n/zh.i18n.json rename to packages/rocketchat-livechat/.app/i18n/zh.i18n.json diff --git a/packages/rocketchat-livechat/app/imports/client/visitor.js b/packages/rocketchat-livechat/.app/imports/client/visitor.js similarity index 100% rename from packages/rocketchat-livechat/app/imports/client/visitor.js rename to packages/rocketchat-livechat/.app/imports/client/visitor.js diff --git a/packages/rocketchat-livechat/app/package.json b/packages/rocketchat-livechat/.app/package.json similarity index 100% rename from packages/rocketchat-livechat/app/package.json rename to packages/rocketchat-livechat/.app/package.json diff --git a/packages/rocketchat-livechat/app/run.sh b/packages/rocketchat-livechat/.app/run.sh similarity index 100% rename from packages/rocketchat-livechat/app/run.sh rename to packages/rocketchat-livechat/.app/run.sh diff --git a/packages/rocketchat-livechat/plugin/build.bat b/packages/rocketchat-livechat/plugin/build.bat index d586b8120482..bf51ac5c687b 100644 --- a/packages/rocketchat-livechat/plugin/build.bat +++ b/packages/rocketchat-livechat/plugin/build.bat @@ -1,7 +1,7 @@ @echo off SET NODE_ENV="production" -cd packages/rocketchat-livechat/app +cd packages/rocketchat-livechat/.app call meteor npm install --production call meteor build --headless --directory .meteor/build/ diff --git a/packages/rocketchat-livechat/plugin/build.sh b/packages/rocketchat-livechat/plugin/build.sh index 1039e6a20717..f44175f215b0 100644 --- a/packages/rocketchat-livechat/plugin/build.sh +++ b/packages/rocketchat-livechat/plugin/build.sh @@ -3,7 +3,7 @@ export LIVECHAT_DIR="../../../public/livechat" export BUILD_DIR="../build" export BUNDLE_DIR="../build/bundle/programs/web.browser" -cd packages/rocketchat-livechat/app +cd packages/rocketchat-livechat/.app meteor npm install --production meteor build --headless --directory $BUILD_DIR diff --git a/private/node_scripts/auto-translate.js b/private/node_scripts/auto-translate.js index e78ad5eabc7f..1e7c2fc194d3 100644 --- a/private/node_scripts/auto-translate.js +++ b/private/node_scripts/auto-translate.js @@ -15,7 +15,7 @@ googleTranslate.getSupportedLanguages(function(err, langs) { return; } - async.eachSeries(['../../packages/rocketchat-lib/i18n/', '../../packages/rocketchat-livechat/app/i18n/'], function(path, callback) { + async.eachSeries(['../../packages/rocketchat-lib/i18n/', '../../packages/rocketchat-livechat/.app/i18n/'], function(path, callback) { console.log(`Translating files in: ${ path }`); const enContents = fs.readFileSync(`${ path }en.i18n.json`, 'utf-8'); const enUnsorted = JSON.parse(enContents); From 1ba5965fcc11bb62a54159a9ebc2102a7b0e0bcb Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 9 Jun 2017 11:08:10 -0300 Subject: [PATCH 04/16] Fix avatar size --- .../.app/client/stylesheets/main.less | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/rocketchat-livechat/.app/client/stylesheets/main.less b/packages/rocketchat-livechat/.app/client/stylesheets/main.less index d4f0e14aa553..695ebb332081 100644 --- a/packages/rocketchat-livechat/.app/client/stylesheets/main.less +++ b/packages/rocketchat-livechat/.app/client/stylesheets/main.less @@ -447,18 +447,23 @@ input:focus { text-decoration: line-through; } - .avatar .avatar-image { + .avatar { height: 100%; width: 100%; - min-height: 20px; - min-width: 20px; - display: block; - position: relative; - background-color: transparent; - background-size: cover; - background-repeat: no-repeat; - background-position: center; - border-radius: 4px; + + .avatar-image { + height: 100%; + width: 100%; + min-height: 20px; + min-width: 20px; + display: block; + position: relative; + background-color: transparent; + background-size: cover; + background-repeat: no-repeat; + background-position: center; + border-radius: 4px; + } } } } From 7eae4d624078cbfbc78a2ec6255123c09714c908 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 15 Aug 2017 12:57:40 -0300 Subject: [PATCH 05/16] Fix visitor info flex tab --- .../client/collections/LivechatVisitor.js | 1 + .../client/views/app/tabbar/visitorInfo.js | 4 +++- packages/rocketchat-livechat/package.js | 1 + .../server/models/LivechatVisitors.js | 12 ++++++++++++ .../server/publications/visitorInfo.js | 4 +++- 5 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 packages/rocketchat-livechat/client/collections/LivechatVisitor.js diff --git a/packages/rocketchat-livechat/client/collections/LivechatVisitor.js b/packages/rocketchat-livechat/client/collections/LivechatVisitor.js new file mode 100644 index 000000000000..e2b44ef3f14f --- /dev/null +++ b/packages/rocketchat-livechat/client/collections/LivechatVisitor.js @@ -0,0 +1 @@ +this.LivechatVisitor = new Mongo.Collection('rocketchat_livechat_visitor'); diff --git a/packages/rocketchat-livechat/client/views/app/tabbar/visitorInfo.js b/packages/rocketchat-livechat/client/views/app/tabbar/visitorInfo.js index 92d1a22ab449..ca1d44ac34b4 100644 --- a/packages/rocketchat-livechat/client/views/app/tabbar/visitorInfo.js +++ b/packages/rocketchat-livechat/client/views/app/tabbar/visitorInfo.js @@ -1,3 +1,5 @@ +/* globals LivechatVisitor */ + import moment from 'moment'; import UAParser from 'ua-parser-js'; @@ -241,6 +243,6 @@ Template.visitorInfo.onCreated(function() { } this.autorun(() => { - this.user.set(Meteor.users.findOne({ '_id': this.visitorId.get() })); + this.user.set(LivechatVisitor.findOne({ '_id': this.visitorId.get() })); }); }); diff --git a/packages/rocketchat-livechat/package.js b/packages/rocketchat-livechat/package.js index 7f162cbb2c63..b0e49bc549f6 100644 --- a/packages/rocketchat-livechat/package.js +++ b/packages/rocketchat-livechat/package.js @@ -67,6 +67,7 @@ Package.onUse(function(api) { api.addFiles('client/collections/LivechatTrigger.js', 'client'); api.addFiles('client/collections/LivechatInquiry.js', 'client'); api.addFiles('client/collections/livechatOfficeHour.js', 'client'); + api.addFiles('client/collections/LivechatVisitor.js', 'client'); api.addFiles('client/methods/changeLivechatStatus.js', 'client'); diff --git a/packages/rocketchat-livechat/server/models/LivechatVisitors.js b/packages/rocketchat-livechat/server/models/LivechatVisitors.js index 13881cbcf0ef..85f0aecccfd5 100644 --- a/packages/rocketchat-livechat/server/models/LivechatVisitors.js +++ b/packages/rocketchat-livechat/server/models/LivechatVisitors.js @@ -15,6 +15,18 @@ class LivechatVisitors extends RocketChat.models._Base { return this.findOne(query, options); } + /** + * Find visitors by _id + * @param {string} token - Visitor token + */ + findById(_id, options) { + const query = { + _id + }; + + return this.find(query, options); + } + /** * Gets visitor by token * @param {string} token - Visitor token diff --git a/packages/rocketchat-livechat/server/publications/visitorInfo.js b/packages/rocketchat-livechat/server/publications/visitorInfo.js index 1e1462b68d51..b09b0d9dac8f 100644 --- a/packages/rocketchat-livechat/server/publications/visitorInfo.js +++ b/packages/rocketchat-livechat/server/publications/visitorInfo.js @@ -1,3 +1,5 @@ +import LivechatVisitors from '../models/LivechatVisitors'; + Meteor.publish('livechat:visitorInfo', function({ rid: roomId }) { if (!this.userId) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorInfo' })); @@ -10,7 +12,7 @@ Meteor.publish('livechat:visitorInfo', function({ rid: roomId }) { const room = RocketChat.models.Rooms.findOneById(roomId); if (room && room.v && room.v._id) { - return RocketChat.models.Users.findById(room.v._id); + return LivechatVisitors.findById(room.v._id); } else { return this.ready(); } From 6bc76dff1c6a17164af86cc47f68e891562060c0 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 15 Aug 2017 12:58:01 -0300 Subject: [PATCH 06/16] Remove duplicate files --- .../imports/server/rest/sms.js | 4 +- .../server/rest/departments.js | 103 ------------- .../rocketchat-livechat/server/rest/sms.js | 71 --------- .../rocketchat-livechat/server/rest/users.js | 139 ------------------ 4 files changed, 2 insertions(+), 315 deletions(-) delete mode 100644 packages/rocketchat-livechat/server/rest/departments.js delete mode 100644 packages/rocketchat-livechat/server/rest/sms.js delete mode 100644 packages/rocketchat-livechat/server/rest/users.js diff --git a/packages/rocketchat-livechat/imports/server/rest/sms.js b/packages/rocketchat-livechat/imports/server/rest/sms.js index 31d5b4e13df7..56ca236c3b5b 100644 --- a/packages/rocketchat-livechat/imports/server/rest/sms.js +++ b/packages/rocketchat-livechat/imports/server/rest/sms.js @@ -32,7 +32,7 @@ RocketChat.API.v1.addRoute('livechat/sms-incoming/:service', { sendMessage.message.rid = Random.id(); sendMessage.message.token = Random.id(); - const userId = RocketChat.Livechat.registerGuest({ + const visitorId = RocketChat.Livechat.registerGuest({ username: sms.from.replace(/[^0-9]/g, ''), token: sendMessage.message.token, phone: { @@ -40,7 +40,7 @@ RocketChat.API.v1.addRoute('livechat/sms-incoming/:service', { } }); - visitor = RocketChat.models.Users.findOneById(userId); + visitor = LivechatVisitors.findOneById(visitorId); } sendMessage.message.msg = sms.body; diff --git a/packages/rocketchat-livechat/server/rest/departments.js b/packages/rocketchat-livechat/server/rest/departments.js deleted file mode 100644 index 810d3a1c6c6d..000000000000 --- a/packages/rocketchat-livechat/server/rest/departments.js +++ /dev/null @@ -1,103 +0,0 @@ -RocketChat.API.v1.addRoute('livechat/department', { authRequired: true }, { - get() { - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { - return RocketChat.API.v1.unauthorized(); - } - - return RocketChat.API.v1.success({ - departments: RocketChat.models.LivechatDepartment.find().fetch() - }); - }, - post() { - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { - return RocketChat.API.v1.unauthorized(); - } - - try { - check(this.bodyParams, { - department: Object, - agents: Array - }); - - const department = RocketChat.Livechat.saveDepartment(null, this.bodyParams.department, this.bodyParams.agents); - - if (department) { - return RocketChat.API.v1.success({ - department, - agents: RocketChat.models.LivechatDepartmentAgents.find({ departmentId: department._id }).fetch() - }); - } - - RocketChat.API.v1.failure(); - } catch (e) { - return RocketChat.API.v1.failure(e); - } - } -}); - -RocketChat.API.v1.addRoute('livechat/department/:_id', { authRequired: true }, { - get() { - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { - return RocketChat.API.v1.unauthorized(); - } - - try { - check(this.urlParams, { - _id: String - }); - - return RocketChat.API.v1.success({ - department: RocketChat.models.LivechatDepartment.findOneById(this.urlParams._id), - agents: RocketChat.models.LivechatDepartmentAgents.find({ departmentId: this.urlParams._id }).fetch() - }); - } catch (e) { - return RocketChat.API.v1.failure(e.error); - } - }, - put() { - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { - return RocketChat.API.v1.unauthorized(); - } - - try { - check(this.urlParams, { - _id: String - }); - - check(this.bodyParams, { - department: Object, - agents: Array - }); - - if (RocketChat.Livechat.saveDepartment(this.urlParams._id, this.bodyParams.department, this.bodyParams.agents)) { - return RocketChat.API.v1.success({ - department: RocketChat.models.LivechatDepartment.findOneById(this.urlParams._id), - agents: RocketChat.models.LivechatDepartmentAgents.find({ departmentId: this.urlParams._id }).fetch() - }); - } - - return RocketChat.API.v1.failure(); - } catch (e) { - return RocketChat.API.v1.failure(e.error); - } - }, - delete() { - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { - return RocketChat.API.v1.unauthorized(); - } - - try { - check(this.urlParams, { - _id: String - }); - - if (RocketChat.Livechat.removeDepartment(this.urlParams._id)) { - return RocketChat.API.v1.success(); - } - - return RocketChat.API.v1.failure(); - } catch (e) { - return RocketChat.API.v1.failure(e.error); - } - } -}); diff --git a/packages/rocketchat-livechat/server/rest/sms.js b/packages/rocketchat-livechat/server/rest/sms.js deleted file mode 100644 index 6bb7d63fead1..000000000000 --- a/packages/rocketchat-livechat/server/rest/sms.js +++ /dev/null @@ -1,71 +0,0 @@ -import LivechatVisitors from '../models/LivechatVisitors'; - -RocketChat.API.v1.addRoute('livechat/sms-incoming/:service', { - post() { - const SMSService = RocketChat.SMS.getService(this.urlParams.service); - - const sms = SMSService.parse(this.bodyParams); - - let visitor = LivechatVisitors.findOneVisitorByPhone(sms.from); - - const sendMessage = { - message: { - _id: Random.id() - }, - roomInfo: { - sms: { - from: sms.to - } - } - }; - - if (visitor) { - const rooms = RocketChat.models.Rooms.findOpenByVisitorToken(visitor.token).fetch(); - - if (rooms && rooms.length > 0) { - sendMessage.message.rid = rooms[0]._id; - } else { - sendMessage.message.rid = Random.id(); - } - sendMessage.message.token = visitor.token; - } else { - sendMessage.message.rid = Random.id(); - sendMessage.message.token = Random.id(); - - const userId = RocketChat.Livechat.registerGuest({ - username: sms.from.replace(/[^0-9]/g, ''), - token: sendMessage.message.token, - phone: { - number: sms.from - } - }); - - visitor = RocketChat.models.Users.findOneById(userId); - } - - sendMessage.message.msg = sms.body; - sendMessage.guest = visitor; - - try { - const message = SMSService.response.call(this, RocketChat.Livechat.sendMessage(sendMessage)); - - Meteor.defer(() => { - if (sms.extra) { - if (sms.extra.fromCountry) { - Meteor.call('livechat:setCustomField', sendMessage.message.token, 'country', sms.extra.fromCountry); - } - if (sms.extra.fromState) { - Meteor.call('livechat:setCustomField', sendMessage.message.token, 'state', sms.extra.fromState); - } - if (sms.extra.fromCity) { - Meteor.call('livechat:setCustomField', sendMessage.message.token, 'city', sms.extra.fromCity); - } - } - }); - - return message; - } catch (e) { - return SMSService.error.call(this, e); - } - } -}); diff --git a/packages/rocketchat-livechat/server/rest/users.js b/packages/rocketchat-livechat/server/rest/users.js deleted file mode 100644 index c203d9df8b87..000000000000 --- a/packages/rocketchat-livechat/server/rest/users.js +++ /dev/null @@ -1,139 +0,0 @@ -RocketChat.API.v1.addRoute('livechat/users/:type', { authRequired: true }, { - get() { - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { - return RocketChat.API.v1.unauthorized(); - } - - try { - check(this.urlParams, { - type: String - }); - - let role; - if (this.urlParams.type === 'agent') { - role = 'livechat-agent'; - } else if (this.urlParams.type === 'manager') { - role = 'livechat-manager'; - } else { - throw 'Invalid type'; - } - - const users = RocketChat.authz.getUsersInRole(role); - - return RocketChat.API.v1.success({ - users: users.fetch().map(user => ({ _id: user._id, username: user.username })) - }); - } catch (e) { - return RocketChat.API.v1.failure(e.error); - } - }, - post() { - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { - return RocketChat.API.v1.unauthorized(); - } - try { - check(this.urlParams, { - type: String - }); - - check(this.bodyParams, { - username: String - }); - - if (this.urlParams.type === 'agent') { - const user = RocketChat.Livechat.addAgent(this.bodyParams.username); - if (user) { - return RocketChat.API.v1.success({ user }); - } - } else if (this.urlParams.type === 'manager') { - const user = RocketChat.Livechat.addManager(this.bodyParams.username); - if (user) { - return RocketChat.API.v1.success({ user }); - } - } else { - throw 'Invalid type'; - } - - return RocketChat.API.v1.failure(); - } catch (e) { - return RocketChat.API.v1.failure(e.error); - } - } -}); - -RocketChat.API.v1.addRoute('livechat/users/:type/:_id', { authRequired: true }, { - get() { - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { - return RocketChat.API.v1.unauthorized(); - } - - try { - check(this.urlParams, { - type: String, - _id: String - }); - - const user = RocketChat.models.Users.findOneById(this.urlParams._id); - - if (!user) { - return RocketChat.API.v1.failure('User not found'); - } - - let role; - - if (this.urlParams.type === 'agent') { - role = 'livechat-agent'; - } else if (this.urlParams.type === 'manager') { - role = 'livechat-manager'; - } else { - throw 'Invalid type'; - } - - if (user.roles.indexOf(role) !== -1) { - return RocketChat.API.v1.success({ - user: _.pick(user, '_id', 'username') - }); - } - - return RocketChat.API.v1.success({ - user: null - }); - } catch (e) { - return RocketChat.API.v1.failure(e.error); - } - }, - delete() { - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { - return RocketChat.API.v1.unauthorized(); - } - - try { - check(this.urlParams, { - type: String, - _id: String - }); - - const user = RocketChat.models.Users.findOneById(this.urlParams._id); - - if (!user) { - return RocketChat.API.v1.failure(); - } - - if (this.urlParams.type === 'agent') { - if (RocketChat.Livechat.removeAgent(user.username)) { - return RocketChat.API.v1.success(); - } - } else if (this.urlParams.type === 'manager') { - if (RocketChat.Livechat.removeManager(user.username)) { - return RocketChat.API.v1.success(); - } - } else { - throw 'Invalid type'; - } - - return RocketChat.API.v1.failure(); - } catch (e) { - return RocketChat.API.v1.failure(e.error); - } - } -}); From 6ec1172ae183477a2986dbf6aef1afbc05b6db94 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 23 Aug 2017 11:19:49 -0300 Subject: [PATCH 07/16] Add support for visitor status --- .../.app/client/lib/chatMessages.js | 2 ++ .../.app/client/lib/commands.js | 2 +- .../.app/client/startup/visitor.js | 11 +++++++ .../.app/client/views/livechatWindow.js | 2 ++ .../.app/client/views/options.js | 2 +- .../.app/client/views/switchDepartment.js | 2 +- .../.app/imports/client/visitor.js | 9 ++++++ packages/rocketchat-livechat/package.js | 1 + packages/rocketchat-livechat/roomType.js | 11 +++---- .../server/lib/Livechat.js | 31 +++++++++++++------ .../server/lib/QueueMethods.js | 6 ++-- .../server/methods/closeByVisitor.js | 16 +++++----- .../server/models/Rooms.js | 28 ++++++++++++----- .../server/visitorStatus.js | 8 +++++ 14 files changed, 95 insertions(+), 36 deletions(-) create mode 100644 packages/rocketchat-livechat/server/visitorStatus.js diff --git a/packages/rocketchat-livechat/.app/client/lib/chatMessages.js b/packages/rocketchat-livechat/.app/client/lib/chatMessages.js index 1b1a3c7975f0..a336a6283e3e 100644 --- a/packages/rocketchat-livechat/.app/client/lib/chatMessages.js +++ b/packages/rocketchat-livechat/.app/client/lib/chatMessages.js @@ -121,6 +121,8 @@ this.ChatMessages = class ChatMessages { ChatMessage.update(result._id, _.omit(result, '_id')); Livechat.room = result.rid; + visitor.setConnected(); + parentCall('callback', 'chat-started'); } }); diff --git a/packages/rocketchat-livechat/.app/client/lib/commands.js b/packages/rocketchat-livechat/.app/client/lib/commands.js index 23e10d3b9812..5851f34b1d69 100644 --- a/packages/rocketchat-livechat/.app/client/lib/commands.js +++ b/packages/rocketchat-livechat/.app/client/lib/commands.js @@ -17,7 +17,7 @@ this.Commands = { if (Livechat.transcript) { // @TODO get visitor email const user = Meteor.user(); - const email = user.visitorEmails && user.visitorEmails.length > 0 ? user.visitorEmails[0].address : ''; + const email = user && user.visitorEmails && user.visitorEmails.length > 0 ? user.visitorEmails[0].address : ''; swal({ title: t('Chat_ended'), diff --git a/packages/rocketchat-livechat/.app/client/startup/visitor.js b/packages/rocketchat-livechat/.app/client/startup/visitor.js index c9aae1ecac63..92b723bc05fa 100644 --- a/packages/rocketchat-livechat/.app/client/startup/visitor.js +++ b/packages/rocketchat-livechat/.app/client/startup/visitor.js @@ -16,3 +16,14 @@ Meteor.startup(() => { }); } }); + +Meteor.startup(() => { + let connected = false; + Tracker.autorun(function() { + var connectionStatus = Meteor.status(); + if (visitor.getRoom() && visitor.getToken() && connectionStatus.connected && !connected) { + connected = connectionStatus.connected; + visitor.setConnected(); + } + }); +}); diff --git a/packages/rocketchat-livechat/.app/client/views/livechatWindow.js b/packages/rocketchat-livechat/.app/client/views/livechatWindow.js index 0d56c2561c2c..24693a6262fc 100644 --- a/packages/rocketchat-livechat/.app/client/views/livechatWindow.js +++ b/packages/rocketchat-livechat/.app/client/views/livechatWindow.js @@ -115,6 +115,8 @@ Template.livechatWindow.onCreated(function() { if (result.room) { Livechat.room = result.room._id; + + visitor.setConnected(); } if (result.agentData) { diff --git a/packages/rocketchat-livechat/.app/client/views/options.js b/packages/rocketchat-livechat/.app/client/views/options.js index ec5bc787377f..4bde94255eef 100644 --- a/packages/rocketchat-livechat/.app/client/views/options.js +++ b/packages/rocketchat-livechat/.app/client/views/options.js @@ -26,7 +26,7 @@ Template.options.events({ closeOnConfirm: true, html: false }, () => { - Meteor.call('livechat:closeByVisitor', visitor.getRoom(), (error) => { + Meteor.call('livechat:closeByVisitor', { roomId: visitor.getRoom(), token: visitor.getToken() }, (error) => { if (error) { return console.log('Error ->', error); } diff --git a/packages/rocketchat-livechat/.app/client/views/switchDepartment.js b/packages/rocketchat-livechat/.app/client/views/switchDepartment.js index 803ec46d442d..80874c292ed7 100644 --- a/packages/rocketchat-livechat/.app/client/views/switchDepartment.js +++ b/packages/rocketchat-livechat/.app/client/views/switchDepartment.js @@ -45,7 +45,7 @@ Template.switchDepartment.events({ closeOnConfirm: true, html: false }, () => { - Meteor.call('livechat:closeByVisitor', visitor.getRoom(), (error) => { + Meteor.call('livechat:closeByVisitor', { roomId: visitor.getRoom(), token: visitor.getToken() }, (error) => { if (error) { return console.log('Error ->', error); } diff --git a/packages/rocketchat-livechat/.app/imports/client/visitor.js b/packages/rocketchat-livechat/.app/imports/client/visitor.js index ad121134c959..7fb60fbcd8c9 100644 --- a/packages/rocketchat-livechat/.app/imports/client/visitor.js +++ b/packages/rocketchat-livechat/.app/imports/client/visitor.js @@ -7,6 +7,7 @@ export default { room: new ReactiveVar(null), roomToSubscribe: new ReactiveVar(null), roomSubscribed: null, + connected: null, register() { if (!localStorage.getItem('visitorToken')) { @@ -70,5 +71,13 @@ export default { } } }); + }, + + setConnected() { + if (this.connected) { + return; + } + this.connected = true; + Meteor.call('UserPresence:connect', this.getToken(), { visitor: this.getToken() }); } }; diff --git a/packages/rocketchat-livechat/package.js b/packages/rocketchat-livechat/package.js index b0e49bc549f6..a46d9b0a6c05 100644 --- a/packages/rocketchat-livechat/package.js +++ b/packages/rocketchat-livechat/package.js @@ -45,6 +45,7 @@ Package.onUse(function(api) { api.addFiles('livechat.js', 'server'); api.addFiles('server/startup.js', 'server'); + api.addFiles('server/visitorStatus.js', 'server'); api.addFiles('permissions.js', 'server'); api.addFiles('messageTypes.js'); api.addFiles('roomType.js'); diff --git a/packages/rocketchat-livechat/roomType.js b/packages/rocketchat-livechat/roomType.js index 84e0ee616117..6effc0c378a2 100644 --- a/packages/rocketchat-livechat/roomType.js +++ b/packages/rocketchat-livechat/roomType.js @@ -38,19 +38,18 @@ RocketChat.roomTypes.add('l', 5, { }, getUserStatus(roomId) { - let guestName; const room = Session.get(`roomData${ roomId }`); if (room) { - guestName = room.v && room.v.username; + return room.v && room.v.status; } else { const inquiry = LivechatInquiry.findOne({ rid: roomId }); - guestName = inquiry && inquiry.v && inquiry.v.username; + return inquiry && inquiry.v && inquiry.v.status; } - if (guestName) { - return Session.get(`user_${ guestName }_status`); - } + // if (guestName) { + // return Session.get(`user_${ guestName }_status`); + // } }, notSubscribedTpl: { diff --git a/packages/rocketchat-livechat/server/lib/Livechat.js b/packages/rocketchat-livechat/server/lib/Livechat.js index d3e19ce5478a..50e3da16ce8a 100644 --- a/packages/rocketchat-livechat/server/lib/Livechat.js +++ b/packages/rocketchat-livechat/server/lib/Livechat.js @@ -198,16 +198,29 @@ RocketChat.Livechat = { return ret; }, - closeRoom({ user, room, comment }) { + closeRoom({ user, visitor, room, comment }) { const now = new Date(); - RocketChat.models.Rooms.closeByRoomId(room._id, { - user: { - _id: user._id, - username: user.username - }, + + const closeData = { closedAt: now, chatDuration: (now.getTime() - room.ts) / 1000 - }); + }; + + if (user) { + closeData.closer = 'user'; + closeData.closedBy = { + _id: user._id, + username: user.username + }; + } else if (visitor) { + closeData.closer = 'visitor'; + closeData.closedBy = { + _id: visitor._id, + username: visitor.username + }; + } + + RocketChat.models.Rooms.closeByRoomId(room._id, closeData); const message = { t: 'livechat-close', @@ -217,8 +230,8 @@ RocketChat.Livechat = { RocketChat.sendMessage(user, message, room); - RocketChat.models.Subscriptions.hideByRoomIdAndUserId(room._id, user._id); - RocketChat.models.Messages.createCommandWithRoomIdAndUser('promptTranscript', room._id, user); + RocketChat.models.Subscriptions.hideByRoomIdAndUserId(room._id, room.servedBy._id); + RocketChat.models.Messages.createCommandWithRoomIdAndUser('promptTranscript', room._id, room.servedBy); Meteor.defer(() => { RocketChat.callbacks.run('livechat.closeRoom', room); diff --git a/packages/rocketchat-livechat/server/lib/QueueMethods.js b/packages/rocketchat-livechat/server/lib/QueueMethods.js index 425dc26fdded..09ea166fb61b 100644 --- a/packages/rocketchat-livechat/server/lib/QueueMethods.js +++ b/packages/rocketchat-livechat/server/lib/QueueMethods.js @@ -24,7 +24,8 @@ RocketChat.QueueMethods = { v: { _id: guest._id, username: guest.username, - token: message.token + token: message.token, + status: guest.status }, servedBy: { _id: agent.agentId, @@ -123,7 +124,8 @@ RocketChat.QueueMethods = { v: { _id: guest._id, username: guest.username, - token: message.token + token: message.token, + status: guest.status }, cl: false, open: true, diff --git a/packages/rocketchat-livechat/server/methods/closeByVisitor.js b/packages/rocketchat-livechat/server/methods/closeByVisitor.js index 4aa20f1a1c8c..c6c54596c53d 100644 --- a/packages/rocketchat-livechat/server/methods/closeByVisitor.js +++ b/packages/rocketchat-livechat/server/methods/closeByVisitor.js @@ -1,21 +1,19 @@ -Meteor.methods({ - 'livechat:closeByVisitor'(roomId) { - if (!Meteor.userId()) { - throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'livechat:closeByVisitor' }); - } +import LivechatVisitors from '../models/LivechatVisitors'; - const room = RocketChat.models.Rooms.findOneOpenByVisitorId(Meteor.userId(), roomId); +Meteor.methods({ + 'livechat:closeByVisitor'({ roomId, token }) { + const room = RocketChat.models.Rooms.findOneOpenByVisitorToken(token, roomId); if (!room || !room.open) { return false; } - const user = Meteor.user(); + const visitor = LivechatVisitors.getVisitorByToken(token); - const language = (user && user.language) || RocketChat.settings.get('language') || 'en'; + const language = (visitor && visitor.language) || RocketChat.settings.get('language') || 'en'; return RocketChat.Livechat.closeRoom({ - user, + visitor, room, comment: TAPi18n.__('Closed_by_visitor', { lng: language }) }); diff --git a/packages/rocketchat-livechat/server/models/Rooms.js b/packages/rocketchat-livechat/server/models/Rooms.js index f22755901968..ea3fdc6158b0 100644 --- a/packages/rocketchat-livechat/server/models/Rooms.js +++ b/packages/rocketchat-livechat/server/models/Rooms.js @@ -115,11 +115,11 @@ RocketChat.models.Rooms.findByVisitorId = function(visitorId) { return this.find(query); }; -RocketChat.models.Rooms.findOneOpenByVisitorId = function(visitorId, roomId) { +RocketChat.models.Rooms.findOneOpenByVisitorToken = function(token, roomId) { const query = { _id: roomId, open: true, - 'v._id': visitorId + 'v.token': token }; return this.findOne(query); @@ -148,12 +148,11 @@ RocketChat.models.Rooms.closeByRoomId = function(roomId, closeInfo) { _id: roomId }, { $set: { - closedBy: { - _id: closeInfo.user._id, - username: closeInfo.user.username - }, + closer: closeInfo.closer, + closedBy: closeInfo.closedBy, closedAt: closeInfo.closedAt, - chatDuration: closeInfo.chatDuration + chatDuration: closeInfo.chatDuration, + 'v.status': 'offline' }, $unset: { open: 1 @@ -202,3 +201,18 @@ RocketChat.models.Rooms.saveCRMDataByRoomId = function(roomId, crmData) { return this.update(query, update); }; + +RocketChat.models.Rooms.updateVisitorStatus = function(token, status) { + const query = { + 'v.token': token, + open: true + }; + + const update = { + $set: { + 'v.status': status + } + }; + + return this.update(query, update); +}; diff --git a/packages/rocketchat-livechat/server/visitorStatus.js b/packages/rocketchat-livechat/server/visitorStatus.js new file mode 100644 index 000000000000..c28b364cb371 --- /dev/null +++ b/packages/rocketchat-livechat/server/visitorStatus.js @@ -0,0 +1,8 @@ +/* globals UserPresenceEvents */ +Meteor.startup(() => { + UserPresenceEvents.on('setStatus', (session, status) => { + if (session && session.metadata && session.metadata.visitor) { + RocketChat.models.Rooms.updateVisitorStatus(session.metadata.visitor, status); + } + }); +}); From 28886fbf43c7f277dfefaeab0e7216c9a7e25a15 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 30 Nov 2017 16:47:03 -0200 Subject: [PATCH 08/16] Set visitor status on setStatus event --- .../rocketchat-livechat/server/models/LivechatVisitors.js | 3 +++ packages/rocketchat-livechat/server/visitorStatus.js | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/rocketchat-livechat/server/models/LivechatVisitors.js b/packages/rocketchat-livechat/server/models/LivechatVisitors.js index 85f0aecccfd5..fe8c4a915119 100644 --- a/packages/rocketchat-livechat/server/models/LivechatVisitors.js +++ b/packages/rocketchat-livechat/server/models/LivechatVisitors.js @@ -1,3 +1,6 @@ +import _ from 'underscore'; +import s from 'underscore.string'; + class LivechatVisitors extends RocketChat.models._Base { constructor() { super('livechat_visitor'); diff --git a/packages/rocketchat-livechat/server/visitorStatus.js b/packages/rocketchat-livechat/server/visitorStatus.js index c28b364cb371..70806f288f7a 100644 --- a/packages/rocketchat-livechat/server/visitorStatus.js +++ b/packages/rocketchat-livechat/server/visitorStatus.js @@ -1,8 +1,8 @@ /* globals UserPresenceEvents */ Meteor.startup(() => { - UserPresenceEvents.on('setStatus', (session, status) => { - if (session && session.metadata && session.metadata.visitor) { - RocketChat.models.Rooms.updateVisitorStatus(session.metadata.visitor, status); + UserPresenceEvents.on('setStatus', (session, status, metadata) => { + if (metadata && metadata.visitor) { + RocketChat.models.Rooms.updateVisitorStatus(metadata.visitor, status); } }); }); From b1fba322ae6b10eac3dcf70e02d2892507d66b35 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Mon, 4 Dec 2017 18:09:13 -0200 Subject: [PATCH 09/16] Track visitor's presence --- .meteor/versions | 2 +- package-lock.json | 924 +----------------- .../.npm/package/npm-shrinkwrap.json | 36 +- .../server/functions/loadMessageHistory.js | 2 + .../rocketchat-livechat/.app/.meteor/packages | 2 + .../rocketchat-livechat/.app/.meteor/versions | 2 + .../.app/imports/client/visitor.js | 5 + .../.app/package-lock.json | 750 ++++++++++++++ .../server/lib/Livechat.js | 2 +- .../server/lib/QueueMethods.js | 5 +- .../server/models/Users.js | 2 - 11 files changed, 796 insertions(+), 936 deletions(-) create mode 100644 packages/rocketchat-livechat/.app/package-lock.json diff --git a/.meteor/versions b/.meteor/versions index cb1f95c189ed..99a60a97cd3d 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -69,7 +69,7 @@ konecty:delayed-task@1.0.0 konecty:mongo-counter@0.0.5_3 konecty:multiple-instances-status@1.0.6_1 konecty:nrr@2.0.2 -konecty:user-presence@1.2.9 +konecty:user-presence@2.0.0 launch-screen@1.1.1 less@2.7.11 livedata@1.0.18 diff --git a/package-lock.json b/package-lock.json index 9827c6fdf1d0..094ac697d04e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,7 @@ "@google-cloud/storage": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/@google-cloud/storage/-/storage-1.4.0.tgz", - "integrity": "sha1-r1vKwqmGmJxG81Kxyhgzvns4Pds=", + "integrity": "sha512-vt1NU7D12OGYPhWfwBD1Q2qFS6Suykorlp3NLaES2W9CW6sEBWLwScxElXt8nPvonYBCFt99jP4g1AqY+0hefw==", "requires": { "@google-cloud/common": "0.13.6", "arrify": "1.0.1", @@ -352,7 +352,7 @@ "autoprefixer": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-7.1.6.tgz", - "integrity": "sha512-C9yv/UF3X+eJTi/zvfxuyfxmLibYrntpF3qoJYrMeQwgUJOZrZvpJiMG2FMQ3qnhWtF/be4pYONBBw95ZGe3vA==", + "integrity": "sha1-+5MwOfdK90qD5xIlznjZ/Vi6hNc=", "dev": true, "requires": { "browserslist": "2.6.1", @@ -1780,7 +1780,6 @@ "requires": { "anymatch": "1.3.2", "async-each": "1.0.1", - "fsevents": "1.1.2", "glob-parent": "2.0.0", "inherits": "2.0.3", "is-binary-path": "1.0.1", @@ -1884,7 +1883,7 @@ "codemirror": { "version": "5.31.0", "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.31.0.tgz", - "integrity": "sha1-7PPQV+t0F0FHBmv8fF83tMTgffI=" + "integrity": "sha512-LKbMZKoAz7pMmWuSEl253G6yyloSulj1kXfvYv+3n3I8wMiI7QwnCHwKM3Zw5S9ItNV28Layq0/ihQXWmn9T9w==" }, "color-convert": { "version": "1.9.0", @@ -1918,7 +1917,7 @@ "commander": { "version": "2.11.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", - "integrity": "sha1-FXFS/R56bI2YpbcVzzdt+SgARWM=", + "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==", "dev": true }, "compare-func": { @@ -2666,7 +2665,7 @@ "es-abstract": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.9.0.tgz", - "integrity": "sha1-aQgpoHyuNrIi5/2bdcDQVz6yUic=", + "integrity": "sha512-kk3IJoKo7A3pWJc0OV8yZ/VEX2oSUytfekrJiqoxBlKJMFAJVJVpGdHClCCTdv+Fn2zHfpDHHIelMFhZVfef3Q==", "requires": { "es-to-primitive": "1.1.1", "function-bind": "1.1.1", @@ -2929,7 +2928,7 @@ "external-editor": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.0.5.tgz", - "integrity": "sha1-UsJJo5gbm6GHx8rPW+tQvx2Rprw=", + "integrity": "sha512-Msjo64WT5W+NhOpQXh0nOHm+n0RfU1QUwDnKYvJ8dEJ8zlwLrqXNTv5mSUTJpepf41PDJGyhueTw2vNZW+Fr/w==", "dev": true, "requires": { "iconv-lite": "0.4.19", @@ -3239,905 +3238,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, - "fsevents": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.2.tgz", - "integrity": "sha1-MoK3E/s62A7eDp/PRhG1qm/AM/Q=", - "dev": true, - "optional": true, - "requires": { - "nan": "2.6.2", - "node-pre-gyp": "0.6.36" - }, - "dependencies": { - "abbrev": { - "version": "1.1.0", - "bundled": true, - "dev": true, - "optional": true - }, - "ajv": { - "version": "4.11.8", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "co": "4.6.0", - "json-stable-stringify": "1.0.1" - } - }, - "ansi-regex": { - "version": "2.1.1", - "bundled": true, - "dev": true - }, - "aproba": { - "version": "1.1.1", - "bundled": true, - "dev": true, - "optional": true - }, - "are-we-there-yet": { - "version": "1.1.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "delegates": "1.0.0", - "readable-stream": "2.2.9" - } - }, - "asn1": { - "version": "0.2.3", - "bundled": true, - "dev": true, - "optional": true - }, - "assert-plus": { - "version": "0.2.0", - "bundled": true, - "dev": true, - "optional": true - }, - "asynckit": { - "version": "0.4.0", - "bundled": true, - "dev": true, - "optional": true - }, - "aws-sign2": { - "version": "0.6.0", - "bundled": true, - "dev": true, - "optional": true - }, - "aws4": { - "version": "1.6.0", - "bundled": true, - "dev": true, - "optional": true - }, - "balanced-match": { - "version": "0.4.2", - "bundled": true, - "dev": true - }, - "bcrypt-pbkdf": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "tweetnacl": "0.14.5" - } - }, - "block-stream": { - "version": "0.0.9", - "bundled": true, - "dev": true, - "requires": { - "inherits": "2.0.3" - } - }, - "boom": { - "version": "2.10.1", - "bundled": true, - "dev": true, - "requires": { - "hoek": "2.16.3" - } - }, - "brace-expansion": { - "version": "1.1.7", - "bundled": true, - "dev": true, - "requires": { - "balanced-match": "0.4.2", - "concat-map": "0.0.1" - } - }, - "buffer-shims": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "caseless": { - "version": "0.12.0", - "bundled": true, - "dev": true, - "optional": true - }, - "co": { - "version": "4.6.0", - "bundled": true, - "dev": true, - "optional": true - }, - "code-point-at": { - "version": "1.1.0", - "bundled": true, - "dev": true - }, - "combined-stream": { - "version": "1.0.5", - "bundled": true, - "dev": true, - "requires": { - "delayed-stream": "1.0.0" - } - }, - "concat-map": { - "version": "0.0.1", - "bundled": true, - "dev": true - }, - "console-control-strings": { - "version": "1.1.0", - "bundled": true, - "dev": true - }, - "core-util-is": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "cryptiles": { - "version": "2.0.5", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "boom": "2.10.1" - } - }, - "dashdash": { - "version": "1.14.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "debug": { - "version": "2.6.8", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "ms": "2.0.0" - } - }, - "deep-extend": { - "version": "0.4.2", - "bundled": true, - "dev": true, - "optional": true - }, - "delayed-stream": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "delegates": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "ecc-jsbn": { - "version": "0.1.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "jsbn": "0.1.1" - } - }, - "extend": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "extsprintf": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "forever-agent": { - "version": "0.6.1", - "bundled": true, - "dev": true, - "optional": true - }, - "form-data": { - "version": "2.1.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "asynckit": "0.4.0", - "combined-stream": "1.0.5", - "mime-types": "2.1.15" - } - }, - "fs.realpath": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "fstream": { - "version": "1.0.11", - "bundled": true, - "dev": true, - "requires": { - "graceful-fs": "4.1.11", - "inherits": "2.0.3", - "mkdirp": "0.5.1", - "rimraf": "2.6.1" - } - }, - "fstream-ignore": { - "version": "1.0.5", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "fstream": "1.0.11", - "inherits": "2.0.3", - "minimatch": "3.0.4" - } - }, - "gauge": { - "version": "2.7.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "aproba": "1.1.1", - "console-control-strings": "1.1.0", - "has-unicode": "2.0.1", - "object-assign": "4.1.1", - "signal-exit": "3.0.2", - "string-width": "1.0.2", - "strip-ansi": "3.0.1", - "wide-align": "1.1.2" - } - }, - "getpass": { - "version": "0.1.7", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "glob": { - "version": "7.1.2", - "bundled": true, - "dev": true, - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - }, - "graceful-fs": { - "version": "4.1.11", - "bundled": true, - "dev": true - }, - "har-schema": { - "version": "1.0.5", - "bundled": true, - "dev": true, - "optional": true - }, - "har-validator": { - "version": "4.2.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "ajv": "4.11.8", - "har-schema": "1.0.5" - } - }, - "has-unicode": { - "version": "2.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "hawk": { - "version": "3.1.3", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "boom": "2.10.1", - "cryptiles": "2.0.5", - "hoek": "2.16.3", - "sntp": "1.0.9" - } - }, - "hoek": { - "version": "2.16.3", - "bundled": true, - "dev": true - }, - "http-signature": { - "version": "1.1.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "0.2.0", - "jsprim": "1.4.0", - "sshpk": "1.13.0" - } - }, - "inflight": { - "version": "1.0.6", - "bundled": true, - "dev": true, - "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" - } - }, - "inherits": { - "version": "2.0.3", - "bundled": true, - "dev": true - }, - "ini": { - "version": "1.3.4", - "bundled": true, - "dev": true, - "optional": true - }, - "is-fullwidth-code-point": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "requires": { - "number-is-nan": "1.0.1" - } - }, - "is-typedarray": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "isarray": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "isstream": { - "version": "0.1.2", - "bundled": true, - "dev": true, - "optional": true - }, - "jodid25519": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "jsbn": "0.1.1" - } - }, - "jsbn": { - "version": "0.1.1", - "bundled": true, - "dev": true, - "optional": true - }, - "json-schema": { - "version": "0.2.3", - "bundled": true, - "dev": true, - "optional": true - }, - "json-stable-stringify": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "jsonify": "0.0.0" - } - }, - "json-stringify-safe": { - "version": "5.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "jsonify": { - "version": "0.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "jsprim": { - "version": "1.4.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "1.0.0", - "extsprintf": "1.0.2", - "json-schema": "0.2.3", - "verror": "1.3.6" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "mime-db": { - "version": "1.27.0", - "bundled": true, - "dev": true - }, - "mime-types": { - "version": "2.1.15", - "bundled": true, - "dev": true, - "requires": { - "mime-db": "1.27.0" - } - }, - "minimatch": { - "version": "3.0.4", - "bundled": true, - "dev": true, - "requires": { - "brace-expansion": "1.1.7" - } - }, - "minimist": { - "version": "0.0.8", - "bundled": true, - "dev": true - }, - "mkdirp": { - "version": "0.5.1", - "bundled": true, - "dev": true, - "requires": { - "minimist": "0.0.8" - } - }, - "ms": { - "version": "2.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "node-pre-gyp": { - "version": "0.6.36", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "mkdirp": "0.5.1", - "nopt": "4.0.1", - "npmlog": "4.1.0", - "rc": "1.2.1", - "request": "2.81.0", - "rimraf": "2.6.1", - "semver": "5.3.0", - "tar": "2.2.1", - "tar-pack": "3.4.0" - } - }, - "nopt": { - "version": "4.0.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "abbrev": "1.1.0", - "osenv": "0.1.4" - } - }, - "npmlog": { - "version": "4.1.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "are-we-there-yet": "1.1.4", - "console-control-strings": "1.1.0", - "gauge": "2.7.4", - "set-blocking": "2.0.0" - } - }, - "number-is-nan": { - "version": "1.0.1", - "bundled": true, - "dev": true - }, - "oauth-sign": { - "version": "0.8.2", - "bundled": true, - "dev": true, - "optional": true - }, - "object-assign": { - "version": "4.1.1", - "bundled": true, - "dev": true, - "optional": true - }, - "once": { - "version": "1.4.0", - "bundled": true, - "dev": true, - "requires": { - "wrappy": "1.0.2" - } - }, - "os-homedir": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "os-tmpdir": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "osenv": { - "version": "0.1.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "os-homedir": "1.0.2", - "os-tmpdir": "1.0.2" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "bundled": true, - "dev": true - }, - "performance-now": { - "version": "0.2.0", - "bundled": true, - "dev": true, - "optional": true - }, - "process-nextick-args": { - "version": "1.0.7", - "bundled": true, - "dev": true - }, - "punycode": { - "version": "1.4.1", - "bundled": true, - "dev": true, - "optional": true - }, - "qs": { - "version": "6.4.0", - "bundled": true, - "dev": true, - "optional": true - }, - "rc": { - "version": "1.2.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "deep-extend": "0.4.2", - "ini": "1.3.4", - "minimist": "1.2.0", - "strip-json-comments": "2.0.1" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "readable-stream": { - "version": "2.2.9", - "bundled": true, - "dev": true, - "requires": { - "buffer-shims": "1.0.0", - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "1.0.7", - "string_decoder": "1.0.1", - "util-deprecate": "1.0.2" - } - }, - "request": { - "version": "2.81.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "aws-sign2": "0.6.0", - "aws4": "1.6.0", - "caseless": "0.12.0", - "combined-stream": "1.0.5", - "extend": "3.0.1", - "forever-agent": "0.6.1", - "form-data": "2.1.4", - "har-validator": "4.2.1", - "hawk": "3.1.3", - "http-signature": "1.1.1", - "is-typedarray": "1.0.0", - "isstream": "0.1.2", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.15", - "oauth-sign": "0.8.2", - "performance-now": "0.2.0", - "qs": "6.4.0", - "safe-buffer": "5.0.1", - "stringstream": "0.0.5", - "tough-cookie": "2.3.2", - "tunnel-agent": "0.6.0", - "uuid": "3.0.1" - } - }, - "rimraf": { - "version": "2.6.1", - "bundled": true, - "dev": true, - "requires": { - "glob": "7.1.2" - } - }, - "safe-buffer": { - "version": "5.0.1", - "bundled": true, - "dev": true - }, - "semver": { - "version": "5.3.0", - "bundled": true, - "dev": true, - "optional": true - }, - "set-blocking": { - "version": "2.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "signal-exit": { - "version": "3.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "sntp": { - "version": "1.0.9", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "hoek": "2.16.3" - } - }, - "sshpk": { - "version": "1.13.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "asn1": "0.2.3", - "assert-plus": "1.0.0", - "bcrypt-pbkdf": "1.0.1", - "dashdash": "1.14.1", - "ecc-jsbn": "0.1.1", - "getpass": "0.1.7", - "jodid25519": "1.0.2", - "jsbn": "0.1.1", - "tweetnacl": "0.14.5" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "string-width": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "requires": { - "code-point-at": "1.1.0", - "is-fullwidth-code-point": "1.0.0", - "strip-ansi": "3.0.1" - } - }, - "string_decoder": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "requires": { - "safe-buffer": "5.0.1" - } - }, - "stringstream": { - "version": "0.0.5", - "bundled": true, - "dev": true, - "optional": true - }, - "strip-ansi": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "requires": { - "ansi-regex": "2.1.1" - } - }, - "strip-json-comments": { - "version": "2.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "tar": { - "version": "2.2.1", - "bundled": true, - "dev": true, - "requires": { - "block-stream": "0.0.9", - "fstream": "1.0.11", - "inherits": "2.0.3" - } - }, - "tar-pack": { - "version": "3.4.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "debug": "2.6.8", - "fstream": "1.0.11", - "fstream-ignore": "1.0.5", - "once": "1.4.0", - "readable-stream": "2.2.9", - "rimraf": "2.6.1", - "tar": "2.2.1", - "uid-number": "0.0.6" - } - }, - "tough-cookie": { - "version": "2.3.2", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "punycode": "1.4.1" - } - }, - "tunnel-agent": { - "version": "0.6.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "safe-buffer": "5.0.1" - } - }, - "tweetnacl": { - "version": "0.14.5", - "bundled": true, - "dev": true, - "optional": true - }, - "uid-number": { - "version": "0.0.6", - "bundled": true, - "dev": true, - "optional": true - }, - "util-deprecate": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "uuid": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "verror": { - "version": "1.3.6", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "extsprintf": "1.0.2" - } - }, - "wide-align": { - "version": "1.1.2", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "string-width": "1.0.2" - } - }, - "wrappy": { - "version": "1.0.2", - "bundled": true, - "dev": true - } - } - }, "fstream": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz", @@ -4405,7 +3505,7 @@ "google-auto-auth": { "version": "0.7.2", "resolved": "https://registry.npmjs.org/google-auto-auth/-/google-auto-auth-0.7.2.tgz", - "integrity": "sha1-v5NS1cSgiXvzH9nEkQKLdl++px4=", + "integrity": "sha512-ux2n2AE2g3+vcLXwL4dP/M12SFMRX5dzCzBfhAEkTeAB7dpyGdOIEj7nmUx0BHKaCcUQrRWg9kT63X/Mmtk1+A==", "requires": { "async": "2.5.0", "gcp-metadata": "0.3.1", @@ -5535,7 +4635,7 @@ "jschardet": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/jschardet/-/jschardet-1.6.0.tgz", - "integrity": "sha1-x9GnHtz/KDnbL57DD8XV69PBpng=", + "integrity": "sha512-xYuhvQ7I9PDJIGBWev9xm0+SMSed3ZDBAmvVjbFR1ZRLAF+vlXcQu6cRI9uAlj81rzikElRVteehwV7DuX2ZmQ==", "dev": true }, "jsesc": { @@ -6073,7 +5173,7 @@ "mime": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", - "integrity": "sha1-Eh+evEnjdm8xGnbh+hyAA8SwOqY=" + "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==" }, "mime-db": { "version": "1.31.0", @@ -6927,7 +6027,7 @@ "postcss-custom-properties": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/postcss-custom-properties/-/postcss-custom-properties-6.2.0.tgz", - "integrity": "sha512-eNR2h9T9ciKMoQEORrPjH33XeN/nuvVuxArOKmHtsFbGbNss631tgTrKou3/pmjAZbA4QQkhLIkPQkIk3WW+8w==", + "integrity": "sha1-XZKafwbpuE4PETNBlMC6mjCs++k=", "dev": true, "requires": { "balanced-match": "1.0.0", @@ -7035,7 +6135,7 @@ "postcss-nesting": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/postcss-nesting/-/postcss-nesting-3.0.0.tgz", - "integrity": "sha512-ijQlEXUcYXXNPdLMFcMEr4i5SEPRKR8fq/Iya4L0mQbNOCz+szTGCBlf0Cvu2HiQLjCNqLnGO4fKFLbNnXe7Ag==", + "integrity": "sha1-sKdJ1+/xHSVQoE3qZCtpXXWC+x0=", "dev": true, "requires": { "postcss": "6.0.13" @@ -8179,7 +7279,7 @@ "stylelint": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/stylelint/-/stylelint-8.2.0.tgz", - "integrity": "sha1-ahUERVP7XDFDsW1iATo3AxRJWw0=", + "integrity": "sha512-57JWIz/1Uh9ehZMZyAqlFC0EDfQrMXCH8yqt8ZuJQQvV3LBKgAM/JYd+CWi1hC4eJtRODSPbIIBYKdGjkPZdMg==", "dev": true, "requires": { "autoprefixer": "7.1.6", diff --git a/packages/rocketchat-google-vision/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-google-vision/.npm/package/npm-shrinkwrap.json index 2b45ef4db29d..3f07f9cdfbe4 100644 --- a/packages/rocketchat-google-vision/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-google-vision/.npm/package/npm-shrinkwrap.json @@ -2,9 +2,9 @@ "lockfileVersion": 1, "dependencies": { "ajv": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.3.0.tgz", - "integrity": "sha1-RBT/dKUIecII7l/cgm4ywwNUnto=" + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.0.tgz", + "integrity": "sha1-6yhAdG6dxIvV4GOjbj/UAMXqtak=" }, "ansi-regex": { "version": "2.1.1", @@ -331,9 +331,9 @@ "integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=" }, "protobufjs": { - "version": "6.8.0", - "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.8.0.tgz", - "integrity": "sha512-47Y49f5JN5Qsbxas2TyI2zFO8j9GpQAQm5thf54fr2O8qcP/jkIXYxmYx1hN2WQFAhESU1xpVn5NWVDBB8WFnw==" + "version": "6.8.3", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.8.3.tgz", + "integrity": "sha512-/iQhTYnSniRNmdRF9Kvw8odMSokwNOWVDOmMJjW64+EVE6igcdj/82Op/4MJ/WimgMRNac7gChlSVX4Gep/tHg==" } } }, @@ -353,9 +353,9 @@ "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" }, "grpc": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/grpc/-/grpc-1.7.1.tgz", - "integrity": "sha512-lMgjZUzJx09VL5iCfs7rFagE5htikdv/9VzX/ji3zuwlzAhijqcU47bi5N5lbVw/UB2fxneeYg8sBTfQfd0c4A==", + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/grpc/-/grpc-1.7.2.tgz", + "integrity": "sha512-GH6xziNGjW8LAtqQ3HmYI7Tx8BIlr46iaMRXHfh46kkaOP6PNWUx47ULNTUlXSYR3P00d0Pl8uzodTLwPk805w==", "dependencies": { "abbrev": { "version": "1.0.9", @@ -1099,9 +1099,9 @@ "integrity": "sha1-6AomYY5S9cQiKGG7dIUQvRDikIk=" }, "mime": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", - "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==" + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" }, "mime-db": { "version": "1.30.0", @@ -1124,9 +1124,9 @@ "integrity": "sha1-O0tCACOmbKfjK9uhbnEJN+FNGws=" }, "nan": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.7.0.tgz", - "integrity": "sha1-2Vv3IeyHfgjbJ27T/G63j5CDrUY=" + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz", + "integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo=" }, "node-forge": { "version": "0.7.1", @@ -1209,9 +1209,9 @@ "integrity": "sha1-WXSNfc8D0tsiwT2p/rAk4Wq4DJE=" }, "pump": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/pump/-/pump-1.0.2.tgz", - "integrity": "sha1-Oz7mUS+U8OV1U4wXmV+fFpkKXVE=" + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/pump/-/pump-1.0.3.tgz", + "integrity": "sha512-8k0JupWme55+9tCVE+FS5ULT3K6AbgqrGa58lTT49RpyfwwcGedHqaC5LlQNdEAumn/wFsu6aPwkuPMioy8kqw==" }, "pumpify": { "version": "1.3.5", diff --git a/packages/rocketchat-lib/server/functions/loadMessageHistory.js b/packages/rocketchat-lib/server/functions/loadMessageHistory.js index f98ba1efe977..f09d9030353f 100644 --- a/packages/rocketchat-lib/server/functions/loadMessageHistory.js +++ b/packages/rocketchat-lib/server/functions/loadMessageHistory.js @@ -1,3 +1,5 @@ +import _ from 'underscore'; + const hideMessagesOfType = []; RocketChat.settings.get(/Message_HideType_.+/, function(key, value) { diff --git a/packages/rocketchat-livechat/.app/.meteor/packages b/packages/rocketchat-livechat/.app/.meteor/packages index 312eb359bf88..4cf1c124f0ea 100644 --- a/packages/rocketchat-livechat/.app/.meteor/packages +++ b/packages/rocketchat-livechat/.app/.meteor/packages @@ -38,3 +38,5 @@ standard-minifier-css@1.3.5 standard-minifier-js@2.2.0 shell-server@0.3.0 dynamic-import@0.2.0 + +konecty:user-presence diff --git a/packages/rocketchat-livechat/.app/.meteor/versions b/packages/rocketchat-livechat/.app/.meteor/versions index 3ac0ab1989a9..367cf492983c 100644 --- a/packages/rocketchat-livechat/.app/.meteor/versions +++ b/packages/rocketchat-livechat/.app/.meteor/versions @@ -40,6 +40,7 @@ jquery@1.11.10 kadira:blaze-layout@2.3.0 kadira:flow-router@2.12.1 konecty:nrr@2.0.2 +konecty:user-presence@2.0.0 less@2.7.11 livedata@1.0.18 localstorage@1.2.0 @@ -57,6 +58,7 @@ momentjs:moment@2.19.1 mongo@1.3.0 mongo-dev-server@1.1.0 mongo-id@1.0.6 +nooitaf:colors@1.1.2_1 npm-bcrypt@0.9.3 npm-mongo@2.2.33 observe-sequence@1.0.16 diff --git a/packages/rocketchat-livechat/.app/imports/client/visitor.js b/packages/rocketchat-livechat/.app/imports/client/visitor.js index 7fb60fbcd8c9..b02ed8a63bd3 100644 --- a/packages/rocketchat-livechat/.app/imports/client/visitor.js +++ b/packages/rocketchat-livechat/.app/imports/client/visitor.js @@ -79,5 +79,10 @@ export default { } this.connected = true; Meteor.call('UserPresence:connect', this.getToken(), { visitor: this.getToken() }); + + Meteor.startup(function() { + UserPresence.awayTime = 300000; // 5 minutes + UserPresence.start(this.getToken()); + }); } }; diff --git a/packages/rocketchat-livechat/.app/package-lock.json b/packages/rocketchat-livechat/.app/package-lock.json new file mode 100644 index 000000000000..2eda1637c29e --- /dev/null +++ b/packages/rocketchat-livechat/.app/package-lock.json @@ -0,0 +1,750 @@ +{ + "name": "rocketchat-livechat", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "abbrev": { + "version": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha1-+PLIh60Qv2f2NPAFtph/7TF5qsg=" + }, + "ajv": { + "version": "https://registry.npmjs.org/ajv/-/ajv-5.5.0.tgz", + "integrity": "sha1-6yhAdG6dxIvV4GOjbj/UAMXqtak=", + "requires": { + "co": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", + "fast-deep-equal": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz", + "fast-json-stable-stringify": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", + "json-schema-traverse": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz" + } + }, + "ansi-regex": { + "version": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + }, + "aproba": { + "version": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", + "integrity": "sha1-aALmJk79GMeQobDVF/DyYnvyyUo=" + }, + "are-we-there-yet": { + "version": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.4.tgz", + "integrity": "sha1-u13KOCu5TwXhUZQ3PRb9O6HKEQ0=", + "requires": { + "delegates": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "readable-stream": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz" + } + }, + "asn1": { + "version": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", + "integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=" + }, + "assert-plus": { + "version": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" + }, + "asynckit": { + "version": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, + "autolinker": { + "version": "https://registry.npmjs.org/autolinker/-/autolinker-1.6.0.tgz", + "integrity": "sha1-utN2t62OQV8i8QL8Dzf2QOZPHL8=" + }, + "aws-sign2": { + "version": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", + "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" + }, + "aws4": { + "version": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz", + "integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4=" + }, + "babel-runtime": { + "version": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", + "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", + "requires": { + "core-js": "https://registry.npmjs.org/core-js/-/core-js-2.5.1.tgz", + "regenerator-runtime": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz" + } + }, + "balanced-match": { + "version": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, + "bcrypt": { + "version": "https://registry.npmjs.org/bcrypt/-/bcrypt-1.0.3.tgz", + "integrity": "sha1-sC3cbAtS6ha40883XVoy54DatUg=", + "requires": { + "nan": "https://registry.npmjs.org/nan/-/nan-2.6.2.tgz", + "node-pre-gyp": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.6.36.tgz" + } + }, + "bcrypt-pbkdf": { + "version": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", + "integrity": "sha1-Y7xdy2EzG5K8Bf1SiVPDNGKgb40=", + "optional": true, + "requires": { + "tweetnacl": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz" + } + }, + "block-stream": { + "version": "https://registry.npmjs.org/block-stream/-/block-stream-0.0.9.tgz", + "integrity": "sha1-E+v+d4oDIFz+A3UUgeu0szAMEmo=", + "requires": { + "inherits": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz" + } + }, + "boom": { + "version": "https://registry.npmjs.org/boom/-/boom-4.3.1.tgz", + "integrity": "sha1-T4owBctKfjiJ90kDD9JbluAdLjE=", + "requires": { + "hoek": "https://registry.npmjs.org/hoek/-/hoek-4.2.0.tgz" + } + }, + "brace-expansion": { + "version": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", + "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", + "requires": { + "balanced-match": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "concat-map": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz" + } + }, + "caseless": { + "version": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" + }, + "co": { + "version": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", + "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=" + }, + "code-point-at": { + "version": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" + }, + "combined-stream": { + "version": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", + "integrity": "sha1-k4NwpXtKUd6ix3wV1cX9+JUWQAk=", + "requires": { + "delayed-stream": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz" + } + }, + "concat-map": { + "version": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "console-control-strings": { + "version": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=" + }, + "core-js": { + "version": "https://registry.npmjs.org/core-js/-/core-js-2.5.1.tgz", + "integrity": "sha1-rmh03GaTd4m4B1T/VCjfZoGcpQs=" + }, + "core-util-is": { + "version": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "cryptiles": { + "version": "https://registry.npmjs.org/cryptiles/-/cryptiles-3.1.2.tgz", + "integrity": "sha1-qJ+7Ig9c4l7FboxKqKT9e1sNKf4=", + "requires": { + "boom": "https://registry.npmjs.org/boom/-/boom-5.2.0.tgz" + }, + "dependencies": { + "boom": { + "version": "https://registry.npmjs.org/boom/-/boom-5.2.0.tgz", + "integrity": "sha1-XdnabuOl8wIHdDYpDLcX0/SlTgI=", + "requires": { + "hoek": "https://registry.npmjs.org/hoek/-/hoek-4.2.0.tgz" + } + } + } + }, + "dashdash": { + "version": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "requires": { + "assert-plus": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz" + } + }, + "debug": { + "version": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha1-XRKFFd8TT/Mn6QpMk/Tgd6U2NB8=", + "requires": { + "ms": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz" + } + }, + "deep-extend": { + "version": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.4.2.tgz", + "integrity": "sha1-SLaZwn4zS/ifEIkr5DL25MfTSn8=" + }, + "delayed-stream": { + "version": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" + }, + "delegates": { + "version": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=" + }, + "ecc-jsbn": { + "version": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", + "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=", + "optional": true, + "requires": { + "jsbn": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz" + } + }, + "extend": { + "version": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", + "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=" + }, + "extsprintf": { + "version": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" + }, + "fast-deep-equal": { + "version": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz", + "integrity": "sha1-liVqO8l1WV6zbYLpkp0GDYk0Of8=" + }, + "fast-json-stable-stringify": { + "version": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", + "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" + }, + "forever-agent": { + "version": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" + }, + "form-data": { + "version": "https://registry.npmjs.org/form-data/-/form-data-2.3.1.tgz", + "integrity": "sha1-b7lPvXGIUwbXPRXMSX/kzE7NRL8=", + "requires": { + "asynckit": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "combined-stream": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", + "mime-types": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz" + } + }, + "fs.realpath": { + "version": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "fstream": { + "version": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz", + "integrity": "sha1-XB+x8RdHcRTwYyoOtLcbPLD9MXE=", + "requires": { + "graceful-fs": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", + "inherits": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "mkdirp": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "rimraf": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz" + } + }, + "fstream-ignore": { + "version": "https://registry.npmjs.org/fstream-ignore/-/fstream-ignore-1.0.5.tgz", + "integrity": "sha1-nDHa40dnAY/h0kmyTa2mfQktoQU=", + "requires": { + "fstream": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz", + "inherits": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "minimatch": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz" + } + }, + "gauge": { + "version": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", + "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", + "requires": { + "aproba": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", + "console-control-strings": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "has-unicode": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "object-assign": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "signal-exit": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", + "string-width": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "strip-ansi": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "wide-align": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.2.tgz" + } + }, + "getpass": { + "version": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "requires": { + "assert-plus": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz" + } + }, + "glob": { + "version": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha1-wZyd+aAocC1nhhI4SmVSQExjbRU=", + "requires": { + "fs.realpath": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "inflight": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "inherits": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "minimatch": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "once": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "path-is-absolute": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz" + } + }, + "graceful-fs": { + "version": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", + "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" + }, + "har-schema": { + "version": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", + "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=" + }, + "har-validator": { + "version": "https://registry.npmjs.org/har-validator/-/har-validator-5.0.3.tgz", + "integrity": "sha1-ukAsJmGU8VlW7xXg/PJCmT9qff0=", + "requires": { + "ajv": "https://registry.npmjs.org/ajv/-/ajv-5.5.0.tgz", + "har-schema": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz" + } + }, + "has-unicode": { + "version": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=" + }, + "hawk": { + "version": "https://registry.npmjs.org/hawk/-/hawk-6.0.2.tgz", + "integrity": "sha1-r02RTrBl+bXOTZ0RwcshJu7MMDg=", + "requires": { + "boom": "https://registry.npmjs.org/boom/-/boom-4.3.1.tgz", + "cryptiles": "https://registry.npmjs.org/cryptiles/-/cryptiles-3.1.2.tgz", + "hoek": "https://registry.npmjs.org/hoek/-/hoek-4.2.0.tgz", + "sntp": "https://registry.npmjs.org/sntp/-/sntp-2.1.0.tgz" + } + }, + "hoek": { + "version": "https://registry.npmjs.org/hoek/-/hoek-4.2.0.tgz", + "integrity": "sha1-ctnQdU9/4lyi0BrY+PmpRJqJUm0=" + }, + "http-signature": { + "version": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", + "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", + "requires": { + "assert-plus": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "jsprim": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", + "sshpk": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz" + } + }, + "inflight": { + "version": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "wrappy": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" + } + }, + "inherits": { + "version": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "ini": { + "version": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", + "integrity": "sha1-7uJfVtscnsYIXgwid4CD9Zar+Sc=" + }, + "is-fullwidth-code-point": { + "version": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "requires": { + "number-is-nan": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz" + } + }, + "is-typedarray": { + "version": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" + }, + "isarray": { + "version": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "isstream": { + "version": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" + }, + "jquery": { + "version": "https://registry.npmjs.org/jquery/-/jquery-3.2.1.tgz", + "integrity": "sha1-XE2d5lKvbNCncBVKYxu6ErAVx4c=" + }, + "jsbn": { + "version": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", + "optional": true + }, + "json-schema": { + "version": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", + "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" + }, + "json-schema-traverse": { + "version": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", + "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=" + }, + "json-stringify-safe": { + "version": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" + }, + "jsprim": { + "version": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", + "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "requires": { + "assert-plus": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "extsprintf": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "json-schema": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", + "verror": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz" + } + }, + "mime-db": { + "version": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz", + "integrity": "sha1-dMZD2i3Z1qRTmZY0ZbJtXKfXHwE=" + }, + "mime-types": { + "version": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz", + "integrity": "sha1-Cdejk/A+mVp5+K+Fe3Cp4KsWVXo=", + "requires": { + "mime-db": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz" + } + }, + "minimatch": { + "version": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=", + "requires": { + "brace-expansion": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz" + } + }, + "minimist": { + "version": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + }, + "mkdirp": { + "version": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "requires": { + "minimist": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz" + } + }, + "moment": { + "version": "https://registry.npmjs.org/moment/-/moment-2.19.3.tgz", + "integrity": "sha1-vbmdJw1tf9p4zA+6zoVeJ/59pp8=" + }, + "ms": { + "version": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "nan": { + "version": "https://registry.npmjs.org/nan/-/nan-2.6.2.tgz", + "integrity": "sha1-5P805slf37WuzAjeZZb0NgWn20U=" + }, + "node-pre-gyp": { + "version": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.6.36.tgz", + "integrity": "sha1-22BBEst04NR3VU6bUFsXq936t4Y=", + "requires": { + "mkdirp": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "nopt": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz", + "npmlog": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", + "rc": "https://registry.npmjs.org/rc/-/rc-1.2.2.tgz", + "request": "https://registry.npmjs.org/request/-/request-2.83.0.tgz", + "rimraf": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", + "semver": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz", + "tar": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz", + "tar-pack": "https://registry.npmjs.org/tar-pack/-/tar-pack-3.4.1.tgz" + } + }, + "nopt": { + "version": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz", + "integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=", + "requires": { + "abbrev": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "osenv": "https://registry.npmjs.org/osenv/-/osenv-0.1.4.tgz" + } + }, + "npmlog": { + "version": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", + "integrity": "sha1-CKfyqL9zRgR3mp76StXMcXq7lUs=", + "requires": { + "are-we-there-yet": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.4.tgz", + "console-control-strings": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "gauge": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", + "set-blocking": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz" + } + }, + "number-is-nan": { + "version": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" + }, + "oauth-sign": { + "version": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", + "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=" + }, + "object-assign": { + "version": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, + "once": { + "version": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" + } + }, + "os-homedir": { + "version": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=" + }, + "os-tmpdir": { + "version": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" + }, + "osenv": { + "version": "https://registry.npmjs.org/osenv/-/osenv-0.1.4.tgz", + "integrity": "sha1-Qv5tWVPfBsgGS+bxdsPQWqqjRkQ=", + "requires": { + "os-homedir": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", + "os-tmpdir": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz" + } + }, + "path-is-absolute": { + "version": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "performance-now": { + "version": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", + "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" + }, + "process-nextick-args": { + "version": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", + "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" + }, + "punycode": { + "version": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" + }, + "qs": { + "version": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", + "integrity": "sha1-NJzfbu+J7EXBLX1es/wMhwNDptg=" + }, + "rc": { + "version": "https://registry.npmjs.org/rc/-/rc-1.2.2.tgz", + "integrity": "sha1-2M6ctX6NZNnHut2YdsfDTL48cHc=", + "requires": { + "deep-extend": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.4.2.tgz", + "ini": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", + "minimist": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "strip-json-comments": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz" + }, + "dependencies": { + "minimist": { + "version": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + } + } + }, + "readable-stream": { + "version": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", + "integrity": "sha1-No8lEtefnUb9/HE0mueHi7weuVw=", + "requires": { + "core-util-is": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "inherits": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "isarray": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "process-nextick-args": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", + "safe-buffer": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "string_decoder": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "util-deprecate": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz" + } + }, + "regenerator-runtime": { + "version": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz", + "integrity": "sha1-flT+W1zNXWYk6mJVw0c74JC4AuE=" + }, + "request": { + "version": "https://registry.npmjs.org/request/-/request-2.83.0.tgz", + "integrity": "sha1-ygtl2gLtYpNYh4COb1EDgQNOM1Y=", + "requires": { + "aws-sign2": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", + "aws4": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz", + "caseless": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "combined-stream": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", + "extend": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", + "forever-agent": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "form-data": "https://registry.npmjs.org/form-data/-/form-data-2.3.1.tgz", + "har-validator": "https://registry.npmjs.org/har-validator/-/har-validator-5.0.3.tgz", + "hawk": "https://registry.npmjs.org/hawk/-/hawk-6.0.2.tgz", + "http-signature": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", + "is-typedarray": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "isstream": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "json-stringify-safe": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "mime-types": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz", + "oauth-sign": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", + "performance-now": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", + "qs": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", + "safe-buffer": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "stringstream": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", + "tough-cookie": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.3.tgz", + "tunnel-agent": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "uuid": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz" + } + }, + "rimraf": { + "version": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", + "integrity": "sha1-LtgVDSShbqhlHm1u8PR8QVjOejY=", + "requires": { + "glob": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz" + } + }, + "safe-buffer": { + "version": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha1-iTMSr2myEj3vcfV4iQAWce6yyFM=" + }, + "semver": { + "version": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz", + "integrity": "sha1-4FnAnYVx8FQII3M0M1BdOi8AsY4=" + }, + "set-blocking": { + "version": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" + }, + "signal-exit": { + "version": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" + }, + "sntp": { + "version": "https://registry.npmjs.org/sntp/-/sntp-2.1.0.tgz", + "integrity": "sha1-LGzsFP7cIiJznK+bXD2F0cxaLMg=", + "requires": { + "hoek": "https://registry.npmjs.org/hoek/-/hoek-4.2.0.tgz" + } + }, + "sprintf-js": { + "version": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.1.tgz", + "integrity": "sha1-Nr54Mgr+WAH2zqPueLblqrlA6gw=" + }, + "sshpk": { + "version": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz", + "integrity": "sha1-US322mKHFEMW3EwY/hzx2UBzm+M=", + "requires": { + "asn1": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", + "assert-plus": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "bcrypt-pbkdf": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", + "dashdash": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "ecc-jsbn": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", + "getpass": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "jsbn": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "tweetnacl": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz" + } + }, + "string-width": { + "version": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "requires": { + "code-point-at": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", + "is-fullwidth-code-point": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "strip-ansi": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz" + } + }, + "string_decoder": { + "version": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha1-D8Z9fBQYJd6UKC3VNr7GubzoYKs=", + "requires": { + "safe-buffer": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz" + } + }, + "stringstream": { + "version": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", + "integrity": "sha1-TkhM1N5aC7vuGORjB3EKioFiGHg=" + }, + "strip-ansi": { + "version": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz" + } + }, + "strip-json-comments": { + "version": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" + }, + "tar": { + "version": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz", + "integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=", + "requires": { + "block-stream": "https://registry.npmjs.org/block-stream/-/block-stream-0.0.9.tgz", + "fstream": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz", + "inherits": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz" + } + }, + "tar-pack": { + "version": "https://registry.npmjs.org/tar-pack/-/tar-pack-3.4.1.tgz", + "integrity": "sha1-4dvAOpudO6B+iWrQJzF+tnmhCh8=", + "requires": { + "debug": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "fstream": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz", + "fstream-ignore": "https://registry.npmjs.org/fstream-ignore/-/fstream-ignore-1.0.5.tgz", + "once": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "readable-stream": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", + "rimraf": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", + "tar": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz", + "uid-number": "https://registry.npmjs.org/uid-number/-/uid-number-0.0.6.tgz" + } + }, + "toastr": { + "version": "https://registry.npmjs.org/toastr/-/toastr-2.1.2.tgz", + "integrity": "sha1-/WkGaudXilszV3JfycfDNem2gd8=" + }, + "tough-cookie": { + "version": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.3.tgz", + "integrity": "sha1-C2GKVWW23qkL80JdBNVe3EdadWE=", + "requires": { + "punycode": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz" + } + }, + "tunnel-agent": { + "version": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", + "requires": { + "safe-buffer": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz" + } + }, + "tweetnacl": { + "version": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", + "optional": true + }, + "uid-number": { + "version": "https://registry.npmjs.org/uid-number/-/uid-number-0.0.6.tgz", + "integrity": "sha1-DqEOgDXo61uOREnwbaHHMGY7qoE=" + }, + "underscore": { + "version": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz", + "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=" + }, + "underscore.string": { + "version": "https://registry.npmjs.org/underscore.string/-/underscore.string-3.3.4.tgz", + "integrity": "sha1-LCo/n4PmR2L9xF5s6sZRQoZCE9s=", + "requires": { + "sprintf-js": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.1.tgz", + "util-deprecate": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz" + } + }, + "util-deprecate": { + "version": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "uuid": { + "version": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", + "integrity": "sha1-PdPT55Crwk17DToDT/q6vijrvAQ=" + }, + "verror": { + "version": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", + "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", + "requires": { + "assert-plus": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "core-util-is": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "extsprintf": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz" + } + }, + "wide-align": { + "version": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.2.tgz", + "integrity": "sha1-Vx4PGwYEY268DfwhsDObvjE0FxA=", + "requires": { + "string-width": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz" + } + }, + "wrappy": { + "version": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + } + } +} diff --git a/packages/rocketchat-livechat/server/lib/Livechat.js b/packages/rocketchat-livechat/server/lib/Livechat.js index 4b1df8022e52..919f7e77a89d 100644 --- a/packages/rocketchat-livechat/server/lib/Livechat.js +++ b/packages/rocketchat-livechat/server/lib/Livechat.js @@ -384,7 +384,7 @@ RocketChat.Livechat = { }, getLivechatRoomGuestInfo(room) { - const visitor = RocketChat.models.Users.findOneById(room.v._id); + const visitor = LivechatVisitors.findOneById(room.v._id); const agent = RocketChat.models.Users.findOneById(room.servedBy._id); const ua = new UAParser(); diff --git a/packages/rocketchat-livechat/server/lib/QueueMethods.js b/packages/rocketchat-livechat/server/lib/QueueMethods.js index 5b7ed00a2a9e..d882ee4f98fb 100644 --- a/packages/rocketchat-livechat/server/lib/QueueMethods.js +++ b/packages/rocketchat-livechat/server/lib/QueueMethods.js @@ -27,7 +27,7 @@ RocketChat.QueueMethods = { _id: guest._id, username: guest.username, token: message.token, - status: guest.status + status: guest.status || 'online' }, servedBy: { _id: agent.agentId, @@ -110,7 +110,8 @@ RocketChat.QueueMethods = { v: { _id: guest._id, username: guest.username, - token: message.token + token: message.token, + status: guest.status || 'online' }, t: 'l' }; diff --git a/packages/rocketchat-livechat/server/models/Users.js b/packages/rocketchat-livechat/server/models/Users.js index 727514dbe9a2..0c341d635216 100644 --- a/packages/rocketchat-livechat/server/models/Users.js +++ b/packages/rocketchat-livechat/server/models/Users.js @@ -1,5 +1,3 @@ -import _ from 'underscore'; -import s from 'underscore.string'; /** * Sets an user as (non)operator * @param {string} _id - User's _id From 3175a53b8025a6c736989558369122a5bb88a1eb Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 6 Dec 2017 10:20:19 -0200 Subject: [PATCH 10/16] Add migration --- server/startup/migrations/v105.js | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 server/startup/migrations/v105.js diff --git a/server/startup/migrations/v105.js b/server/startup/migrations/v105.js new file mode 100644 index 000000000000..9c4ed1f4fd9a --- /dev/null +++ b/server/startup/migrations/v105.js @@ -0,0 +1,46 @@ +import LivechatVisitors from 'meteor/rocketchat:livechat/server/models/LivechatVisitors'; + +RocketChat.Migrations.add({ + version: 105, + up() { + const visitors = Meteor.users.find({ type: 'visitor' }); + const total = visitors.count(); + let current = 1; + + console.log('Migrating livechat visitors, this may take a while ...'); + + Meteor.setTimeout(() => { + visitors.forEach(user => { + console.log(`Migrating visitor ${ current++ }/${ total }`); + + const { + _id, + name, + username, + deparment, + userAgent, + ip, + host, + visitorEmails, + phone + } = user; + LivechatVisitors.insert({ + _id, + name, + username, + deparment, + userAgent, + ip, + host, + visitorEmails, + phone, + token: user.profile.token + }); + + Meteor.users.remove({ _id }); + }); + + console.log('Livechat visitors migration finished.'); + }, 1000); + } +}); From 4a59fcc899041f3d652185d7d0706103d8bf0117 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 6 Dec 2017 17:10:33 -0200 Subject: [PATCH 11/16] Remove TODO --- .../rocketchat-lib/server/lib/sendNotificationsOnMessage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index 25f9b2519db1..c835ad62b136 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -166,7 +166,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) { const user = RocketChat.models.Users.findOneById(message.u._id); - // @TODO maybe a livechat visitor + // might be a livechat visitor if (!user) { return message; } From 88154da1dae582466862b2881233a2c2aef439a5 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 6 Dec 2017 17:53:04 -0200 Subject: [PATCH 12/16] Fix few issues --- .../.app/client/lib/chatMessages.js | 21 ------------------- .../.app/client/lib/commands.js | 7 +++---- .../.app/client/views/avatar.js | 5 +++-- .../.app/client/views/livechatWindow.js | 4 ++++ .../.app/imports/client/visitor.js | 15 +++++++++++-- .../server/methods/getInitialData.js | 15 +++++++++++++ .../server/methods/sendTranscript.js | 13 +++++++----- 7 files changed, 46 insertions(+), 34 deletions(-) diff --git a/packages/rocketchat-livechat/.app/client/lib/chatMessages.js b/packages/rocketchat-livechat/.app/client/lib/chatMessages.js index ce916a0333a5..664f7df344a8 100644 --- a/packages/rocketchat-livechat/.app/client/lib/chatMessages.js +++ b/packages/rocketchat-livechat/.app/client/lib/chatMessages.js @@ -187,21 +187,6 @@ this.ChatMessages = class ChatMessages { } } - tryCompletion(input) { - let value = input.value.match(/[^\s]+$/); - if (value && value.length > 0) { - value = value[0]; - - const re = new RegExp(value, 'i'); - - // @TODO verify if used - const user = Meteor.users.findOne({ username: re }, { fields: { username: 1 } }); - if (user) { - input.value = input.value.replace(value, `@${ user.username } `); - } - } - } - keyup(rid, event) { let i; const input = event.currentTarget; @@ -246,12 +231,6 @@ this.ChatMessages = class ChatMessages { return; } - if (k === 9) { - event.preventDefault(); - event.stopPropagation(); - this.tryCompletion(input); - } - if (k === 27) { if (this.editing.id) { event.preventDefault(); diff --git a/packages/rocketchat-livechat/.app/client/lib/commands.js b/packages/rocketchat-livechat/.app/client/lib/commands.js index 5851f34b1d69..c4201f125d72 100644 --- a/packages/rocketchat-livechat/.app/client/lib/commands.js +++ b/packages/rocketchat-livechat/.app/client/lib/commands.js @@ -15,9 +15,8 @@ this.Commands = { promptTranscript() { if (Livechat.transcript) { - // @TODO get visitor email - const user = Meteor.user(); - const email = user && user.visitorEmails && user.visitorEmails.length > 0 ? user.visitorEmails[0].address : ''; + const visitorData = visitor.getData(); + const email = visitorData && visitorData.visitorEmails && visitorData.visitorEmails.length > 0 ? visitorData.visitorEmails[0].address : ''; swal({ title: t('Chat_ended'), @@ -41,7 +40,7 @@ this.Commands = { swal.showInputError(t('please enter your email')); return false; } else { - Meteor.call('livechat:sendTranscript', visitor.getRoom(), response, (err) => { + Meteor.call('livechat:sendTranscript', visitor.getToken(), visitor.getRoom(), response, (err) => { if (err) { console.error(err); } diff --git a/packages/rocketchat-livechat/.app/client/views/avatar.js b/packages/rocketchat-livechat/.app/client/views/avatar.js index e863c6ba45aa..62443cf49912 100644 --- a/packages/rocketchat-livechat/.app/client/views/avatar.js +++ b/packages/rocketchat-livechat/.app/client/views/avatar.js @@ -1,3 +1,5 @@ +import visitor from '../../imports/client/visitor'; + Template.avatar.helpers({ imageUrl() { let username = this.username; @@ -6,8 +8,7 @@ Template.avatar.helpers({ username = user && user.username; } - // @TODO get visitor username - const currentUser = Meteor.users.findOne(Meteor.userId(), { fields: { username: 1 }}); + const currentUser = visitor.getData(); if (!username || (currentUser && currentUser.username === username)) { return; } diff --git a/packages/rocketchat-livechat/.app/client/views/livechatWindow.js b/packages/rocketchat-livechat/.app/client/views/livechatWindow.js index 24693a6262fc..7651415e6b48 100644 --- a/packages/rocketchat-livechat/.app/client/views/livechatWindow.js +++ b/packages/rocketchat-livechat/.app/client/views/livechatWindow.js @@ -119,6 +119,10 @@ Template.livechatWindow.onCreated(function() { visitor.setConnected(); } + if (result.visitor) { + visitor.setData(result.visitor); + } + if (result.agentData) { Livechat.agent = result.agentData; } diff --git a/packages/rocketchat-livechat/.app/imports/client/visitor.js b/packages/rocketchat-livechat/.app/imports/client/visitor.js index b02ed8a63bd3..457cb47dafd8 100644 --- a/packages/rocketchat-livechat/.app/imports/client/visitor.js +++ b/packages/rocketchat-livechat/.app/imports/client/visitor.js @@ -5,6 +5,7 @@ export default { id: new ReactiveVar(null), token: new ReactiveVar(null), room: new ReactiveVar(null), + data: new ReactiveVar(null), roomToSubscribe: new ReactiveVar(null), roomSubscribed: null, connected: null, @@ -25,6 +26,14 @@ export default { return this.id.set(id); }, + getData() { + return this.data.get(); + }, + + setData(data) { + this.data.set(data); + }, + getToken() { return this.token.get(); }, @@ -77,12 +86,14 @@ export default { if (this.connected) { return; } + const token = this.getToken(); + this.connected = true; - Meteor.call('UserPresence:connect', this.getToken(), { visitor: this.getToken() }); + Meteor.call('UserPresence:connect', token, { visitor: token }); Meteor.startup(function() { UserPresence.awayTime = 300000; // 5 minutes - UserPresence.start(this.getToken()); + UserPresence.start(token); }); } }; diff --git a/packages/rocketchat-livechat/server/methods/getInitialData.js b/packages/rocketchat-livechat/server/methods/getInitialData.js index 26e99aef2ffa..bca2a9787764 100644 --- a/packages/rocketchat-livechat/server/methods/getInitialData.js +++ b/packages/rocketchat-livechat/server/methods/getInitialData.js @@ -1,5 +1,7 @@ import _ from 'underscore'; +import LivechatVisitors from '../models/LivechatVisitors'; + Meteor.methods({ 'livechat:getInitialData'(visitorToken) { const info = { @@ -8,6 +10,7 @@ Meteor.methods({ color: null, registrationForm: null, room: null, + visitor: null, triggers: [], departments: [], allowSwitchingDepartments: null, @@ -36,6 +39,18 @@ Meteor.methods({ info.room = room[0]; } + const visitor = LivechatVisitors.getVisitorByToken(visitorToken, { + fields: { + name: 1, + username: 1, + visitorEmails: 1 + } + }); + + if (room) { + info.visitor = visitor; + } + const initSettings = RocketChat.Livechat.getInitSettings(); info.title = initSettings.Livechat_title; diff --git a/packages/rocketchat-livechat/server/methods/sendTranscript.js b/packages/rocketchat-livechat/server/methods/sendTranscript.js index 2b5474718e8c..949642ab232e 100644 --- a/packages/rocketchat-livechat/server/methods/sendTranscript.js +++ b/packages/rocketchat-livechat/server/methods/sendTranscript.js @@ -2,17 +2,20 @@ /* Send a transcript of the room converstation to the given email */ import moment from 'moment'; +import LivechatVisitors from '../models/LivechatVisitors'; + Meteor.methods({ - 'livechat:sendTranscript'(rid, email) { + 'livechat:sendTranscript'(token, rid, email) { check(rid, String); check(email, String); const room = RocketChat.models.Rooms.findOneById(rid); - const user = Meteor.user(); - const userLanguage = user.language || RocketChat.settings.get('language') || 'en'; + + const visitor = LivechatVisitors.getVisitorByToken(token); + const userLanguage = (visitor && visitor.language) || RocketChat.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 !== user.token) { + if (!room || room.t !== 'l' || !room.v || room.v.token !== token) { throw new Meteor.Error('error-invalid-room', 'Invalid room'); } @@ -27,7 +30,7 @@ Meteor.methods({ } let author; - if (message.u._id === Meteor.userId()) { + if (message.u._id === visitor._id) { author = TAPi18n.__('You', { lng: userLanguage }); } else { author = message.u.username; From 2e03dae655931c91be5c177c67f3cac111003add Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 7 Dec 2017 16:36:33 -0200 Subject: [PATCH 13/16] Fix stream issues --- .meteor/versions | 2 +- .../server/functions/canAccessRoom.js | 4 +-- .../server/functions/Notifications.js | 23 +++++++++---- .../rocketchat-livechat/.app/.meteor/versions | 2 +- .../.app/client/lib/_livechat.js | 2 +- .../.app/client/lib/fromApp/Notifications.js | 10 +++--- .../.app/client/lib/msgTyping.js | 10 +++--- .../.app/imports/client/visitor.js | 2 +- .../client/views/app/tabbar/visitorForward.js | 2 +- .../server/lib/Livechat.js | 13 ++++++-- .../server/methods/loginByToken.js | 19 ----------- .../server/methods/registerGuest.js | 3 -- .../server/methods/sendMessageLivechat.js | 2 -- .../server/methods/transfer.js | 5 ++- .../rocketchat-livechat/server/startup.js | 6 ++-- .../rocketchat-tokenpass/server/startup.js | 2 +- server/methods/canAccessRoom.js | 16 +++++----- server/stream/messages.js | 32 +++++++++---------- 18 files changed, 75 insertions(+), 80 deletions(-) diff --git a/.meteor/versions b/.meteor/versions index 8c3afe372f70..0be4284e30ab 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -211,7 +211,7 @@ rocketchat:smarsh-connector@0.0.1 rocketchat:sms@0.0.1 rocketchat:spotify@0.0.1 rocketchat:statistics@0.0.1 -rocketchat:streamer@0.5.0 +rocketchat:streamer@0.6.0 rocketchat:theme@0.0.1 rocketchat:tokenpass@0.0.1 rocketchat:tooltip@0.0.1 diff --git a/packages/rocketchat-authorization/server/functions/canAccessRoom.js b/packages/rocketchat-authorization/server/functions/canAccessRoom.js index 82a6b761c1bb..31a6e17674de 100644 --- a/packages/rocketchat-authorization/server/functions/canAccessRoom.js +++ b/packages/rocketchat-authorization/server/functions/canAccessRoom.js @@ -17,9 +17,9 @@ RocketChat.authz.roomAccessValidators = [ } ]; -RocketChat.authz.canAccessRoom = function(room, user) { +RocketChat.authz.canAccessRoom = function(room, user, extraData) { return RocketChat.authz.roomAccessValidators.some((validator) => { - return validator.call(this, room, user); + return validator.call(this, room, user, extraData); }); }; diff --git a/packages/rocketchat-lib/server/functions/Notifications.js b/packages/rocketchat-lib/server/functions/Notifications.js index 1ebd77f6e8d9..808d0b8bb902 100644 --- a/packages/rocketchat-lib/server/functions/Notifications.js +++ b/packages/rocketchat-lib/server/functions/Notifications.js @@ -25,10 +25,7 @@ RocketChat.Notifications = new class { this.streamUser.allowWrite('logged'); this.streamAll.allowRead('all'); this.streamLogged.allowRead('logged'); - this.streamRoom.allowRead(function(eventName) { - if (this.userId == null) { - return false; - } + this.streamRoom.allowRead(function(eventName, extraData) { const [roomId] = eventName.split('/'); const user = Meteor.users.findOne(this.userId, { fields: { @@ -40,9 +37,12 @@ RocketChat.Notifications = new class { console.warn(`Invalid streamRoom eventName: "${ eventName }"`); return false; } - if (room.t === 'l' && room.v._id === user._id) { + if (room.t === 'l' && extraData && extraData.token && room.v.token === extraData.token) { return true; } + if (this.userId == null) { + return false; + } return room.usernames.indexOf(user.username) > -1; }); this.streamRoomUsers.allowRead('none'); @@ -117,12 +117,21 @@ RocketChat.Notifications = new class { } }; -RocketChat.Notifications.streamRoom.allowWrite(function(eventName, username) { - const [, e] = eventName.split('/'); +RocketChat.Notifications.streamRoom.allowWrite(function(eventName, username, typing, extraData) { + const [roomId, e] = eventName.split('/'); if (e === 'webrtc') { return true; } if (e === 'typing') { + + // typing from livechat widget + if (extraData && extraData.token) { + const room = RocketChat.models.Rooms.findOneById(roomId); + if (room && room.t === 'l' && room.v.token === extraData.token) { + return true; + } + } + const user = Meteor.users.findOne(this.userId, { fields: { username: 1 diff --git a/packages/rocketchat-livechat/.app/.meteor/versions b/packages/rocketchat-livechat/.app/.meteor/versions index 367cf492983c..afcbc4d476a6 100644 --- a/packages/rocketchat-livechat/.app/.meteor/versions +++ b/packages/rocketchat-livechat/.app/.meteor/versions @@ -70,7 +70,7 @@ rate-limit@1.0.8 reactive-dict@1.2.0 reactive-var@1.0.11 retry@1.0.9 -rocketchat:streamer@0.5.0 +rocketchat:streamer@0.6.0 routepolicy@1.0.12 service-configuration@1.0.11 session@1.1.7 diff --git a/packages/rocketchat-livechat/.app/client/lib/_livechat.js b/packages/rocketchat-livechat/.app/client/lib/_livechat.js index d1a04ec71600..c0185a16b436 100644 --- a/packages/rocketchat-livechat/.app/client/lib/_livechat.js +++ b/packages/rocketchat-livechat/.app/client/lib/_livechat.js @@ -42,7 +42,7 @@ this.Livechat = new (class Livechat { this._agent.set(result); } }); - this.stream.on(this._room.get(), (eventData) => { + this.stream.on(this._room.get(), { token: visitor.getToken() }, (eventData) => { if (!eventData || !eventData.type) { return; } diff --git a/packages/rocketchat-livechat/.app/client/lib/fromApp/Notifications.js b/packages/rocketchat-livechat/.app/client/lib/fromApp/Notifications.js index 935312f3f94c..8acbe3d5da12 100644 --- a/packages/rocketchat-livechat/.app/client/lib/fromApp/Notifications.js +++ b/packages/rocketchat-livechat/.app/client/lib/fromApp/Notifications.js @@ -47,23 +47,23 @@ this.Notifications = new class { return this.streamUser.emit.apply(this.streamUser, args); } onAll(eventName, callback) { - return this.streamAll.on(eventName, callback); + return this.streamAll.on(eventName, { token: visitor.getToken() }, callback); } onLogged(eventName, callback) { return this.onLogin(() => { - return this.streamLogged.on(eventName, callback); + return this.streamLogged.on(eventName, { token: visitor.getToken() }, callback); }); } onRoom(room, eventName, callback) { if (this.debug === true) { - this.streamRoom.on(room, function() { + this.streamRoom.on(room, { token: visitor.getToken() }, function() { return console.log(`RocketChat.Notifications: onRoom ${ room }`, arguments); }); } - return this.streamRoom.on(`${ room }/${ eventName }`, callback); + return this.streamRoom.on(`${ room }/${ eventName }`, { token: visitor.getToken() }, callback); } onUser(eventName, callback) { - return this.streamUser.on(`${ visitor.getId() }/${ eventName }`, callback); + return this.streamUser.on(`${ visitor.getId() }/${ eventName }`, { token: visitor.getToken() }, callback); } unAll(callback) { return this.streamAll.removeListener('notify', callback); diff --git a/packages/rocketchat-livechat/.app/client/lib/msgTyping.js b/packages/rocketchat-livechat/.app/client/lib/msgTyping.js index 2fcd9c87c72d..378af82a34aa 100644 --- a/packages/rocketchat-livechat/.app/client/lib/msgTyping.js +++ b/packages/rocketchat-livechat/.app/client/lib/msgTyping.js @@ -16,7 +16,7 @@ export const MsgTyping = (function() { return; } usersTyping[room] = { users: {} }; - return Notifications.onRoom(room, 'typing', function(username, typing) { + return Notifications.onRoom(room, 'typing', function(username, typing, extraData) { const user = Meteor.user(); if (username === (user && user.username)) { return; @@ -49,8 +49,8 @@ export const MsgTyping = (function() { clearTimeout(timeouts[room]); timeouts[room] = null; } - const user = Meteor.user(); - return Notifications.notifyRoom(room, 'typing', user && user.username, false); + const visitorData = visitor.getData(); + return Notifications.notifyRoom(room, 'typing', visitorData && visitorData.username, false, { token: visitor.getToken() }); }; const start = function(room) { if (!renew) { return; } @@ -59,8 +59,8 @@ export const MsgTyping = (function() { renew = false; selfTyping.set(true); - const user = Meteor.user(); - Notifications.notifyRoom(room, 'typing', user && user.username, true); + const visitorData = visitor.getData(); + Notifications.notifyRoom(room, 'typing', visitorData && visitorData.username, true, { token: visitor.getToken() }); clearTimeout(timeouts[room]); return timeouts[room] = Meteor.setTimeout(() => stop(room), timeout); }; diff --git a/packages/rocketchat-livechat/.app/imports/client/visitor.js b/packages/rocketchat-livechat/.app/imports/client/visitor.js index 457cb47dafd8..bb0613cb92e0 100644 --- a/packages/rocketchat-livechat/.app/imports/client/visitor.js +++ b/packages/rocketchat-livechat/.app/imports/client/visitor.js @@ -63,7 +63,7 @@ export default { this.roomSubscribed = roomId; - msgStream.on(roomId, (msg) => { + msgStream.on(roomId, { token: this.getToken() }, (msg) => { if (msg.t === 'command') { Commands[msg.msg] && Commands[msg.msg](); } else if (msg.t !== 'livechat_video_call') { diff --git a/packages/rocketchat-livechat/client/views/app/tabbar/visitorForward.js b/packages/rocketchat-livechat/client/views/app/tabbar/visitorForward.js index 97afe34d0a99..58331022a08f 100644 --- a/packages/rocketchat-livechat/client/views/app/tabbar/visitorForward.js +++ b/packages/rocketchat-livechat/client/views/app/tabbar/visitorForward.js @@ -68,7 +68,7 @@ Template.visitorForward.events({ }, 'change #forwardUser, blur #forwardUser'(event, instance) { - if (event.currentTarget.value) { + if (event.currentTarget.value && instance.find('#forwardDepartment')) { instance.find('#forwardDepartment').value = ''; } }, diff --git a/packages/rocketchat-livechat/server/lib/Livechat.js b/packages/rocketchat-livechat/server/lib/Livechat.js index 919f7e77a89d..8600c2d3f062 100644 --- a/packages/rocketchat-livechat/server/lib/Livechat.js +++ b/packages/rocketchat-livechat/server/lib/Livechat.js @@ -551,8 +551,17 @@ RocketChat.Livechat = { RocketChat.Livechat.stream = new Meteor.Streamer('livechat-room'); -// @TODO create a allow function -RocketChat.Livechat.stream.allowRead('all'); +RocketChat.Livechat.stream.allowRead((roomId, extraData) => { + const room = RocketChat.models.Rooms.findOneById(roomId); + if (!room) { + console.warn(`Invalid eventName: "${ roomId }"`); + return false; + } + if (room.t === 'l' && extraData && extraData.token && room.v.token === extraData.token) { + return true; + } + return false; +}); RocketChat.settings.get('Livechat_history_monitor_type', (key, value) => { RocketChat.Livechat.historyMonitorType = value; diff --git a/packages/rocketchat-livechat/server/methods/loginByToken.js b/packages/rocketchat-livechat/server/methods/loginByToken.js index 264e97caaa7a..577bceb6c9f7 100644 --- a/packages/rocketchat-livechat/server/methods/loginByToken.js +++ b/packages/rocketchat-livechat/server/methods/loginByToken.js @@ -11,24 +11,5 @@ Meteor.methods({ return { _id: user._id }; - - // const stampedToken = Accounts._generateStampedLoginToken(); - // const hashStampedToken = Accounts._hashStampedToken(stampedToken); - - // const updateUser = { - // $set: { - // services: { - // resume: { - // loginTokens: [ hashStampedToken ] - // } - // } - // } - // }; - - // Meteor.users.update(user._id, updateUser); - - // return { - // token: stampedToken.token - // }; } }); diff --git a/packages/rocketchat-livechat/server/methods/registerGuest.js b/packages/rocketchat-livechat/server/methods/registerGuest.js index 303fd58a9075..5cef4e7c19a4 100644 --- a/packages/rocketchat-livechat/server/methods/registerGuest.js +++ b/packages/rocketchat-livechat/server/methods/registerGuest.js @@ -1,8 +1,5 @@ Meteor.methods({ 'livechat:registerGuest'({ token, name, email, department } = {}) { - // const stampedToken = Accounts._generateStampedLoginToken(); - // const hashStampedToken = Accounts._hashStampedToken(stampedToken); - const userId = RocketChat.Livechat.registerGuest.call(this, { token, name, diff --git a/packages/rocketchat-livechat/server/methods/sendMessageLivechat.js b/packages/rocketchat-livechat/server/methods/sendMessageLivechat.js index 4dabd29c07cf..b112474e4aeb 100644 --- a/packages/rocketchat-livechat/server/methods/sendMessageLivechat.js +++ b/packages/rocketchat-livechat/server/methods/sendMessageLivechat.js @@ -16,8 +16,6 @@ Meteor.methods({ } }); - console.log('guest ->', guest); - if (!guest) { throw new Meteor.Error('invalid-token'); } diff --git a/packages/rocketchat-livechat/server/methods/transfer.js b/packages/rocketchat-livechat/server/methods/transfer.js index aa842498cd23..e2af06273488 100644 --- a/packages/rocketchat-livechat/server/methods/transfer.js +++ b/packages/rocketchat-livechat/server/methods/transfer.js @@ -1,4 +1,7 @@ /* eslint new-cap: [2, {"capIsNewExceptions": ["Match.Optional"]}] */ + +import LivechatVisitors from '../models/LivechatVisitors'; + Meteor.methods({ 'livechat:transfer'(transferData) { if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-l-room')) { @@ -13,7 +16,7 @@ Meteor.methods({ const room = RocketChat.models.Rooms.findOneById(transferData.roomId); - const guest = RocketChat.models.Users.findOneById(room.v._id); + const guest = LivechatVisitors.findOneById(room.v._id); const user = Meteor.user(); diff --git a/packages/rocketchat-livechat/server/startup.js b/packages/rocketchat-livechat/server/startup.js index 11c7792cff51..1af415b4fbdc 100644 --- a/packages/rocketchat-livechat/server/startup.js +++ b/packages/rocketchat-livechat/server/startup.js @@ -4,11 +4,11 @@ Meteor.startup(() => { }); RocketChat.authz.addRoomAccessValidator(function(room, user) { - return room.t === 'l' && RocketChat.authz.hasPermission(user._id, 'view-livechat-rooms'); + return room.t === 'l' && user && RocketChat.authz.hasPermission(user._id, 'view-livechat-rooms'); }); - RocketChat.authz.addRoomAccessValidator(function(room, user) { - return room.t === 'l' && room.v && room.v._id === user._id; + RocketChat.authz.addRoomAccessValidator(function(room, user, extraData) { + return room.t === 'l' && extraData && extraData.token && room.v && room.v.token === extraData.token; }); RocketChat.callbacks.add('beforeLeaveRoom', function(user, room) { diff --git a/packages/rocketchat-tokenpass/server/startup.js b/packages/rocketchat-tokenpass/server/startup.js index 143e404d94ec..e6c0acfebde2 100644 --- a/packages/rocketchat-tokenpass/server/startup.js +++ b/packages/rocketchat-tokenpass/server/startup.js @@ -23,7 +23,7 @@ function validateTokenAccess(userData, roomData) { Meteor.startup(function() { RocketChat.authz.addRoomAccessValidator(function(room, user) { - if (!room.tokenpass) { + if (!room.tokenpass || !user) { return false; } diff --git a/server/methods/canAccessRoom.js b/server/methods/canAccessRoom.js index dbb1d468b448..a21be60f438b 100644 --- a/server/methods/canAccessRoom.js +++ b/server/methods/canAccessRoom.js @@ -1,16 +1,10 @@ Meteor.methods({ - canAccessRoom(rid, userId) { + canAccessRoom(rid, userId, extraData) { check(rid, String); check(userId, Match.Maybe(String)); let user; - if (!userId && RocketChat.settings.get('Accounts_AllowAnonymousRead') === false) { - throw new Meteor.Error('error-invalid-user', 'Invalid user', { - method: 'canAccessRoom' - }); - } - if (userId) { user = RocketChat.models.Users.findOneById(userId, { fields: { @@ -33,13 +27,19 @@ Meteor.methods({ const room = RocketChat.models.Rooms.findOneById(rid); if (room) { - if (RocketChat.authz.canAccessRoom.call(this, room, user)) { + if (RocketChat.authz.canAccessRoom.call(this, room, user, extraData)) { if (user) { room.username = user.username; } return room; } + if (!userId && RocketChat.settings.get('Accounts_AllowAnonymousRead') === false) { + throw new Meteor.Error('error-invalid-user', 'Invalid user', { + method: 'canAccessRoom' + }); + } + return false; } else { throw new Meteor.Error('error-invalid-room', 'Invalid room', { diff --git a/server/stream/messages.js b/server/stream/messages.js index 94dded4a9485..71c68bcdfe0d 100644 --- a/server/stream/messages.js +++ b/server/stream/messages.js @@ -3,26 +3,24 @@ this.msgStream = msgStream; msgStream.allowWrite('none'); -msgStream.allowRead('all'); -// @TODO fix livechat -// msgStream.allowRead(function(eventName) { -// try { -// const room = Meteor.call('canAccessRoom', eventName, this.userId); +msgStream.allowRead(function(eventName, args) { + try { + const room = Meteor.call('canAccessRoom', eventName, this.userId, args); -// if (!room) { -// return false; -// } + if (!room) { + return false; + } -// if (room.t === 'c' && !RocketChat.authz.hasPermission(this.userId, 'preview-c-room') && room.usernames.indexOf(room.username) === -1) { -// return false; -// } + if (room.t === 'c' && !RocketChat.authz.hasPermission(this.userId, 'preview-c-room') && room.usernames.indexOf(room.username) === -1) { + return false; + } -// return true; -// } catch (error) { -// /*error*/ -// return false; -// } -// }); + return true; + } catch (error) { + /*error*/ + return false; + } +}); msgStream.allowRead('__my_messages__', 'all'); From 60f6adbcb6c3655fdec72f90e6990b2b2b7a4d41 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 7 Dec 2017 17:07:51 -0200 Subject: [PATCH 14/16] Code cleanup --- packages/rocketchat-livechat/roomType.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/rocketchat-livechat/roomType.js b/packages/rocketchat-livechat/roomType.js index f408e10032bf..5a012f7edf5d 100644 --- a/packages/rocketchat-livechat/roomType.js +++ b/packages/rocketchat-livechat/roomType.js @@ -58,17 +58,12 @@ class LivechatRoomType extends RoomTypeConfig { getUserStatus(roomId) { const room = Session.get(`roomData${ roomId }`); - if (room) { return room.v && room.v.status; - } else { - const inquiry = LivechatInquiry.findOne({ rid: roomId }); - return inquiry && inquiry.v && inquiry.v.status; } - // if (guestName) { - // return Session.get(`user_${ guestName }_status`); - // } + const inquiry = LivechatInquiry.findOne({ rid: roomId }); + return inquiry && inquiry.v && inquiry.v.status; } allowRoomSettingChange(room, setting) { From 474920adcdd45e94034e4daf2cca047de4edd664 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 7 Dec 2017 17:33:29 -0200 Subject: [PATCH 15/16] Fix livechat visitor status on inquiries --- .../server/lib/Livechat.js | 27 ------------------- .../server/models/LivechatInquiry.js | 15 +++++++++++ .../server/visitorStatus.js | 1 + 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/packages/rocketchat-livechat/server/lib/Livechat.js b/packages/rocketchat-livechat/server/lib/Livechat.js index 8600c2d3f062..dcd6c381ced3 100644 --- a/packages/rocketchat-livechat/server/lib/Livechat.js +++ b/packages/rocketchat-livechat/server/lib/Livechat.js @@ -62,8 +62,6 @@ RocketChat.Livechat = { newRoom = true; } - console.log('getRoom.room ->', room); - console.log('getRoom.guest ->', guest); if (room.v.token !== guest.token) { throw new Meteor.Error('cannot-access-room'); @@ -94,12 +92,6 @@ RocketChat.Livechat = { if (user) { userId = user._id; - // if (loginToken) { - // if (!updateUser.$addToSet) { - // updateUser.$addToSet = {}; - // } - // updateUser.$addToSet['services.resume.loginTokens'] = loginToken; - // } } else { if (!username) { username = LivechatVisitors.getNextVisitorUsername(); @@ -108,21 +100,11 @@ RocketChat.Livechat = { let existingUser = null; if (s.trim(email) !== '' && (existingUser = LivechatVisitors.findOneGuestByEmailAddress(email))) { - // if (loginToken) { - // if (!updateUser.$addToSet) { - // updateUser.$addToSet = {}; - // } - // updateUser.$addToSet['services.resume.loginTokens'] = loginToken; - // } - userId = existingUser._id; } else { const userData = { username, - // globalRoles: ['livechat-guest'], department - // type: 'visitor', - // joinDefaultChannels: false }; if (this.connection) { @@ -131,15 +113,6 @@ RocketChat.Livechat = { userData.host = this.connection.httpHeaders.host; } - // userId = Accounts.insertUserDoc({}, userData); - - // if (loginToken) { - // updateUser.$set.services = { - // resume: { - // loginTokens: [ loginToken ] - // } - // }; - // } userId = LivechatVisitors.insert(userData); } } diff --git a/packages/rocketchat-livechat/server/models/LivechatInquiry.js b/packages/rocketchat-livechat/server/models/LivechatInquiry.js index 29439c3a0dbd..c7800535f61c 100644 --- a/packages/rocketchat-livechat/server/models/LivechatInquiry.js +++ b/packages/rocketchat-livechat/server/models/LivechatInquiry.js @@ -43,6 +43,21 @@ class LivechatInquiry extends RocketChat.models._Base { getStatus(inquiryId) { return this.findOne({'_id': inquiryId}).status; } + + updateVisitorStatus(token, status) { + const query = { + 'v.token': token, + status: 'open' + }; + + const update = { + $set: { + 'v.status': status + } + }; + + return this.update(query, update); + } } RocketChat.models.LivechatInquiry = new LivechatInquiry(); diff --git a/packages/rocketchat-livechat/server/visitorStatus.js b/packages/rocketchat-livechat/server/visitorStatus.js index 70806f288f7a..4c31c386e71c 100644 --- a/packages/rocketchat-livechat/server/visitorStatus.js +++ b/packages/rocketchat-livechat/server/visitorStatus.js @@ -2,6 +2,7 @@ Meteor.startup(() => { UserPresenceEvents.on('setStatus', (session, status, metadata) => { if (metadata && metadata.visitor) { + RocketChat.models.LivechatInquiry.updateVisitorStatus(metadata.visitor, status); RocketChat.models.Rooms.updateVisitorStatus(metadata.visitor, status); } }); From 16aca2395fe07c1395040472863c6222b2214173 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 14 Dec 2017 17:35:31 -0200 Subject: [PATCH 16/16] Extract lead data from livechat message and send to CRM --- packages/rocketchat-i18n/i18n/en.i18n.json | 5 +- packages/rocketchat-livechat/config.js | 21 ++++++ packages/rocketchat-livechat/package.js | 1 + .../server/hooks/leadCapture.js | 53 +++++++++++++++ .../server/hooks/sendToCRM.js | 67 ++++++++++--------- .../server/lib/Livechat.js | 6 +- .../server/models/LivechatVisitors.js | 32 +++++++++ 7 files changed, 149 insertions(+), 36 deletions(-) create mode 100644 packages/rocketchat-livechat/server/hooks/leadCapture.js diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 3b9f3c2c6b1c..9471113b77ad 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -1082,6 +1082,8 @@ "LDAP_Username_Field": "Username Field", "LDAP_Username_Field_Description": "Which field will be used as *username* for new users. Leave empty to use the username informed on login page.
You can use template tags too, like `#{givenName}.#{sn}`.
Default value is `sAMAccountName`.", "Execute_Synchronization_Now": "Execute Synchronization Now", + "Lead_capture_email_regex": "Lead capture email regex", + "Lead_capture_phone_regex": "Lead capture phone regex", "Least_Amount": "Least Amount", "Leave_Group_Warning": "Are you sure you want to leave the group \"%s\"?", "Leave_Livechat_Warning": "Are you sure you want to leave the livechat with \"%s\"?", @@ -1624,6 +1626,7 @@ "Send_invitation_email_info": "You can send multiple email invitations at once.", "Send_invitation_email_success": "You have successfully sent an invitation email to the following addresses:", "Send_request_on_chat_close": "Send Request on Chat Close", + "Send_request_on_lead_capture": "Send request on lead capture", "Send_request_on_offline_messages": "Send Request on Offline Messages", "Send_Test": "Send Test", "Send_welcome_email": "Send welcome email", @@ -2122,4 +2125,4 @@ "your_message_optional": "your message (optional)", "Your_password_is_wrong": "Your password is wrong!", "Your_push_was_sent_to_s_devices": "Your push was sent to %s devices" -} \ No newline at end of file +} diff --git a/packages/rocketchat-livechat/config.js b/packages/rocketchat-livechat/config.js index 2d0500d738d8..b404935af44e 100644 --- a/packages/rocketchat-livechat/config.js +++ b/packages/rocketchat-livechat/config.js @@ -131,6 +131,27 @@ Meteor.startup(function() { i18nLabel: 'Send_request_on_offline_messages' }); + RocketChat.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', { + 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])|$))', { + type: 'string', + group: 'Livechat', + section: 'CRM_Integration', + i18nLabel: 'Lead_capture_phone_regex' + }); + RocketChat.settings.add('Livechat_Knowledge_Enabled', false, { type: 'boolean', group: 'Livechat', diff --git a/packages/rocketchat-livechat/package.js b/packages/rocketchat-livechat/package.js index 2b0c1ca3b6d3..ea9bbad4675e 100644 --- a/packages/rocketchat-livechat/package.js +++ b/packages/rocketchat-livechat/package.js @@ -131,6 +131,7 @@ Package.onUse(function(api) { // hooks api.addFiles('server/hooks/externalMessage.js', 'server'); + api.addFiles('server/hooks/leadCapture.js', 'server'); api.addFiles('server/hooks/markRoomResponded.js', 'server'); api.addFiles('server/hooks/offlineMessage.js', 'server'); api.addFiles('server/hooks/RDStation.js', 'server'); diff --git a/packages/rocketchat-livechat/server/hooks/leadCapture.js b/packages/rocketchat-livechat/server/hooks/leadCapture.js new file mode 100644 index 000000000000..0d3cc63e66bf --- /dev/null +++ b/packages/rocketchat-livechat/server/hooks/leadCapture.js @@ -0,0 +1,53 @@ +import LivechatVisitors from '../../server/models/LivechatVisitors'; + +function validateMessage(message, room) { + // skips this callback if the message was edited + if (message.editedAt) { + return false; + } + + if (!RocketChat.settings.get('Livechat_Facebook_Enabled')) { + return false; + } + + // only send the sms by SMS if it is a livechat room with SMS set to true + if (!(typeof room.t !== 'undefined' && room.t === 'l' && room.v && room.v.token)) { + return false; + } + + // if the message hasn't a token, it was NOT sent from the visitor, so ignore it + if (!message.token) { + return false; + } + + // if the message has a type means it is a special message (like the closing comment), so skips + if (message.t) { + return false; + } + + return true; +} + +RocketChat.callbacks.add('afterSaveMessage', function(message, room) { + if (!RocketChat.settings.get('Livechat_webhook_on_capture')) { + return message; + } + + if (!validateMessage(message, room)) { + return message; + } + + const phoneRegexp = new RegExp(RocketChat.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 msgEmails = message.msg.match(emailRegexp); + + if (msgEmails || msgPhones) { + LivechatVisitors.saveGuestEmailPhoneById(room.v._id, msgEmails, msgPhones); + + RocketChat.callbacks.run('livechat.leadCapture', room); + } + + return message; +}, RocketChat.callbacks.priority.LOW, 'leadCapture'); diff --git a/packages/rocketchat-livechat/server/hooks/sendToCRM.js b/packages/rocketchat-livechat/server/hooks/sendToCRM.js index 7a09bbc0fed9..8b2926997a29 100644 --- a/packages/rocketchat-livechat/server/hooks/sendToCRM.js +++ b/packages/rocketchat-livechat/server/hooks/sendToCRM.js @@ -1,37 +1,27 @@ -function sendToCRM(hook, room) { - if (!RocketChat.settings.get('Livechat_webhook_on_close')) { - return room; - } - - // Do not send to CRM if the chat is still open - if (hook === 'saveLivechatInfo' && room.open) { - return room; - } - +function sendToCRM(type, room, includeMessages = true) { const postData = RocketChat.Livechat.getLivechatRoomGuestInfo(room); - if (hook === 'closeRoom') { - postData.type = 'LivechatSession'; - } else if (hook === 'saveLivechatInfo') { - postData.type = 'LivechatEdit'; - } + + postData.type = type; postData.messages = []; - RocketChat.models.Messages.findVisibleByRoomId(room._id, { sort: { ts: 1 } }).forEach((message) => { - if (message.t) { - return; - } - const msg = { - username: message.u.username, - msg: message.msg, - ts: message.ts - }; - - if (message.u.username !== postData.visitor.username) { - msg.agentId = message.u._id; - } - postData.messages.push(msg); - }); + if (includeMessages) { + RocketChat.models.Messages.findVisibleByRoomId(room._id, { sort: { ts: 1 } }).forEach((message) => { + if (message.t) { + return; + } + const msg = { + username: message.u.username, + msg: message.msg, + ts: message.ts + }; + + if (message.u.username !== postData.visitor.username) { + msg.agentId = message.u._id; + } + postData.messages.push(msg); + }); + } const response = RocketChat.Livechat.sendRequest(postData); @@ -43,9 +33,22 @@ function sendToCRM(hook, room) { } RocketChat.callbacks.add('livechat.closeRoom', (room) => { - return sendToCRM('closeRoom', room); + if (!RocketChat.settings.get('Livechat_webhook_on_close')) { + return room; + } + + return sendToCRM('LivechatSession', room); }, RocketChat.callbacks.priority.MEDIUM, 'livechat-send-crm-close-room'); RocketChat.callbacks.add('livechat.saveInfo', (room) => { - return sendToCRM('saveLivechatInfo', 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'); + +RocketChat.callbacks.add('livechat.leadCapture', (room) => { + return sendToCRM('LeadCapture', room, false); +}, RocketChat.callbacks.priority.MEDIUM, 'livechat-send-crm-lead-capture'); diff --git a/packages/rocketchat-livechat/server/lib/Livechat.js b/packages/rocketchat-livechat/server/lib/Livechat.js index 5b638fcd0061..2769b7ff2e35 100644 --- a/packages/rocketchat-livechat/server/lib/Livechat.js +++ b/packages/rocketchat-livechat/server/lib/Livechat.js @@ -397,14 +397,14 @@ RocketChat.Livechat = { } if (visitor.visitorEmails && visitor.visitorEmails.length > 0) { - postData.visitor.email = visitor.visitorEmails[0].address; + postData.visitor.email = visitor.visitorEmails; } if (visitor.phone && visitor.phone.length > 0) { - postData.visitor.phone = visitor.phone[0].phoneNumber; + postData.visitor.phone = visitor.phone; } if (agent.emails && agent.emails.length > 0) { - postData.agent.email = agent.emails[0].address; + postData.agent.email = agent.emails; } return postData; diff --git a/packages/rocketchat-livechat/server/models/LivechatVisitors.js b/packages/rocketchat-livechat/server/models/LivechatVisitors.js index fe8c4a915119..d9eb7e7ce983 100644 --- a/packages/rocketchat-livechat/server/models/LivechatVisitors.js +++ b/packages/rocketchat-livechat/server/models/LivechatVisitors.js @@ -158,6 +158,38 @@ class LivechatVisitors extends RocketChat.models._Base { return this.findOne(query); } + + saveGuestEmailPhoneById(_id, emails, phones) { + const update = { + $addToSet: {} + }; + + const saveEmail = [].concat(emails) + .filter(email => email && email.trim()) + .map(email => { + return { address: email }; + }); + + if (saveEmail.length > 0) { + update.$addToSet.visitorEmails = { $each: saveEmail }; + } + + const savePhone = [].concat(phones) + .filter(phone => phone && phone.trim().replace(/[^\d]/g, '')) + .map(phone => { + return { phoneNumber: phone }; + }); + + if (savePhone.length > 0) { + update.$addToSet.phone = { $each: savePhone }; + } + + if (!update.$addToSet.visitorEmails && !update.$addToSet.phone) { + return; + } + + return this.update({ _id }, update); + } } export default new LivechatVisitors();