Livechat fixes

- Use guest name or username as room and subscription name
- Save guest _id on rooms to best lookup
- Some UI fixes
pull/3124/head
Diego Sampaio 10 years ago
parent 2a6969ed06
commit 4c4d2dbd71
  1. 1
      packages/rocketchat-lib/i18n/en.i18n.json
  2. 6
      packages/rocketchat-lib/server/models/Users.coffee
  3. 5
      packages/rocketchat-livechat/client/ui.js
  4. 2
      packages/rocketchat-livechat/client/views/app/livechatCurrentChats.html
  5. 3
      packages/rocketchat-livechat/client/views/app/livechatCurrentChats.js
  6. 1
      packages/rocketchat-livechat/client/views/app/tabbar/externalSearch.js
  7. 8
      packages/rocketchat-livechat/client/views/app/tabbar/visitorHistory.js
  8. 14
      packages/rocketchat-livechat/client/views/app/tabbar/visitorInfo.js
  9. 4
      packages/rocketchat-livechat/client/views/app/tabbar/visitorNavigation.html
  10. 2
      packages/rocketchat-livechat/client/views/app/tabbar/visitorNavigation.js
  11. 4
      packages/rocketchat-livechat/server/lib/Livechat.js
  12. 8
      packages/rocketchat-livechat/server/models/Rooms.js
  13. 6
      packages/rocketchat-livechat/server/publications/visitorHistory.js
  14. 6
      packages/rocketchat-livechat/server/publications/visitorInfo.js
  15. 2
      packages/rocketchat-livechat/server/publications/visitorPageVisited.js
  16. 5
      packages/rocketchat-livechat/server/sendMessageBySMS.js
  17. 1
      packages/rocketchat-livechat/server/startup.js
  18. 21
      server/startup/migrations/v051.js

@ -1082,6 +1082,7 @@
"Visibility" : "Visibility",
"Visible" : "Visible",
"Visitor" : "Visitor",
"Visitor_Info" : "Visitor Info",
"Visitor_Navigation" : "Visitor Navigation",
"Visitor_page_URL" : "Visitor page URL",
"Visitor_time_on_site" : "Visitor time on site",

@ -54,6 +54,12 @@ RocketChat.models.Users = new class extends RocketChat.models._Base
# FIND
findById: (userId) ->
query =
_id: userId
return @find query
findUsersNotOffline: (options) ->
query =
username:

@ -23,10 +23,7 @@ RocketChat.roomTypes.add('l', 5, {
roomName(roomData) {
if (!roomData.name) {
const sub = ChatSubscription.findOne({ rid: roomData._id }, { fields: { name: 1 } });
if (sub) {
return sub.name;
}
return roomData.label;
} else {
return roomData.name;
}

@ -11,7 +11,7 @@
<tbody>
{{#each livechatRoom}}
<tr class="row-link">
<td>{{name}}</td>
<td>{{label}}</td>
<td>{{startedAt}}</td>
<td>{{lastMessage}}</td>
</tr>

@ -7,9 +7,6 @@ Template.livechatCurrentChats.helpers({
},
lastMessage() {
return moment(this.lm).format('L LTS');
},
name() {
return 'Livechat ' + this.code;
}
});

@ -1,6 +1,5 @@
Template.externalSearch.helpers({
messages() {
console.log('messages helper');
return RocketChat.models.LivechatExternalMessage.findByRoomId(this.rid, { ts: 1 });
}
});

@ -6,7 +6,7 @@ Template.visitorHistory.helpers({
previousChats() {
return ChatRoom.find({
_id: { $ne: this.rid },
'v.token': Template.instance().visitorToken.get()
'v._id': Template.instance().visitorId.get()
}, {
sort: {
ts: -1
@ -21,14 +21,14 @@ Template.visitorHistory.helpers({
Template.visitorHistory.onCreated(function() {
var currentData = Template.currentData();
this.visitorToken = new ReactiveVar();
this.visitorId = new ReactiveVar();
this.autorun(() => {
const room = ChatRoom.findOne({ _id: Template.currentData().rid });
this.visitorToken.set(room.v.token);
this.visitorId.set(room.v._id);
});
if (currentData && currentData.rid) {
this.loadHistory = this.subscribe('livechat:visitorHistory', currentData.rid);
this.loadHistory = this.subscribe('livechat:visitorHistory', { rid: currentData.rid });
}
});

@ -141,7 +141,7 @@ Template.visitorInfo.events({
});
Template.visitorInfo.onCreated(function() {
this.visitorToken = new ReactiveVar(null);
this.visitorId = new ReactiveVar(null);
this.customFields = new ReactiveVar([]);
this.editing = new ReactiveVar(false);
this.user = new ReactiveVar();
@ -156,18 +156,18 @@ Template.visitorInfo.onCreated(function() {
if (currentData && currentData.rid) {
this.autorun(() => {
var room = ChatRoom.findOne(currentData.rid);
if (room && room.v && room.v.token) {
this.visitorToken.set(room.v.token);
let room = ChatRoom.findOne(currentData.rid);
if (room && room.v && room.v._id) {
this.visitorId.set(room.v._id);
} else {
this.visitorToken.set();
this.visitorId.set();
}
});
this.subscribe('livechat:visitorInfo', currentData.rid);
this.subscribe('livechat:visitorInfo', { rid: currentData.rid });
}
this.autorun(() => {
this.user.set(Meteor.users.findOne({ 'profile.token': this.visitorToken.get() }));
this.user.set(Meteor.users.findOne({ '_id': this.visitorId.get() }));
});
});

@ -1,9 +1,7 @@
<template name="visitorNavigation">
<div class="content">
<div class="list-view">
<div class="title">
<h2>{{_ "Navigation_History"}}</h2>
</div>
<h4>{{_ "Navigation_History"}}</h4>
<div class="visitor-navigation">
{{#if loadingNavigation}}
{{_ "Loading..."}}

@ -22,6 +22,6 @@ Template.visitorNavigation.onCreated(function() {
var currentData = Template.currentData();
if (currentData && currentData.rid) {
this.pageVisited = this.subscribe('livechat:visitorPageVisited', currentData.rid);
this.pageVisited = this.subscribe('livechat:visitorPageVisited', { rid: currentData.rid });
}
});

@ -37,17 +37,19 @@ RocketChat.Livechat = {
msgs: 1,
lm: new Date(),
code: roomCode,
label: guest.name || guest.username,
usernames: [agent.username, guest.username],
t: 'l',
ts: new Date(),
v: {
_id: guest._id,
token: message.token
},
open: true
}, roomInfo);
let subscriptionData = {
rid: message.rid,
name: guest.username,
name: guest.name || guest.username,
alert: true,
open: true,
unread: 1,

@ -93,6 +93,14 @@ RocketChat.models.Rooms.findByVisitorToken = function(visitorToken) {
return this.find(query);
};
RocketChat.models.Rooms.findByVisitorId = function(visitorId) {
const query = {
'v._id': visitorId
};
return this.find(query);
};
RocketChat.models.Rooms.closeByRoomId = function(roomId) {
return this.update({ _id: roomId }, { $unset: { open: 1 } });
};

@ -1,4 +1,4 @@
Meteor.publish('livechat:visitorHistory', function(roomId) {
Meteor.publish('livechat:visitorHistory', function({ rid: roomId }) {
if (!this.userId) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorHistory' }));
}
@ -15,8 +15,8 @@ Meteor.publish('livechat:visitorHistory', function(roomId) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorHistory' }));
}
if (room && room.v && room.v.token) {
return RocketChat.models.Rooms.findByVisitorToken(room.v.token);
if (room && room.v && room.v._id) {
return RocketChat.models.Rooms.findByVisitorId(room.v._id);
} else {
return this.ready();
}

@ -1,4 +1,4 @@
Meteor.publish('livechat:visitorInfo', function(roomId) {
Meteor.publish('livechat:visitorInfo', function({ rid: roomId }) {
if (!this.userId) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorInfo' }));
}
@ -9,8 +9,8 @@ Meteor.publish('livechat:visitorInfo', function(roomId) {
var room = RocketChat.models.Rooms.findOneById(roomId);
if (room && room.v && room.v.token) {
return RocketChat.models.Users.findVisitorByToken(room.v.token);
if (room && room.v && room.v._id) {
return RocketChat.models.Users.findById(room.v._id);
} else {
return this.ready();
}

@ -1,4 +1,4 @@
Meteor.publish('livechat:visitorPageVisited', function(roomId) {
Meteor.publish('livechat:visitorPageVisited', function({ rid: roomId }) {
if (!this.userId) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorPageVisited' }));
}

@ -18,6 +18,11 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
return message;
}
// if the message has a type means it is a special message (like the closing comment), so skips
if (message.t) {
return message;
}
const SMSService = RocketChat.SMS.getService(RocketChat.settings.get('SMS_Service'));
if (!SMSService) {

@ -5,6 +5,7 @@ Meteor.startup(() => {
t: 1,
cl: 1,
u: 1,
label: 1,
usernames: 1,
v: 1,
livechatData: 1,

@ -0,0 +1,21 @@
RocketChat.Migrations.add({
version: 51,
up: function() {
RocketChat.models.Rooms.find({ t: 'l', 'v.token': { $exists: true }, label: { $exists: false }}).forEach(function(room) {
var user = RocketChat.models.Users.findOne({ 'profile.token': room.v.token });
if (user) {
RocketChat.models.Rooms.update({ _id: room._id }, {
$set: {
label: user.name || user.username,
'v._id': user._id
}
});
RocketChat.models.Subscriptions.update({ rid: room._id }, {
$set: {
name: user.name || user.username
}
}, { multi: true });
}
});
}
});
Loading…
Cancel
Save