commented out unimplemented method returnAsInquiry removed console.logs removed trailing white spaces and dead code more code styling more more code styling fixed bug in takeInquiry, code styling switched to single quotes fixed names of files translations added, type fixed, meteor.userId() used, multi agent take inquiry bug fixed removed dead code fixes string switched to single quote added return room as inquiry functionality redirects to home when livechat returned and other code fixes removed trailing whitespace Change return to inquiry button icon Fix eslint errorspull/3323/head^2
parent
299163ee95
commit
ea7483bcac
@ -0,0 +1 @@ |
||||
this.LivechatInquiry = new Mongo.Collection('rocketchat_livechat_inquiry'); |
||||
@ -0,0 +1,114 @@ |
||||
RocketChat.QueueMethods = { |
||||
/* Least Amount Queuing method: |
||||
* |
||||
* default method where the agent with the least number |
||||
* of open chats is paired with the incoming livechat |
||||
*/ |
||||
'Least_Amount' : function(guest, message, roomInfo) { |
||||
const agent = RocketChat.Livechat.getNextAgent(guest.department); |
||||
if (!agent) { |
||||
throw new Meteor.Error('no-agent-online', 'Sorry, no online agents'); |
||||
} |
||||
|
||||
const roomCode = RocketChat.models.Rooms.getNextLivechatRoomCode(); |
||||
|
||||
const room = _.extend({ |
||||
_id: message.rid, |
||||
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 |
||||
}, |
||||
servedBy: { |
||||
_id: agent.agentId, |
||||
username: agent.username |
||||
}, |
||||
open: true |
||||
}, roomInfo); |
||||
let subscriptionData = { |
||||
rid: message.rid, |
||||
name: guest.name || guest.username, |
||||
alert: true, |
||||
open: true, |
||||
unread: 1, |
||||
answered: false, |
||||
code: roomCode, |
||||
u: { |
||||
_id: agent.agentId, |
||||
username: agent.username |
||||
}, |
||||
t: 'l', |
||||
desktopNotifications: 'all', |
||||
mobilePushNotifications: 'all', |
||||
emailNotifications: 'all' |
||||
}; |
||||
|
||||
RocketChat.models.Rooms.insert(room); |
||||
RocketChat.models.Subscriptions.insert(subscriptionData); |
||||
|
||||
return room; |
||||
}, |
||||
/* Guest Pool Queuing Method: |
||||
* |
||||
* An incomming livechat is created as an Inquiry |
||||
* which is picked up from an agent. |
||||
* An Inquiry is visible to all agents (TODO: in the correct department) |
||||
* |
||||
* A room is still created with the initial message, but it is occupied by |
||||
* only the client until paired with an agent |
||||
*/ |
||||
'Guest_Pool' : function(guest, message, roomInfo) { |
||||
const agents = RocketChat.Livechat.getAgents(guest.department); |
||||
if (!agents) { |
||||
throw new Meteor.Error('no-agent-online', 'Sorry, no online agents'); |
||||
} |
||||
|
||||
const roomCode = RocketChat.models.Rooms.getNextLivechatRoomCode(); |
||||
|
||||
const agentIds = []; |
||||
|
||||
agents.forEach((agent) => { |
||||
if (guest.department) { |
||||
agentIds.push(agent.agentId); |
||||
} else { |
||||
agentIds.push(agent._id); |
||||
} |
||||
}); |
||||
|
||||
var inquiry = { |
||||
rid: message.rid, |
||||
message: message.msg, |
||||
name: guest.name || guest.username, |
||||
ts: new Date(), |
||||
code: roomCode, |
||||
department: guest.department, |
||||
agents: agentIds, |
||||
status: 'open' |
||||
}; |
||||
const room = _.extend({ |
||||
_id: message.rid, |
||||
msgs: 1, |
||||
lm: new Date(), |
||||
code: roomCode, |
||||
label: guest.name || guest.username, |
||||
usernames: [guest.username], |
||||
t: 'l', |
||||
ts: new Date(), |
||||
v: { |
||||
_id: guest._id, |
||||
token: message.token |
||||
}, |
||||
open: true |
||||
}, roomInfo); |
||||
RocketChat.models.LivechatInquiry.insert(inquiry); |
||||
RocketChat.models.Rooms.insert(room); |
||||
|
||||
return room; |
||||
} |
||||
}; |
||||
@ -0,0 +1,20 @@ |
||||
Meteor.methods({ |
||||
'livechat:returnAsInquiry'(rid) { |
||||
if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-l-room')) { |
||||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveDepartment' }); |
||||
} |
||||
|
||||
// //delete agent and room subscription
|
||||
RocketChat.models.Subscriptions.removeByRoomId(rid); |
||||
|
||||
// remove user from room
|
||||
var username = Meteor.user().name; |
||||
RocketChat.models.Rooms.removeUsernameById(rid, username); |
||||
|
||||
// find inquiry corresponding to room
|
||||
var inquiry = RocketChat.models.LivechatInquiry.findOne({rid: rid}); |
||||
|
||||
// mark inquiry as open
|
||||
return RocketChat.models.LivechatInquiry.openInquiry(inquiry._id); |
||||
} |
||||
}); |
||||
@ -0,0 +1,40 @@ |
||||
Meteor.methods({ |
||||
'livechat:takeInquiry'(inquiry, agent) { |
||||
if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'view-l-room')) { |
||||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:takeInquiry' }); |
||||
} |
||||
|
||||
if (RocketChat.models.LivechatInquiry.getStatus(inquiry._id) === 'taken') { |
||||
throw new Meteor.Error('error-not-allowed', 'Inquiry already taken', { method: 'livechat:takeInquiry' }); |
||||
} |
||||
|
||||
// add subscription
|
||||
var subscriptionData = { |
||||
rid: inquiry.rid, |
||||
name: inquiry.name, |
||||
alert: true, |
||||
open: true, |
||||
unread: 1, |
||||
code: inquiry.code, |
||||
u: { |
||||
_id: agent._id, |
||||
username: agent.username |
||||
}, |
||||
t: 'l', |
||||
desktopNotifications: 'all', |
||||
mobilePushNotifications: 'all', |
||||
emailNotifications: 'all', |
||||
answered: 'false' |
||||
}; |
||||
RocketChat.models.Subscriptions.insert(subscriptionData); |
||||
|
||||
// add user to room
|
||||
RocketChat.models.Rooms.addUsernameById(inquiry.rid, agent.username); |
||||
|
||||
// mark inquiry as taken
|
||||
RocketChat.models.LivechatInquiry.takeInquiry(inquiry._id); |
||||
|
||||
// return room corresponding to inquiry (for redirecting agent to the room route)
|
||||
return RocketChat.models.Rooms.findOneById(inquiry.rid); |
||||
} |
||||
}); |
||||
@ -0,0 +1,45 @@ |
||||
class LivechatInquiry extends RocketChat.models._Base { |
||||
constructor() { |
||||
super(); |
||||
this._initModel('livechat_inquiry'); |
||||
|
||||
this.tryEnsureIndex({ 'rid': 1 }); // room id corresponding to this inquiry
|
||||
this.tryEnsureIndex({ 'name': 1 }); // name of the inquiry (client name for now)
|
||||
this.tryEnsureIndex({ 'message': 1 }); // message sent by the client
|
||||
this.tryEnsureIndex({ 'ts': 1 }); // timestamp
|
||||
this.tryEnsureIndex({ 'code': 1 }); // (for routing)
|
||||
this.tryEnsureIndex({ 'agents': 1}); // Id's of the agents who can see the inquiry (handle departments)
|
||||
this.tryEnsureIndex({ 'status': 1}); // 'open', 'taken'
|
||||
} |
||||
|
||||
/* |
||||
* mark the inquiry as taken |
||||
*/ |
||||
takeInquiry(inquiryId) { |
||||
this.update({ |
||||
'_id': inquiryId |
||||
}, { |
||||
$set: { status: 'taken' } |
||||
}); |
||||
} |
||||
|
||||
/* |
||||
* mark inquiry as open |
||||
*/ |
||||
openInquiry(inquiryId) { |
||||
this.update({ |
||||
'_id': inquiryId |
||||
}, { |
||||
$set: { status: 'open' } |
||||
}); |
||||
} |
||||
|
||||
/* |
||||
* return the status of the inquiry (open or taken) |
||||
*/ |
||||
getStatus(inquiryId) { |
||||
return this.findOne({'_id': inquiryId}).status; |
||||
} |
||||
} |
||||
|
||||
RocketChat.models.LivechatInquiry = new LivechatInquiry(); |
||||
@ -0,0 +1,12 @@ |
||||
Meteor.publish('livechat:inquiry', function() { |
||||
if (!this.userId) { |
||||
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:inquiry' })); |
||||
} |
||||
|
||||
if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) { |
||||
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:inquiry' })); |
||||
} |
||||
|
||||
|
||||
return RocketChat.models.LivechatInquiry.find(); |
||||
}); |
||||
@ -0,0 +1,11 @@ |
||||
<template name="livechatInquiryItem"> |
||||
<li class="link-room-{{rid}} {{active}} {{#if unread}}has-unread{{/if}} {{#if alert}}has-alert{{/if}}"> |
||||
<a class="open-room" href="{{route}}" title="{{name}}"> |
||||
<!-- {{#if unread}} --> |
||||
<!-- <span class="unread">{{unread}}</span> --> |
||||
<!-- {{/if}} --> |
||||
<i class="{{roomIcon}} {{userStatus}}" aria-label=""></i> |
||||
<span class='name'>{{name}}</span> |
||||
</a> |
||||
</li> |
||||
</template> |
||||
@ -0,0 +1,65 @@ |
||||
/* globals KonchatNotification */ |
||||
Template.livechatInquiryItem.helpers({ |
||||
alert: function() { |
||||
if (FlowRouter.getParam('_id') !== this.rid || !document.hasFocus()) { |
||||
return this.alert; |
||||
} |
||||
}, |
||||
unread: function() { |
||||
return 1; |
||||
}, |
||||
userStatus: function() { |
||||
return 'status-' + (Session.get('user_' + this.name + '_status') || 'offline'); |
||||
}, |
||||
name: function() { |
||||
return this.name; |
||||
}, |
||||
roomIcon: function() { |
||||
return RocketChat.roomTypes.getIcon(this.t); |
||||
}, |
||||
active: function() { |
||||
if (Session.get('openedRoom') === this.rid) { |
||||
return 'active'; |
||||
} |
||||
}, |
||||
route: function() { |
||||
return RocketChat.roomTypes.getRouteLink(this.t, this); |
||||
} |
||||
}); |
||||
|
||||
Template.livechatInquiryItem.rendered = function() { |
||||
if (!((FlowRouter.getParam('_id') != null) && FlowRouter.getParam('_id') === this.data.rid) && !this.data.ls && this.data.alert === true) { |
||||
return KonchatNotification.newRoom(this.data.rid); |
||||
} |
||||
}; |
||||
|
||||
Template.livechatInquiryItem.events({ |
||||
'click .open-room': function(e) { |
||||
e.stopPropagation(); |
||||
e.preventDefault(); |
||||
|
||||
var inquiry = this; |
||||
|
||||
swal({ |
||||
title: t('Livechat_Take_Confirm'), |
||||
text: t('Message') + ': ' + inquiry.message, |
||||
showCancelButton: true, |
||||
confirmButtonColor: '#3085d6', |
||||
cancelButtonColor: '#d33', |
||||
confirmButtonText: 'Take it!' |
||||
}, function(isConfirm) { |
||||
if (isConfirm) { |
||||
// make server method call
|
||||
Meteor.call('livechat:takeInquiry', inquiry, Meteor.user(), function(error, result) { |
||||
if (!error) { |
||||
FlowRouter.go(RocketChat.roomTypes.getRouteLink(result.t, result)); |
||||
} |
||||
}); |
||||
} |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
Template.livechatInquiryItem.onDestroyed(function() { |
||||
swal.close(); |
||||
}); |
||||
Loading…
Reference in new issue