chat4app-client-angular 0.0.11 → 0.0.13

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,439 +6,465 @@ 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.dateHour = data.dateHour;
233
- chat4appMessage.data.type = data.type;
234
- chat4appMessage.notification.body = data.body;
235
- if (data.fileId && data.fileId.length > 0) {
236
- chat4appMessage.data.fileId = data.fileId;
237
- chat4appMessage.data.fileName = data.fileName;
238
- chat4appMessage.data.fileSize = data.fileSize;
239
- chat4appMessage.data.fileType = data.fileType;
240
- }
241
- let datTmp = new Map();
242
- for (let key in data) {
243
- datTmp.set(key, data[key]);
244
- }
245
- chat4appMessage.data.all = datTmp;
246
- chatCallback.onMessage(chat4appMessage);
247
- }
248
- else if ((data.type == "on" || data.type == "off")) {
249
- let chat4appMessage = new Chat4AppMessageReceive();
250
- chat4appMessage.data.chatId = data.chatId;
251
- chat4appMessage.data.chatMessageId = data.chatMessageId;
252
- chat4appMessage.data.externalId = data.externalId;
253
- chat4appMessage.data.fromId = data.fromId;
254
- chat4appMessage.data.toId = data.toId;
255
- chat4appMessage.data.dateHour = data.dateHour;
256
- chat4appMessage.data.type = data.type;
257
- let datTmp = new Map();
258
- for (let key in data) {
259
- datTmp.set(key, data[key]);
260
- }
261
- chat4appMessage.data.all = datTmp;
262
- chatCallback.onOffline(chat4appMessage);
263
- }
264
- else if (data.type == "read") {
265
- let chat4appMessage = new Chat4AppMessageReceive();
266
- chat4appMessage.data.chatId = data.chatId;
267
- chat4appMessage.data.chatMessageId = data.chatMessageId;
268
- chat4appMessage.data.externalId = data.externalId;
269
- chat4appMessage.data.fromId = data.fromId;
270
- chat4appMessage.data.toId = data.toId;
271
- chat4appMessage.data.dateHour = data.dateHour;
272
- chat4appMessage.data.type = data.type;
273
- let datTmp = new Map();
274
- for (let key in data) {
275
- datTmp.set(key, data[key]);
276
- }
277
- chat4appMessage.data.all = datTmp;
278
- chatCallback.onRead(chat4appMessage);
279
- }
280
- }
281
- connectWebsocket(chatCallback, token) {
282
- this.disconnect();
283
- let securityToken = this.getBearerToken();
284
- this.sock = new SockJS(this.chatServer + '/stomp/gkz-stomp-endpoint?token=' + securityToken);
285
- this.stompClient = Stomp.over(this.sock);
286
- this.stompClient.debug = function (msg) {
287
- //console.log(msg);
288
- };
289
- this.stompClient.connect({}, (frame) => {
290
- //console.log(frame);
291
- this.stompClient.subscribe('/queue/' + token, (msg) => {
292
- //console.log('mensagem', msg);
293
- if (msg.command == "MESSAGE") {
294
- //console.log(msg)
295
- let msgObj = JSON.parse(msg.body);
296
- let datTmp = new Map();
297
- for (let key in msgObj.data) {
298
- datTmp.set(key, msgObj.data[key]);
299
- }
300
- msgObj.data.all = datTmp;
301
- if (msgObj.data.type == "msg") {
302
- chatCallback.onMessage(msgObj);
303
- }
304
- else if ((msgObj.data.type == "on" || msgObj.data.type == "off")) {
305
- chatCallback.onOffline(msgObj);
306
- }
307
- else if (msgObj.data.type == "read") {
308
- chatCallback.onRead(msgObj);
309
- }
310
- //callback(msg.body);
311
- // ichatcallback.forEach((iChat)=>{
312
- // iChat.onMessage(JSON.parse(msg.body) );
313
- // });
314
- }
315
- });
316
- }, (message) => {
317
- // check message for disconnect
318
- //console.log("Disconnect");
319
- setTimeout(() => {
320
- this.connectWebsocket(chatCallback, token);
321
- }, 500);
322
- });
323
- }
324
- disconnect() {
325
- // console.log("disconnect")
326
- try {
327
- if (this.stompClient) {
328
- this.stompClient.disconnect();
329
- }
330
- }
331
- catch (e) {
332
- console.log(e);
333
- }
334
- }
335
- convertChat4AppMessageReceiveToChatMessage4App(msg) {
336
- let message = new ChatMessage4App();
337
- message.body = msg.notification.body;
338
- message.chatId = msg.data.chatId;
339
- message.fromId = msg.data.fromId;
340
- message.toId = msg.data.toId;
341
- message.dateHourIncluded = moment.utc(msg.data.dateHour, "DD-MM-YYYY hh:mm:ss").toDate();
342
- message.id = msg.data.chatMessageId;
343
- if (msg.data.fileId && msg.data.fileId.length > 0) {
344
- let messageFile = new ChatMessageFile4App();
345
- messageFile.id = msg.data.fileId;
346
- messageFile.name = msg.data.fileName;
347
- messageFile.size = msg.data.fileSize;
348
- messageFile.type = msg.data.fileType;
349
- message.chatMessageFile = messageFile;
350
- }
351
- return message;
352
- }
353
- }
354
- Chat4appClientAngularService.ɵprov = i0.ɵɵdefineInjectable({ factory: function Chat4appClientAngularService_Factory() { return new Chat4appClientAngularService(i0.ɵɵinject(i1.HttpClient)); }, token: Chat4appClientAngularService, providedIn: "root" });
355
- Chat4appClientAngularService.decorators = [
356
- { type: Injectable, args: [{
357
- providedIn: 'root'
358
- },] }
359
- ];
360
- Chat4appClientAngularService.ctorParameters = () => [
361
- { type: HttpClient }
362
- ];
363
- class Chat4App {
364
- }
365
- class ChatUser4App {
366
- }
367
- class ChatMessage4App {
368
- }
369
- class ChatMessageFile4App {
370
- }
371
- class ChatMessageMeta4App {
372
- }
373
- class Chat4AppMessageReceive {
374
- constructor() {
375
- this.data = new Chat4AppMessageReceiveData();
376
- this.notification = new Chat4AppMessageReceiveNotification();
377
- }
378
- }
379
- class Chat4AppMessageReceiveData {
380
- }
381
- class Chat4AppMessageReceiveNotification {
382
- }
383
- class ChatUserResponse4App {
384
- }
385
- class ChatFilterRequest4App {
386
- }
387
- class Chat4AppConfig {
388
- constructor(endpoint) {
389
- this.endpoint = endpoint;
390
- }
391
- }
392
- class Chat4AppTranslate {
393
- }
394
- var ChatStatus4App;
395
- (function (ChatStatus4App) {
396
- ChatStatus4App["CREATED"] = "CREATED";
397
- ChatStatus4App["CLOSED"] = "CLOSED";
398
- })(ChatStatus4App || (ChatStatus4App = {}));
399
- var ChatUserStatus4App;
400
- (function (ChatUserStatus4App) {
401
- ChatUserStatus4App["REMOVED"] = "REMOVED";
402
- })(ChatUserStatus4App || (ChatUserStatus4App = {}));
403
- var ChatFilterType;
404
- (function (ChatFilterType) {
405
- ChatFilterType[ChatFilterType["COUNT_NOT_READ"] = 1] = "COUNT_NOT_READ";
406
- 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
+ this.stompClient.connect({}, (frame) => {
310
+ //console.log(frame);
311
+ this.stompClient.subscribe('/queue/' + token, (msg) => {
312
+ //console.log('mensagem', msg);
313
+ if (msg.command == "MESSAGE") {
314
+ //console.log(msg)
315
+ if (!chatCallback.isTokenFirebaseActive()) {
316
+ let msgObj = JSON.parse(msg.body);
317
+ let datTmp = new Map();
318
+ for (let key in msgObj.data) {
319
+ datTmp.set(key, msgObj.data[key]);
320
+ }
321
+ msgObj.data.all = datTmp;
322
+ if (msgObj.data.type == "msg") {
323
+ chatCallback.onMessage(msgObj);
324
+ }
325
+ else if ((msgObj.data.type == "on" || msgObj.data.type == "off")) {
326
+ chatCallback.onOffline(msgObj);
327
+ }
328
+ else if (msgObj.data.type == "read") {
329
+ chatCallback.onRead(msgObj);
330
+ }
331
+ else if (msgObj.data.type == "startTyping" || msgObj.data.type == "stopTyping") {
332
+ chatCallback.onStartStopTyping(msgObj);
333
+ }
334
+ }
335
+ //callback(msg.body);
336
+ // ichatcallback.forEach((iChat)=>{
337
+ // iChat.onMessage(JSON.parse(msg.body) );
338
+ // });
339
+ }
340
+ });
341
+ }, (message) => {
342
+ // check message for disconnect
343
+ //console.log("Disconnect");
344
+ setTimeout(() => {
345
+ this.connectWebsocket(chatCallback, token);
346
+ }, 500);
347
+ });
348
+ }
349
+ disconnect() {
350
+ // console.log("disconnect")
351
+ try {
352
+ if (this.stompClient) {
353
+ this.stompClient.disconnect();
354
+ }
355
+ }
356
+ catch (e) {
357
+ console.log(e);
358
+ }
359
+ }
360
+ convertChat4AppMessageReceiveToChatMessage4App(msg) {
361
+ let message = new ChatMessage4App();
362
+ message.body = msg.notification.body;
363
+ message.chatId = msg.data.chatId;
364
+ message.fromId = msg.data.fromId;
365
+ message.toId = msg.data.toId;
366
+ message.groupId = msg.data.groupId;
367
+ message.dateHourIncluded = moment.utc(msg.data.dateHour, "DD-MM-YYYY hh:mm:ss").toDate();
368
+ message.id = msg.data.chatMessageId;
369
+ if (msg.data.fileId && msg.data.fileId.length > 0) {
370
+ let messageFile = new ChatMessageFile4App();
371
+ messageFile.id = msg.data.fileId;
372
+ messageFile.name = msg.data.fileName;
373
+ messageFile.size = msg.data.fileSize;
374
+ messageFile.type = msg.data.fileType;
375
+ message.chatMessageFile = messageFile;
376
+ }
377
+ return message;
378
+ }
379
+ }
380
+ Chat4appClientAngularService.ɵprov = i0.ɵɵdefineInjectable({ factory: function Chat4appClientAngularService_Factory() { return new Chat4appClientAngularService(i0.ɵɵinject(i1.HttpClient)); }, token: Chat4appClientAngularService, providedIn: "root" });
381
+ Chat4appClientAngularService.decorators = [
382
+ { type: Injectable, args: [{
383
+ providedIn: 'root'
384
+ },] }
385
+ ];
386
+ Chat4appClientAngularService.ctorParameters = () => [
387
+ { type: HttpClient }
388
+ ];
389
+ class Chat4App {
390
+ }
391
+ class ChatUser4App {
392
+ }
393
+ class ChatMessage4App {
394
+ }
395
+ class ChatMessageFile4App {
396
+ }
397
+ class ChatMessageMeta4App {
398
+ }
399
+ class Chat4AppMessageReceive {
400
+ constructor() {
401
+ this.data = new Chat4AppMessageReceiveData();
402
+ this.notification = new Chat4AppMessageReceiveNotification();
403
+ }
404
+ }
405
+ class Chat4AppMessageReceiveData {
406
+ }
407
+ class Chat4AppMessageReceiveNotification {
408
+ }
409
+ class ChatUserResponse4App {
410
+ }
411
+ class ChatFilterRequest4App {
412
+ }
413
+ class Chat4AppConfig {
414
+ constructor(endpoint) {
415
+ this.endpoint = endpoint;
416
+ }
417
+ }
418
+ class Chat4AppTranslate {
419
+ }
420
+ var ChatStatus4App;
421
+ (function (ChatStatus4App) {
422
+ ChatStatus4App["CREATED"] = "CREATED";
423
+ ChatStatus4App["CLOSED"] = "CLOSED";
424
+ })(ChatStatus4App || (ChatStatus4App = {}));
425
+ var ChatUserStatus4App;
426
+ (function (ChatUserStatus4App) {
427
+ ChatUserStatus4App["REMOVED"] = "REMOVED";
428
+ })(ChatUserStatus4App || (ChatUserStatus4App = {}));
429
+ var ChatFilterType;
430
+ (function (ChatFilterType) {
431
+ ChatFilterType[ChatFilterType["COUNT_NOT_READ"] = 1] = "COUNT_NOT_READ";
432
+ ChatFilterType[ChatFilterType["LAST_MESSAGE"] = 2] = "LAST_MESSAGE";
407
433
  })(ChatFilterType || (ChatFilterType = {}));
408
434
 
409
- class Chat4appClientAngularComponent {
410
- constructor() { }
411
- ngOnInit() {
412
- }
413
- }
414
- Chat4appClientAngularComponent.decorators = [
415
- { type: Component, args: [{
416
- selector: 'lib-chat4app-client-angular',
435
+ class Chat4appClientAngularComponent {
436
+ constructor() { }
437
+ ngOnInit() {
438
+ }
439
+ }
440
+ Chat4appClientAngularComponent.decorators = [
441
+ { type: Component, args: [{
442
+ selector: 'lib-chat4app-client-angular',
417
443
  template: `
418
444
  <p>
419
445
  chat4app-client-angular works!
420
446
  </p>
421
- `
422
- },] }
423
- ];
447
+ `
448
+ },] }
449
+ ];
424
450
  Chat4appClientAngularComponent.ctorParameters = () => [];
425
451
 
426
- class Chat4appClientAngularModule {
427
- }
428
- Chat4appClientAngularModule.decorators = [
429
- { type: NgModule, args: [{
430
- declarations: [Chat4appClientAngularComponent],
431
- imports: [],
432
- exports: [Chat4appClientAngularComponent]
433
- },] }
452
+ class Chat4appClientAngularModule {
453
+ }
454
+ Chat4appClientAngularModule.decorators = [
455
+ { type: NgModule, args: [{
456
+ declarations: [Chat4appClientAngularComponent],
457
+ imports: [],
458
+ exports: [Chat4appClientAngularComponent]
459
+ },] }
434
460
  ];
435
461
 
436
- /*
437
- * Public API Surface of chat4app-client-angular
462
+ /*
463
+ * Public API Surface of chat4app-client-angular
438
464
  */
439
465
 
440
- /**
441
- * Generated bundle index. Do not edit.
466
+ /**
467
+ * Generated bundle index. Do not edit.
442
468
  */
443
469
 
444
470
  export { Chat4App, Chat4AppConfig, Chat4AppMessageReceive, Chat4AppMessageReceiveData, Chat4AppMessageReceiveNotification, Chat4AppTranslate, Chat4appClientAngularComponent, Chat4appClientAngularModule, Chat4appClientAngularService, ChatFilterRequest4App, ChatFilterType, ChatMessage4App, ChatMessageFile4App, ChatMessageMeta4App, ChatStatus4App, ChatUser4App, ChatUserResponse4App, ChatUserStatus4App };