chat4app-client-angular 0.0.34 → 0.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,663 +27,663 @@
27
27
  var SockJS__namespace = /*#__PURE__*/_interopNamespace(SockJS);
28
28
  var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
29
29
 
30
- var Chat4appClientAngularService = /** @class */ (function () {
31
- function Chat4appClientAngularService(http) {
32
- this.http = http;
33
- this.chatServer = "";
34
- this.chatUrl = "";
35
- this.debug = false;
36
- this.timeoutReconnect = 500;
37
- }
38
- Chat4appClientAngularService.prototype.ngOnInit = function () {
39
- };
40
- Chat4appClientAngularService.prototype.config = function (chat4AppConfig) {
41
- this.chatServer = chat4AppConfig.endpoint;
42
- this.chatUrl = chat4AppConfig.endpoint + "/api/v1/";
43
- this.debug = chat4AppConfig.debug;
44
- };
45
- Chat4appClientAngularService.prototype.init = function (securityChatToken, callback, chatCallback, connectionClientId) {
46
- if (!this.chatServer || this.chatServer.trim().length == 0) {
47
- throw new Error("Endpoint is empty");
48
- }
49
- if (!securityChatToken || securityChatToken.trim().length == 0) {
50
- throw new Error("SecurityChatToken is empty");
51
- }
52
- this.setTokenChat4app(securityChatToken);
53
- if (chatCallback && connectionClientId) {
54
- this.connectWebsocket(chatCallback, connectionClientId);
55
- }
56
- callback(securityChatToken);
57
- };
58
- Chat4appClientAngularService.prototype.getChatUrlDownload = function (messageFileId) {
59
- return this.chatUrl + "chatmessage/getFile?messageFileId=" + messageFileId + "&token=" + this.getBearerToken();
60
- };
61
- Chat4appClientAngularService.prototype.getMessageChat = function (chatId, fromId, toId) {
62
- var url = this.chatUrl + "chatmessage/" + chatId + "/" + fromId + "/" + toId;
63
- return this.http.get(url, {
64
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
65
- });
66
- };
67
- Chat4appClientAngularService.prototype.getMessageChatByGrop = function (chatId, groupId, fromId) {
68
- var url = this.chatUrl + "chatmessage/byGroup/" + chatId + "/" + groupId + "/" + fromId;
69
- return this.http.get(url, {
70
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
71
- });
72
- };
73
- Chat4appClientAngularService.prototype.addMessageChat = function (chatMessage4App) {
74
- var url = this.chatUrl + "chatmessage/" + chatMessage4App.chatId;
75
- return this.http.post(url, chatMessage4App, {
76
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
77
- });
78
- };
79
- Chat4appClientAngularService.prototype.props = function (chatFilterRequest4App) {
80
- var url = this.chatUrl + "chatmessage/props";
81
- return this.http.post(url, chatFilterRequest4App, {
82
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
83
- });
84
- };
85
- Chat4appClientAngularService.prototype.removeUsersChat = function (chatId, chatUsersId, chatUsersExternalId) {
86
- var params = new Array();
87
- if (chatUsersId && chatUsersId.length > 0) {
88
- chatUsersId.forEach(function (cui) {
89
- params.push("chatUserId=" + cui);
90
- });
91
- }
92
- else if (chatUsersExternalId && chatUsersExternalId.length > 0) {
93
- chatUsersExternalId.forEach(function (cuei) {
94
- params.push("chatUserExternalId=" + cuei);
95
- });
96
- }
97
- var url = this.chatUrl + "chatuser/" + chatId + "?" + params.join("&");
98
- return this.http.delete(url, {
99
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
100
- });
101
- };
102
- Chat4appClientAngularService.prototype.removeUserChat = function (chatId, chatUserId, chatUserExternalId) {
103
- var param = "";
104
- if (chatUserId) {
105
- param = "chatUserId=" + chatUserId;
106
- }
107
- else {
108
- param = "chatUserExternalId=" + chatUserExternalId;
109
- }
110
- var url = this.chatUrl + "chatuser/" + chatId + "?" + param;
111
- return this.http.delete(url, {
112
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
113
- });
114
- };
115
- Chat4appClientAngularService.prototype.updateUserChat = function (chatId, charUser4AppUpdate) {
116
- var url = this.chatUrl + "chatuser/" + chatId;
117
- return this.http.put(url, charUser4AppUpdate, {
118
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
119
- });
120
- };
121
- Chat4appClientAngularService.prototype.createUserChat = function (chatId, chatUser4App) {
122
- var url = this.chatUrl + "chatuser/" + chatId;
123
- return this.http.post(url, chatUser4App, {
124
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
125
- });
126
- };
127
- Chat4appClientAngularService.prototype.createUsersChat = function (chatId, chatUser4App) {
128
- var url = this.chatUrl + "chatuser/users/" + chatId;
129
- return this.http.post(url, chatUser4App, {
130
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
131
- });
132
- };
133
- Chat4appClientAngularService.prototype.createChat = function (chat4app) {
134
- var url = this.chatUrl + "chat";
135
- return this.http.post(url, chat4app, {
136
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
137
- });
138
- };
139
- Chat4appClientAngularService.prototype.createUpdateChat = function (chat4app) {
140
- var url = this.chatUrl + "chat";
141
- return this.http.put(url, chat4app, {
142
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
143
- });
144
- };
145
- Chat4appClientAngularService.prototype.getLastMessageGroup = function (chatExternalId, groupId) {
146
- var url = this.chatUrl + "chatmessage/lastMessageGroup?chatExternalId=" + chatExternalId + "&groupId=" + groupId;
147
- return this.http.get(url, {
148
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
149
- });
150
- };
151
- Chat4appClientAngularService.prototype.getLastMessage = function (chatExternalId, chatUserExternalId) {
152
- var url = this.chatUrl + "chatmessage/lastMessage?chatExternalId=" + chatExternalId + "&chatUserExternalId=" + chatUserExternalId;
153
- return this.http.get(url, {
154
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
155
- });
156
- };
157
- Chat4appClientAngularService.prototype.countNotReadMessages = function (chatUserExternalId, chatExternalId, groupId, fromId) {
158
- var url = this.chatUrl + "chatmessage/countNotReadMessages?chatUserExternalId=" + chatUserExternalId;
159
- if (chatExternalId && chatExternalId.length > 0) {
160
- url += "&chatExternalId=" + chatExternalId;
161
- }
162
- if (groupId && groupId.length > 0) {
163
- url += "&groupId=" + groupId;
164
- }
165
- if (fromId && fromId.length > 0) {
166
- url += "&fromId=" + groupId;
167
- }
168
- return this.http.get(url, {
169
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
170
- });
171
- };
172
- Chat4appClientAngularService.prototype.getChatByExternalId = function (externalId) {
173
- var url = this.chatUrl + "chat?externalId=" + externalId;
174
- return this.http.get(url, {
175
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
176
- });
177
- };
178
- Chat4appClientAngularService.prototype.getChatById = function (id) {
179
- var url = this.chatUrl + "chat?chatId=" + id;
180
- return this.http.get(url, {
181
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
182
- });
183
- };
184
- Chat4appClientAngularService.prototype.listChatByUser = function (externalUserId, userId, chatStatus) {
185
- var url = this.chatUrl + "chat/listChatByUser/?externalUserId=" + externalUserId
186
- + "&userId=" + userId
187
- + "&chatStatus=" + chatStatus;
188
- return this.http.get(url, {
189
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
190
- });
191
- };
192
- Chat4appClientAngularService.prototype.closeChat = function (chatId, chatExternalId) {
193
- var url = this.chatUrl;
194
- if (chatId && chatId.length > 0) {
195
- url += "chat?chatId=" + chatId;
196
- }
197
- if (chatExternalId && chatExternalId.length > 0) {
198
- url += "chat?externalId=" + chatExternalId;
199
- }
200
- return this.http.delete(url, {
201
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
202
- });
203
- };
204
- Chat4appClientAngularService.prototype.readMessage = function (chatMessageId, toId) {
205
- var url = this.chatUrl + "chatmessage/read/" + chatMessageId;
206
- if (toId && toId.length > 0) {
207
- url += "/" + toId;
208
- }
209
- return this.http.put(url, null, {
210
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
211
- });
212
- };
213
- Chat4appClientAngularService.prototype.online = function (chatId) {
214
- var url = this.chatUrl + "chatmessage/online/" + chatId;
215
- return this.http.get(url, {
216
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
217
- });
218
- };
219
- Chat4appClientAngularService.prototype.sendFile = function (chatId, fromId, toId, fileToUpload) {
220
- var endpoint = this.chatUrl + "chatmessage/sendFile/" + chatId + "/" + fromId + "/" + toId;
221
- var formData = new FormData();
222
- formData.append('file', fileToUpload);
223
- return this.http
224
- .post(endpoint, formData, {
225
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
226
- });
227
- };
228
- Chat4appClientAngularService.prototype.sendFileGroup = function (chatId, fromId, groupId, fileToUpload) {
229
- var endpoint = this.chatUrl + "chatmessage/sendFileGroup/" + chatId + "/" + fromId + "/" + groupId;
230
- var formData = new FormData();
231
- formData.append('file', fileToUpload);
232
- return this.http
233
- .post(endpoint, formData, {
234
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
235
- });
236
- };
237
- Chat4appClientAngularService.prototype.translateMessage = function (chatMessageId, languageTarget) {
238
- var url = this.chatUrl + "chatmessage/translate/" + chatMessageId + "/" + languageTarget;
239
- return this.http.get(url, {
240
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
241
- });
242
- };
243
- Chat4appClientAngularService.prototype.startTyping = function (chatId, fromId, toId) {
244
- var url = this.chatUrl + "chatmessage/startTyping/" + chatId + "/" + fromId + "/" + toId;
245
- return this.http.put(url, null, {
246
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
247
- });
248
- };
249
- Chat4appClientAngularService.prototype.startTypingGroup = function (chatId, fromId, groupId) {
250
- var url = this.chatUrl + "chatmessage/startTypingGroup/" + chatId + "/" + fromId + "/" + groupId;
251
- return this.http.put(url, null, {
252
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
253
- });
254
- };
255
- Chat4appClientAngularService.prototype.stopTyping = function (chatId, fromId, toId) {
256
- var url = this.chatUrl + "chatmessage/stopTyping/" + chatId + "/" + fromId + "/" + toId;
257
- return this.http.put(url, null, {
258
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
259
- });
260
- };
261
- Chat4appClientAngularService.prototype.stopTypingGroup = function (chatId, fromId, groupId) {
262
- var url = this.chatUrl + "chatmessage/stopTypingGroup/" + chatId + "/" + fromId + "/" + groupId;
263
- return this.http.put(url, null, {
264
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
265
- });
266
- };
267
- Chat4appClientAngularService.prototype.createGroup = function (group) {
268
- var url = this.chatUrl + "/group";
269
- return this.http.post(url, group, {
270
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
271
- });
272
- };
273
- Chat4appClientAngularService.prototype.getGroup = function (chatId, groupId) {
274
- var url = this.chatUrl + "/group/" + groupId + "/" + chatId;
275
- return this.http.get(url, {
276
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
277
- });
278
- };
279
- Chat4appClientAngularService.prototype.listGroups = function (chatId, externalId) {
280
- var url = this.chatUrl + "/group/";
281
- if (chatId && chatId.length > 0) {
282
- url += "&chatId=" + chatId;
283
- }
284
- if (externalId && externalId.length > 0) {
285
- url += "&externalId=" + externalId;
286
- }
287
- return this.http.get(url, {
288
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
289
- });
290
- };
291
- Chat4appClientAngularService.prototype.listFilesGroup = function (chatId, groupId) {
292
- var url = this.chatUrl + "/group/" + chatId;
293
- if (groupId && groupId.length > 0) {
294
- url += "&groupId=" + chatId;
295
- }
296
- return this.http.get(url, {
297
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
298
- });
299
- };
300
- /* Token */
301
- Chat4appClientAngularService.prototype.getBearerToken = function () {
302
- var ret = "Bearer " + window.sessionStorage.getItem("chat4AppSessionToken");
303
- return ret;
304
- };
305
- Chat4appClientAngularService.prototype.setTokenChat4app = function (chat4AppSessionToken) {
306
- window.sessionStorage.setItem("chat4AppSessionToken", chat4AppSessionToken);
307
- };
308
- /* Connection */
309
- Chat4appClientAngularService.prototype.onMessageFirebaseReceived = function (data, chatCallback) {
310
- //alert("onMessageReceived connectFirebase");
311
- if (data.type == "msg") {
312
- var chat4appMessage = new Chat4AppMessageReceive();
313
- chat4appMessage.data.chatId = data.chatId;
314
- chat4appMessage.data.chatMessageId = data.chatMessageId;
315
- chat4appMessage.data.externalId = data.externalId;
316
- chat4appMessage.data.fromId = data.fromId;
317
- chat4appMessage.data.toId = data.toId;
318
- chat4appMessage.data.groupId = data.groupId;
319
- chat4appMessage.data.dateHour = data.dateHour;
320
- chat4appMessage.data.type = data.type;
321
- chat4appMessage.notification.body = data.body;
322
- if (data.fileId && data.fileId.length > 0) {
323
- chat4appMessage.data.fileId = data.fileId;
324
- chat4appMessage.data.fileName = data.fileName;
325
- chat4appMessage.data.fileSize = data.fileSize;
326
- chat4appMessage.data.fileType = data.fileType;
327
- }
328
- var datTmp = new Map();
329
- for (var key in data) {
330
- datTmp.set(key, data[key]);
331
- }
332
- chat4appMessage.data.all = datTmp;
333
- chatCallback.onMessage(chat4appMessage);
334
- }
335
- else if ((data.type == "on" || data.type == "off")) {
336
- var chat4appMessage = new Chat4AppMessageReceive();
337
- chat4appMessage.data.chatId = data.chatId;
338
- chat4appMessage.data.chatMessageId = data.chatMessageId;
339
- chat4appMessage.data.externalId = data.externalId;
340
- chat4appMessage.data.fromId = data.fromId;
341
- chat4appMessage.data.toId = data.toId;
342
- chat4appMessage.data.groupId = data.groupId;
343
- chat4appMessage.data.dateHour = data.dateHour;
344
- chat4appMessage.data.type = data.type;
345
- var datTmp = new Map();
346
- for (var key in data) {
347
- datTmp.set(key, data[key]);
348
- }
349
- chat4appMessage.data.all = datTmp;
350
- chatCallback.onOffline(chat4appMessage);
351
- }
352
- else if (data.type == "read") {
353
- var chat4appMessage = new Chat4AppMessageReceive();
354
- chat4appMessage.data.chatId = data.chatId;
355
- chat4appMessage.data.chatMessageId = data.chatMessageId;
356
- chat4appMessage.data.externalId = data.externalId;
357
- chat4appMessage.data.fromId = data.fromId;
358
- chat4appMessage.data.toId = data.toId;
359
- chat4appMessage.data.groupId = data.groupId;
360
- chat4appMessage.data.dateHour = data.dateHour;
361
- chat4appMessage.data.type = data.type;
362
- var datTmp = new Map();
363
- for (var key in data) {
364
- datTmp.set(key, data[key]);
365
- }
366
- chat4appMessage.data.all = datTmp;
367
- chatCallback.onRead(chat4appMessage);
368
- }
369
- else if (data.type == "startTyping" || data.type == "stopTyping") {
370
- var chat4appMessage = new Chat4AppMessageReceive();
371
- chat4appMessage.data.chatId = data.chatId;
372
- chat4appMessage.data.chatMessageId = data.chatMessageId;
373
- chat4appMessage.data.externalId = data.externalId;
374
- chat4appMessage.data.fromId = data.fromId;
375
- chat4appMessage.data.toId = data.toId;
376
- chat4appMessage.data.groupId = data.groupId;
377
- chat4appMessage.data.dateHour = data.dateHour;
378
- chat4appMessage.data.type = data.type;
379
- var datTmp = new Map();
380
- for (var key in data) {
381
- datTmp.set(key, data[key]);
382
- }
383
- chat4appMessage.data.all = datTmp;
384
- chatCallback.onStartStopTyping(chat4appMessage);
385
- }
386
- else if (data.type == "new_user") {
387
- var chat4appMessage = new Chat4AppMessageReceive();
388
- chat4appMessage.data.chatId = data.chatId;
389
- chat4appMessage.data.chatMessageId = data.chatMessageId;
390
- chat4appMessage.data.externalId = data.externalId;
391
- chat4appMessage.data.fromId = data.fromId;
392
- chat4appMessage.data.toId = data.toId;
393
- chat4appMessage.data.groupId = data.groupId;
394
- chat4appMessage.data.dateHour = data.dateHour;
395
- chat4appMessage.data.type = data.type;
396
- var datTmp = new Map();
397
- for (var key in data) {
398
- datTmp.set(key, data[key]);
399
- }
400
- chat4appMessage.data.all = datTmp;
401
- chatCallback.onNewUser(chat4appMessage);
402
- }
403
- else if (data.type == "remove_user") {
404
- var chat4appMessage = new Chat4AppMessageReceive();
405
- chat4appMessage.data.chatId = data.chatId;
406
- chat4appMessage.data.chatMessageId = data.chatMessageId;
407
- chat4appMessage.data.externalId = data.externalId;
408
- chat4appMessage.data.fromId = data.fromId;
409
- chat4appMessage.data.toId = data.toId;
410
- chat4appMessage.data.groupId = data.groupId;
411
- chat4appMessage.data.dateHour = data.dateHour;
412
- chat4appMessage.data.type = data.type;
413
- var datTmp = new Map();
414
- for (var key in data) {
415
- datTmp.set(key, data[key]);
416
- }
417
- chat4appMessage.data.all = datTmp;
418
- chatCallback.onRemoveUser(chat4appMessage);
419
- }
420
- else if (data.type == "chat_closed") {
421
- var chat4appMessage = new Chat4AppMessageReceive();
422
- chat4appMessage.data.chatId = data.chatId;
423
- chat4appMessage.data.chatMessageId = data.chatMessageId;
424
- chat4appMessage.data.externalId = data.externalId;
425
- chat4appMessage.data.fromId = data.fromId;
426
- chat4appMessage.data.toId = data.toId;
427
- chat4appMessage.data.groupId = data.groupId;
428
- chat4appMessage.data.dateHour = data.dateHour;
429
- chat4appMessage.data.type = data.type;
430
- var datTmp = new Map();
431
- for (var key in data) {
432
- datTmp.set(key, data[key]);
433
- }
434
- chat4appMessage.data.all = datTmp;
435
- chatCallback.onChatClosed(chat4appMessage);
436
- }
437
- };
438
- Chat4appClientAngularService.prototype.connectWebsocket = function (chatCallback, token) {
439
- var _this = this;
440
- this.disconnect();
441
- var securityToken = this.getBearerToken();
442
- this.sock = new SockJS__namespace(this.chatServer + '/stomp/gkz-stomp-endpoint?token=' + securityToken);
443
- this.stompClient = Stomp__namespace.over(this.sock);
444
- var that = this;
445
- this.stompClient.debug = function (msg) {
446
- if (this.debug) {
447
- console.log(msg);
448
- }
449
- };
450
- var tokenAuth = "";
451
- if (securityToken && securityToken.startsWith("Bearer ")) {
452
- tokenAuth = securityToken;
453
- }
454
- else {
455
- tokenAuth = "Bearer " + securityToken;
456
- }
457
- this.stompClient.connect({ "X-Authorization": tokenAuth }, function (frame) {
458
- //console.log(frame);
459
- that.timeoutReconnect = 500;
460
- _this.stompClient.subscribe('/queue/' + token, function (msg) {
461
- //console.log('mensagem', msg);
462
- if (msg.command == "MESSAGE") {
463
- //console.log(msg)
464
- if (!chatCallback.isTokenFirebaseActive()) {
465
- var msgObj = JSON.parse(msg.body);
466
- var datTmp = new Map();
467
- for (var key in msgObj.data) {
468
- datTmp.set(key, msgObj.data[key]);
469
- }
470
- msgObj.data.all = datTmp;
471
- if (msgObj.data.type == "msg") {
472
- chatCallback.onMessage(msgObj);
473
- }
474
- else if ((msgObj.data.type == "on" || msgObj.data.type == "off")) {
475
- chatCallback.onOffline(msgObj);
476
- }
477
- else if (msgObj.data.type == "read") {
478
- chatCallback.onRead(msgObj);
479
- }
480
- else if (msgObj.data.type == "startTyping" || msgObj.data.type == "stopTyping") {
481
- chatCallback.onStartStopTyping(msgObj);
482
- }
483
- else if (msgObj.data.type == "new_user") {
484
- chatCallback.onNewUser(msgObj);
485
- }
486
- else if (msgObj.data.type == "remove_user") {
487
- chatCallback.onRemoveUser(msgObj);
488
- }
489
- else if (msgObj.data.type == "chat_closed") {
490
- chatCallback.onChatClosed(msgObj);
491
- }
492
- }
493
- //callback(msg.body);
494
- // ichatcallback.forEach((iChat)=>{
495
- // iChat.onMessage(JSON.parse(msg.body) );
496
- // });
497
- }
498
- });
499
- }, function (message) {
500
- // check message for disconnect
501
- //console.log("Disconnect");
502
- setTimeout(function () {
503
- that.timeoutReconnect *= 100;
504
- _this.connectWebsocket(chatCallback, token);
505
- }, that.timeoutReconnect);
506
- });
507
- };
508
- Chat4appClientAngularService.prototype.disconnect = function () {
509
- // console.log("disconnect")
510
- try {
511
- if (this.stompClient) {
512
- this.stompClient.disconnect();
513
- }
514
- }
515
- catch (e) {
516
- console.log(e);
517
- }
518
- };
519
- Chat4appClientAngularService.prototype.convertChat4AppMessageReceiveToChatMessage4App = function (msg) {
520
- var _a;
521
- var message = new ChatMessage4App();
522
- message.body = (_a = msg === null || msg === void 0 ? void 0 : msg.notification) === null || _a === void 0 ? void 0 : _a.body;
523
- message.chatId = msg.data.chatId;
524
- message.fromId = msg.data.fromId;
525
- message.toId = msg.data.toId;
526
- message.groupId = msg.data.groupId;
527
- message.replyFrom = msg.data.replyFrom;
528
- if (msg.data.dateHour && msg.data.dateHour.length > 0) {
529
- message.dateHourIncluded = msg.data.dateHour.substring(6, 10) + "-"
530
- + msg.data.dateHour.substring(3, 5) + "-"
531
- + msg.data.dateHour.substring(0, 2)
532
- + msg.data.dateHour.substring(10);
533
- }
534
- message.id = msg.data.chatMessageId;
535
- if (msg.data.fileId && msg.data.fileId.length > 0) {
536
- var messageFile = new ChatMessageFile4App();
537
- messageFile.id = msg.data.fileId;
538
- messageFile.name = msg.data.fileName;
539
- messageFile.size = msg.data.fileSize;
540
- messageFile.type = msg.data.fileType;
541
- message.chatMessageFile = messageFile;
542
- }
543
- if (msg.data.vFileId && msg.data.vFileId.length > 0) {
544
- var messageFile = new ChatMessageFile4App();
545
- messageFile.id = msg.data.vFileId;
546
- messageFile.name = msg.data.vFileName;
547
- messageFile.size = msg.data.vFileSize;
548
- messageFile.type = msg.data.vFileType;
549
- message.chatVoiceFile = messageFile;
550
- }
551
- return message;
552
- };
553
- return Chat4appClientAngularService;
554
- }());
555
- Chat4appClientAngularService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function Chat4appClientAngularService_Factory() { return new Chat4appClientAngularService(i0__namespace.ɵɵinject(i1__namespace.HttpClient)); }, token: Chat4appClientAngularService, providedIn: "root" });
556
- Chat4appClientAngularService.decorators = [
557
- { type: i0.Injectable, args: [{
558
- providedIn: 'root'
559
- },] }
560
- ];
561
- Chat4appClientAngularService.ctorParameters = function () { return [
562
- { type: i1.HttpClient }
563
- ]; };
564
- var Chat4App = /** @class */ (function () {
565
- function Chat4App() {
566
- }
567
- return Chat4App;
568
- }());
569
- var ChatUser4App = /** @class */ (function () {
570
- function ChatUser4App() {
571
- }
572
- return ChatUser4App;
573
- }());
574
- var ChatMessage4App = /** @class */ (function () {
575
- function ChatMessage4App() {
576
- }
577
- return ChatMessage4App;
578
- }());
579
- var ChatMessageFile4App = /** @class */ (function () {
580
- function ChatMessageFile4App() {
581
- }
582
- return ChatMessageFile4App;
583
- }());
584
- var ChatMessageMeta4App = /** @class */ (function () {
585
- function ChatMessageMeta4App() {
586
- }
587
- return ChatMessageMeta4App;
588
- }());
589
- var Chat4AppMessageReceive = /** @class */ (function () {
590
- function Chat4AppMessageReceive() {
591
- this.data = new Chat4AppMessageReceiveData();
592
- this.notification = new Chat4AppMessageReceiveNotification();
593
- }
594
- return Chat4AppMessageReceive;
595
- }());
596
- var Chat4AppMessageReceiveData = /** @class */ (function () {
597
- function Chat4AppMessageReceiveData() {
598
- }
599
- return Chat4AppMessageReceiveData;
600
- }());
601
- var Chat4AppMessageReceiveNotification = /** @class */ (function () {
602
- function Chat4AppMessageReceiveNotification() {
603
- }
604
- return Chat4AppMessageReceiveNotification;
605
- }());
606
- var ChatUserResponse4App = /** @class */ (function () {
607
- function ChatUserResponse4App() {
608
- }
609
- return ChatUserResponse4App;
610
- }());
611
- var ChatFilterRequest4App = /** @class */ (function () {
612
- function ChatFilterRequest4App() {
613
- }
614
- return ChatFilterRequest4App;
615
- }());
616
- var Chat4AppConfig = /** @class */ (function () {
617
- function Chat4AppConfig(endpoint, debug) {
618
- this.endpoint = endpoint;
619
- this.debug = debug;
620
- }
621
- return Chat4AppConfig;
622
- }());
623
- var Chat4AppTranslate = /** @class */ (function () {
624
- function Chat4AppTranslate() {
625
- }
626
- return Chat4AppTranslate;
627
- }());
628
- var ChatGroupApp = /** @class */ (function () {
629
- function ChatGroupApp() {
630
- }
631
- return ChatGroupApp;
632
- }());
633
- exports.ChatStatus4App = void 0;
634
- (function (ChatStatus4App) {
635
- ChatStatus4App["CREATED"] = "CREATED";
636
- ChatStatus4App["CLOSED"] = "CLOSED";
637
- })(exports.ChatStatus4App || (exports.ChatStatus4App = {}));
638
- exports.ChatUserStatus4App = void 0;
639
- (function (ChatUserStatus4App) {
640
- ChatUserStatus4App["REMOVED"] = "REMOVED";
641
- })(exports.ChatUserStatus4App || (exports.ChatUserStatus4App = {}));
642
- exports.ChatFilterType = void 0;
643
- (function (ChatFilterType) {
644
- ChatFilterType[ChatFilterType["COUNT_NOT_READ"] = 1] = "COUNT_NOT_READ";
645
- ChatFilterType[ChatFilterType["LAST_MESSAGE"] = 2] = "LAST_MESSAGE";
646
- })(exports.ChatFilterType || (exports.ChatFilterType = {}));
647
- exports.GroupStatus4App = void 0;
648
- (function (GroupStatus4App) {
649
- GroupStatus4App["CREATED"] = "CREATED";
650
- GroupStatus4App["CLOSED"] = "REMOVED";
30
+ var Chat4appClientAngularService = /** @class */ (function () {
31
+ function Chat4appClientAngularService(http) {
32
+ this.http = http;
33
+ this.chatServer = "";
34
+ this.chatUrl = "";
35
+ this.debug = false;
36
+ this.timeoutReconnect = 500;
37
+ }
38
+ Chat4appClientAngularService.prototype.ngOnInit = function () {
39
+ };
40
+ Chat4appClientAngularService.prototype.config = function (chat4AppConfig) {
41
+ this.chatServer = chat4AppConfig.endpoint;
42
+ this.chatUrl = chat4AppConfig.endpoint + "/api/v1/";
43
+ this.debug = chat4AppConfig.debug;
44
+ };
45
+ Chat4appClientAngularService.prototype.init = function (securityChatToken, callback, chatCallback, connectionClientId) {
46
+ if (!this.chatServer || this.chatServer.trim().length == 0) {
47
+ throw new Error("Endpoint is empty");
48
+ }
49
+ if (!securityChatToken || securityChatToken.trim().length == 0) {
50
+ throw new Error("SecurityChatToken is empty");
51
+ }
52
+ this.setTokenChat4app(securityChatToken);
53
+ if (chatCallback && connectionClientId) {
54
+ this.connectWebsocket(chatCallback, connectionClientId);
55
+ }
56
+ callback(securityChatToken);
57
+ };
58
+ Chat4appClientAngularService.prototype.getChatUrlDownload = function (messageFileId) {
59
+ return this.chatUrl + "chatmessage/getFile?messageFileId=" + messageFileId + "&token=" + this.getBearerToken();
60
+ };
61
+ Chat4appClientAngularService.prototype.getMessageChat = function (chatId, fromId, toId) {
62
+ var url = this.chatUrl + "chatmessage/" + chatId + "/" + fromId + "/" + toId;
63
+ return this.http.get(url, {
64
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
65
+ });
66
+ };
67
+ Chat4appClientAngularService.prototype.getMessageChatByGrop = function (chatId, groupId, fromId) {
68
+ var url = this.chatUrl + "chatmessage/byGroup/" + chatId + "/" + groupId + "/" + fromId;
69
+ return this.http.get(url, {
70
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
71
+ });
72
+ };
73
+ Chat4appClientAngularService.prototype.addMessageChat = function (chatMessage4App) {
74
+ var url = this.chatUrl + "chatmessage/" + chatMessage4App.chatId;
75
+ return this.http.post(url, chatMessage4App, {
76
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
77
+ });
78
+ };
79
+ Chat4appClientAngularService.prototype.props = function (chatFilterRequest4App) {
80
+ var url = this.chatUrl + "chatmessage/props";
81
+ return this.http.post(url, chatFilterRequest4App, {
82
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
83
+ });
84
+ };
85
+ Chat4appClientAngularService.prototype.removeUsersChat = function (chatId, chatUsersId, chatUsersExternalId) {
86
+ var params = new Array();
87
+ if (chatUsersId && chatUsersId.length > 0) {
88
+ chatUsersId.forEach(function (cui) {
89
+ params.push("chatUserId=" + cui);
90
+ });
91
+ }
92
+ else if (chatUsersExternalId && chatUsersExternalId.length > 0) {
93
+ chatUsersExternalId.forEach(function (cuei) {
94
+ params.push("chatUserExternalId=" + cuei);
95
+ });
96
+ }
97
+ var url = this.chatUrl + "chatuser/" + chatId + "?" + params.join("&");
98
+ return this.http.delete(url, {
99
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
100
+ });
101
+ };
102
+ Chat4appClientAngularService.prototype.removeUserChat = function (chatId, chatUserId, chatUserExternalId) {
103
+ var param = "";
104
+ if (chatUserId) {
105
+ param = "chatUserId=" + chatUserId;
106
+ }
107
+ else {
108
+ param = "chatUserExternalId=" + chatUserExternalId;
109
+ }
110
+ var url = this.chatUrl + "chatuser/" + chatId + "?" + param;
111
+ return this.http.delete(url, {
112
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
113
+ });
114
+ };
115
+ Chat4appClientAngularService.prototype.updateUserChat = function (chatId, charUser4AppUpdate) {
116
+ var url = this.chatUrl + "chatuser/" + chatId;
117
+ return this.http.put(url, charUser4AppUpdate, {
118
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
119
+ });
120
+ };
121
+ Chat4appClientAngularService.prototype.createUserChat = function (chatId, chatUser4App) {
122
+ var url = this.chatUrl + "chatuser/" + chatId;
123
+ return this.http.post(url, chatUser4App, {
124
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
125
+ });
126
+ };
127
+ Chat4appClientAngularService.prototype.createUsersChat = function (chatId, chatUser4App) {
128
+ var url = this.chatUrl + "chatuser/users/" + chatId;
129
+ return this.http.post(url, chatUser4App, {
130
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
131
+ });
132
+ };
133
+ Chat4appClientAngularService.prototype.createChat = function (chat4app) {
134
+ var url = this.chatUrl + "chat";
135
+ return this.http.post(url, chat4app, {
136
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
137
+ });
138
+ };
139
+ Chat4appClientAngularService.prototype.createUpdateChat = function (chat4app) {
140
+ var url = this.chatUrl + "chat";
141
+ return this.http.put(url, chat4app, {
142
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
143
+ });
144
+ };
145
+ Chat4appClientAngularService.prototype.getLastMessageGroup = function (chatExternalId, groupId) {
146
+ var url = this.chatUrl + "chatmessage/lastMessageGroup?chatExternalId=" + chatExternalId + "&groupId=" + groupId;
147
+ return this.http.get(url, {
148
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
149
+ });
150
+ };
151
+ Chat4appClientAngularService.prototype.getLastMessage = function (chatExternalId, chatUserExternalId) {
152
+ var url = this.chatUrl + "chatmessage/lastMessage?chatExternalId=" + chatExternalId + "&chatUserExternalId=" + chatUserExternalId;
153
+ return this.http.get(url, {
154
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
155
+ });
156
+ };
157
+ Chat4appClientAngularService.prototype.countNotReadMessages = function (chatUserExternalId, chatExternalId, groupId, fromId) {
158
+ var url = this.chatUrl + "chatmessage/countNotReadMessages?chatUserExternalId=" + chatUserExternalId;
159
+ if (chatExternalId && chatExternalId.length > 0) {
160
+ url += "&chatExternalId=" + chatExternalId;
161
+ }
162
+ if (groupId && groupId.length > 0) {
163
+ url += "&groupId=" + groupId;
164
+ }
165
+ if (fromId && fromId.length > 0) {
166
+ url += "&fromId=" + groupId;
167
+ }
168
+ return this.http.get(url, {
169
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
170
+ });
171
+ };
172
+ Chat4appClientAngularService.prototype.getChatByExternalId = function (externalId) {
173
+ var url = this.chatUrl + "chat?externalId=" + externalId;
174
+ return this.http.get(url, {
175
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
176
+ });
177
+ };
178
+ Chat4appClientAngularService.prototype.getChatById = function (id) {
179
+ var url = this.chatUrl + "chat?chatId=" + id;
180
+ return this.http.get(url, {
181
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
182
+ });
183
+ };
184
+ Chat4appClientAngularService.prototype.listChatByUser = function (externalUserId, userId, chatStatus) {
185
+ var url = this.chatUrl + "chat/listChatByUser/?externalUserId=" + externalUserId
186
+ + "&userId=" + userId
187
+ + "&chatStatus=" + chatStatus;
188
+ return this.http.get(url, {
189
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
190
+ });
191
+ };
192
+ Chat4appClientAngularService.prototype.closeChat = function (chatId, chatExternalId) {
193
+ var url = this.chatUrl;
194
+ if (chatId && chatId.length > 0) {
195
+ url += "chat?chatId=" + chatId;
196
+ }
197
+ if (chatExternalId && chatExternalId.length > 0) {
198
+ url += "chat?externalId=" + chatExternalId;
199
+ }
200
+ return this.http.delete(url, {
201
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
202
+ });
203
+ };
204
+ Chat4appClientAngularService.prototype.readMessage = function (chatMessageId, toId) {
205
+ var url = this.chatUrl + "chatmessage/read/" + chatMessageId;
206
+ if (toId && toId.length > 0) {
207
+ url += "/" + toId;
208
+ }
209
+ return this.http.put(url, null, {
210
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
211
+ });
212
+ };
213
+ Chat4appClientAngularService.prototype.online = function (chatId) {
214
+ var url = this.chatUrl + "chatmessage/online/" + chatId;
215
+ return this.http.get(url, {
216
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
217
+ });
218
+ };
219
+ Chat4appClientAngularService.prototype.sendFile = function (chatId, fromId, toId, fileToUpload) {
220
+ var endpoint = this.chatUrl + "chatmessage/sendFile/" + chatId + "/" + fromId + "/" + toId;
221
+ var formData = new FormData();
222
+ formData.append('file', fileToUpload);
223
+ return this.http
224
+ .post(endpoint, formData, {
225
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
226
+ });
227
+ };
228
+ Chat4appClientAngularService.prototype.sendFileGroup = function (chatId, fromId, groupId, fileToUpload) {
229
+ var endpoint = this.chatUrl + "chatmessage/sendFileGroup/" + chatId + "/" + fromId + "/" + groupId;
230
+ var formData = new FormData();
231
+ formData.append('file', fileToUpload);
232
+ return this.http
233
+ .post(endpoint, formData, {
234
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
235
+ });
236
+ };
237
+ Chat4appClientAngularService.prototype.translateMessage = function (chatMessageId, languageTarget) {
238
+ var url = this.chatUrl + "chatmessage/translate/" + chatMessageId + "/" + languageTarget;
239
+ return this.http.get(url, {
240
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
241
+ });
242
+ };
243
+ Chat4appClientAngularService.prototype.startTyping = function (chatId, fromId, toId) {
244
+ var url = this.chatUrl + "chatmessage/startTyping/" + chatId + "/" + fromId + "/" + toId;
245
+ return this.http.put(url, null, {
246
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
247
+ });
248
+ };
249
+ Chat4appClientAngularService.prototype.startTypingGroup = function (chatId, fromId, groupId) {
250
+ var url = this.chatUrl + "chatmessage/startTypingGroup/" + chatId + "/" + fromId + "/" + groupId;
251
+ return this.http.put(url, null, {
252
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
253
+ });
254
+ };
255
+ Chat4appClientAngularService.prototype.stopTyping = function (chatId, fromId, toId) {
256
+ var url = this.chatUrl + "chatmessage/stopTyping/" + chatId + "/" + fromId + "/" + toId;
257
+ return this.http.put(url, null, {
258
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
259
+ });
260
+ };
261
+ Chat4appClientAngularService.prototype.stopTypingGroup = function (chatId, fromId, groupId) {
262
+ var url = this.chatUrl + "chatmessage/stopTypingGroup/" + chatId + "/" + fromId + "/" + groupId;
263
+ return this.http.put(url, null, {
264
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
265
+ });
266
+ };
267
+ Chat4appClientAngularService.prototype.createGroup = function (group) {
268
+ var url = this.chatUrl + "/group";
269
+ return this.http.post(url, group, {
270
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
271
+ });
272
+ };
273
+ Chat4appClientAngularService.prototype.getGroup = function (chatId, groupId) {
274
+ var url = this.chatUrl + "/group/" + groupId + "/" + chatId;
275
+ return this.http.get(url, {
276
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
277
+ });
278
+ };
279
+ Chat4appClientAngularService.prototype.listGroups = function (chatId, externalId) {
280
+ var url = this.chatUrl + "/group/";
281
+ if (chatId && chatId.length > 0) {
282
+ url += "&chatId=" + chatId;
283
+ }
284
+ if (externalId && externalId.length > 0) {
285
+ url += "&externalId=" + externalId;
286
+ }
287
+ return this.http.get(url, {
288
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
289
+ });
290
+ };
291
+ Chat4appClientAngularService.prototype.listFilesGroup = function (chatId, groupId) {
292
+ var url = this.chatUrl + "/group/" + chatId;
293
+ if (groupId && groupId.length > 0) {
294
+ url += "&groupId=" + chatId;
295
+ }
296
+ return this.http.get(url, {
297
+ headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
298
+ });
299
+ };
300
+ /* Token */
301
+ Chat4appClientAngularService.prototype.getBearerToken = function () {
302
+ var ret = "Bearer " + window.sessionStorage.getItem("chat4AppSessionToken");
303
+ return ret;
304
+ };
305
+ Chat4appClientAngularService.prototype.setTokenChat4app = function (chat4AppSessionToken) {
306
+ window.sessionStorage.setItem("chat4AppSessionToken", chat4AppSessionToken);
307
+ };
308
+ /* Connection */
309
+ Chat4appClientAngularService.prototype.onMessageFirebaseReceived = function (data, chatCallback) {
310
+ //alert("onMessageReceived connectFirebase");
311
+ if (data.type == "msg") {
312
+ var chat4appMessage = new Chat4AppMessageReceive();
313
+ chat4appMessage.data.chatId = data.chatId;
314
+ chat4appMessage.data.chatMessageId = data.chatMessageId;
315
+ chat4appMessage.data.externalId = data.externalId;
316
+ chat4appMessage.data.fromId = data.fromId;
317
+ chat4appMessage.data.toId = data.toId;
318
+ chat4appMessage.data.groupId = data.groupId;
319
+ chat4appMessage.data.dateHour = data.dateHour;
320
+ chat4appMessage.data.type = data.type;
321
+ chat4appMessage.notification.body = data.body;
322
+ if (data.fileId && data.fileId.length > 0) {
323
+ chat4appMessage.data.fileId = data.fileId;
324
+ chat4appMessage.data.fileName = data.fileName;
325
+ chat4appMessage.data.fileSize = data.fileSize;
326
+ chat4appMessage.data.fileType = data.fileType;
327
+ }
328
+ var datTmp = new Map();
329
+ for (var key in data) {
330
+ datTmp.set(key, data[key]);
331
+ }
332
+ chat4appMessage.data.all = datTmp;
333
+ chatCallback.onMessage(chat4appMessage);
334
+ }
335
+ else if ((data.type == "on" || data.type == "off")) {
336
+ var chat4appMessage = new Chat4AppMessageReceive();
337
+ chat4appMessage.data.chatId = data.chatId;
338
+ chat4appMessage.data.chatMessageId = data.chatMessageId;
339
+ chat4appMessage.data.externalId = data.externalId;
340
+ chat4appMessage.data.fromId = data.fromId;
341
+ chat4appMessage.data.toId = data.toId;
342
+ chat4appMessage.data.groupId = data.groupId;
343
+ chat4appMessage.data.dateHour = data.dateHour;
344
+ chat4appMessage.data.type = data.type;
345
+ var datTmp = new Map();
346
+ for (var key in data) {
347
+ datTmp.set(key, data[key]);
348
+ }
349
+ chat4appMessage.data.all = datTmp;
350
+ chatCallback.onOffline(chat4appMessage);
351
+ }
352
+ else if (data.type == "read") {
353
+ var chat4appMessage = new Chat4AppMessageReceive();
354
+ chat4appMessage.data.chatId = data.chatId;
355
+ chat4appMessage.data.chatMessageId = data.chatMessageId;
356
+ chat4appMessage.data.externalId = data.externalId;
357
+ chat4appMessage.data.fromId = data.fromId;
358
+ chat4appMessage.data.toId = data.toId;
359
+ chat4appMessage.data.groupId = data.groupId;
360
+ chat4appMessage.data.dateHour = data.dateHour;
361
+ chat4appMessage.data.type = data.type;
362
+ var datTmp = new Map();
363
+ for (var key in data) {
364
+ datTmp.set(key, data[key]);
365
+ }
366
+ chat4appMessage.data.all = datTmp;
367
+ chatCallback.onRead(chat4appMessage);
368
+ }
369
+ else if (data.type == "startTyping" || data.type == "stopTyping") {
370
+ var chat4appMessage = new Chat4AppMessageReceive();
371
+ chat4appMessage.data.chatId = data.chatId;
372
+ chat4appMessage.data.chatMessageId = data.chatMessageId;
373
+ chat4appMessage.data.externalId = data.externalId;
374
+ chat4appMessage.data.fromId = data.fromId;
375
+ chat4appMessage.data.toId = data.toId;
376
+ chat4appMessage.data.groupId = data.groupId;
377
+ chat4appMessage.data.dateHour = data.dateHour;
378
+ chat4appMessage.data.type = data.type;
379
+ var datTmp = new Map();
380
+ for (var key in data) {
381
+ datTmp.set(key, data[key]);
382
+ }
383
+ chat4appMessage.data.all = datTmp;
384
+ chatCallback.onStartStopTyping(chat4appMessage);
385
+ }
386
+ else if (data.type == "new_user") {
387
+ var chat4appMessage = new Chat4AppMessageReceive();
388
+ chat4appMessage.data.chatId = data.chatId;
389
+ chat4appMessage.data.chatMessageId = data.chatMessageId;
390
+ chat4appMessage.data.externalId = data.externalId;
391
+ chat4appMessage.data.fromId = data.fromId;
392
+ chat4appMessage.data.toId = data.toId;
393
+ chat4appMessage.data.groupId = data.groupId;
394
+ chat4appMessage.data.dateHour = data.dateHour;
395
+ chat4appMessage.data.type = data.type;
396
+ var datTmp = new Map();
397
+ for (var key in data) {
398
+ datTmp.set(key, data[key]);
399
+ }
400
+ chat4appMessage.data.all = datTmp;
401
+ chatCallback.onNewUser(chat4appMessage);
402
+ }
403
+ else if (data.type == "remove_user") {
404
+ var chat4appMessage = new Chat4AppMessageReceive();
405
+ chat4appMessage.data.chatId = data.chatId;
406
+ chat4appMessage.data.chatMessageId = data.chatMessageId;
407
+ chat4appMessage.data.externalId = data.externalId;
408
+ chat4appMessage.data.fromId = data.fromId;
409
+ chat4appMessage.data.toId = data.toId;
410
+ chat4appMessage.data.groupId = data.groupId;
411
+ chat4appMessage.data.dateHour = data.dateHour;
412
+ chat4appMessage.data.type = data.type;
413
+ var datTmp = new Map();
414
+ for (var key in data) {
415
+ datTmp.set(key, data[key]);
416
+ }
417
+ chat4appMessage.data.all = datTmp;
418
+ chatCallback.onRemoveUser(chat4appMessage);
419
+ }
420
+ else if (data.type == "chat_closed") {
421
+ var chat4appMessage = new Chat4AppMessageReceive();
422
+ chat4appMessage.data.chatId = data.chatId;
423
+ chat4appMessage.data.chatMessageId = data.chatMessageId;
424
+ chat4appMessage.data.externalId = data.externalId;
425
+ chat4appMessage.data.fromId = data.fromId;
426
+ chat4appMessage.data.toId = data.toId;
427
+ chat4appMessage.data.groupId = data.groupId;
428
+ chat4appMessage.data.dateHour = data.dateHour;
429
+ chat4appMessage.data.type = data.type;
430
+ var datTmp = new Map();
431
+ for (var key in data) {
432
+ datTmp.set(key, data[key]);
433
+ }
434
+ chat4appMessage.data.all = datTmp;
435
+ chatCallback.onChatClosed(chat4appMessage);
436
+ }
437
+ };
438
+ Chat4appClientAngularService.prototype.connectWebsocket = function (chatCallback, token) {
439
+ var _this = this;
440
+ this.disconnect();
441
+ var securityToken = this.getBearerToken();
442
+ this.sock = new SockJS__namespace(this.chatServer + '/stomp/gkz-stomp-endpoint?token=' + securityToken);
443
+ this.stompClient = Stomp__namespace.over(this.sock);
444
+ var that = this;
445
+ this.stompClient.debug = function (msg) {
446
+ if (this.debug) {
447
+ console.log(msg);
448
+ }
449
+ };
450
+ var tokenAuth = "";
451
+ if (securityToken && securityToken.startsWith("Bearer ")) {
452
+ tokenAuth = securityToken;
453
+ }
454
+ else {
455
+ tokenAuth = "Bearer " + securityToken;
456
+ }
457
+ this.stompClient.connect({ "X-Authorization": tokenAuth }, function (frame) {
458
+ //console.log(frame);
459
+ that.timeoutReconnect = 500;
460
+ _this.stompClient.subscribe('/queue/' + token, function (msg) {
461
+ //console.log('mensagem', msg);
462
+ if (msg.command == "MESSAGE") {
463
+ //console.log(msg)
464
+ if (!chatCallback.isTokenFirebaseActive()) {
465
+ var msgObj = JSON.parse(msg.body);
466
+ var datTmp = new Map();
467
+ for (var key in msgObj.data) {
468
+ datTmp.set(key, msgObj.data[key]);
469
+ }
470
+ msgObj.data.all = datTmp;
471
+ if (msgObj.data.type == "msg") {
472
+ chatCallback.onMessage(msgObj);
473
+ }
474
+ else if ((msgObj.data.type == "on" || msgObj.data.type == "off")) {
475
+ chatCallback.onOffline(msgObj);
476
+ }
477
+ else if (msgObj.data.type == "read") {
478
+ chatCallback.onRead(msgObj);
479
+ }
480
+ else if (msgObj.data.type == "startTyping" || msgObj.data.type == "stopTyping") {
481
+ chatCallback.onStartStopTyping(msgObj);
482
+ }
483
+ else if (msgObj.data.type == "new_user") {
484
+ chatCallback.onNewUser(msgObj);
485
+ }
486
+ else if (msgObj.data.type == "remove_user") {
487
+ chatCallback.onRemoveUser(msgObj);
488
+ }
489
+ else if (msgObj.data.type == "chat_closed") {
490
+ chatCallback.onChatClosed(msgObj);
491
+ }
492
+ }
493
+ //callback(msg.body);
494
+ // ichatcallback.forEach((iChat)=>{
495
+ // iChat.onMessage(JSON.parse(msg.body) );
496
+ // });
497
+ }
498
+ });
499
+ }, function (message) {
500
+ // check message for disconnect
501
+ //console.log("Disconnect");
502
+ setTimeout(function () {
503
+ that.timeoutReconnect *= 100;
504
+ _this.connectWebsocket(chatCallback, token);
505
+ }, that.timeoutReconnect);
506
+ });
507
+ };
508
+ Chat4appClientAngularService.prototype.disconnect = function () {
509
+ // console.log("disconnect")
510
+ try {
511
+ if (this.stompClient) {
512
+ this.stompClient.disconnect();
513
+ }
514
+ }
515
+ catch (e) {
516
+ console.log(e);
517
+ }
518
+ };
519
+ Chat4appClientAngularService.prototype.convertChat4AppMessageReceiveToChatMessage4App = function (msg) {
520
+ var _a;
521
+ var message = new ChatMessage4App();
522
+ message.body = (_a = msg === null || msg === void 0 ? void 0 : msg.notification) === null || _a === void 0 ? void 0 : _a.body;
523
+ message.chatId = msg.data.chatId;
524
+ message.fromId = msg.data.fromId;
525
+ message.toId = msg.data.toId;
526
+ message.groupId = msg.data.groupId;
527
+ message.replyFrom = msg.data.replyFrom;
528
+ if (msg.data.dateHour && msg.data.dateHour.length > 0) {
529
+ message.dateHourIncluded = msg.data.dateHour.substring(6, 10) + "-"
530
+ + msg.data.dateHour.substring(3, 5) + "-"
531
+ + msg.data.dateHour.substring(0, 2)
532
+ + msg.data.dateHour.substring(10);
533
+ }
534
+ message.id = msg.data.chatMessageId;
535
+ if (msg.data.fileId && msg.data.fileId.length > 0) {
536
+ var messageFile = new ChatMessageFile4App();
537
+ messageFile.id = msg.data.fileId;
538
+ messageFile.name = msg.data.fileName;
539
+ messageFile.size = msg.data.fileSize;
540
+ messageFile.type = msg.data.fileType;
541
+ message.chatMessageFile = messageFile;
542
+ }
543
+ if (msg.data.vFileId && msg.data.vFileId.length > 0) {
544
+ var messageFile = new ChatMessageFile4App();
545
+ messageFile.id = msg.data.vFileId;
546
+ messageFile.name = msg.data.vFileName;
547
+ messageFile.size = msg.data.vFileSize;
548
+ messageFile.type = msg.data.vFileType;
549
+ message.chatVoiceFile = messageFile;
550
+ }
551
+ return message;
552
+ };
553
+ return Chat4appClientAngularService;
554
+ }());
555
+ Chat4appClientAngularService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function Chat4appClientAngularService_Factory() { return new Chat4appClientAngularService(i0__namespace.ɵɵinject(i1__namespace.HttpClient)); }, token: Chat4appClientAngularService, providedIn: "root" });
556
+ Chat4appClientAngularService.decorators = [
557
+ { type: i0.Injectable, args: [{
558
+ providedIn: 'root'
559
+ },] }
560
+ ];
561
+ Chat4appClientAngularService.ctorParameters = function () { return [
562
+ { type: i1.HttpClient }
563
+ ]; };
564
+ var Chat4App = /** @class */ (function () {
565
+ function Chat4App() {
566
+ }
567
+ return Chat4App;
568
+ }());
569
+ var ChatUser4App = /** @class */ (function () {
570
+ function ChatUser4App() {
571
+ }
572
+ return ChatUser4App;
573
+ }());
574
+ var ChatMessage4App = /** @class */ (function () {
575
+ function ChatMessage4App() {
576
+ }
577
+ return ChatMessage4App;
578
+ }());
579
+ var ChatMessageFile4App = /** @class */ (function () {
580
+ function ChatMessageFile4App() {
581
+ }
582
+ return ChatMessageFile4App;
583
+ }());
584
+ var ChatMessageMeta4App = /** @class */ (function () {
585
+ function ChatMessageMeta4App() {
586
+ }
587
+ return ChatMessageMeta4App;
588
+ }());
589
+ var Chat4AppMessageReceive = /** @class */ (function () {
590
+ function Chat4AppMessageReceive() {
591
+ this.data = new Chat4AppMessageReceiveData();
592
+ this.notification = new Chat4AppMessageReceiveNotification();
593
+ }
594
+ return Chat4AppMessageReceive;
595
+ }());
596
+ var Chat4AppMessageReceiveData = /** @class */ (function () {
597
+ function Chat4AppMessageReceiveData() {
598
+ }
599
+ return Chat4AppMessageReceiveData;
600
+ }());
601
+ var Chat4AppMessageReceiveNotification = /** @class */ (function () {
602
+ function Chat4AppMessageReceiveNotification() {
603
+ }
604
+ return Chat4AppMessageReceiveNotification;
605
+ }());
606
+ var ChatUserResponse4App = /** @class */ (function () {
607
+ function ChatUserResponse4App() {
608
+ }
609
+ return ChatUserResponse4App;
610
+ }());
611
+ var ChatFilterRequest4App = /** @class */ (function () {
612
+ function ChatFilterRequest4App() {
613
+ }
614
+ return ChatFilterRequest4App;
615
+ }());
616
+ var Chat4AppConfig = /** @class */ (function () {
617
+ function Chat4AppConfig(endpoint, debug) {
618
+ this.endpoint = endpoint;
619
+ this.debug = debug;
620
+ }
621
+ return Chat4AppConfig;
622
+ }());
623
+ var Chat4AppTranslate = /** @class */ (function () {
624
+ function Chat4AppTranslate() {
625
+ }
626
+ return Chat4AppTranslate;
627
+ }());
628
+ var ChatGroupApp = /** @class */ (function () {
629
+ function ChatGroupApp() {
630
+ }
631
+ return ChatGroupApp;
632
+ }());
633
+ exports.ChatStatus4App = void 0;
634
+ (function (ChatStatus4App) {
635
+ ChatStatus4App["CREATED"] = "CREATED";
636
+ ChatStatus4App["CLOSED"] = "CLOSED";
637
+ })(exports.ChatStatus4App || (exports.ChatStatus4App = {}));
638
+ exports.ChatUserStatus4App = void 0;
639
+ (function (ChatUserStatus4App) {
640
+ ChatUserStatus4App["REMOVED"] = "REMOVED";
641
+ })(exports.ChatUserStatus4App || (exports.ChatUserStatus4App = {}));
642
+ exports.ChatFilterType = void 0;
643
+ (function (ChatFilterType) {
644
+ ChatFilterType[ChatFilterType["COUNT_NOT_READ"] = 1] = "COUNT_NOT_READ";
645
+ ChatFilterType[ChatFilterType["LAST_MESSAGE"] = 2] = "LAST_MESSAGE";
646
+ })(exports.ChatFilterType || (exports.ChatFilterType = {}));
647
+ exports.GroupStatus4App = void 0;
648
+ (function (GroupStatus4App) {
649
+ GroupStatus4App["CREATED"] = "CREATED";
650
+ GroupStatus4App["CLOSED"] = "REMOVED";
651
651
  })(exports.GroupStatus4App || (exports.GroupStatus4App = {}));
652
652
 
653
- var Chat4appClientAngularComponent = /** @class */ (function () {
654
- function Chat4appClientAngularComponent() {
655
- }
656
- Chat4appClientAngularComponent.prototype.ngOnInit = function () {
657
- };
658
- return Chat4appClientAngularComponent;
659
- }());
660
- Chat4appClientAngularComponent.decorators = [
661
- { type: i0.Component, args: [{
662
- selector: 'lib-chat4app-client-angular',
663
- template: "\n <p>\n chat4app-client-angular works!\n </p>\n "
664
- },] }
665
- ];
653
+ var Chat4appClientAngularComponent = /** @class */ (function () {
654
+ function Chat4appClientAngularComponent() {
655
+ }
656
+ Chat4appClientAngularComponent.prototype.ngOnInit = function () {
657
+ };
658
+ return Chat4appClientAngularComponent;
659
+ }());
660
+ Chat4appClientAngularComponent.decorators = [
661
+ { type: i0.Component, args: [{
662
+ selector: 'lib-chat4app-client-angular',
663
+ template: "\n <p>\n chat4app-client-angular works!\n </p>\n "
664
+ },] }
665
+ ];
666
666
  Chat4appClientAngularComponent.ctorParameters = function () { return []; };
667
667
 
668
- var Chat4appClientAngularModule = /** @class */ (function () {
669
- function Chat4appClientAngularModule() {
670
- }
671
- return Chat4appClientAngularModule;
672
- }());
673
- Chat4appClientAngularModule.decorators = [
674
- { type: i0.NgModule, args: [{
675
- declarations: [Chat4appClientAngularComponent],
676
- imports: [],
677
- exports: [Chat4appClientAngularComponent]
678
- },] }
668
+ var Chat4appClientAngularModule = /** @class */ (function () {
669
+ function Chat4appClientAngularModule() {
670
+ }
671
+ return Chat4appClientAngularModule;
672
+ }());
673
+ Chat4appClientAngularModule.decorators = [
674
+ { type: i0.NgModule, args: [{
675
+ declarations: [Chat4appClientAngularComponent],
676
+ imports: [],
677
+ exports: [Chat4appClientAngularComponent]
678
+ },] }
679
679
  ];
680
680
 
681
- /*
682
- * Public API Surface of chat4app-client-angular
681
+ /*
682
+ * Public API Surface of chat4app-client-angular
683
683
  */
684
684
 
685
- /**
686
- * Generated bundle index. Do not edit.
685
+ /**
686
+ * Generated bundle index. Do not edit.
687
687
  */
688
688
 
689
689
  exports.Chat4App = Chat4App;