@tiledesk/tiledesk-server 2.9.27 → 2.9.28
Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
@@ -2,6 +2,7 @@ const authEvent = require('../../event/authEvent');
|
|
2
2
|
const requestEvent = require('../../event/requestEvent');
|
3
3
|
var Project = require('../../models/project');
|
4
4
|
var Project_user = require('../../models/project_user');
|
5
|
+
var Request = require('../../models/request')
|
5
6
|
var winston = require('../../config/winston');
|
6
7
|
|
7
8
|
var ProjectUserUtil = require("../../utils/project_userUtil");
|
@@ -34,44 +35,88 @@ class Listener {
|
|
34
35
|
this.enabled = false;
|
35
36
|
}
|
36
37
|
winston.debug("Listener this.enabled: "+ this.enabled);
|
37
|
-
}
|
38
|
+
}
|
38
39
|
|
39
40
|
|
40
|
-
|
41
|
+
// db.getCollection('project_users').find({"number_assigned_requests" : {"$lt":0}}).count()
|
42
|
+
|
43
|
+
// New version of updateProjectUser() method.
|
44
|
+
// This will not increment or decrement the number_assigned_requests field but search the exact number of assigned conversation to the project user
|
45
|
+
updateProjectUser(id_user, id_project, operation) {
|
46
|
+
winston.debug("Route queue updateProjectUser start operation: " + operation + "id_user " + id_user + " id_project " + id_project);
|
47
|
+
|
48
|
+
return Request.countDocuments({ id_project: id_project, participantsAgents: id_user, status: { $lt: 1000 } }, (err, requestsCount) => {
|
49
|
+
console.log("requestsCount for id_user: ", id_user, "and project: ", id_project, "-->", requestsCount);
|
50
|
+
if (err) {
|
51
|
+
return winston.error(err);
|
52
|
+
}
|
53
|
+
|
54
|
+
return Project_user
|
55
|
+
.findOneAndUpdate({ id_user: id_user, id_project: id_project }, { number_assigned_requests: requestsCount }, { new: true, upsert: false }, function (err, updatedPU) {
|
56
|
+
if (err) {
|
57
|
+
return winston.error(err);
|
58
|
+
}
|
59
|
+
// winston.debug("Route queue number_assigned_requests +1 :" + updatedPU.id);
|
60
|
+
// winston.debug("Route queue number_assigned_requests +1 :" + updatedPU.id);
|
61
|
+
winston.debug("Route queue number_assigned_requests updated to " + requestsCount + "for project user " + updatedPU.id);
|
62
|
+
|
63
|
+
updatedPU.populate({ path: 'id_user', select: { 'firstname': 1, 'lastname': 1 } }, function (err, updatedProject_userPopulated) {
|
64
|
+
|
65
|
+
var pu = updatedProject_userPopulated.toJSON();
|
66
|
+
|
67
|
+
return Project.findById(id_project).exec(function (err, project) {
|
68
|
+
pu.isBusy = ProjectUserUtil.isBusy(updatedProject_userPopulated, project.settings && project.settings.max_agent_assigned_chat);
|
69
|
+
winston.debug("Route queue pu.isBusy: " + pu.isBusy);
|
70
|
+
|
71
|
+
authEvent.emit('project_user.update', { updatedProject_userPopulated: pu, req: undefined, skipArchive: true }); //if queued with jobs -> websocket notification on project_user.update doesn't work??? forse si in quanto viene convertito in .pub.queue e poi rifunziiona
|
72
|
+
|
73
|
+
|
74
|
+
// project_user.update triggers activityArchiver(tested), cache invalidation(tested), subscriptionNotifierQueued and websocket(tested works from queue i trigger ws)
|
75
|
+
if (requestEvent.queueEnabled) { //force to .queue to be catched into the queue (activity archiver, subscriptionNotifierQueued )
|
76
|
+
authEvent.emit('project_user.update.queue', { updatedProject_userPopulated: pu, req: undefined, skipArchive: true });
|
77
|
+
}
|
78
|
+
|
79
|
+
})
|
80
|
+
|
81
|
+
});
|
82
|
+
|
83
|
+
});
|
84
|
+
})
|
41
85
|
|
86
|
+
}
|
42
87
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
88
|
+
_updateProjectUser(id_user, id_project, operation) {
|
89
|
+
winston.debug("Route queue updateProjectUser start operation: " + operation + "id_user " + id_user + " id_project " + id_project);
|
90
|
+
return Project_user
|
91
|
+
.findOneAndUpdate({ id_user: id_user, id_project: id_project }, { $inc: { 'number_assigned_requests': operation } }, { new: true, upsert: false }, function (err, updatedPU) {
|
92
|
+
if (err) {
|
93
|
+
return winston.error(err);
|
94
|
+
}
|
95
|
+
winston.debug("Route queue number_assigned_requests +1 :" + updatedPU.id);
|
96
|
+
winston.debug("Route queue number_assigned_requests +1 :" + updatedPU.id);
|
52
97
|
|
53
|
-
|
98
|
+
updatedPU.populate({ path: 'id_user', select: { 'firstname': 1, 'lastname': 1 } }, function (err, updatedProject_userPopulated) {
|
54
99
|
|
55
|
-
|
100
|
+
var pu = updatedProject_userPopulated.toJSON();
|
56
101
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
authEvent.emit('project_user.update', {updatedProject_userPopulated:pu, req: undefined, skipArchive: true}); //if queued with jobs -> websocket notification on project_user.update doesn't work??? forse si in quanto viene convertito in .pub.queue e poi rifunziiona
|
102
|
+
return Project.findById(id_project).exec(function (err, project) {
|
103
|
+
pu.isBusy = ProjectUserUtil.isBusy(updatedProject_userPopulated, project.settings && project.settings.max_agent_assigned_chat);
|
104
|
+
winston.debug("Route queue pu.isBusy: " + pu.isBusy);
|
62
105
|
|
106
|
+
authEvent.emit('project_user.update', { updatedProject_userPopulated: pu, req: undefined, skipArchive: true }); //if queued with jobs -> websocket notification on project_user.update doesn't work??? forse si in quanto viene convertito in .pub.queue e poi rifunziiona
|
63
107
|
|
64
|
-
// project_user.update triggers activityArchiver(tested), cache invalidation(tested), subscriptionNotifierQueued and websocket(tested works from queue i trigger ws)
|
65
|
-
if (requestEvent.queueEnabled) { //force to .queue to be catched into the queue (activity archiver, subscriptionNotifierQueued )
|
66
|
-
authEvent.emit('project_user.update.queue', {updatedProject_userPopulated:pu, req: undefined, skipArchive: true});
|
67
|
-
}
|
68
108
|
|
69
|
-
|
70
|
-
|
71
|
-
|
109
|
+
// project_user.update triggers activityArchiver(tested), cache invalidation(tested), subscriptionNotifierQueued and websocket(tested works from queue i trigger ws)
|
110
|
+
if (requestEvent.queueEnabled) { //force to .queue to be catched into the queue (activity archiver, subscriptionNotifierQueued )
|
111
|
+
authEvent.emit('project_user.update.queue', { updatedProject_userPopulated: pu, req: undefined, skipArchive: true });
|
112
|
+
}
|
72
113
|
|
73
|
-
|
74
|
-
|
114
|
+
})
|
115
|
+
|
116
|
+
});
|
117
|
+
|
118
|
+
});
|
119
|
+
}
|
75
120
|
|
76
121
|
updateParticipatingProjectUsers(request, operation) {
|
77
122
|
winston.debug("Route queue request.participatingAgents", request.participatingAgents);
|
@@ -198,27 +198,6 @@ class WebSocketServer {
|
|
198
198
|
var projectId = urlSub[1];
|
199
199
|
winston.debug('projectId: ' + projectId);
|
200
200
|
|
201
|
-
// sponz support 65203e12f8c0cf002cf4110b
|
202
|
-
// johnny support 62c3f10152dc7400352bab0d
|
203
|
-
// sponz collaudo 66acec0cf7ebf80013d67974
|
204
|
-
// johnny collaudo 6613ff078890fc0013ad3c3a
|
205
|
-
// sponz prod 6565047fdd64fd001323f37c
|
206
|
-
// mweb prod 656054000410fa00132e5dcc
|
207
|
-
|
208
|
-
if (projectId === "65203e12f8c0cf002cf4110b"
|
209
|
-
|| projectId === "62c3f10152dc7400352bab0d"
|
210
|
-
|| projectId === "66acec0cf7ebf80013d67974"
|
211
|
-
|| projectId === "6613ff078890fc0013ad3c3a"
|
212
|
-
|| projectId === "6565047fdd64fd001323f37c"
|
213
|
-
|| projectId === "656054000410fa00132e5dcc") {
|
214
|
-
|
215
|
-
console.log('WSS onSubscribeCallback - ProjectID ' + projectId);
|
216
|
-
console.log("x-forwarded-for: ", req.headers['x-forwarded-for'], "remote port: ", req.socket.remotePort);
|
217
|
-
console.log("remoteAddress: ", req.socket.remoteAddress)
|
218
|
-
}
|
219
|
-
|
220
|
-
|
221
|
-
|
222
201
|
let q = Project.findOne({ _id: projectId, status: 100 })
|
223
202
|
|
224
203
|
if (cacheEnabler.project) {
|