|
1 | 1 | import { Meteor } from 'meteor/meteor'; |
2 | 2 | import { Match, check } from 'meteor/check'; |
| 3 | +import moment from 'moment'; |
3 | 4 |
|
4 | 5 | import { hasRole } from '../../../../../app/authorization'; |
5 | | -import { LivechatDepartment, Users, LivechatInquiry } from '../../../../../app/models/server'; |
| 6 | +import { LivechatDepartment, Users, LivechatInquiry, LivechatRooms } from '../../../../../app/models/server'; |
6 | 7 | import { Rooms as RoomRaw } from '../../../../../app/models/server/raw'; |
7 | 8 | import { settings } from '../../../../../app/settings'; |
8 | 9 | import { Livechat } from '../../../../../app/livechat/server/lib/Livechat'; |
@@ -64,7 +65,7 @@ export const normalizeQueueInfo = async ({ position, queueInfo, department }) => |
64 | 65 | queueInfo = await getQueueInfo(department); |
65 | 66 | } |
66 | 67 |
|
67 | | - const { message, numberMostRecentChats, statistics: { avgChatDuration } = { } } = queueInfo; |
| 68 | + const { message, numberMostRecentChats, statistics: { avgChatDuration } = {} } = queueInfo; |
68 | 69 | const spot = position + 1; |
69 | 70 | const estimatedWaitTimeSeconds = getSpotEstimatedWaitTime(spot, numberMostRecentChats, avgChatDuration); |
70 | 71 | return { spot, message, estimatedWaitTimeSeconds }; |
@@ -137,3 +138,31 @@ export const allowAgentSkipQueue = (agent) => { |
137 | 138 |
|
138 | 139 | return settings.get('Livechat_assign_new_conversation_to_bot') && hasRole(agent.agentId, 'bot'); |
139 | 140 | }; |
| 141 | + |
| 142 | +export const setPredictedVisitorAbandonmentTime = (room) => { |
| 143 | + if (!room.v || !room.v.lastMessageTs || !settings.get('Livechat_auto_close_abandoned_rooms')) { |
| 144 | + return; |
| 145 | + } |
| 146 | + |
| 147 | + let secondsToAdd = settings.get('Livechat_visitor_inactivity_timeout'); |
| 148 | + |
| 149 | + const department = room.departmentId && LivechatDepartment.findOneById(room.departmentId); |
| 150 | + if (department && department.visitorInactivityTimeoutInSeconds) { |
| 151 | + secondsToAdd = department.visitorInactivityTimeoutInSeconds; |
| 152 | + } |
| 153 | + |
| 154 | + if (secondsToAdd <= 0) { |
| 155 | + return; |
| 156 | + } |
| 157 | + |
| 158 | + const willBeAbandonedAt = moment(room.v.lastMessageTs).add(Number(secondsToAdd), 'seconds').toDate(); |
| 159 | + LivechatRooms.setPredictedVisitorAbandonment(room._id, willBeAbandonedAt); |
| 160 | +}; |
| 161 | + |
| 162 | +export const updatePredictedVisitorAbandonment = () => { |
| 163 | + if (settings.get('Livechat_auto_close_abandoned_rooms')) { |
| 164 | + LivechatRooms.findLivechat({ open: true }).forEach((room) => setPredictedVisitorAbandonmentTime(room)); |
| 165 | + } else { |
| 166 | + LivechatRooms.unsetPredictedVisitorAbandonment(); |
| 167 | + } |
| 168 | +}; |
0 commit comments