chat4app-client-angular 0.0.32 → 0.0.34

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,617 +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) {
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
- return this.http.get(url, {
166
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
167
- });
168
- };
169
- Chat4appClientAngularService.prototype.getChatByExternalId = function (externalId) {
170
- var url = this.chatUrl + "chat?externalId=" + externalId;
171
- return this.http.get(url, {
172
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
173
- });
174
- };
175
- Chat4appClientAngularService.prototype.getChatById = function (id) {
176
- var url = this.chatUrl + "chat?chatId=" + id;
177
- return this.http.get(url, {
178
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
179
- });
180
- };
181
- Chat4appClientAngularService.prototype.listChatByUser = function (externalUserId, userId, chatStatus) {
182
- var url = this.chatUrl + "chat/listChatByUser/?externalUserId=" + externalUserId
183
- + "&userId=" + userId
184
- + "&chatStatus=" + chatStatus;
185
- return this.http.get(url, {
186
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
187
- });
188
- };
189
- Chat4appClientAngularService.prototype.closeChat = function (chatId, chatExternalId) {
190
- var url = this.chatUrl;
191
- if (chatId && chatId.length > 0) {
192
- url += "chat?chatId=" + chatId;
193
- }
194
- if (chatExternalId && chatExternalId.length > 0) {
195
- url += "chat?externalId=" + chatExternalId;
196
- }
197
- return this.http.delete(url, {
198
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
199
- });
200
- };
201
- Chat4appClientAngularService.prototype.readMessage = function (chatMessageId, toId) {
202
- var url = this.chatUrl + "chatmessage/read/" + chatMessageId;
203
- if (toId && toId.length > 0) {
204
- url += "/" + toId;
205
- }
206
- return this.http.put(url, null, {
207
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
208
- });
209
- };
210
- Chat4appClientAngularService.prototype.online = function (chatId) {
211
- var url = this.chatUrl + "chatmessage/online/" + chatId;
212
- return this.http.get(url, {
213
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
214
- });
215
- };
216
- Chat4appClientAngularService.prototype.sendFile = function (chatId, fromId, toId, fileToUpload) {
217
- var endpoint = this.chatUrl + "chatmessage/sendFile/" + chatId + "/" + fromId + "/" + toId;
218
- var formData = new FormData();
219
- formData.append('file', fileToUpload);
220
- return this.http
221
- .post(endpoint, formData, {
222
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
223
- });
224
- };
225
- Chat4appClientAngularService.prototype.sendFileGroup = function (chatId, fromId, groupId, fileToUpload) {
226
- var endpoint = this.chatUrl + "chatmessage/sendFileGroup/" + chatId + "/" + fromId + "/" + groupId;
227
- var formData = new FormData();
228
- formData.append('file', fileToUpload);
229
- return this.http
230
- .post(endpoint, formData, {
231
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
232
- });
233
- };
234
- Chat4appClientAngularService.prototype.translateMessage = function (chatMessageId, languageTarget) {
235
- var url = this.chatUrl + "chatmessage/translate/" + chatMessageId + "/" + languageTarget;
236
- return this.http.get(url, {
237
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
238
- });
239
- };
240
- Chat4appClientAngularService.prototype.startTyping = function (chatId, fromId, toId) {
241
- var url = this.chatUrl + "chatmessage/startTyping/" + chatId + "/" + fromId + "/" + toId;
242
- return this.http.put(url, null, {
243
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
244
- });
245
- };
246
- Chat4appClientAngularService.prototype.startTypingGroup = function (chatId, fromId, groupId) {
247
- var url = this.chatUrl + "chatmessage/startTypingGroup/" + chatId + "/" + fromId + "/" + groupId;
248
- return this.http.put(url, null, {
249
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
250
- });
251
- };
252
- Chat4appClientAngularService.prototype.stopTyping = function (chatId, fromId, toId) {
253
- var url = this.chatUrl + "chatmessage/stopTyping/" + chatId + "/" + fromId + "/" + toId;
254
- return this.http.put(url, null, {
255
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
256
- });
257
- };
258
- Chat4appClientAngularService.prototype.stopTypingGroup = function (chatId, fromId, groupId) {
259
- var url = this.chatUrl + "chatmessage/stopTypingGroup/" + chatId + "/" + fromId + "/" + groupId;
260
- return this.http.put(url, null, {
261
- headers: new i1.HttpHeaders().set('Authorization', this.getBearerToken())
262
- });
263
- };
264
- /* Token */
265
- Chat4appClientAngularService.prototype.getBearerToken = function () {
266
- var ret = "Bearer " + window.sessionStorage.getItem("chat4AppSessionToken");
267
- return ret;
268
- };
269
- Chat4appClientAngularService.prototype.setTokenChat4app = function (chat4AppSessionToken) {
270
- window.sessionStorage.setItem("chat4AppSessionToken", chat4AppSessionToken);
271
- };
272
- /* Connection */
273
- Chat4appClientAngularService.prototype.onMessageFirebaseReceived = function (data, chatCallback) {
274
- //alert("onMessageReceived connectFirebase");
275
- if (data.type == "msg") {
276
- var chat4appMessage = new Chat4AppMessageReceive();
277
- chat4appMessage.data.chatId = data.chatId;
278
- chat4appMessage.data.chatMessageId = data.chatMessageId;
279
- chat4appMessage.data.externalId = data.externalId;
280
- chat4appMessage.data.fromId = data.fromId;
281
- chat4appMessage.data.toId = data.toId;
282
- chat4appMessage.data.groupId = data.groupId;
283
- chat4appMessage.data.dateHour = data.dateHour;
284
- chat4appMessage.data.type = data.type;
285
- chat4appMessage.notification.body = data.body;
286
- if (data.fileId && data.fileId.length > 0) {
287
- chat4appMessage.data.fileId = data.fileId;
288
- chat4appMessage.data.fileName = data.fileName;
289
- chat4appMessage.data.fileSize = data.fileSize;
290
- chat4appMessage.data.fileType = data.fileType;
291
- }
292
- var datTmp = new Map();
293
- for (var key in data) {
294
- datTmp.set(key, data[key]);
295
- }
296
- chat4appMessage.data.all = datTmp;
297
- chatCallback.onMessage(chat4appMessage);
298
- }
299
- else if ((data.type == "on" || data.type == "off")) {
300
- var chat4appMessage = new Chat4AppMessageReceive();
301
- chat4appMessage.data.chatId = data.chatId;
302
- chat4appMessage.data.chatMessageId = data.chatMessageId;
303
- chat4appMessage.data.externalId = data.externalId;
304
- chat4appMessage.data.fromId = data.fromId;
305
- chat4appMessage.data.toId = data.toId;
306
- chat4appMessage.data.groupId = data.groupId;
307
- chat4appMessage.data.dateHour = data.dateHour;
308
- chat4appMessage.data.type = data.type;
309
- var datTmp = new Map();
310
- for (var key in data) {
311
- datTmp.set(key, data[key]);
312
- }
313
- chat4appMessage.data.all = datTmp;
314
- chatCallback.onOffline(chat4appMessage);
315
- }
316
- else if (data.type == "read") {
317
- var chat4appMessage = new Chat4AppMessageReceive();
318
- chat4appMessage.data.chatId = data.chatId;
319
- chat4appMessage.data.chatMessageId = data.chatMessageId;
320
- chat4appMessage.data.externalId = data.externalId;
321
- chat4appMessage.data.fromId = data.fromId;
322
- chat4appMessage.data.toId = data.toId;
323
- chat4appMessage.data.groupId = data.groupId;
324
- chat4appMessage.data.dateHour = data.dateHour;
325
- chat4appMessage.data.type = data.type;
326
- var datTmp = new Map();
327
- for (var key in data) {
328
- datTmp.set(key, data[key]);
329
- }
330
- chat4appMessage.data.all = datTmp;
331
- chatCallback.onRead(chat4appMessage);
332
- }
333
- else if (data.type == "startTyping" || data.type == "stopTyping") {
334
- var chat4appMessage = new Chat4AppMessageReceive();
335
- chat4appMessage.data.chatId = data.chatId;
336
- chat4appMessage.data.chatMessageId = data.chatMessageId;
337
- chat4appMessage.data.externalId = data.externalId;
338
- chat4appMessage.data.fromId = data.fromId;
339
- chat4appMessage.data.toId = data.toId;
340
- chat4appMessage.data.groupId = data.groupId;
341
- chat4appMessage.data.dateHour = data.dateHour;
342
- chat4appMessage.data.type = data.type;
343
- var datTmp = new Map();
344
- for (var key in data) {
345
- datTmp.set(key, data[key]);
346
- }
347
- chat4appMessage.data.all = datTmp;
348
- chatCallback.onStartStopTyping(chat4appMessage);
349
- }
350
- else if (data.type == "new_user") {
351
- var chat4appMessage = new Chat4AppMessageReceive();
352
- chat4appMessage.data.chatId = data.chatId;
353
- chat4appMessage.data.chatMessageId = data.chatMessageId;
354
- chat4appMessage.data.externalId = data.externalId;
355
- chat4appMessage.data.fromId = data.fromId;
356
- chat4appMessage.data.toId = data.toId;
357
- chat4appMessage.data.groupId = data.groupId;
358
- chat4appMessage.data.dateHour = data.dateHour;
359
- chat4appMessage.data.type = data.type;
360
- var datTmp = new Map();
361
- for (var key in data) {
362
- datTmp.set(key, data[key]);
363
- }
364
- chat4appMessage.data.all = datTmp;
365
- chatCallback.onNewUser(chat4appMessage);
366
- }
367
- else if (data.type == "remove_user") {
368
- var chat4appMessage = new Chat4AppMessageReceive();
369
- chat4appMessage.data.chatId = data.chatId;
370
- chat4appMessage.data.chatMessageId = data.chatMessageId;
371
- chat4appMessage.data.externalId = data.externalId;
372
- chat4appMessage.data.fromId = data.fromId;
373
- chat4appMessage.data.toId = data.toId;
374
- chat4appMessage.data.groupId = data.groupId;
375
- chat4appMessage.data.dateHour = data.dateHour;
376
- chat4appMessage.data.type = data.type;
377
- var datTmp = new Map();
378
- for (var key in data) {
379
- datTmp.set(key, data[key]);
380
- }
381
- chat4appMessage.data.all = datTmp;
382
- chatCallback.onRemoveUser(chat4appMessage);
383
- }
384
- else if (data.type == "chat_closed") {
385
- var chat4appMessage = new Chat4AppMessageReceive();
386
- chat4appMessage.data.chatId = data.chatId;
387
- chat4appMessage.data.chatMessageId = data.chatMessageId;
388
- chat4appMessage.data.externalId = data.externalId;
389
- chat4appMessage.data.fromId = data.fromId;
390
- chat4appMessage.data.toId = data.toId;
391
- chat4appMessage.data.groupId = data.groupId;
392
- chat4appMessage.data.dateHour = data.dateHour;
393
- chat4appMessage.data.type = data.type;
394
- var datTmp = new Map();
395
- for (var key in data) {
396
- datTmp.set(key, data[key]);
397
- }
398
- chat4appMessage.data.all = datTmp;
399
- chatCallback.onChatClosed(chat4appMessage);
400
- }
401
- };
402
- Chat4appClientAngularService.prototype.connectWebsocket = function (chatCallback, token) {
403
- var _this = this;
404
- this.disconnect();
405
- var securityToken = this.getBearerToken();
406
- this.sock = new SockJS__namespace(this.chatServer + '/stomp/gkz-stomp-endpoint?token=' + securityToken);
407
- this.stompClient = Stomp__namespace.over(this.sock);
408
- var that = this;
409
- this.stompClient.debug = function (msg) {
410
- if (this.debug) {
411
- console.log(msg);
412
- }
413
- };
414
- var tokenAuth = "";
415
- if (securityToken && securityToken.startsWith("Bearer ")) {
416
- tokenAuth = securityToken;
417
- }
418
- else {
419
- tokenAuth = "Bearer " + securityToken;
420
- }
421
- this.stompClient.connect({ "X-Authorization": tokenAuth }, function (frame) {
422
- //console.log(frame);
423
- that.timeoutReconnect = 500;
424
- _this.stompClient.subscribe('/queue/' + token, function (msg) {
425
- //console.log('mensagem', msg);
426
- if (msg.command == "MESSAGE") {
427
- //console.log(msg)
428
- if (!chatCallback.isTokenFirebaseActive()) {
429
- var msgObj = JSON.parse(msg.body);
430
- var datTmp = new Map();
431
- for (var key in msgObj.data) {
432
- datTmp.set(key, msgObj.data[key]);
433
- }
434
- msgObj.data.all = datTmp;
435
- if (msgObj.data.type == "msg") {
436
- chatCallback.onMessage(msgObj);
437
- }
438
- else if ((msgObj.data.type == "on" || msgObj.data.type == "off")) {
439
- chatCallback.onOffline(msgObj);
440
- }
441
- else if (msgObj.data.type == "read") {
442
- chatCallback.onRead(msgObj);
443
- }
444
- else if (msgObj.data.type == "startTyping" || msgObj.data.type == "stopTyping") {
445
- chatCallback.onStartStopTyping(msgObj);
446
- }
447
- else if (msgObj.data.type == "new_user") {
448
- chatCallback.onNewUser(msgObj);
449
- }
450
- else if (msgObj.data.type == "remove_user") {
451
- chatCallback.onRemoveUser(msgObj);
452
- }
453
- else if (msgObj.data.type == "chat_closed") {
454
- chatCallback.onChatClosed(msgObj);
455
- }
456
- }
457
- //callback(msg.body);
458
- // ichatcallback.forEach((iChat)=>{
459
- // iChat.onMessage(JSON.parse(msg.body) );
460
- // });
461
- }
462
- });
463
- }, function (message) {
464
- // check message for disconnect
465
- //console.log("Disconnect");
466
- setTimeout(function () {
467
- that.timeoutReconnect *= 100;
468
- _this.connectWebsocket(chatCallback, token);
469
- }, that.timeoutReconnect);
470
- });
471
- };
472
- Chat4appClientAngularService.prototype.disconnect = function () {
473
- // console.log("disconnect")
474
- try {
475
- if (this.stompClient) {
476
- this.stompClient.disconnect();
477
- }
478
- }
479
- catch (e) {
480
- console.log(e);
481
- }
482
- };
483
- Chat4appClientAngularService.prototype.convertChat4AppMessageReceiveToChatMessage4App = function (msg) {
484
- var _a;
485
- var message = new ChatMessage4App();
486
- message.body = (_a = msg === null || msg === void 0 ? void 0 : msg.notification) === null || _a === void 0 ? void 0 : _a.body;
487
- message.chatId = msg.data.chatId;
488
- message.fromId = msg.data.fromId;
489
- message.toId = msg.data.toId;
490
- message.groupId = msg.data.groupId;
491
- message.replyFrom = msg.data.replyFrom;
492
- if (msg.data.dateHour && msg.data.dateHour.length > 0) {
493
- message.dateHourIncluded = msg.data.dateHour.substring(6, 10) + "-"
494
- + msg.data.dateHour.substring(3, 5) + "-"
495
- + msg.data.dateHour.substring(0, 2)
496
- + msg.data.dateHour.substring(10);
497
- }
498
- message.id = msg.data.chatMessageId;
499
- if (msg.data.fileId && msg.data.fileId.length > 0) {
500
- var messageFile = new ChatMessageFile4App();
501
- messageFile.id = msg.data.fileId;
502
- messageFile.name = msg.data.fileName;
503
- messageFile.size = msg.data.fileSize;
504
- messageFile.type = msg.data.fileType;
505
- message.chatMessageFile = messageFile;
506
- }
507
- if (msg.data.vFileId && msg.data.vFileId.length > 0) {
508
- var messageFile = new ChatMessageFile4App();
509
- messageFile.id = msg.data.vFileId;
510
- messageFile.name = msg.data.vFileName;
511
- messageFile.size = msg.data.vFileSize;
512
- messageFile.type = msg.data.vFileType;
513
- message.chatVoiceFile = messageFile;
514
- }
515
- return message;
516
- };
517
- return Chat4appClientAngularService;
518
- }());
519
- Chat4appClientAngularService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function Chat4appClientAngularService_Factory() { return new Chat4appClientAngularService(i0__namespace.ɵɵinject(i1__namespace.HttpClient)); }, token: Chat4appClientAngularService, providedIn: "root" });
520
- Chat4appClientAngularService.decorators = [
521
- { type: i0.Injectable, args: [{
522
- providedIn: 'root'
523
- },] }
524
- ];
525
- Chat4appClientAngularService.ctorParameters = function () { return [
526
- { type: i1.HttpClient }
527
- ]; };
528
- var Chat4App = /** @class */ (function () {
529
- function Chat4App() {
530
- }
531
- return Chat4App;
532
- }());
533
- var ChatUser4App = /** @class */ (function () {
534
- function ChatUser4App() {
535
- }
536
- return ChatUser4App;
537
- }());
538
- var ChatMessage4App = /** @class */ (function () {
539
- function ChatMessage4App() {
540
- }
541
- return ChatMessage4App;
542
- }());
543
- var ChatMessageFile4App = /** @class */ (function () {
544
- function ChatMessageFile4App() {
545
- }
546
- return ChatMessageFile4App;
547
- }());
548
- var ChatMessageMeta4App = /** @class */ (function () {
549
- function ChatMessageMeta4App() {
550
- }
551
- return ChatMessageMeta4App;
552
- }());
553
- var Chat4AppMessageReceive = /** @class */ (function () {
554
- function Chat4AppMessageReceive() {
555
- this.data = new Chat4AppMessageReceiveData();
556
- this.notification = new Chat4AppMessageReceiveNotification();
557
- }
558
- return Chat4AppMessageReceive;
559
- }());
560
- var Chat4AppMessageReceiveData = /** @class */ (function () {
561
- function Chat4AppMessageReceiveData() {
562
- }
563
- return Chat4AppMessageReceiveData;
564
- }());
565
- var Chat4AppMessageReceiveNotification = /** @class */ (function () {
566
- function Chat4AppMessageReceiveNotification() {
567
- }
568
- return Chat4AppMessageReceiveNotification;
569
- }());
570
- var ChatUserResponse4App = /** @class */ (function () {
571
- function ChatUserResponse4App() {
572
- }
573
- return ChatUserResponse4App;
574
- }());
575
- var ChatFilterRequest4App = /** @class */ (function () {
576
- function ChatFilterRequest4App() {
577
- }
578
- return ChatFilterRequest4App;
579
- }());
580
- var Chat4AppConfig = /** @class */ (function () {
581
- function Chat4AppConfig(endpoint, debug) {
582
- this.endpoint = endpoint;
583
- this.debug = debug;
584
- }
585
- return Chat4AppConfig;
586
- }());
587
- var Chat4AppTranslate = /** @class */ (function () {
588
- function Chat4AppTranslate() {
589
- }
590
- return Chat4AppTranslate;
591
- }());
592
- exports.ChatStatus4App = void 0;
593
- (function (ChatStatus4App) {
594
- ChatStatus4App["CREATED"] = "CREATED";
595
- ChatStatus4App["CLOSED"] = "CLOSED";
596
- })(exports.ChatStatus4App || (exports.ChatStatus4App = {}));
597
- exports.ChatUserStatus4App = void 0;
598
- (function (ChatUserStatus4App) {
599
- ChatUserStatus4App["REMOVED"] = "REMOVED";
600
- })(exports.ChatUserStatus4App || (exports.ChatUserStatus4App = {}));
601
- exports.ChatFilterType = void 0;
602
- (function (ChatFilterType) {
603
- ChatFilterType[ChatFilterType["COUNT_NOT_READ"] = 1] = "COUNT_NOT_READ";
604
- ChatFilterType[ChatFilterType["LAST_MESSAGE"] = 2] = "LAST_MESSAGE";
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";
605
646
  })(exports.ChatFilterType || (exports.ChatFilterType = {}));
647
+ exports.GroupStatus4App = void 0;
648
+ (function (GroupStatus4App) {
649
+ GroupStatus4App["CREATED"] = "CREATED";
650
+ GroupStatus4App["CLOSED"] = "REMOVED";
651
+ })(exports.GroupStatus4App || (exports.GroupStatus4App = {}));
606
652
 
607
- var Chat4appClientAngularComponent = /** @class */ (function () {
608
- function Chat4appClientAngularComponent() {
609
- }
610
- Chat4appClientAngularComponent.prototype.ngOnInit = function () {
611
- };
612
- return Chat4appClientAngularComponent;
613
- }());
614
- Chat4appClientAngularComponent.decorators = [
615
- { type: i0.Component, args: [{
616
- selector: 'lib-chat4app-client-angular',
617
- template: "\n <p>\n chat4app-client-angular works!\n </p>\n "
618
- },] }
619
- ];
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
+ ];
620
666
  Chat4appClientAngularComponent.ctorParameters = function () { return []; };
621
667
 
622
- var Chat4appClientAngularModule = /** @class */ (function () {
623
- function Chat4appClientAngularModule() {
624
- }
625
- return Chat4appClientAngularModule;
626
- }());
627
- Chat4appClientAngularModule.decorators = [
628
- { type: i0.NgModule, args: [{
629
- declarations: [Chat4appClientAngularComponent],
630
- imports: [],
631
- exports: [Chat4appClientAngularComponent]
632
- },] }
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
+ },] }
633
679
  ];
634
680
 
635
- /*
636
- * Public API Surface of chat4app-client-angular
681
+ /*
682
+ * Public API Surface of chat4app-client-angular
637
683
  */
638
684
 
639
- /**
640
- * Generated bundle index. Do not edit.
685
+ /**
686
+ * Generated bundle index. Do not edit.
641
687
  */
642
688
 
643
689
  exports.Chat4App = Chat4App;
@@ -650,6 +696,7 @@
650
696
  exports.Chat4appClientAngularModule = Chat4appClientAngularModule;
651
697
  exports.Chat4appClientAngularService = Chat4appClientAngularService;
652
698
  exports.ChatFilterRequest4App = ChatFilterRequest4App;
699
+ exports.ChatGroupApp = ChatGroupApp;
653
700
  exports.ChatMessage4App = ChatMessage4App;
654
701
  exports.ChatMessageFile4App = ChatMessageFile4App;
655
702
  exports.ChatMessageMeta4App = ChatMessageMeta4App;