ncloudchat 1.0.16 → 1.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.
@@ -0,0 +1,1676 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
4
+
5
+ var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
6
+
7
+ _Object$defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+
11
+ exports["default"] = void 0;
12
+
13
+ require("core-js/modules/es6.array.map");
14
+
15
+ require("core-js/modules/es6.regexp.split");
16
+
17
+ require("core-js/modules/es6.function.bind");
18
+
19
+ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
20
+
21
+ require("core-js/modules/es6.function.name");
22
+
23
+ var _iterator = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol/iterator"));
24
+
25
+ var _symbol = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol"));
26
+
27
+ var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
28
+
29
+ var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
30
+
31
+ var _socket = require("socket.io-client");
32
+
33
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
34
+
35
+ var _Dispatcher = _interopRequireDefault(require("./Dispatcher"));
36
+
37
+ var _logger = require("./logger");
38
+
39
+ var _queries = require("./queries");
40
+
41
+ var _mutations = require("./mutations");
42
+
43
+ var __assign = void 0 && (void 0).__assign || function () {
44
+ __assign = _assign["default"] || function (t) {
45
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
46
+ s = arguments[i];
47
+
48
+ for (var p in s) {
49
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
50
+ }
51
+ }
52
+
53
+ return t;
54
+ };
55
+
56
+ return __assign.apply(this, arguments);
57
+ };
58
+
59
+ var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
60
+ function adopt(value) {
61
+ return value instanceof P ? value : new P(function (resolve) {
62
+ resolve(value);
63
+ });
64
+ }
65
+
66
+ return new (P || (P = _promise["default"]))(function (resolve, reject) {
67
+ function fulfilled(value) {
68
+ try {
69
+ step(generator.next(value));
70
+ } catch (e) {
71
+ reject(e);
72
+ }
73
+ }
74
+
75
+ function rejected(value) {
76
+ try {
77
+ step(generator["throw"](value));
78
+ } catch (e) {
79
+ reject(e);
80
+ }
81
+ }
82
+
83
+ function step(result) {
84
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
85
+ }
86
+
87
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
88
+ });
89
+ };
90
+
91
+ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
92
+ var _ = {
93
+ label: 0,
94
+ sent: function sent() {
95
+ if (t[0] & 1) throw t[1];
96
+ return t[1];
97
+ },
98
+ trys: [],
99
+ ops: []
100
+ },
101
+ f,
102
+ y,
103
+ t,
104
+ g;
105
+ return g = {
106
+ next: verb(0),
107
+ "throw": verb(1),
108
+ "return": verb(2)
109
+ }, typeof _symbol["default"] === "function" && (g[_iterator["default"]] = function () {
110
+ return this;
111
+ }), g;
112
+
113
+ function verb(n) {
114
+ return function (v) {
115
+ return step([n, v]);
116
+ };
117
+ }
118
+
119
+ function step(op) {
120
+ if (f) throw new TypeError("Generator is already executing.");
121
+
122
+ while (_) {
123
+ try {
124
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
125
+ if (y = 0, t) op = [op[0] & 2, t.value];
126
+
127
+ switch (op[0]) {
128
+ case 0:
129
+ case 1:
130
+ t = op;
131
+ break;
132
+
133
+ case 4:
134
+ _.label++;
135
+ return {
136
+ value: op[1],
137
+ done: false
138
+ };
139
+
140
+ case 5:
141
+ _.label++;
142
+ y = op[1];
143
+ op = [0];
144
+ continue;
145
+
146
+ case 7:
147
+ op = _.ops.pop();
148
+
149
+ _.trys.pop();
150
+
151
+ continue;
152
+
153
+ default:
154
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
155
+ _ = 0;
156
+ continue;
157
+ }
158
+
159
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
160
+ _.label = op[1];
161
+ break;
162
+ }
163
+
164
+ if (op[0] === 6 && _.label < t[1]) {
165
+ _.label = t[1];
166
+ t = op;
167
+ break;
168
+ }
169
+
170
+ if (t && _.label < t[2]) {
171
+ _.label = t[2];
172
+
173
+ _.ops.push(op);
174
+
175
+ break;
176
+ }
177
+
178
+ if (t[2]) _.ops.pop();
179
+
180
+ _.trys.pop();
181
+
182
+ continue;
183
+ }
184
+
185
+ op = body.call(thisArg, _);
186
+ } catch (e) {
187
+ op = [6, e];
188
+ y = 0;
189
+ } finally {
190
+ f = t = 0;
191
+ }
192
+ }
193
+
194
+ if (op[0] & 5) throw op[1];
195
+ return {
196
+ value: op[0] ? op[1] : void 0,
197
+ done: true
198
+ };
199
+ }
200
+ };
201
+
202
+ var NCloudChat =
203
+ /** @class */
204
+ function () {
205
+ function NCloudChat() {
206
+ this.socket = null;
207
+ this.connected = false;
208
+ this.connectedCount = 0;
209
+ this.dp = new _Dispatcher["default"]();
210
+ }
211
+
212
+ NCloudChat.prototype.clear = function () {};
213
+
214
+ NCloudChat.prototype.initialize = function (projectId) {
215
+ _CoreManager["default"].set("PROJECT_ID", projectId);
216
+
217
+ _CoreManager["default"].set("USER", {
218
+ id: "",
219
+ name: "",
220
+ image: ""
221
+ });
222
+ };
223
+
224
+ NCloudChat.prototype.getLang = function () {
225
+ return navigator.language;
226
+ };
227
+
228
+ NCloudChat.prototype.getUser = function () {
229
+ return _CoreManager["default"].get("USER");
230
+ };
231
+
232
+ NCloudChat.prototype.setServerUrl = function (url) {
233
+ if (!/^[hHtTpP]{4}(s)?(:\/\/)[a-zA-Z0-9\.\/-:]+/.test(url)) {
234
+ throw Error("invalied url : (ex)http://domain.com, https://domain.com");
235
+ return;
236
+ }
237
+
238
+ if (url.length > 1 && url.substring(url.length - 1) === '/') {
239
+ url = url.substring(0, url.length - 1);
240
+ }
241
+
242
+ return _CoreManager["default"].set("SERVER_URL", url);
243
+ };
244
+
245
+ NCloudChat.prototype.setSocketUrl = function (url) {
246
+ _CoreManager["default"].set("SOCKET_URL", url);
247
+ };
248
+
249
+ NCloudChat.prototype.setProjectId = function (projectId) {
250
+ return _CoreManager["default"].set("PROJECT_ID", projectId);
251
+ };
252
+
253
+ NCloudChat.prototype.setToken = function (token) {
254
+ return _CoreManager["default"].set("TOKEN", token);
255
+ };
256
+
257
+ NCloudChat.prototype.setUser = function (user) {
258
+ _CoreManager["default"].set("USER", user);
259
+ };
260
+
261
+ NCloudChat.prototype.connect = function (user, userToken) {
262
+ if (userToken === void 0) {
263
+ userToken = "";
264
+ }
265
+
266
+ return __awaiter(this, void 0, void 0, function () {
267
+ var url, project_id, image, name, lang, e_1, options;
268
+
269
+ var _this = this;
270
+
271
+ return __generator(this, function (_a) {
272
+ switch (_a.label) {
273
+ case 0:
274
+ if (!this.isConnected()) return [3
275
+ /*break*/
276
+ , 2];
277
+ return [4
278
+ /*yield*/
279
+ , this.disconnect()];
280
+
281
+ case 1:
282
+ _a.sent();
283
+
284
+ _a.label = 2;
285
+
286
+ case 2:
287
+ url = _CoreManager["default"].get("SOCKET_URL") + '/cloudchat';
288
+ project_id = _CoreManager["default"].get("PROJECT_ID");
289
+
290
+ if (!project_id) {
291
+ throw Error("Project ID not found");
292
+ } // const user = CoreManager.get("USER");
293
+ // if (!user.id && user.id) user_id = user.id;
294
+
295
+
296
+ if (!user.id) {
297
+ throw Error("UserID not found");
298
+ }
299
+
300
+ image = user.profile;
301
+ name = user.name;
302
+ lang = this.getLang();
303
+ _a.label = 3;
304
+
305
+ case 3:
306
+ _a.trys.push([3, 5,, 6]);
307
+
308
+ return [4
309
+ /*yield*/
310
+ , (0, _mutations.login)(user.id, name, image, userToken)];
311
+
312
+ case 4:
313
+ userToken = _a.sent();
314
+ return [3
315
+ /*break*/
316
+ , 6];
317
+
318
+ case 5:
319
+ e_1 = _a.sent();
320
+ throw e_1;
321
+
322
+ case 6:
323
+ if (!userToken) {
324
+ throw Error("Token is not found");
325
+ }
326
+
327
+ _CoreManager["default"].set("TOKEN", userToken);
328
+
329
+ options = {
330
+ transports: ["websocket"],
331
+ reconnection: true,
332
+ reconnectionAttempts: 10,
333
+ reconnectionDelay: 2000,
334
+ reconnectionDelayMax: 2000 * 100,
335
+ randomizationFactor: 0.5,
336
+ query: {
337
+ project_id: project_id,
338
+ user_id: user.id,
339
+ lang: lang,
340
+ image: image,
341
+ name: name,
342
+ token: userToken
343
+ }
344
+ };
345
+ this.socket = (0, _socket.io)(url, options);
346
+ this.socket.on("connect", function (data) {
347
+ _this.connectedCount++;
348
+ _this.connected = true;
349
+ (0, _logger.info)("Connected to " + url + " with id: " + _this.socket.id + ", ConnectCount:" + _this.connectedCount);
350
+
351
+ _this.dp.dispatch("onConnected", data);
352
+ });
353
+ this.socket.on("unauthorized", function (data) {});
354
+ this.socket.on("disconnect", function (reason) {
355
+ _this.connected = false;
356
+ (0, _logger.info)("Disconnected to " + url + " with id: " + _this.socket.id);
357
+
358
+ _this.dp.dispatch("onDisconnected", reason);
359
+ });
360
+ this.socket.on("message", function (payload) {
361
+ var message = JSON.parse(payload);
362
+
363
+ _this.dp.dispatch("onMessageReceived", message.channel_id, message);
364
+ });
365
+ this.socket.on("event", function (payload) {
366
+ var message = JSON.parse(payload);
367
+
368
+ _this.dp.dispatch("onEventReceived", message.channel_id, message);
369
+ });
370
+ this.socket.on("start typing", function (payload) {
371
+ var data = JSON.parse(payload);
372
+
373
+ _this.dp.dispatch("onStartTyping", data);
374
+ });
375
+ this.socket.on("stop typing", function (payload) {
376
+ var data = JSON.parse(payload);
377
+
378
+ _this.dp.dispatch("onStopTyping", data);
379
+ });
380
+ this.socket.on("member added", function (payload) {
381
+ var data = JSON.parse(payload);
382
+
383
+ _this.dp.dispatch("onMemberAdded", data);
384
+ });
385
+ this.socket.on("member removed", function (payload) {
386
+ var data = JSON.parse(payload);
387
+
388
+ _this.dp.dispatch("onMemberRemoved", data);
389
+ });
390
+ this.socket.on("member updated", function (payload) {
391
+ var data = JSON.parse(payload);
392
+
393
+ _this.dp.dispatch("onMemberUpdated", data);
394
+ });
395
+ this.socket.on("message deleted", function (payload) {
396
+ var data = JSON.parse(payload);
397
+
398
+ _this.dp.dispatch("onMessageDeleted", data);
399
+ });
400
+ this.socket.on("message updated", function (payload) {
401
+ var data = JSON.parse(payload);
402
+
403
+ _this.dp.dispatch("onMessageUpdated", data);
404
+ });
405
+ this.socket.on("user banned", function (payload) {
406
+ var data = JSON.parse(payload);
407
+
408
+ _this.dp.dispatch("onUserBanned", data);
409
+ });
410
+ this.socket.on("user deleted", function (payload) {
411
+ var data = JSON.parse(payload);
412
+
413
+ _this.dp.dispatch("onUserDeleted", data);
414
+ });
415
+ this.socket.on("user updated", function (payload) {
416
+ var data = JSON.parse(payload);
417
+
418
+ _this.dp.dispatch("onUserUpdated", data);
419
+ });
420
+ this.socket.on("result", function (payload) {
421
+ var message = JSON.parse(payload);
422
+
423
+ _this.dp.dispatch("onResult", message);
424
+ });
425
+ this.socket.on("error", function (payload) {
426
+ var message = JSON.parse(payload);
427
+
428
+ _this.dp.dispatch("onErrorReceived", message);
429
+ });
430
+ return [2
431
+ /*return*/
432
+ , user];
433
+ }
434
+ });
435
+ });
436
+ };
437
+
438
+ NCloudChat.prototype.mute = function (channel) {
439
+ return __awaiter(this, void 0, void 0, function () {
440
+ var subscription, e_2;
441
+ return __generator(this, function (_a) {
442
+ switch (_a.label) {
443
+ case 0:
444
+ if (!this.isConnected()) {
445
+ throw Error("You are not connected.");
446
+ }
447
+
448
+ _a.label = 1;
449
+
450
+ case 1:
451
+ _a.trys.push([1, 3,, 4]);
452
+
453
+ return [4
454
+ /*yield*/
455
+ , (0, _mutations.updateSubscription)(channel, null, (0, _stringify["default"])({
456
+ mute: true
457
+ }))];
458
+
459
+ case 2:
460
+ subscription = _a.sent();
461
+ if (subscription) subscription.id = this.ObjectId(subscription.id);
462
+ return [2
463
+ /*return*/
464
+ , subscription];
465
+
466
+ case 3:
467
+ e_2 = _a.sent();
468
+ throw e_2;
469
+
470
+ case 4:
471
+ return [2
472
+ /*return*/
473
+ , null];
474
+ }
475
+ });
476
+ });
477
+ };
478
+
479
+ NCloudChat.prototype.unmute = function (channel) {
480
+ return __awaiter(this, void 0, void 0, function () {
481
+ var subscription, e_3;
482
+ return __generator(this, function (_a) {
483
+ switch (_a.label) {
484
+ case 0:
485
+ if (!this.isConnected()) {
486
+ throw Error("You are not connected.");
487
+ }
488
+
489
+ _a.label = 1;
490
+
491
+ case 1:
492
+ _a.trys.push([1, 3,, 4]);
493
+
494
+ return [4
495
+ /*yield*/
496
+ , (0, _mutations.updateSubscription)(channel, null, (0, _stringify["default"])({
497
+ mute: false
498
+ }))];
499
+
500
+ case 2:
501
+ subscription = _a.sent();
502
+ if (subscription) subscription.id = this.ObjectId(subscription.id);
503
+ return [2
504
+ /*return*/
505
+ , subscription];
506
+
507
+ case 3:
508
+ e_3 = _a.sent();
509
+ throw e_3;
510
+
511
+ case 4:
512
+ return [2
513
+ /*return*/
514
+ , null];
515
+ }
516
+ });
517
+ });
518
+ };
519
+
520
+ NCloudChat.prototype.subscribe = function (channel, option) {
521
+ if (option === void 0) {
522
+ option = null;
523
+ }
524
+
525
+ return __awaiter(this, void 0, void 0, function () {
526
+ var subscription, e_4;
527
+ return __generator(this, function (_a) {
528
+ switch (_a.label) {
529
+ case 0:
530
+ if (!this.isConnected()) {
531
+ throw Error("You are not connected.");
532
+ }
533
+
534
+ _a.label = 1;
535
+
536
+ case 1:
537
+ _a.trys.push([1, 3,, 4]);
538
+
539
+ return [4
540
+ /*yield*/
541
+ , (0, _mutations.createSubscription)(channel, (0, _stringify["default"])(option))];
542
+
543
+ case 2:
544
+ subscription = _a.sent();
545
+ if (subscription) subscription.id = this.ObjectId(subscription.id);
546
+ return [2
547
+ /*return*/
548
+ , subscription];
549
+
550
+ case 3:
551
+ e_4 = _a.sent();
552
+ throw e_4;
553
+
554
+ case 4:
555
+ return [2
556
+ /*return*/
557
+ , null];
558
+ }
559
+ });
560
+ });
561
+ };
562
+
563
+ NCloudChat.prototype.unsubscribe = function (channel) {
564
+ return __awaiter(this, void 0, void 0, function () {
565
+ var subscription, e_5;
566
+ return __generator(this, function (_a) {
567
+ switch (_a.label) {
568
+ case 0:
569
+ if (!this.isConnected()) {
570
+ throw Error("You are not connected.");
571
+ }
572
+
573
+ _a.label = 1;
574
+
575
+ case 1:
576
+ _a.trys.push([1, 3,, 4]);
577
+
578
+ return [4
579
+ /*yield*/
580
+ , (0, _mutations.deleteSubscription)(channel)];
581
+
582
+ case 2:
583
+ subscription = _a.sent();
584
+ return [2
585
+ /*return*/
586
+ , subscription];
587
+
588
+ case 3:
589
+ e_5 = _a.sent();
590
+ throw e_5;
591
+
592
+ case 4:
593
+ return [2
594
+ /*return*/
595
+ , null];
596
+ }
597
+ });
598
+ });
599
+ };
600
+
601
+ NCloudChat.prototype.translateMessage = function (channelId, source, target, message) {
602
+ return __awaiter(this, void 0, void 0, function () {
603
+ var user, result, e_6;
604
+ return __generator(this, function (_a) {
605
+ switch (_a.label) {
606
+ case 0:
607
+ if (!this.isConnected()) {
608
+ throw Error("You are not connected.");
609
+ }
610
+
611
+ _a.label = 1;
612
+
613
+ case 1:
614
+ _a.trys.push([1, 3,, 4]);
615
+
616
+ user = _CoreManager["default"].get("USER");
617
+ return [4
618
+ /*yield*/
619
+ , (0, _mutations.translate)(channelId, source, target, message)];
620
+
621
+ case 2:
622
+ result = _a.sent();
623
+ return [2
624
+ /*return*/
625
+ , result];
626
+
627
+ case 3:
628
+ e_6 = _a.sent();
629
+ throw Error(e_6.message);
630
+
631
+ case 4:
632
+ return [2
633
+ /*return*/
634
+ , null];
635
+ }
636
+ });
637
+ });
638
+ };
639
+
640
+ NCloudChat.prototype.sendMessage = function (channel, opt) {
641
+ return __awaiter(this, void 0, void 0, function () {
642
+ var user, data;
643
+ return __generator(this, function (_a) {
644
+ if (!this.isConnected()) {
645
+ throw Error("You are not connected.");
646
+ } // 채널 아이디가 존재하지 않을 경우 오류
647
+
648
+
649
+ if (!channel) {
650
+ throw Error("Channel ID is not found");
651
+ }
652
+
653
+ if (!opt.type) opt.type = "text";
654
+
655
+ if (!opt.message) {
656
+ throw Error("Message is NULL");
657
+ }
658
+
659
+ user = _CoreManager["default"].get("USER");
660
+
661
+ try {
662
+ data = __assign({
663
+ channelId: channel,
664
+ user: user
665
+ }, opt);
666
+ this.socket.emit("message", data);
667
+ return [2
668
+ /*return*/
669
+ , data];
670
+ } catch (e) {
671
+ return [2
672
+ /*return*/
673
+ , false];
674
+ }
675
+
676
+ return [2
677
+ /*return*/
678
+ ];
679
+ });
680
+ });
681
+ };
682
+
683
+ NCloudChat.prototype.sendImage = function (channelId, file) {
684
+ return __awaiter(this, void 0, void 0, function () {
685
+ var user, result;
686
+ return __generator(this, function (_a) {
687
+ switch (_a.label) {
688
+ case 0:
689
+ if (!this.isConnected()) {
690
+ throw Error("You are not connected.");
691
+ }
692
+
693
+ user = _CoreManager["default"].get("USER");
694
+ return [4
695
+ /*yield*/
696
+ , (0, _mutations.upload)(channelId, file)];
697
+
698
+ case 1:
699
+ result = _a.sent();
700
+ if (!result.status) throw Error(result.message);
701
+ return [2
702
+ /*return*/
703
+ , result];
704
+ }
705
+ });
706
+ });
707
+ };
708
+
709
+ NCloudChat.prototype.updateMessage = function (channel, message_id, message) {
710
+ return __awaiter(this, void 0, void 0, function () {
711
+ return __generator(this, function (_a) {
712
+ return [2
713
+ /*return*/
714
+ ];
715
+ });
716
+ });
717
+ };
718
+
719
+ NCloudChat.prototype.deleteMessage = function (channel, message_id) {
720
+ return __awaiter(this, void 0, void 0, function () {
721
+ return __generator(this, function (_a) {
722
+ return [2
723
+ /*return*/
724
+ ];
725
+ });
726
+ });
727
+ };
728
+
729
+ NCloudChat.prototype.disconnect = function () {
730
+ return __awaiter(this, void 0, void 0, function () {
731
+ return __generator(this, function (_a) {
732
+ if (!this.isConnected()) return [2
733
+ /*return*/
734
+ ];
735
+ this.socket.disconnect();
736
+ return [2
737
+ /*return*/
738
+ ];
739
+ });
740
+ });
741
+ };
742
+
743
+ NCloudChat.prototype.isConnected = function () {
744
+ return this.connected ? true : false;
745
+ };
746
+
747
+ NCloudChat.prototype.bind = function (id, fn) {
748
+ return __awaiter(this, void 0, void 0, function () {
749
+ return __generator(this, function (_a) {
750
+ this.dp.on(id, fn);
751
+ return [2
752
+ /*return*/
753
+ ];
754
+ });
755
+ });
756
+ };
757
+
758
+ NCloudChat.prototype.unbind = function (id, fn) {
759
+ return __awaiter(this, void 0, void 0, function () {
760
+ return __generator(this, function (_a) {
761
+ this.dp.off(id, fn);
762
+ return [2
763
+ /*return*/
764
+ ];
765
+ });
766
+ });
767
+ };
768
+
769
+ NCloudChat.prototype.unbindall = function (id) {
770
+ return __awaiter(this, void 0, void 0, function () {
771
+ return __generator(this, function (_a) {
772
+ this.dp.offall(id);
773
+ return [2
774
+ /*return*/
775
+ ];
776
+ });
777
+ });
778
+ };
779
+
780
+ NCloudChat.prototype.ObjectId = function (id) {
781
+ if (!id) return "";
782
+ return atob(id).split(":")[1];
783
+ };
784
+
785
+ NCloudChat.prototype.getFriendships = function (filter, sort, option) {
786
+ if (sort === void 0) {
787
+ sort = {};
788
+ }
789
+
790
+ if (option === void 0) {
791
+ option = {};
792
+ }
793
+
794
+ return __awaiter(this, void 0, void 0, function () {
795
+ var entries, friends, e_7;
796
+ return __generator(this, function (_a) {
797
+ switch (_a.label) {
798
+ case 0:
799
+ if (!this.isConnected()) {
800
+ throw Error("You are not connected.");
801
+ }
802
+
803
+ _a.label = 1;
804
+
805
+ case 1:
806
+ _a.trys.push([1, 3,, 4]);
807
+
808
+ return [4
809
+ /*yield*/
810
+ , (0, _queries.getFriendships)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
811
+
812
+ case 2:
813
+ entries = _a.sent();
814
+
815
+ if (entries) {
816
+ friends = entries.map(function (item) {
817
+ return __assign(__assign({}, item.node), {
818
+ id: item.node.id
819
+ });
820
+ });
821
+ return [2
822
+ /*return*/
823
+ , friends];
824
+ }
825
+
826
+ return [2
827
+ /*return*/
828
+ , entries];
829
+
830
+ case 3:
831
+ e_7 = _a.sent();
832
+ throw e_7;
833
+
834
+ case 4:
835
+ return [2
836
+ /*return*/
837
+ ];
838
+ }
839
+ });
840
+ });
841
+ };
842
+
843
+ NCloudChat.prototype.getMembers = function (filter, sort, option) {
844
+ if (sort === void 0) {
845
+ sort = {};
846
+ }
847
+
848
+ if (option === void 0) {
849
+ option = {};
850
+ }
851
+
852
+ return __awaiter(this, void 0, void 0, function () {
853
+ var entries, members, e_8;
854
+
855
+ var _this = this;
856
+
857
+ return __generator(this, function (_a) {
858
+ switch (_a.label) {
859
+ case 0:
860
+ if (!this.isConnected()) {
861
+ throw Error("You are not connected.");
862
+ }
863
+
864
+ _a.label = 1;
865
+
866
+ case 1:
867
+ _a.trys.push([1, 3,, 4]);
868
+
869
+ return [4
870
+ /*yield*/
871
+ , (0, _queries.getMembers)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
872
+
873
+ case 2:
874
+ entries = _a.sent();
875
+
876
+ if (entries) {
877
+ members = entries.map(function (item) {
878
+ return __assign(__assign({}, item.node), {
879
+ id: _this.ObjectId(item.node.id)
880
+ });
881
+ });
882
+ return [2
883
+ /*return*/
884
+ , members];
885
+ }
886
+
887
+ return [2
888
+ /*return*/
889
+ , entries];
890
+
891
+ case 3:
892
+ e_8 = _a.sent();
893
+ throw e_8;
894
+
895
+ case 4:
896
+ return [2
897
+ /*return*/
898
+ ];
899
+ }
900
+ });
901
+ });
902
+ };
903
+
904
+ NCloudChat.prototype.getChannels = function (filter, sort, option) {
905
+ if (sort === void 0) {
906
+ sort = {};
907
+ }
908
+
909
+ if (option === void 0) {
910
+ option = {};
911
+ }
912
+
913
+ return __awaiter(this, void 0, void 0, function () {
914
+ var entries, channels, e_9;
915
+
916
+ var _this = this;
917
+
918
+ return __generator(this, function (_a) {
919
+ switch (_a.label) {
920
+ case 0:
921
+ if (!this.isConnected()) {
922
+ throw Error("You are not connected.");
923
+ }
924
+
925
+ _a.label = 1;
926
+
927
+ case 1:
928
+ _a.trys.push([1, 3,, 4]);
929
+
930
+ return [4
931
+ /*yield*/
932
+ , (0, _queries.getChannels)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
933
+
934
+ case 2:
935
+ entries = _a.sent();
936
+
937
+ if (entries) {
938
+ channels = entries.map(function (item) {
939
+ return __assign(__assign({}, item.node), {
940
+ id: _this.ObjectId(item.node.id)
941
+ });
942
+ });
943
+ return [2
944
+ /*return*/
945
+ , channels];
946
+ }
947
+
948
+ return [2
949
+ /*return*/
950
+ , entries];
951
+
952
+ case 3:
953
+ e_9 = _a.sent();
954
+ throw e_9;
955
+
956
+ case 4:
957
+ return [2
958
+ /*return*/
959
+ ];
960
+ }
961
+ });
962
+ });
963
+ };
964
+
965
+ NCloudChat.prototype.requestFriend = function (friendId) {
966
+ return __awaiter(this, void 0, void 0, function () {
967
+ var e_10;
968
+ return __generator(this, function (_a) {
969
+ switch (_a.label) {
970
+ case 0:
971
+ if (!this.isConnected()) {
972
+ throw Error("You are not connected.");
973
+ }
974
+
975
+ _a.label = 1;
976
+
977
+ case 1:
978
+ _a.trys.push([1, 3,, 4]);
979
+
980
+ return [4
981
+ /*yield*/
982
+ , (0, _mutations.requestFriend)(friendId)];
983
+
984
+ case 2:
985
+ return [2
986
+ /*return*/
987
+ , _a.sent()];
988
+
989
+ case 3:
990
+ e_10 = _a.sent();
991
+ throw e_10;
992
+
993
+ case 4:
994
+ return [2
995
+ /*return*/
996
+ ];
997
+ }
998
+ });
999
+ });
1000
+ };
1001
+
1002
+ NCloudChat.prototype.acceptFriend = function (friendId) {
1003
+ return __awaiter(this, void 0, void 0, function () {
1004
+ var e_11;
1005
+ return __generator(this, function (_a) {
1006
+ switch (_a.label) {
1007
+ case 0:
1008
+ if (!this.isConnected()) {
1009
+ throw Error("You are not connected.");
1010
+ }
1011
+
1012
+ _a.label = 1;
1013
+
1014
+ case 1:
1015
+ _a.trys.push([1, 3,, 4]);
1016
+
1017
+ return [4
1018
+ /*yield*/
1019
+ , (0, _mutations.acceptFriend)(friendId)];
1020
+
1021
+ case 2:
1022
+ return [2
1023
+ /*return*/
1024
+ , _a.sent()];
1025
+
1026
+ case 3:
1027
+ e_11 = _a.sent();
1028
+ throw e_11;
1029
+
1030
+ case 4:
1031
+ return [2
1032
+ /*return*/
1033
+ ];
1034
+ }
1035
+ });
1036
+ });
1037
+ };
1038
+
1039
+ NCloudChat.prototype.rejectFriend = function (friendId) {
1040
+ return __awaiter(this, void 0, void 0, function () {
1041
+ var e_12;
1042
+ return __generator(this, function (_a) {
1043
+ switch (_a.label) {
1044
+ case 0:
1045
+ if (!this.isConnected()) {
1046
+ throw Error("You are not connected.");
1047
+ }
1048
+
1049
+ _a.label = 1;
1050
+
1051
+ case 1:
1052
+ _a.trys.push([1, 3,, 4]);
1053
+
1054
+ return [4
1055
+ /*yield*/
1056
+ , (0, _mutations.rejectFriend)(friendId)];
1057
+
1058
+ case 2:
1059
+ return [2
1060
+ /*return*/
1061
+ , _a.sent()];
1062
+
1063
+ case 3:
1064
+ e_12 = _a.sent();
1065
+ throw e_12;
1066
+
1067
+ case 4:
1068
+ return [2
1069
+ /*return*/
1070
+ ];
1071
+ }
1072
+ });
1073
+ });
1074
+ };
1075
+
1076
+ NCloudChat.prototype.removeFriend = function (friendId) {
1077
+ return __awaiter(this, void 0, void 0, function () {
1078
+ var e_13;
1079
+ return __generator(this, function (_a) {
1080
+ switch (_a.label) {
1081
+ case 0:
1082
+ if (!this.isConnected()) {
1083
+ throw Error("You are not connected.");
1084
+ }
1085
+
1086
+ _a.label = 1;
1087
+
1088
+ case 1:
1089
+ _a.trys.push([1, 3,, 4]);
1090
+
1091
+ return [4
1092
+ /*yield*/
1093
+ , (0, _mutations.removeFriend)(friendId)];
1094
+
1095
+ case 2:
1096
+ return [2
1097
+ /*return*/
1098
+ , _a.sent()];
1099
+
1100
+ case 3:
1101
+ e_13 = _a.sent();
1102
+ throw e_13;
1103
+
1104
+ case 4:
1105
+ return [2
1106
+ /*return*/
1107
+ ];
1108
+ }
1109
+ });
1110
+ });
1111
+ };
1112
+
1113
+ NCloudChat.prototype.countUnread = function (channelId) {
1114
+ return __awaiter(this, void 0, void 0, function () {
1115
+ var e_14;
1116
+ return __generator(this, function (_a) {
1117
+ switch (_a.label) {
1118
+ case 0:
1119
+ if (!this.isConnected()) {
1120
+ throw Error("You are not connected.");
1121
+ }
1122
+
1123
+ _a.label = 1;
1124
+
1125
+ case 1:
1126
+ _a.trys.push([1, 3,, 4]);
1127
+
1128
+ return [4
1129
+ /*yield*/
1130
+ , (0, _queries.unreadCount)(channelId)];
1131
+
1132
+ case 2:
1133
+ return [2
1134
+ /*return*/
1135
+ , _a.sent()];
1136
+
1137
+ case 3:
1138
+ e_14 = _a.sent();
1139
+ throw e_14;
1140
+
1141
+ case 4:
1142
+ return [2
1143
+ /*return*/
1144
+ ];
1145
+ }
1146
+ });
1147
+ });
1148
+ };
1149
+
1150
+ NCloudChat.prototype.getSubscription = function (channelId, id) {
1151
+ return __awaiter(this, void 0, void 0, function () {
1152
+ var e_15;
1153
+ return __generator(this, function (_a) {
1154
+ switch (_a.label) {
1155
+ case 0:
1156
+ if (!this.isConnected()) {
1157
+ throw Error("You are not connected.");
1158
+ }
1159
+
1160
+ _a.label = 1;
1161
+
1162
+ case 1:
1163
+ _a.trys.push([1, 3,, 4]);
1164
+
1165
+ return [4
1166
+ /*yield*/
1167
+ , (0, _queries.getSubscription)(channelId, id)];
1168
+
1169
+ case 2:
1170
+ return [2
1171
+ /*return*/
1172
+ , _a.sent()];
1173
+
1174
+ case 3:
1175
+ e_15 = _a.sent();
1176
+ throw e_15;
1177
+
1178
+ case 4:
1179
+ return [2
1180
+ /*return*/
1181
+ , null];
1182
+ }
1183
+ });
1184
+ });
1185
+ };
1186
+
1187
+ NCloudChat.prototype.getChannel = function (channelId) {
1188
+ return __awaiter(this, void 0, void 0, function () {
1189
+ var e_16;
1190
+ return __generator(this, function (_a) {
1191
+ switch (_a.label) {
1192
+ case 0:
1193
+ if (!this.isConnected()) {
1194
+ throw Error("You are not connected.");
1195
+ }
1196
+
1197
+ _a.label = 1;
1198
+
1199
+ case 1:
1200
+ _a.trys.push([1, 3,, 4]);
1201
+
1202
+ return [4
1203
+ /*yield*/
1204
+ , (0, _queries.getChannel)(channelId)];
1205
+
1206
+ case 2:
1207
+ return [2
1208
+ /*return*/
1209
+ , _a.sent()];
1210
+
1211
+ case 3:
1212
+ e_16 = _a.sent();
1213
+ throw e_16;
1214
+
1215
+ case 4:
1216
+ return [2
1217
+ /*return*/
1218
+ , null];
1219
+ }
1220
+ });
1221
+ });
1222
+ };
1223
+
1224
+ NCloudChat.prototype.getMessage = function (channelId, messageId) {
1225
+ return __awaiter(this, void 0, void 0, function () {
1226
+ var entry, e_17;
1227
+ return __generator(this, function (_a) {
1228
+ switch (_a.label) {
1229
+ case 0:
1230
+ if (!this.isConnected()) {
1231
+ throw Error("You are not connected.");
1232
+ }
1233
+
1234
+ _a.label = 1;
1235
+
1236
+ case 1:
1237
+ _a.trys.push([1, 3,, 4]);
1238
+
1239
+ return [4
1240
+ /*yield*/
1241
+ , (0, _queries.getMessage)(channelId, messageId)];
1242
+
1243
+ case 2:
1244
+ entry = _a.sent();
1245
+
1246
+ if (entry) {
1247
+ entry.id = this.ObjectId(entry.id);
1248
+ return [2
1249
+ /*return*/
1250
+ , entry];
1251
+ }
1252
+
1253
+ return [2
1254
+ /*return*/
1255
+ , null];
1256
+
1257
+ case 3:
1258
+ e_17 = _a.sent();
1259
+ throw e_17;
1260
+
1261
+ case 4:
1262
+ return [2
1263
+ /*return*/
1264
+ ];
1265
+ }
1266
+ });
1267
+ });
1268
+ };
1269
+
1270
+ NCloudChat.prototype.getMessages = function (filter, sort, option) {
1271
+ return __awaiter(this, void 0, void 0, function () {
1272
+ var entries, messages, e_18;
1273
+
1274
+ var _this = this;
1275
+
1276
+ return __generator(this, function (_a) {
1277
+ switch (_a.label) {
1278
+ case 0:
1279
+ if (!this.isConnected()) {
1280
+ throw Error("You are not connected.");
1281
+ }
1282
+
1283
+ _a.label = 1;
1284
+
1285
+ case 1:
1286
+ _a.trys.push([1, 3,, 4]);
1287
+
1288
+ return [4
1289
+ /*yield*/
1290
+ , (0, _queries.getMessages)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
1291
+
1292
+ case 2:
1293
+ entries = _a.sent();
1294
+
1295
+ if (entries) {
1296
+ messages = entries.map(function (item) {
1297
+ return __assign(__assign({}, item.node), {
1298
+ id: _this.ObjectId(item.node.id)
1299
+ });
1300
+ });
1301
+ return [2
1302
+ /*return*/
1303
+ , messages];
1304
+ }
1305
+
1306
+ return [2
1307
+ /*return*/
1308
+ , entries];
1309
+
1310
+ case 3:
1311
+ e_18 = _a.sent();
1312
+ throw e_18;
1313
+
1314
+ case 4:
1315
+ return [2
1316
+ /*return*/
1317
+ ];
1318
+ }
1319
+ });
1320
+ });
1321
+ };
1322
+
1323
+ NCloudChat.prototype.getSubscriptions = function (filter, sort, option) {
1324
+ return __awaiter(this, void 0, void 0, function () {
1325
+ var entries, subscribes, e_19;
1326
+
1327
+ var _this = this;
1328
+
1329
+ return __generator(this, function (_a) {
1330
+ switch (_a.label) {
1331
+ case 0:
1332
+ if (!this.isConnected()) {
1333
+ throw Error("You are not connected.");
1334
+ }
1335
+
1336
+ _a.label = 1;
1337
+
1338
+ case 1:
1339
+ _a.trys.push([1, 3,, 4]);
1340
+
1341
+ return [4
1342
+ /*yield*/
1343
+ , (0, _queries.getSubscriptions)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
1344
+
1345
+ case 2:
1346
+ entries = _a.sent();
1347
+
1348
+ if (entries) {
1349
+ subscribes = entries.map(function (item) {
1350
+ return __assign(__assign({}, item.node), {
1351
+ id: _this.ObjectId(item.node.id)
1352
+ });
1353
+ });
1354
+ return [2
1355
+ /*return*/
1356
+ , subscribes];
1357
+ }
1358
+
1359
+ return [2
1360
+ /*return*/
1361
+ , entries];
1362
+
1363
+ case 3:
1364
+ e_19 = _a.sent();
1365
+ throw e_19;
1366
+
1367
+ case 4:
1368
+ return [2
1369
+ /*return*/
1370
+ ];
1371
+ }
1372
+ });
1373
+ });
1374
+ };
1375
+
1376
+ NCloudChat.prototype.createChannel = function (channel) {
1377
+ return __awaiter(this, void 0, void 0, function () {
1378
+ var e_20;
1379
+ return __generator(this, function (_a) {
1380
+ switch (_a.label) {
1381
+ case 0:
1382
+ if (!this.isConnected()) {
1383
+ throw Error("You are not connected.");
1384
+ }
1385
+
1386
+ _a.label = 1;
1387
+
1388
+ case 1:
1389
+ _a.trys.push([1, 3,, 4]);
1390
+
1391
+ return [4
1392
+ /*yield*/
1393
+ , (0, _mutations.createChannel)(channel)];
1394
+
1395
+ case 2:
1396
+ return [2
1397
+ /*return*/
1398
+ , _a.sent()];
1399
+
1400
+ case 3:
1401
+ e_20 = _a.sent();
1402
+ throw e_20;
1403
+
1404
+ case 4:
1405
+ return [2
1406
+ /*return*/
1407
+ ];
1408
+ }
1409
+ });
1410
+ });
1411
+ };
1412
+
1413
+ NCloudChat.prototype.updateChannel = function (channelId, channel) {
1414
+ return __awaiter(this, void 0, void 0, function () {
1415
+ var e_21;
1416
+ return __generator(this, function (_a) {
1417
+ switch (_a.label) {
1418
+ case 0:
1419
+ if (!this.isConnected()) {
1420
+ throw Error("You are not connected.");
1421
+ }
1422
+
1423
+ _a.label = 1;
1424
+
1425
+ case 1:
1426
+ _a.trys.push([1, 3,, 4]);
1427
+
1428
+ return [4
1429
+ /*yield*/
1430
+ , (0, _mutations.updateChannel)(channelId, channel)];
1431
+
1432
+ case 2:
1433
+ return [2
1434
+ /*return*/
1435
+ , _a.sent()];
1436
+
1437
+ case 3:
1438
+ e_21 = _a.sent();
1439
+ throw e_21;
1440
+
1441
+ case 4:
1442
+ return [2
1443
+ /*return*/
1444
+ ];
1445
+ }
1446
+ });
1447
+ });
1448
+ };
1449
+
1450
+ NCloudChat.prototype.deleteChannel = function (channelId) {
1451
+ return __awaiter(this, void 0, void 0, function () {
1452
+ var e_22;
1453
+ return __generator(this, function (_a) {
1454
+ switch (_a.label) {
1455
+ case 0:
1456
+ if (!this.isConnected()) {
1457
+ throw Error("You are not connected.");
1458
+ }
1459
+
1460
+ _a.label = 1;
1461
+
1462
+ case 1:
1463
+ _a.trys.push([1, 3,, 4]);
1464
+
1465
+ return [4
1466
+ /*yield*/
1467
+ , (0, _mutations.deleteChannel)(channelId)];
1468
+
1469
+ case 2:
1470
+ return [2
1471
+ /*return*/
1472
+ , _a.sent()];
1473
+
1474
+ case 3:
1475
+ e_22 = _a.sent();
1476
+ throw e_22;
1477
+
1478
+ case 4:
1479
+ return [2
1480
+ /*return*/
1481
+ ];
1482
+ }
1483
+ });
1484
+ });
1485
+ };
1486
+
1487
+ NCloudChat.prototype.markRead = function (channelId, mark, option) {
1488
+ if (option === void 0) {
1489
+ option = null;
1490
+ }
1491
+
1492
+ return __awaiter(this, void 0, void 0, function () {
1493
+ var e_23;
1494
+ return __generator(this, function (_a) {
1495
+ switch (_a.label) {
1496
+ case 0:
1497
+ if (!this.isConnected()) {
1498
+ throw Error("You are not connected.");
1499
+ }
1500
+
1501
+ _a.label = 1;
1502
+
1503
+ case 1:
1504
+ _a.trys.push([1, 3,, 4]);
1505
+
1506
+ return [4
1507
+ /*yield*/
1508
+ , (0, _mutations.updateSubscription)(channelId, mark, (0, _stringify["default"])(option))];
1509
+
1510
+ case 2:
1511
+ return [2
1512
+ /*return*/
1513
+ , _a.sent()];
1514
+
1515
+ case 3:
1516
+ e_23 = _a.sent();
1517
+ throw e_23;
1518
+
1519
+ case 4:
1520
+ return [2
1521
+ /*return*/
1522
+ ];
1523
+ }
1524
+ });
1525
+ });
1526
+ };
1527
+
1528
+ NCloudChat.prototype.addMembers = function (channelId, memberIds, options) {
1529
+ return __awaiter(this, void 0, void 0, function () {
1530
+ var input, e_24;
1531
+ return __generator(this, function (_a) {
1532
+ switch (_a.label) {
1533
+ case 0:
1534
+ if (!this.isConnected()) {
1535
+ throw Error("You are not connected.");
1536
+ }
1537
+
1538
+ _a.label = 1;
1539
+
1540
+ case 1:
1541
+ _a.trys.push([1, 3,, 4]);
1542
+
1543
+ input = {
1544
+ members: memberIds
1545
+ };
1546
+ return [4
1547
+ /*yield*/
1548
+ , (0, _mutations.addChannelMembers)(channelId, memberIds, options)];
1549
+
1550
+ case 2:
1551
+ return [2
1552
+ /*return*/
1553
+ , _a.sent()];
1554
+
1555
+ case 3:
1556
+ e_24 = _a.sent();
1557
+ throw e_24;
1558
+
1559
+ case 4:
1560
+ return [2
1561
+ /*return*/
1562
+ ];
1563
+ }
1564
+ });
1565
+ });
1566
+ };
1567
+
1568
+ NCloudChat.prototype.removeMembers = function (channelId, memberIds, options) {
1569
+ return __awaiter(this, void 0, void 0, function () {
1570
+ var e_25;
1571
+ return __generator(this, function (_a) {
1572
+ switch (_a.label) {
1573
+ case 0:
1574
+ if (!this.isConnected()) {
1575
+ throw Error("You are not connected.");
1576
+ }
1577
+
1578
+ _a.label = 1;
1579
+
1580
+ case 1:
1581
+ _a.trys.push([1, 4,, 5]);
1582
+
1583
+ return [4
1584
+ /*yield*/
1585
+ , (0, _mutations.removeChannelMembers)(channelId, memberIds, options)];
1586
+
1587
+ case 2:
1588
+ return [4
1589
+ /*yield*/
1590
+ , _a.sent()];
1591
+
1592
+ case 3:
1593
+ return [2
1594
+ /*return*/
1595
+ , _a.sent()];
1596
+
1597
+ case 4:
1598
+ e_25 = _a.sent();
1599
+ throw e_25;
1600
+
1601
+ case 5:
1602
+ return [2
1603
+ /*return*/
1604
+ ];
1605
+ }
1606
+ });
1607
+ });
1608
+ };
1609
+
1610
+ NCloudChat.prototype.startTyping = function (channelId, threadId) {
1611
+ if (threadId === void 0) {
1612
+ threadId = "";
1613
+ }
1614
+
1615
+ return __awaiter(this, void 0, void 0, function () {
1616
+ var data;
1617
+ return __generator(this, function (_a) {
1618
+ if (!this.isConnected()) {
1619
+ throw Error("You are not connected.");
1620
+ }
1621
+
1622
+ try {
1623
+ data = {
1624
+ channelId: channelId,
1625
+ threadId: threadId
1626
+ };
1627
+ return [2
1628
+ /*return*/
1629
+ , this.socket.emit("start typing", data)];
1630
+ } catch (e) {
1631
+ throw e;
1632
+ }
1633
+
1634
+ return [2
1635
+ /*return*/
1636
+ ];
1637
+ });
1638
+ });
1639
+ };
1640
+
1641
+ NCloudChat.prototype.stopTyping = function (channelId, threadId) {
1642
+ if (threadId === void 0) {
1643
+ threadId = "";
1644
+ }
1645
+
1646
+ return __awaiter(this, void 0, void 0, function () {
1647
+ var data;
1648
+ return __generator(this, function (_a) {
1649
+ if (!this.isConnected()) {
1650
+ throw Error("You are not connected.");
1651
+ }
1652
+
1653
+ try {
1654
+ data = {
1655
+ channelId: channelId,
1656
+ threadId: threadId
1657
+ };
1658
+ return [2
1659
+ /*return*/
1660
+ , this.socket.emit("stop typing", data)];
1661
+ } catch (e) {
1662
+ throw e;
1663
+ }
1664
+
1665
+ return [2
1666
+ /*return*/
1667
+ ];
1668
+ });
1669
+ });
1670
+ };
1671
+
1672
+ return NCloudChat;
1673
+ }();
1674
+
1675
+ var _default = NCloudChat;
1676
+ exports["default"] = _default;