chat4app-client-angular 0.0.15 → 0.0.17

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.
@@ -6,472 +6,472 @@ import * as i1 from '@angular/common/http';
6
6
  import { HttpHeaders, HttpClient } from '@angular/common/http';
7
7
  import * as moment from 'moment';
8
8
 
9
- class Chat4appClientAngularService {
10
- constructor(http) {
11
- this.http = http;
12
- this.chatServer = "";
13
- this.chatUrl = "";
14
- }
15
- ngOnInit() {
16
- }
17
- config(chat4AppConfig) {
18
- this.chatServer = chat4AppConfig.endpoint;
19
- this.chatUrl = chat4AppConfig.endpoint + "/api/v1/";
20
- }
21
- init(securityChatToken, callback, chatCallback, connectionClientId) {
22
- if (!this.chatServer || this.chatServer.trim().length == 0) {
23
- throw new Error("Endpoint is empty");
24
- }
25
- if (!securityChatToken || securityChatToken.trim().length == 0) {
26
- throw new Error("SecurityChatToken is empty");
27
- }
28
- this.setTokenChat4app(securityChatToken);
29
- if (chatCallback && connectionClientId) {
30
- this.connectWebsocket(chatCallback, connectionClientId);
31
- }
32
- callback(securityChatToken);
33
- }
34
- getChatUrlDownload(messageFileId) {
35
- return this.chatUrl + "chatmessage/getFile?messageFileId=" + messageFileId + "&token=" + this.getBearerToken();
36
- }
37
- getMessageChat(chatId, fromId, toId) {
38
- let url = this.chatUrl + "chatmessage/" + chatId + "/" + fromId + "/" + toId;
39
- return this.http.get(url, {
40
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
41
- });
42
- }
43
- getMessageChatByGrop(chatId, groupId, fromId) {
44
- let url = this.chatUrl + "chatmessage/byGroup/" + chatId + "/" + groupId + "/" + fromId;
45
- return this.http.get(url, {
46
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
47
- });
48
- }
49
- addMessageChat(chatMessage4App) {
50
- let url = this.chatUrl + "chatmessage/" + chatMessage4App.chatId;
51
- return this.http.post(url, chatMessage4App, {
52
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
53
- });
54
- }
55
- props(chatFilterRequest4App) {
56
- let url = this.chatUrl + "chatmessage/props";
57
- return this.http.post(url, chatFilterRequest4App, {
58
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
59
- });
60
- }
61
- removeUsersChat(chatId, chatUsersId, chatUsersExternalId) {
62
- let params = new Array();
63
- if (chatUsersId && chatUsersId.length > 0) {
64
- chatUsersId.forEach(cui => {
65
- params.push("chatUserId=" + cui);
66
- });
67
- }
68
- else if (chatUsersExternalId && chatUsersExternalId.length > 0) {
69
- chatUsersExternalId.forEach(cuei => {
70
- params.push("chatUserExternalId=" + cuei);
71
- });
72
- }
73
- let url = this.chatUrl + "chatuser/" + chatId + "?" + params.join("&");
74
- return this.http.delete(url, {
75
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
76
- });
77
- }
78
- removeUserChat(chatId, chatUserId, chatUserExternalId) {
79
- let param = "";
80
- if (chatUserId) {
81
- param = "chatUserId=" + chatUserId;
82
- }
83
- else {
84
- param = "chatUserExternalId=" + chatUserExternalId;
85
- }
86
- let url = this.chatUrl + "chatuser/" + chatId + "?" + param;
87
- return this.http.delete(url, {
88
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
89
- });
90
- }
91
- updateUserChat(chatId, charUser4AppUpdate) {
92
- let url = this.chatUrl + "chatuser/" + chatId;
93
- return this.http.put(url, charUser4AppUpdate, {
94
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
95
- });
96
- }
97
- createUserChat(chatId, chatUser4App) {
98
- let url = this.chatUrl + "chatuser/" + chatId;
99
- return this.http.post(url, chatUser4App, {
100
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
101
- });
102
- }
103
- createUsersChat(chatId, chatUser4App) {
104
- let url = this.chatUrl + "chatuser/users/" + chatId;
105
- return this.http.post(url, chatUser4App, {
106
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
107
- });
108
- }
109
- createChat(chat4app) {
110
- let url = this.chatUrl + "chat";
111
- return this.http.post(url, chat4app, {
112
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
113
- });
114
- }
115
- createUpdateChat(chat4app) {
116
- let url = this.chatUrl + "chat";
117
- return this.http.put(url, chat4app, {
118
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
119
- });
120
- }
121
- getLastMessageGroup(chatExternalId, groupId) {
122
- let url = this.chatUrl + "chatmessage/lastMessageGroup?chatExternalId=" + chatExternalId + "&groupId=" + groupId;
123
- return this.http.get(url, {
124
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
125
- });
126
- }
127
- getLastMessage(chatExternalId, chatUserExternalId) {
128
- let url = this.chatUrl + "chatmessage/lastMessage?chatExternalId=" + chatExternalId + "&chatUserExternalId=" + chatUserExternalId;
129
- return this.http.get(url, {
130
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
131
- });
132
- }
133
- countNotReadMessages(chatUserExternalId, chatExternalId, groupId) {
134
- let url = this.chatUrl + "chatmessage/countNotReadMessages?chatUserExternalId=" + chatUserExternalId;
135
- if (chatExternalId && chatExternalId.length > 0) {
136
- url += "&chatExternalId=" + chatExternalId;
137
- }
138
- if (groupId && groupId.length > 0) {
139
- url += "&groupId=" + groupId;
140
- }
141
- return this.http.get(url, {
142
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
143
- });
144
- }
145
- getChatByExternalId(externalId) {
146
- let url = this.chatUrl + "chat?externalId=" + externalId;
147
- return this.http.get(url, {
148
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
149
- });
150
- }
151
- readMessage(chatMessageId, toId) {
152
- let url = this.chatUrl + "chatmessage/read/" + chatMessageId;
153
- if (toId && toId.length > 0) {
154
- url += "/" + toId;
155
- }
156
- return this.http.put(url, null, {
157
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
158
- });
159
- }
160
- online(chatId, chatUserId) {
161
- let url = this.chatUrl + "chatmessage/online/" + chatId + "/" + chatUserId;
162
- return this.http.get(url, {
163
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
164
- });
165
- }
166
- sendFile(chatId, fromId, toId, fileToUpload) {
167
- const endpoint = this.chatUrl + "chatmessage/sendFile/" + chatId + "/" + fromId + "/" + toId;
168
- const formData = new FormData();
169
- formData.append('file', fileToUpload);
170
- return this.http
171
- .post(endpoint, formData, {
172
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
173
- });
174
- }
175
- sendFileGroup(chatId, fromId, groupId, fileToUpload) {
176
- const endpoint = this.chatUrl + "chatmessage/sendFileGroup/" + chatId + "/" + fromId + "/" + groupId;
177
- const formData = new FormData();
178
- formData.append('file', fileToUpload);
179
- return this.http
180
- .post(endpoint, formData, {
181
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
182
- });
183
- }
184
- translateMessage(chatMessageId, languageTarget) {
185
- let url = this.chatUrl + "chatmessage/translate/" + chatMessageId + "/" + languageTarget;
186
- return this.http.get(url, {
187
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
188
- });
189
- }
190
- startTyping(chatId, fromId, toId) {
191
- let url = this.chatUrl + "chatmessage/startTyping/" + chatId + "/" + fromId + "/" + toId;
192
- return this.http.put(url, null, {
193
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
194
- });
195
- }
196
- startTypingGroup(chatId, fromId, groupId) {
197
- let url = this.chatUrl + "chatmessage/startTypingGroup/" + chatId + "/" + fromId + "/" + groupId;
198
- return this.http.put(url, null, {
199
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
200
- });
201
- }
202
- stopTyping(chatId, fromId, toId) {
203
- let url = this.chatUrl + "chatmessage/stopTyping/" + chatId + "/" + fromId + "/" + toId;
204
- return this.http.put(url, null, {
205
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
206
- });
207
- }
208
- stopTypingGroup(chatId, fromId, groupId) {
209
- let url = this.chatUrl + "chatmessage/stopTypingGroup/" + chatId + "/" + fromId + "/" + groupId;
210
- return this.http.put(url, null, {
211
- headers: new HttpHeaders().set('Authorization', this.getBearerToken())
212
- });
213
- }
214
- /* Token */
215
- getBearerToken() {
216
- let ret = "Bearer " + window.sessionStorage.getItem("chat4AppSessionToken");
217
- return ret;
218
- }
219
- setTokenChat4app(chat4AppSessionToken) {
220
- window.sessionStorage.setItem("chat4AppSessionToken", chat4AppSessionToken);
221
- }
222
- /* Connection */
223
- onMessageFirebaseReceived(data, chatCallback) {
224
- //alert("onMessageReceived connectFirebase");
225
- if (data.type == "msg") {
226
- let chat4appMessage = new Chat4AppMessageReceive();
227
- chat4appMessage.data.chatId = data.chatId;
228
- chat4appMessage.data.chatMessageId = data.chatMessageId;
229
- chat4appMessage.data.externalId = data.externalId;
230
- chat4appMessage.data.fromId = data.fromId;
231
- chat4appMessage.data.toId = data.toId;
232
- chat4appMessage.data.groupId = data.groupId;
233
- chat4appMessage.data.dateHour = data.dateHour;
234
- chat4appMessage.data.type = data.type;
235
- chat4appMessage.notification.body = data.body;
236
- if (data.fileId && data.fileId.length > 0) {
237
- chat4appMessage.data.fileId = data.fileId;
238
- chat4appMessage.data.fileName = data.fileName;
239
- chat4appMessage.data.fileSize = data.fileSize;
240
- chat4appMessage.data.fileType = data.fileType;
241
- }
242
- let datTmp = new Map();
243
- for (let key in data) {
244
- datTmp.set(key, data[key]);
245
- }
246
- chat4appMessage.data.all = datTmp;
247
- chatCallback.onMessage(chat4appMessage);
248
- }
249
- else if ((data.type == "on" || data.type == "off")) {
250
- let chat4appMessage = new Chat4AppMessageReceive();
251
- chat4appMessage.data.chatId = data.chatId;
252
- chat4appMessage.data.chatMessageId = data.chatMessageId;
253
- chat4appMessage.data.externalId = data.externalId;
254
- chat4appMessage.data.fromId = data.fromId;
255
- chat4appMessage.data.toId = data.toId;
256
- chat4appMessage.data.groupId = data.groupId;
257
- chat4appMessage.data.dateHour = data.dateHour;
258
- chat4appMessage.data.type = data.type;
259
- let datTmp = new Map();
260
- for (let key in data) {
261
- datTmp.set(key, data[key]);
262
- }
263
- chat4appMessage.data.all = datTmp;
264
- chatCallback.onOffline(chat4appMessage);
265
- }
266
- else if (data.type == "read") {
267
- let chat4appMessage = new Chat4AppMessageReceive();
268
- chat4appMessage.data.chatId = data.chatId;
269
- chat4appMessage.data.chatMessageId = data.chatMessageId;
270
- chat4appMessage.data.externalId = data.externalId;
271
- chat4appMessage.data.fromId = data.fromId;
272
- chat4appMessage.data.toId = data.toId;
273
- chat4appMessage.data.groupId = data.groupId;
274
- chat4appMessage.data.dateHour = data.dateHour;
275
- chat4appMessage.data.type = data.type;
276
- let datTmp = new Map();
277
- for (let key in data) {
278
- datTmp.set(key, data[key]);
279
- }
280
- chat4appMessage.data.all = datTmp;
281
- chatCallback.onRead(chat4appMessage);
282
- }
283
- else if (data.type == "startTyping" || data.type == "stopTyping") {
284
- let chat4appMessage = new Chat4AppMessageReceive();
285
- chat4appMessage.data.chatId = data.chatId;
286
- chat4appMessage.data.chatMessageId = data.chatMessageId;
287
- chat4appMessage.data.externalId = data.externalId;
288
- chat4appMessage.data.fromId = data.fromId;
289
- chat4appMessage.data.toId = data.toId;
290
- chat4appMessage.data.groupId = data.groupId;
291
- chat4appMessage.data.dateHour = data.dateHour;
292
- chat4appMessage.data.type = data.type;
293
- let datTmp = new Map();
294
- for (let key in data) {
295
- datTmp.set(key, data[key]);
296
- }
297
- chat4appMessage.data.all = datTmp;
298
- chatCallback.onStartStopTyping(chat4appMessage);
299
- }
300
- }
301
- connectWebsocket(chatCallback, token) {
302
- this.disconnect();
303
- let securityToken = this.getBearerToken();
304
- this.sock = new SockJS(this.chatServer + '/stomp/gkz-stomp-endpoint?token=' + securityToken);
305
- this.stompClient = Stomp.over(this.sock);
306
- this.stompClient.debug = function (msg) {
307
- //console.log(msg);
308
- };
309
- let tokenAuth = "";
310
- if (securityToken && securityToken.startsWith("Bearer ")) {
311
- tokenAuth = securityToken;
312
- }
313
- else {
314
- tokenAuth = "Bearer " + securityToken;
315
- }
316
- this.stompClient.connect({ "X-Authorization": tokenAuth }, (frame) => {
317
- //console.log(frame);
318
- this.stompClient.subscribe('/queue/' + token, (msg) => {
319
- //console.log('mensagem', msg);
320
- if (msg.command == "MESSAGE") {
321
- //console.log(msg)
322
- if (!chatCallback.isTokenFirebaseActive()) {
323
- let msgObj = JSON.parse(msg.body);
324
- let datTmp = new Map();
325
- for (let key in msgObj.data) {
326
- datTmp.set(key, msgObj.data[key]);
327
- }
328
- msgObj.data.all = datTmp;
329
- if (msgObj.data.type == "msg") {
330
- chatCallback.onMessage(msgObj);
331
- }
332
- else if ((msgObj.data.type == "on" || msgObj.data.type == "off")) {
333
- chatCallback.onOffline(msgObj);
334
- }
335
- else if (msgObj.data.type == "read") {
336
- chatCallback.onRead(msgObj);
337
- }
338
- else if (msgObj.data.type == "startTyping" || msgObj.data.type == "stopTyping") {
339
- chatCallback.onStartStopTyping(msgObj);
340
- }
341
- }
342
- //callback(msg.body);
343
- // ichatcallback.forEach((iChat)=>{
344
- // iChat.onMessage(JSON.parse(msg.body) );
345
- // });
346
- }
347
- });
348
- }, (message) => {
349
- // check message for disconnect
350
- //console.log("Disconnect");
351
- setTimeout(() => {
352
- this.connectWebsocket(chatCallback, token);
353
- }, 500);
354
- });
355
- }
356
- disconnect() {
357
- // console.log("disconnect")
358
- try {
359
- if (this.stompClient) {
360
- this.stompClient.disconnect();
361
- }
362
- }
363
- catch (e) {
364
- console.log(e);
365
- }
366
- }
367
- convertChat4AppMessageReceiveToChatMessage4App(msg) {
368
- let message = new ChatMessage4App();
369
- message.body = msg.notification.body;
370
- message.chatId = msg.data.chatId;
371
- message.fromId = msg.data.fromId;
372
- message.toId = msg.data.toId;
373
- message.groupId = msg.data.groupId;
374
- message.dateHourIncluded = moment.utc(msg.data.dateHour, "DD-MM-YYYY hh:mm:ss").toDate();
375
- message.id = msg.data.chatMessageId;
376
- if (msg.data.fileId && msg.data.fileId.length > 0) {
377
- let messageFile = new ChatMessageFile4App();
378
- messageFile.id = msg.data.fileId;
379
- messageFile.name = msg.data.fileName;
380
- messageFile.size = msg.data.fileSize;
381
- messageFile.type = msg.data.fileType;
382
- message.chatMessageFile = messageFile;
383
- }
384
- return message;
385
- }
386
- }
387
- Chat4appClientAngularService.ɵprov = i0.ɵɵdefineInjectable({ factory: function Chat4appClientAngularService_Factory() { return new Chat4appClientAngularService(i0.ɵɵinject(i1.HttpClient)); }, token: Chat4appClientAngularService, providedIn: "root" });
388
- Chat4appClientAngularService.decorators = [
389
- { type: Injectable, args: [{
390
- providedIn: 'root'
391
- },] }
392
- ];
393
- Chat4appClientAngularService.ctorParameters = () => [
394
- { type: HttpClient }
395
- ];
396
- class Chat4App {
397
- }
398
- class ChatUser4App {
399
- }
400
- class ChatMessage4App {
401
- }
402
- class ChatMessageFile4App {
403
- }
404
- class ChatMessageMeta4App {
405
- }
406
- class Chat4AppMessageReceive {
407
- constructor() {
408
- this.data = new Chat4AppMessageReceiveData();
409
- this.notification = new Chat4AppMessageReceiveNotification();
410
- }
411
- }
412
- class Chat4AppMessageReceiveData {
413
- }
414
- class Chat4AppMessageReceiveNotification {
415
- }
416
- class ChatUserResponse4App {
417
- }
418
- class ChatFilterRequest4App {
419
- }
420
- class Chat4AppConfig {
421
- constructor(endpoint) {
422
- this.endpoint = endpoint;
423
- }
424
- }
425
- class Chat4AppTranslate {
426
- }
427
- var ChatStatus4App;
428
- (function (ChatStatus4App) {
429
- ChatStatus4App["CREATED"] = "CREATED";
430
- ChatStatus4App["CLOSED"] = "CLOSED";
431
- })(ChatStatus4App || (ChatStatus4App = {}));
432
- var ChatUserStatus4App;
433
- (function (ChatUserStatus4App) {
434
- ChatUserStatus4App["REMOVED"] = "REMOVED";
435
- })(ChatUserStatus4App || (ChatUserStatus4App = {}));
436
- var ChatFilterType;
437
- (function (ChatFilterType) {
438
- ChatFilterType[ChatFilterType["COUNT_NOT_READ"] = 1] = "COUNT_NOT_READ";
439
- ChatFilterType[ChatFilterType["LAST_MESSAGE"] = 2] = "LAST_MESSAGE";
9
+ class Chat4appClientAngularService {
10
+ constructor(http) {
11
+ this.http = http;
12
+ this.chatServer = "";
13
+ this.chatUrl = "";
14
+ }
15
+ ngOnInit() {
16
+ }
17
+ config(chat4AppConfig) {
18
+ this.chatServer = chat4AppConfig.endpoint;
19
+ this.chatUrl = chat4AppConfig.endpoint + "/api/v1/";
20
+ }
21
+ init(securityChatToken, callback, chatCallback, connectionClientId) {
22
+ if (!this.chatServer || this.chatServer.trim().length == 0) {
23
+ throw new Error("Endpoint is empty");
24
+ }
25
+ if (!securityChatToken || securityChatToken.trim().length == 0) {
26
+ throw new Error("SecurityChatToken is empty");
27
+ }
28
+ this.setTokenChat4app(securityChatToken);
29
+ if (chatCallback && connectionClientId) {
30
+ this.connectWebsocket(chatCallback, connectionClientId);
31
+ }
32
+ callback(securityChatToken);
33
+ }
34
+ getChatUrlDownload(messageFileId) {
35
+ return this.chatUrl + "chatmessage/getFile?messageFileId=" + messageFileId + "&token=" + this.getBearerToken();
36
+ }
37
+ getMessageChat(chatId, fromId, toId) {
38
+ let url = this.chatUrl + "chatmessage/" + chatId + "/" + fromId + "/" + toId;
39
+ return this.http.get(url, {
40
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
41
+ });
42
+ }
43
+ getMessageChatByGrop(chatId, groupId, fromId) {
44
+ let url = this.chatUrl + "chatmessage/byGroup/" + chatId + "/" + groupId + "/" + fromId;
45
+ return this.http.get(url, {
46
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
47
+ });
48
+ }
49
+ addMessageChat(chatMessage4App) {
50
+ let url = this.chatUrl + "chatmessage/" + chatMessage4App.chatId;
51
+ return this.http.post(url, chatMessage4App, {
52
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
53
+ });
54
+ }
55
+ props(chatFilterRequest4App) {
56
+ let url = this.chatUrl + "chatmessage/props";
57
+ return this.http.post(url, chatFilterRequest4App, {
58
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
59
+ });
60
+ }
61
+ removeUsersChat(chatId, chatUsersId, chatUsersExternalId) {
62
+ let params = new Array();
63
+ if (chatUsersId && chatUsersId.length > 0) {
64
+ chatUsersId.forEach(cui => {
65
+ params.push("chatUserId=" + cui);
66
+ });
67
+ }
68
+ else if (chatUsersExternalId && chatUsersExternalId.length > 0) {
69
+ chatUsersExternalId.forEach(cuei => {
70
+ params.push("chatUserExternalId=" + cuei);
71
+ });
72
+ }
73
+ let url = this.chatUrl + "chatuser/" + chatId + "?" + params.join("&");
74
+ return this.http.delete(url, {
75
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
76
+ });
77
+ }
78
+ removeUserChat(chatId, chatUserId, chatUserExternalId) {
79
+ let param = "";
80
+ if (chatUserId) {
81
+ param = "chatUserId=" + chatUserId;
82
+ }
83
+ else {
84
+ param = "chatUserExternalId=" + chatUserExternalId;
85
+ }
86
+ let url = this.chatUrl + "chatuser/" + chatId + "?" + param;
87
+ return this.http.delete(url, {
88
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
89
+ });
90
+ }
91
+ updateUserChat(chatId, charUser4AppUpdate) {
92
+ let url = this.chatUrl + "chatuser/" + chatId;
93
+ return this.http.put(url, charUser4AppUpdate, {
94
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
95
+ });
96
+ }
97
+ createUserChat(chatId, chatUser4App) {
98
+ let url = this.chatUrl + "chatuser/" + chatId;
99
+ return this.http.post(url, chatUser4App, {
100
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
101
+ });
102
+ }
103
+ createUsersChat(chatId, chatUser4App) {
104
+ let url = this.chatUrl + "chatuser/users/" + chatId;
105
+ return this.http.post(url, chatUser4App, {
106
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
107
+ });
108
+ }
109
+ createChat(chat4app) {
110
+ let url = this.chatUrl + "chat";
111
+ return this.http.post(url, chat4app, {
112
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
113
+ });
114
+ }
115
+ createUpdateChat(chat4app) {
116
+ let url = this.chatUrl + "chat";
117
+ return this.http.put(url, chat4app, {
118
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
119
+ });
120
+ }
121
+ getLastMessageGroup(chatExternalId, groupId) {
122
+ let url = this.chatUrl + "chatmessage/lastMessageGroup?chatExternalId=" + chatExternalId + "&groupId=" + groupId;
123
+ return this.http.get(url, {
124
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
125
+ });
126
+ }
127
+ getLastMessage(chatExternalId, chatUserExternalId) {
128
+ let url = this.chatUrl + "chatmessage/lastMessage?chatExternalId=" + chatExternalId + "&chatUserExternalId=" + chatUserExternalId;
129
+ return this.http.get(url, {
130
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
131
+ });
132
+ }
133
+ countNotReadMessages(chatUserExternalId, chatExternalId, groupId) {
134
+ let url = this.chatUrl + "chatmessage/countNotReadMessages?chatUserExternalId=" + chatUserExternalId;
135
+ if (chatExternalId && chatExternalId.length > 0) {
136
+ url += "&chatExternalId=" + chatExternalId;
137
+ }
138
+ if (groupId && groupId.length > 0) {
139
+ url += "&groupId=" + groupId;
140
+ }
141
+ return this.http.get(url, {
142
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
143
+ });
144
+ }
145
+ getChatByExternalId(externalId) {
146
+ let url = this.chatUrl + "chat?externalId=" + externalId;
147
+ return this.http.get(url, {
148
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
149
+ });
150
+ }
151
+ readMessage(chatMessageId, toId) {
152
+ let url = this.chatUrl + "chatmessage/read/" + chatMessageId;
153
+ if (toId && toId.length > 0) {
154
+ url += "/" + toId;
155
+ }
156
+ return this.http.put(url, null, {
157
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
158
+ });
159
+ }
160
+ online(chatId, chatUserId) {
161
+ let url = this.chatUrl + "chatmessage/online/" + chatId + "/" + chatUserId;
162
+ return this.http.get(url, {
163
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
164
+ });
165
+ }
166
+ sendFile(chatId, fromId, toId, fileToUpload) {
167
+ const endpoint = this.chatUrl + "chatmessage/sendFile/" + chatId + "/" + fromId + "/" + toId;
168
+ const formData = new FormData();
169
+ formData.append('file', fileToUpload);
170
+ return this.http
171
+ .post(endpoint, formData, {
172
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
173
+ });
174
+ }
175
+ sendFileGroup(chatId, fromId, groupId, fileToUpload) {
176
+ const endpoint = this.chatUrl + "chatmessage/sendFileGroup/" + chatId + "/" + fromId + "/" + groupId;
177
+ const formData = new FormData();
178
+ formData.append('file', fileToUpload);
179
+ return this.http
180
+ .post(endpoint, formData, {
181
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
182
+ });
183
+ }
184
+ translateMessage(chatMessageId, languageTarget) {
185
+ let url = this.chatUrl + "chatmessage/translate/" + chatMessageId + "/" + languageTarget;
186
+ return this.http.get(url, {
187
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
188
+ });
189
+ }
190
+ startTyping(chatId, fromId, toId) {
191
+ let url = this.chatUrl + "chatmessage/startTyping/" + chatId + "/" + fromId + "/" + toId;
192
+ return this.http.put(url, null, {
193
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
194
+ });
195
+ }
196
+ startTypingGroup(chatId, fromId, groupId) {
197
+ let url = this.chatUrl + "chatmessage/startTypingGroup/" + chatId + "/" + fromId + "/" + groupId;
198
+ return this.http.put(url, null, {
199
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
200
+ });
201
+ }
202
+ stopTyping(chatId, fromId, toId) {
203
+ let url = this.chatUrl + "chatmessage/stopTyping/" + chatId + "/" + fromId + "/" + toId;
204
+ return this.http.put(url, null, {
205
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
206
+ });
207
+ }
208
+ stopTypingGroup(chatId, fromId, groupId) {
209
+ let url = this.chatUrl + "chatmessage/stopTypingGroup/" + chatId + "/" + fromId + "/" + groupId;
210
+ return this.http.put(url, null, {
211
+ headers: new HttpHeaders().set('Authorization', this.getBearerToken())
212
+ });
213
+ }
214
+ /* Token */
215
+ getBearerToken() {
216
+ let ret = "Bearer " + window.sessionStorage.getItem("chat4AppSessionToken");
217
+ return ret;
218
+ }
219
+ setTokenChat4app(chat4AppSessionToken) {
220
+ window.sessionStorage.setItem("chat4AppSessionToken", chat4AppSessionToken);
221
+ }
222
+ /* Connection */
223
+ onMessageFirebaseReceived(data, chatCallback) {
224
+ //alert("onMessageReceived connectFirebase");
225
+ if (data.type == "msg") {
226
+ let chat4appMessage = new Chat4AppMessageReceive();
227
+ chat4appMessage.data.chatId = data.chatId;
228
+ chat4appMessage.data.chatMessageId = data.chatMessageId;
229
+ chat4appMessage.data.externalId = data.externalId;
230
+ chat4appMessage.data.fromId = data.fromId;
231
+ chat4appMessage.data.toId = data.toId;
232
+ chat4appMessage.data.groupId = data.groupId;
233
+ chat4appMessage.data.dateHour = data.dateHour;
234
+ chat4appMessage.data.type = data.type;
235
+ chat4appMessage.notification.body = data.body;
236
+ if (data.fileId && data.fileId.length > 0) {
237
+ chat4appMessage.data.fileId = data.fileId;
238
+ chat4appMessage.data.fileName = data.fileName;
239
+ chat4appMessage.data.fileSize = data.fileSize;
240
+ chat4appMessage.data.fileType = data.fileType;
241
+ }
242
+ let datTmp = new Map();
243
+ for (let key in data) {
244
+ datTmp.set(key, data[key]);
245
+ }
246
+ chat4appMessage.data.all = datTmp;
247
+ chatCallback.onMessage(chat4appMessage);
248
+ }
249
+ else if ((data.type == "on" || data.type == "off")) {
250
+ let chat4appMessage = new Chat4AppMessageReceive();
251
+ chat4appMessage.data.chatId = data.chatId;
252
+ chat4appMessage.data.chatMessageId = data.chatMessageId;
253
+ chat4appMessage.data.externalId = data.externalId;
254
+ chat4appMessage.data.fromId = data.fromId;
255
+ chat4appMessage.data.toId = data.toId;
256
+ chat4appMessage.data.groupId = data.groupId;
257
+ chat4appMessage.data.dateHour = data.dateHour;
258
+ chat4appMessage.data.type = data.type;
259
+ let datTmp = new Map();
260
+ for (let key in data) {
261
+ datTmp.set(key, data[key]);
262
+ }
263
+ chat4appMessage.data.all = datTmp;
264
+ chatCallback.onOffline(chat4appMessage);
265
+ }
266
+ else if (data.type == "read") {
267
+ let chat4appMessage = new Chat4AppMessageReceive();
268
+ chat4appMessage.data.chatId = data.chatId;
269
+ chat4appMessage.data.chatMessageId = data.chatMessageId;
270
+ chat4appMessage.data.externalId = data.externalId;
271
+ chat4appMessage.data.fromId = data.fromId;
272
+ chat4appMessage.data.toId = data.toId;
273
+ chat4appMessage.data.groupId = data.groupId;
274
+ chat4appMessage.data.dateHour = data.dateHour;
275
+ chat4appMessage.data.type = data.type;
276
+ let datTmp = new Map();
277
+ for (let key in data) {
278
+ datTmp.set(key, data[key]);
279
+ }
280
+ chat4appMessage.data.all = datTmp;
281
+ chatCallback.onRead(chat4appMessage);
282
+ }
283
+ else if (data.type == "startTyping" || data.type == "stopTyping") {
284
+ let chat4appMessage = new Chat4AppMessageReceive();
285
+ chat4appMessage.data.chatId = data.chatId;
286
+ chat4appMessage.data.chatMessageId = data.chatMessageId;
287
+ chat4appMessage.data.externalId = data.externalId;
288
+ chat4appMessage.data.fromId = data.fromId;
289
+ chat4appMessage.data.toId = data.toId;
290
+ chat4appMessage.data.groupId = data.groupId;
291
+ chat4appMessage.data.dateHour = data.dateHour;
292
+ chat4appMessage.data.type = data.type;
293
+ let datTmp = new Map();
294
+ for (let key in data) {
295
+ datTmp.set(key, data[key]);
296
+ }
297
+ chat4appMessage.data.all = datTmp;
298
+ chatCallback.onStartStopTyping(chat4appMessage);
299
+ }
300
+ }
301
+ connectWebsocket(chatCallback, token) {
302
+ this.disconnect();
303
+ let securityToken = this.getBearerToken();
304
+ this.sock = new SockJS(this.chatServer + '/stomp/gkz-stomp-endpoint?token=' + securityToken);
305
+ this.stompClient = Stomp.over(this.sock);
306
+ this.stompClient.debug = function (msg) {
307
+ //console.log(msg);
308
+ };
309
+ let tokenAuth = "";
310
+ if (securityToken && securityToken.startsWith("Bearer ")) {
311
+ tokenAuth = securityToken;
312
+ }
313
+ else {
314
+ tokenAuth = "Bearer " + securityToken;
315
+ }
316
+ this.stompClient.connect({ "X-Authorization": tokenAuth }, (frame) => {
317
+ //console.log(frame);
318
+ this.stompClient.subscribe('/queue/' + token, (msg) => {
319
+ //console.log('mensagem', msg);
320
+ if (msg.command == "MESSAGE") {
321
+ //console.log(msg)
322
+ if (!chatCallback.isTokenFirebaseActive()) {
323
+ let msgObj = JSON.parse(msg.body);
324
+ let datTmp = new Map();
325
+ for (let key in msgObj.data) {
326
+ datTmp.set(key, msgObj.data[key]);
327
+ }
328
+ msgObj.data.all = datTmp;
329
+ if (msgObj.data.type == "msg") {
330
+ chatCallback.onMessage(msgObj);
331
+ }
332
+ else if ((msgObj.data.type == "on" || msgObj.data.type == "off")) {
333
+ chatCallback.onOffline(msgObj);
334
+ }
335
+ else if (msgObj.data.type == "read") {
336
+ chatCallback.onRead(msgObj);
337
+ }
338
+ else if (msgObj.data.type == "startTyping" || msgObj.data.type == "stopTyping") {
339
+ chatCallback.onStartStopTyping(msgObj);
340
+ }
341
+ }
342
+ //callback(msg.body);
343
+ // ichatcallback.forEach((iChat)=>{
344
+ // iChat.onMessage(JSON.parse(msg.body) );
345
+ // });
346
+ }
347
+ });
348
+ }, (message) => {
349
+ // check message for disconnect
350
+ //console.log("Disconnect");
351
+ setTimeout(() => {
352
+ this.connectWebsocket(chatCallback, token);
353
+ }, 500);
354
+ });
355
+ }
356
+ disconnect() {
357
+ // console.log("disconnect")
358
+ try {
359
+ if (this.stompClient) {
360
+ this.stompClient.disconnect();
361
+ }
362
+ }
363
+ catch (e) {
364
+ console.log(e);
365
+ }
366
+ }
367
+ convertChat4AppMessageReceiveToChatMessage4App(msg) {
368
+ let message = new ChatMessage4App();
369
+ message.body = msg.notification.body;
370
+ message.chatId = msg.data.chatId;
371
+ message.fromId = msg.data.fromId;
372
+ message.toId = msg.data.toId;
373
+ message.groupId = msg.data.groupId;
374
+ message.dateHourIncluded = moment.utc(msg.data.dateHour, "DD-MM-YYYY hh:mm:ss").toDate();
375
+ message.id = msg.data.chatMessageId;
376
+ if (msg.data.fileId && msg.data.fileId.length > 0) {
377
+ let messageFile = new ChatMessageFile4App();
378
+ messageFile.id = msg.data.fileId;
379
+ messageFile.name = msg.data.fileName;
380
+ messageFile.size = msg.data.fileSize;
381
+ messageFile.type = msg.data.fileType;
382
+ message.chatMessageFile = messageFile;
383
+ }
384
+ return message;
385
+ }
386
+ }
387
+ Chat4appClientAngularService.ɵprov = i0.ɵɵdefineInjectable({ factory: function Chat4appClientAngularService_Factory() { return new Chat4appClientAngularService(i0.ɵɵinject(i1.HttpClient)); }, token: Chat4appClientAngularService, providedIn: "root" });
388
+ Chat4appClientAngularService.decorators = [
389
+ { type: Injectable, args: [{
390
+ providedIn: 'root'
391
+ },] }
392
+ ];
393
+ Chat4appClientAngularService.ctorParameters = () => [
394
+ { type: HttpClient }
395
+ ];
396
+ class Chat4App {
397
+ }
398
+ class ChatUser4App {
399
+ }
400
+ class ChatMessage4App {
401
+ }
402
+ class ChatMessageFile4App {
403
+ }
404
+ class ChatMessageMeta4App {
405
+ }
406
+ class Chat4AppMessageReceive {
407
+ constructor() {
408
+ this.data = new Chat4AppMessageReceiveData();
409
+ this.notification = new Chat4AppMessageReceiveNotification();
410
+ }
411
+ }
412
+ class Chat4AppMessageReceiveData {
413
+ }
414
+ class Chat4AppMessageReceiveNotification {
415
+ }
416
+ class ChatUserResponse4App {
417
+ }
418
+ class ChatFilterRequest4App {
419
+ }
420
+ class Chat4AppConfig {
421
+ constructor(endpoint) {
422
+ this.endpoint = endpoint;
423
+ }
424
+ }
425
+ class Chat4AppTranslate {
426
+ }
427
+ var ChatStatus4App;
428
+ (function (ChatStatus4App) {
429
+ ChatStatus4App["CREATED"] = "CREATED";
430
+ ChatStatus4App["CLOSED"] = "CLOSED";
431
+ })(ChatStatus4App || (ChatStatus4App = {}));
432
+ var ChatUserStatus4App;
433
+ (function (ChatUserStatus4App) {
434
+ ChatUserStatus4App["REMOVED"] = "REMOVED";
435
+ })(ChatUserStatus4App || (ChatUserStatus4App = {}));
436
+ var ChatFilterType;
437
+ (function (ChatFilterType) {
438
+ ChatFilterType[ChatFilterType["COUNT_NOT_READ"] = 1] = "COUNT_NOT_READ";
439
+ ChatFilterType[ChatFilterType["LAST_MESSAGE"] = 2] = "LAST_MESSAGE";
440
440
  })(ChatFilterType || (ChatFilterType = {}));
441
441
 
442
- class Chat4appClientAngularComponent {
443
- constructor() { }
444
- ngOnInit() {
445
- }
446
- }
447
- Chat4appClientAngularComponent.decorators = [
448
- { type: Component, args: [{
449
- selector: 'lib-chat4app-client-angular',
442
+ class Chat4appClientAngularComponent {
443
+ constructor() { }
444
+ ngOnInit() {
445
+ }
446
+ }
447
+ Chat4appClientAngularComponent.decorators = [
448
+ { type: Component, args: [{
449
+ selector: 'lib-chat4app-client-angular',
450
450
  template: `
451
451
  <p>
452
452
  chat4app-client-angular works!
453
453
  </p>
454
- `
455
- },] }
456
- ];
454
+ `
455
+ },] }
456
+ ];
457
457
  Chat4appClientAngularComponent.ctorParameters = () => [];
458
458
 
459
- class Chat4appClientAngularModule {
460
- }
461
- Chat4appClientAngularModule.decorators = [
462
- { type: NgModule, args: [{
463
- declarations: [Chat4appClientAngularComponent],
464
- imports: [],
465
- exports: [Chat4appClientAngularComponent]
466
- },] }
459
+ class Chat4appClientAngularModule {
460
+ }
461
+ Chat4appClientAngularModule.decorators = [
462
+ { type: NgModule, args: [{
463
+ declarations: [Chat4appClientAngularComponent],
464
+ imports: [],
465
+ exports: [Chat4appClientAngularComponent]
466
+ },] }
467
467
  ];
468
468
 
469
- /*
470
- * Public API Surface of chat4app-client-angular
469
+ /*
470
+ * Public API Surface of chat4app-client-angular
471
471
  */
472
472
 
473
- /**
474
- * Generated bundle index. Do not edit.
473
+ /**
474
+ * Generated bundle index. Do not edit.
475
475
  */
476
476
 
477
477
  export { Chat4App, Chat4AppConfig, Chat4AppMessageReceive, Chat4AppMessageReceiveData, Chat4AppMessageReceiveNotification, Chat4AppTranslate, Chat4appClientAngularComponent, Chat4appClientAngularModule, Chat4appClientAngularService, ChatFilterRequest4App, ChatFilterType, ChatMessage4App, ChatMessageFile4App, ChatMessageMeta4App, ChatStatus4App, ChatUser4App, ChatUserResponse4App, ChatUserStatus4App };