chat4app-client-angular 0.0.2 → 0.0.5

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