ncloudchat 1.0.33 → 1.0.36

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.
Files changed (105) hide show
  1. package/README.md +17 -409
  2. package/{deploy.sh → deploy.sh.bak} +0 -0
  3. package/dist/ncloudchat.d.ts +1298 -0
  4. package/dist/ncloudchat.min.js +1 -0
  5. package/esm/CloudChat.js +72 -62
  6. package/esm/CloudChat.js.map +1 -1
  7. package/esm/CoreManager.js +3 -1
  8. package/esm/CoreManager.js.map +1 -1
  9. package/esm/Dispatcher.js +3 -1
  10. package/esm/Dispatcher.js.map +1 -1
  11. package/esm/Network.js +14 -7
  12. package/esm/Network.js.map +1 -1
  13. package/esm/Type.js +7 -4
  14. package/esm/Type.js.map +1 -1
  15. package/esm/Util.js +4 -1
  16. package/esm/Util.js.map +1 -1
  17. package/esm/graphql/channel.js +10 -7
  18. package/esm/graphql/channel.js.map +1 -1
  19. package/esm/graphql/friend.js +8 -5
  20. package/esm/graphql/friend.js.map +1 -1
  21. package/esm/graphql/invite.js +4 -1
  22. package/esm/graphql/invite.js.map +1 -1
  23. package/esm/graphql/member.js +8 -5
  24. package/esm/graphql/member.js.map +1 -1
  25. package/esm/graphql/message.js +8 -5
  26. package/esm/graphql/message.js.map +1 -1
  27. package/esm/graphql/pin.js +7 -4
  28. package/esm/graphql/pin.js.map +1 -1
  29. package/esm/graphql/subscription.js +8 -5
  30. package/esm/graphql/subscription.js.map +1 -1
  31. package/esm/index.js +8 -2
  32. package/esm/index.js.map +1 -1
  33. package/esm/logger.js +6 -1
  34. package/esm/logger.js.map +1 -1
  35. package/esm/mutations/channel.js +29 -18
  36. package/esm/mutations/channel.js.map +1 -1
  37. package/esm/mutations/friend.js +25 -15
  38. package/esm/mutations/friend.js.map +1 -1
  39. package/esm/mutations/index.js +23 -7
  40. package/esm/mutations/index.js.map +1 -1
  41. package/esm/mutations/invite.js +13 -6
  42. package/esm/mutations/invite.js.map +1 -1
  43. package/esm/mutations/member.js +22 -13
  44. package/esm/mutations/member.js.map +1 -1
  45. package/esm/mutations/message.js +24 -15
  46. package/esm/mutations/message.js.map +1 -1
  47. package/esm/mutations/pin.js +17 -9
  48. package/esm/mutations/pin.js.map +1 -1
  49. package/esm/mutations/subscription.js +21 -12
  50. package/esm/mutations/subscription.js.map +1 -1
  51. package/esm/queries/channel.js +17 -9
  52. package/esm/queries/channel.js.map +1 -1
  53. package/esm/queries/friend.js +13 -6
  54. package/esm/queries/friend.js.map +1 -1
  55. package/esm/queries/index.js +24 -8
  56. package/esm/queries/index.js.map +1 -1
  57. package/esm/queries/member.js +13 -6
  58. package/esm/queries/member.js.map +1 -1
  59. package/esm/queries/memberblocks.js +13 -6
  60. package/esm/queries/memberblocks.js.map +1 -1
  61. package/esm/queries/message.js +21 -12
  62. package/esm/queries/message.js.map +1 -1
  63. package/esm/queries/pin.js +17 -9
  64. package/esm/queries/pin.js.map +1 -1
  65. package/esm/queries/project.js +2 -1
  66. package/esm/queries/project.js.map +1 -1
  67. package/esm/queries/subscription.js +17 -9
  68. package/esm/queries/subscription.js.map +1 -1
  69. package/package.json +2 -4
  70. package/tsconfig.json +1 -1
  71. package/lib/CloudChat.js +0 -2661
  72. package/lib/CoreManager.js +0 -45
  73. package/lib/Dispatcher.js +0 -125
  74. package/lib/Network.js +0 -229
  75. package/lib/Type.js +0 -44
  76. package/lib/Util.js +0 -32
  77. package/lib/graphql/channel.js +0 -32
  78. package/lib/graphql/friend.js +0 -27
  79. package/lib/graphql/invite.js +0 -18
  80. package/lib/graphql/member.js +0 -27
  81. package/lib/graphql/message.js +0 -27
  82. package/lib/graphql/pin.js +0 -25
  83. package/lib/graphql/project.js +0 -7
  84. package/lib/graphql/subscription.js +0 -27
  85. package/lib/index.js +0 -18
  86. package/lib/logger.js +0 -33
  87. package/lib/mutations/channel.js +0 -354
  88. package/lib/mutations/friend.js +0 -299
  89. package/lib/mutations/index.js +0 -109
  90. package/lib/mutations/invite.js +0 -205
  91. package/lib/mutations/member.js +0 -304
  92. package/lib/mutations/message.js +0 -300
  93. package/lib/mutations/pin.js +0 -229
  94. package/lib/mutations/subscription.js +0 -281
  95. package/lib/queries/channel.js +0 -239
  96. package/lib/queries/friend.js +0 -207
  97. package/lib/queries/index.js +0 -123
  98. package/lib/queries/member.js +0 -207
  99. package/lib/queries/memberblocks.js +0 -207
  100. package/lib/queries/message.js +0 -273
  101. package/lib/queries/pin.js +0 -243
  102. package/lib/queries/project.js +0 -7
  103. package/lib/queries/subscription.js +0 -241
  104. package/ncloudchat_javascript.md +0 -289
  105. package//353/260/260/355/217/254/354/210/234/354/204/234.md +0 -8
package/lib/CloudChat.js DELETED
@@ -1,2661 +0,0 @@
1
- "use strict";
2
-
3
- var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
4
-
5
- var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
6
-
7
- _Object$defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
-
11
- exports["default"] = void 0;
12
-
13
- require("core-js/modules/es6.regexp.replace.js");
14
-
15
- require("core-js/modules/es6.array.slice.js");
16
-
17
- require("core-js/modules/es6.function.name.js");
18
-
19
- require("core-js/modules/es6.function.bind.js");
20
-
21
- require("core-js/modules/es6.regexp.split.js");
22
-
23
- require("core-js/modules/es6.array.map.js");
24
-
25
- var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
26
-
27
- var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
28
-
29
- var _symbol = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol"));
30
-
31
- var _iterator = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol/iterator"));
32
-
33
- var _entries = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/entries"));
34
-
35
- var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
36
-
37
- var _socket = require("socket.io-client");
38
-
39
- var _CoreManager = _interopRequireDefault(require("./CoreManager"));
40
-
41
- var _Dispatcher = _interopRequireDefault(require("./Dispatcher"));
42
-
43
- var _logger = require("./logger");
44
-
45
- var _queries = require("./queries");
46
-
47
- var _mutations = require("./mutations");
48
-
49
- /**
50
- * Copyright (c) NBASE CORP. and its affiliates.
51
- *
52
- * This source code is licensed under the MIT license found in the
53
- * LICENSE file in the root directory of this source tree.
54
- */
55
- var __assign = void 0 && (void 0).__assign || function () {
56
- __assign = _assign["default"] || function (t) {
57
- for (var s, i = 1, n = arguments.length; i < n; i++) {
58
- s = arguments[i];
59
-
60
- for (var p in s) {
61
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
62
- }
63
- }
64
-
65
- return t;
66
- };
67
-
68
- return __assign.apply(this, arguments);
69
- };
70
-
71
- var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
72
- function adopt(value) {
73
- return value instanceof P ? value : new P(function (resolve) {
74
- resolve(value);
75
- });
76
- }
77
-
78
- return new (P || (P = _promise["default"]))(function (resolve, reject) {
79
- function fulfilled(value) {
80
- try {
81
- step(generator.next(value));
82
- } catch (e) {
83
- reject(e);
84
- }
85
- }
86
-
87
- function rejected(value) {
88
- try {
89
- step(generator["throw"](value));
90
- } catch (e) {
91
- reject(e);
92
- }
93
- }
94
-
95
- function step(result) {
96
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
97
- }
98
-
99
- step((generator = generator.apply(thisArg, _arguments || [])).next());
100
- });
101
- };
102
-
103
- var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
104
- var _ = {
105
- label: 0,
106
- sent: function sent() {
107
- if (t[0] & 1) throw t[1];
108
- return t[1];
109
- },
110
- trys: [],
111
- ops: []
112
- },
113
- f,
114
- y,
115
- t,
116
- g;
117
- return g = {
118
- next: verb(0),
119
- "throw": verb(1),
120
- "return": verb(2)
121
- }, typeof _symbol["default"] === "function" && (g[_iterator["default"]] = function () {
122
- return this;
123
- }), g;
124
-
125
- function verb(n) {
126
- return function (v) {
127
- return step([n, v]);
128
- };
129
- }
130
-
131
- function step(op) {
132
- if (f) throw new TypeError("Generator is already executing.");
133
-
134
- while (_) {
135
- try {
136
- 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;
137
- if (y = 0, t) op = [op[0] & 2, t.value];
138
-
139
- switch (op[0]) {
140
- case 0:
141
- case 1:
142
- t = op;
143
- break;
144
-
145
- case 4:
146
- _.label++;
147
- return {
148
- value: op[1],
149
- done: false
150
- };
151
-
152
- case 5:
153
- _.label++;
154
- y = op[1];
155
- op = [0];
156
- continue;
157
-
158
- case 7:
159
- op = _.ops.pop();
160
-
161
- _.trys.pop();
162
-
163
- continue;
164
-
165
- default:
166
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
167
- _ = 0;
168
- continue;
169
- }
170
-
171
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
172
- _.label = op[1];
173
- break;
174
- }
175
-
176
- if (op[0] === 6 && _.label < t[1]) {
177
- _.label = t[1];
178
- t = op;
179
- break;
180
- }
181
-
182
- if (t && _.label < t[2]) {
183
- _.label = t[2];
184
-
185
- _.ops.push(op);
186
-
187
- break;
188
- }
189
-
190
- if (t[2]) _.ops.pop();
191
-
192
- _.trys.pop();
193
-
194
- continue;
195
- }
196
-
197
- op = body.call(thisArg, _);
198
- } catch (e) {
199
- op = [6, e];
200
- y = 0;
201
- } finally {
202
- f = t = 0;
203
- }
204
- }
205
-
206
- if (op[0] & 5) throw op[1];
207
- return {
208
- value: op[0] ? op[1] : void 0,
209
- done: true
210
- };
211
- }
212
- };
213
-
214
- var __values = void 0 && (void 0).__values || function (o) {
215
- var s = typeof _symbol["default"] === "function" && _iterator["default"],
216
- m = s && o[s],
217
- i = 0;
218
- if (m) return m.call(o);
219
- if (o && typeof o.length === "number") return {
220
- next: function next() {
221
- if (o && i >= o.length) o = void 0;
222
- return {
223
- value: o && o[i++],
224
- done: !o
225
- };
226
- }
227
- };
228
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
229
- };
230
-
231
- var __read = void 0 && (void 0).__read || function (o, n) {
232
- var m = typeof _symbol["default"] === "function" && o[_iterator["default"]];
233
- if (!m) return o;
234
- var i = m.call(o),
235
- r,
236
- ar = [],
237
- e;
238
-
239
- try {
240
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
241
- ar.push(r.value);
242
- }
243
- } catch (error) {
244
- e = {
245
- error: error
246
- };
247
- } finally {
248
- try {
249
- if (r && !r.done && (m = i["return"])) m.call(i);
250
- } finally {
251
- if (e) throw e.error;
252
- }
253
- }
254
-
255
- return ar;
256
- };
257
-
258
- /**
259
- * Class NCloudChat holds all the NCloudChat functionalities.
260
- *
261
- * @class
262
- */
263
- var NCloudChat =
264
- /** @class */
265
- function () {
266
- /**
267
- * Create a `NCloudChat` instance and a Dispatcher.
268
- *
269
- * @constructs
270
- */
271
- function NCloudChat(debug) {
272
- if (debug === void 0) {
273
- debug = false;
274
- }
275
-
276
- this.socket = null;
277
- this.connected = false;
278
- this.connectedCount = 0;
279
- this.dp = new _Dispatcher["default"]();
280
- if (!debug) console.log = function () {};
281
- }
282
-
283
- NCloudChat.prototype.clear = function () {};
284
- /**
285
- * Initialize a new `NCloudChat` instance of project and user.
286
- *
287
- * @function initialize
288
- * @param {string} projectId - The id of a project.
289
- */
290
-
291
-
292
- NCloudChat.prototype.initialize = function (projectId) {
293
- this.setProjectId(projectId);
294
- this.setLang(navigator.language);
295
- };
296
-
297
- NCloudChat.prototype.getLang = function () {
298
- return _CoreManager["default"].get("LANGUAGE");
299
- };
300
-
301
- NCloudChat.prototype.setLang = function (lang) {
302
- return _CoreManager["default"].set("LANGUAGE", lang);
303
- };
304
-
305
- NCloudChat.prototype.getUser = function () {
306
- return _CoreManager["default"].get("USER");
307
- };
308
-
309
- NCloudChat.prototype.getProjectId = function () {
310
- return _CoreManager["default"].get("PROJECT_ID");
311
- };
312
-
313
- NCloudChat.prototype.setServerUrl = function (url) {
314
- if (!/^[hHtTpP]{4}(s)?(:\/\/)[a-zA-Z0-9\.\/-:]+/.test(url)) {
315
- throw Error("invalied url : (ex)http://domain.com, https://domain.com");
316
- return;
317
- }
318
-
319
- if (url.length > 1 && url.substring(url.length - 1) === "/") {
320
- url = url.substring(0, url.length - 1);
321
- }
322
-
323
- return _CoreManager["default"].set("SERVER_URL", url);
324
- };
325
-
326
- NCloudChat.prototype.setSocketUrl = function (url) {
327
- _CoreManager["default"].set("SOCKET_URL", url);
328
- };
329
-
330
- NCloudChat.prototype.setProjectId = function (projectId) {
331
- return _CoreManager["default"].set("PROJECT_ID", projectId);
332
- };
333
-
334
- NCloudChat.prototype.setToken = function (token) {
335
- return _CoreManager["default"].set("TOKEN", token);
336
- };
337
-
338
- NCloudChat.prototype.setUser = function (user) {
339
- _CoreManager["default"].set("USER", user);
340
- };
341
-
342
- NCloudChat.prototype.inputValidation = function (inputs) {
343
- var e_1, _a;
344
-
345
- try {
346
- // if (!this.isConnected()) throw Error(`You are not connected.`);
347
- for (var _b = __values((0, _entries["default"])(inputs)), _c = _b.next(); !_c.done; _c = _b.next()) {
348
- var _d = __read(_c.value, 2),
349
- key = _d[0],
350
- value = _d[1];
351
-
352
- if (!value) {
353
- var result = key.replace(/([A-Z])/g, " $1");
354
- var word = result.charAt(0).toUpperCase() + result.slice(1);
355
- throw Error("You need a(n) ".concat(word, "."));
356
- }
357
- }
358
- } catch (e_1_1) {
359
- e_1 = {
360
- error: e_1_1
361
- };
362
- } finally {
363
- try {
364
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
365
- } finally {
366
- if (e_1) throw e_1.error;
367
- }
368
- }
369
- };
370
- /**
371
- * Create a connection between a socket and a client.
372
- *
373
- * @async connect
374
- * @param {any} user
375
- * @param {string} userToken
376
- * @returns
377
- */
378
-
379
-
380
- NCloudChat.prototype.connect = function (user, userToken) {
381
- if (userToken === void 0) {
382
- userToken = "";
383
- }
384
-
385
- return __awaiter(this, void 0, void 0, function () {
386
- var url, image, name, lang, customField, response, e_2, options;
387
-
388
- var _this = this;
389
-
390
- return __generator(this, function (_a) {
391
- switch (_a.label) {
392
- case 0:
393
- if (!this.isConnected()) return [3
394
- /*break*/
395
- , 2];
396
- return [4
397
- /*yield*/
398
- , this.disconnect()];
399
-
400
- case 1:
401
- _a.sent();
402
-
403
- _a.label = 2;
404
-
405
- case 2:
406
- url = _CoreManager["default"].get("SOCKET_URL") + "/cloudchat";
407
- if (!user.id) throw Error("UserID not found");
408
- image = user.profile;
409
- name = user.name;
410
- lang = this.getLang();
411
- customField = user.customField;
412
- _a.label = 3;
413
-
414
- case 3:
415
- _a.trys.push([3, 5,, 6]);
416
-
417
- return [4
418
- /*yield*/
419
- , (0, _mutations.login)(user.id, name, image, userToken, customField)];
420
-
421
- case 4:
422
- response = _a.sent();
423
- this.setUser({
424
- id: user.id,
425
- name: name,
426
- image: image,
427
- customField: customField
428
- });
429
- userToken = response["token"]; // parse token object
430
-
431
- return [3
432
- /*break*/
433
- , 6];
434
-
435
- case 5:
436
- e_2 = _a.sent();
437
- throw e_2;
438
-
439
- case 6:
440
- _CoreManager["default"].set("TOKEN", userToken);
441
-
442
- options = {
443
- transports: ["websocket"],
444
- reconnection: true,
445
- reconnectionAttempts: 10,
446
- reconnectionDelay: 2000,
447
- reconnectionDelayMax: 2000 * 100,
448
- randomizationFactor: 0.5,
449
- query: {
450
- project_id: this.getProjectId(),
451
- user_id: user.id,
452
- lang: lang,
453
- image: image,
454
- name: name,
455
- customField: customField,
456
- token: userToken
457
- }
458
- };
459
- this.socket = (0, _socket.io)(url, options);
460
- this.socket.on("connect", function (data) {
461
- _this.connectedCount++;
462
- _this.connected = true;
463
- (0, _logger.info)("Connected to ".concat(url, " with id: ").concat(_this.socket.id));
464
-
465
- _this.dp.dispatch("onConnected", data);
466
- });
467
- this.socket.on("unauthorized", function (data) {});
468
- this.socket.on("disconnect", function (reason) {
469
- _this.connected = false;
470
- (0, _logger.info)("Disconnected to ".concat(url, " with id: ").concat(_this.socket.id));
471
-
472
- _this.dp.dispatch("onDisconnected", reason);
473
- });
474
- this.socket.on("message", function (payload) {
475
- var message = JSON.parse(payload);
476
-
477
- _this.dp.dispatch("onMessageReceived", message.channel_id, message);
478
- });
479
- this.socket.on("event", function (payload) {
480
- var message = JSON.parse(payload);
481
-
482
- _this.dp.dispatch("onEventReceived", message.channel_id, message);
483
- });
484
- this.socket.on("start typing", function (payload) {
485
- var data = JSON.parse(payload);
486
-
487
- _this.dp.dispatch("onStartTyping", data);
488
- });
489
- this.socket.on("stop typing", function (payload) {
490
- var data = JSON.parse(payload);
491
-
492
- _this.dp.dispatch("onStopTyping", data);
493
- });
494
- this.socket.on("member joined", function (payload) {
495
- var data = JSON.parse(payload);
496
-
497
- _this.dp.dispatch("onMemberJoined", data);
498
- });
499
- this.socket.on("member leaved", function (payload) {
500
- var data = JSON.parse(payload);
501
-
502
- _this.dp.dispatch("onMemberLeaved", data);
503
- });
504
- this.socket.on("member updated", function (payload) {
505
- var data = JSON.parse(payload);
506
-
507
- _this.dp.dispatch("onMemberUpdated", data);
508
- });
509
- this.socket.on("message deleted", function (payload) {
510
- var data = JSON.parse(payload);
511
-
512
- _this.dp.dispatch("onMessageDeleted", data);
513
- });
514
- this.socket.on("message updated", function (payload) {
515
- var data = JSON.parse(payload);
516
-
517
- _this.dp.dispatch("onMessageUpdated", data);
518
- });
519
- this.socket.on("user banned", function (payload) {
520
- var data = JSON.parse(payload);
521
-
522
- _this.dp.dispatch("onUserBanned", data);
523
- });
524
- this.socket.on("user deleted", function (payload) {
525
- var data = JSON.parse(payload);
526
-
527
- _this.dp.dispatch("onUserDeleted", data);
528
- });
529
- this.socket.on("user updated", function (payload) {
530
- var data = JSON.parse(payload);
531
-
532
- _this.dp.dispatch("onUserUpdated", data);
533
- });
534
- this.socket.on("result", function (payload) {
535
- var message = JSON.parse(payload);
536
-
537
- _this.dp.dispatch("onResult", message);
538
- });
539
- this.socket.on("error", function (payload) {
540
- var message = JSON.parse(payload);
541
-
542
- _this.dp.dispatch("onErrorReceived", message);
543
- });
544
- return [2
545
- /*return*/
546
- , user];
547
- }
548
- });
549
- });
550
- };
551
- /**
552
- * Mute channel notifications.
553
- *
554
- * @async
555
- * @function mute
556
- * @param {string} channel
557
- * @returns {Promise<any>}
558
- */
559
-
560
-
561
- NCloudChat.prototype.mute = function (channel) {
562
- return __awaiter(this, void 0, void 0, function () {
563
- var subscription, e_3;
564
- return __generator(this, function (_a) {
565
- switch (_a.label) {
566
- case 0:
567
- this.inputValidation({
568
- channelId: channel
569
- });
570
- _a.label = 1;
571
-
572
- case 1:
573
- _a.trys.push([1, 3,, 4]);
574
-
575
- return [4
576
- /*yield*/
577
- , (0, _mutations.updateSubscription)(channel, null, (0, _stringify["default"])({
578
- mute: true
579
- }))];
580
-
581
- case 2:
582
- subscription = _a.sent();
583
- if (subscription["subscription"]) subscription["subscription"]["id"] = this.ObjectId(subscription["subscription"]["id"]);
584
- return [2
585
- /*return*/
586
- , subscription["subscription"]];
587
-
588
- case 3:
589
- e_3 = _a.sent();
590
- throw e_3;
591
-
592
- case 4:
593
- return [2
594
- /*return*/
595
- ];
596
- }
597
- });
598
- });
599
- };
600
- /**
601
- * Unmute channel notifications.
602
- *
603
- * @async
604
- * @function unmute
605
- * @param {string} channel
606
- * @returns {Promise<any>}
607
- */
608
-
609
-
610
- NCloudChat.prototype.unmute = function (channel) {
611
- return __awaiter(this, void 0, void 0, function () {
612
- var subscription, e_4;
613
- return __generator(this, function (_a) {
614
- switch (_a.label) {
615
- case 0:
616
- this.inputValidation({
617
- channelId: channel
618
- });
619
- _a.label = 1;
620
-
621
- case 1:
622
- _a.trys.push([1, 3,, 4]);
623
-
624
- return [4
625
- /*yield*/
626
- , (0, _mutations.updateSubscription)(channel, null, (0, _stringify["default"])({
627
- mute: false
628
- }))];
629
-
630
- case 2:
631
- subscription = _a.sent();
632
- if (subscription["subscription"]) subscription["subscription"]["id"] = this.ObjectId(subscription["subscription"]["id"]);
633
- return [2
634
- /*return*/
635
- , subscription["subscription"]];
636
-
637
- case 3:
638
- e_4 = _a.sent();
639
- throw e_4;
640
-
641
- case 4:
642
- return [2
643
- /*return*/
644
- ];
645
- }
646
- });
647
- });
648
- };
649
- /**
650
- * Subscribe a channel.
651
- *
652
- * @async
653
- * @function subscibe
654
- * @param {string} channel - The id of a channel.
655
- * @param {any} option
656
- * @returns
657
- */
658
-
659
-
660
- NCloudChat.prototype.subscribe = function (channel, option) {
661
- if (option === void 0) {
662
- option = null;
663
- }
664
-
665
- return __awaiter(this, void 0, void 0, function () {
666
- var subscription, e_5;
667
- return __generator(this, function (_a) {
668
- switch (_a.label) {
669
- case 0:
670
- this.inputValidation({
671
- channelId: channel
672
- });
673
- _a.label = 1;
674
-
675
- case 1:
676
- _a.trys.push([1, 3,, 4]);
677
-
678
- return [4
679
- /*yield*/
680
- , (0, _mutations.createSubscription)(channel, (0, _stringify["default"])(option))];
681
-
682
- case 2:
683
- subscription = _a.sent();
684
- if (subscription["subscription"]) subscription["subscription"]["id"] = this.ObjectId(subscription["subscription"]["id"]);
685
- return [2
686
- /*return*/
687
- , subscription["subscription"]];
688
-
689
- case 3:
690
- e_5 = _a.sent();
691
- throw e_5;
692
-
693
- case 4:
694
- return [2
695
- /*return*/
696
- ];
697
- }
698
- });
699
- });
700
- };
701
- /**
702
- * Unsubscribe from a channel.
703
- *
704
- * @async
705
- * @function unsubscribe
706
- * @param {string} channel - The id of a chennel
707
- * @returns {Promise<any>}
708
- */
709
-
710
-
711
- NCloudChat.prototype.unsubscribe = function (channel) {
712
- return __awaiter(this, void 0, void 0, function () {
713
- var subscription, e_6;
714
- return __generator(this, function (_a) {
715
- switch (_a.label) {
716
- case 0:
717
- this.inputValidation({
718
- channelId: channel
719
- });
720
- _a.label = 1;
721
-
722
- case 1:
723
- _a.trys.push([1, 3,, 4]);
724
-
725
- return [4
726
- /*yield*/
727
- , (0, _mutations.deleteSubscription)(channel)];
728
-
729
- case 2:
730
- subscription = _a.sent();
731
- if (subscription["subscription"]) subscription["subscription"]["id"] = this.ObjectId(subscription["subscription"]["id"]);
732
- return [2
733
- /*return*/
734
- , subscription["subscription"]];
735
-
736
- case 3:
737
- e_6 = _a.sent();
738
- throw e_6;
739
-
740
- case 4:
741
- return [2
742
- /*return*/
743
- ];
744
- }
745
- });
746
- });
747
- };
748
- /**
749
- * Translate a message from a souce language to a target language.
750
- *
751
- * @async
752
- * @function translateMessage
753
- * @param {string} channelId - The id of a channel.
754
- * @param {string} source - A source language.
755
- * @param {string} target - A target language.
756
- * @param {string} message - An message to be translated.
757
- * @returns {Promise<any>}
758
- */
759
-
760
-
761
- NCloudChat.prototype.translateMessage = function (channelId, source, target, message) {
762
- return __awaiter(this, void 0, void 0, function () {
763
- var result, e_7;
764
- return __generator(this, function (_a) {
765
- switch (_a.label) {
766
- case 0:
767
- this.inputValidation({
768
- channelId: channelId,
769
- sourceLanguage: source,
770
- targetLanguage: target
771
- });
772
- _a.label = 1;
773
-
774
- case 1:
775
- _a.trys.push([1, 3,, 4]);
776
-
777
- return [4
778
- /*yield*/
779
- , (0, _mutations.translate)(channelId, source, target, message)];
780
-
781
- case 2:
782
- result = _a.sent();
783
- return [2
784
- /*return*/
785
- , result["translation"]];
786
-
787
- case 3:
788
- e_7 = _a.sent();
789
-
790
- if (e_7 instanceof Error) {
791
- throw Error(e_7.message);
792
- }
793
-
794
- return [3
795
- /*break*/
796
- , 4];
797
-
798
- case 4:
799
- return [2
800
- /*return*/
801
- ];
802
- }
803
- });
804
- });
805
- };
806
- /**
807
- * Send a message to a channel.
808
- *
809
- * @async
810
- * @function sendMessage
811
- * @param {string} channel - The id of a channel.
812
- * @param {any} opt
813
- * @returns {Promise<any>}
814
- */
815
-
816
-
817
- NCloudChat.prototype.sendMessage = function (channel, opt) {
818
- return __awaiter(this, void 0, void 0, function () {
819
- var data, result, e_8;
820
- return __generator(this, function (_a) {
821
- switch (_a.label) {
822
- case 0:
823
- this.inputValidation({
824
- channelId: channel,
825
- message: opt.message
826
- });
827
- if (!opt.type) opt.type = "text";
828
- _a.label = 1;
829
-
830
- case 1:
831
- _a.trys.push([1, 3,, 4]);
832
-
833
- data = __assign({
834
- channelId: channel
835
- }, opt);
836
- return [4
837
- /*yield*/
838
- , (0, _mutations.message)(data)];
839
-
840
- case 2:
841
- result = _a.sent();
842
- return [2
843
- /*return*/
844
- , result["message"]];
845
-
846
- case 3:
847
- e_8 = _a.sent();
848
- throw e_8;
849
-
850
- case 4:
851
- return [2
852
- /*return*/
853
- ];
854
- }
855
- });
856
- });
857
- };
858
- /**
859
- * Send an express message to a channel.
860
- *
861
- * @async
862
- * @function sendExpressMessage
863
- * @param {string} channel - The id of a channel.
864
- * @param {any} opt
865
- * @returns {Promise<any>}
866
- */
867
-
868
-
869
- NCloudChat.prototype.sendExpressMessage = function (channel, opt) {
870
- return __awaiter(this, void 0, void 0, function () {
871
- var user, data;
872
- return __generator(this, function (_a) {
873
- if (!this.isConnected()) throw Error("You are not connected.");
874
- this.inputValidation({
875
- channelId: channel,
876
- message: opt.message
877
- });
878
- if (!opt.type) opt.type = "text";
879
- user = _CoreManager["default"].get("USER");
880
- if (!user) throw Error('user is null');
881
-
882
- try {
883
- data = __assign({
884
- channelId: channel,
885
- user: user
886
- }, opt);
887
- this.socket.emit("express message", data);
888
- return [2
889
- /*return*/
890
- , data];
891
- } catch (e) {
892
- throw e;
893
- }
894
-
895
- return [2
896
- /*return*/
897
- ];
898
- });
899
- });
900
- };
901
- /**
902
- * Send an image to a channel. Only supports png, jpg, jpeg file types.
903
- *
904
- * @async
905
- * @function sendImage
906
- * @param {string} channelId - The id of a channel.
907
- * @param {any} file - An image file.
908
- * @returns {Promise<any>}
909
- */
910
-
911
-
912
- NCloudChat.prototype.sendImage = function (channelId, file) {
913
- return __awaiter(this, void 0, void 0, function () {
914
- var result;
915
- return __generator(this, function (_a) {
916
- switch (_a.label) {
917
- case 0:
918
- this.inputValidation({
919
- channelId: channelId
920
- });
921
- return [4
922
- /*yield*/
923
- , (0, _mutations.upload)(channelId, file)];
924
-
925
- case 1:
926
- result = _a.sent();
927
- if (!result.status) throw Error(result.message);
928
- return [2
929
- /*return*/
930
- , result];
931
- }
932
- });
933
- });
934
- };
935
- /**
936
- * Update a message.
937
- *
938
- * @todo
939
- * @async
940
- * @function updateMessage
941
- * @param {string} channel
942
- * @param {string} message_id
943
- * @param {string} message
944
- */
945
-
946
-
947
- NCloudChat.prototype.updateMessage = function (channel, message_id, message) {
948
- return __awaiter(this, void 0, void 0, function () {
949
- return __generator(this, function (_a) {
950
- return [2
951
- /*return*/
952
- ];
953
- });
954
- });
955
- };
956
- /**
957
- * Delete a message.
958
- * @async
959
- * @function deleteMessage
960
- * @param {string} channel
961
- * @param {string} message_id
962
- */
963
-
964
-
965
- NCloudChat.prototype.deleteMessage = function (channel, message_id) {
966
- return __awaiter(this, void 0, void 0, function () {
967
- return __generator(this, function (_a) {
968
- return [2
969
- /*return*/
970
- ];
971
- });
972
- });
973
- };
974
- /**
975
- * Disconnect from a socket.
976
- *
977
- * @async
978
- * @function disconnect
979
- * @returns
980
- */
981
-
982
-
983
- NCloudChat.prototype.disconnect = function () {
984
- return __awaiter(this, void 0, void 0, function () {
985
- return __generator(this, function (_a) {
986
- if (!this.isConnected()) return [2
987
- /*return*/
988
- ];
989
- this.socket.disconnect();
990
-
991
- _CoreManager["default"].set("TOKEN", "");
992
-
993
- return [2
994
- /*return*/
995
- ];
996
- });
997
- });
998
- };
999
- /**
1000
- * Check if a client is connected to a socket.
1001
- *
1002
- * @function isConnected
1003
- * @returns {boolean}
1004
- */
1005
-
1006
-
1007
- NCloudChat.prototype.isConnected = function () {
1008
- var token = _CoreManager["default"].get("TOKEN");
1009
-
1010
- if (token) return true;
1011
- return false;
1012
- };
1013
-
1014
- NCloudChat.prototype.isSocketConnected = function () {
1015
- return this.connected ? true : false;
1016
- };
1017
- /**
1018
- * Bind fn event handlers.
1019
- *
1020
- * @async
1021
- * @function bind
1022
- * @param {string} id
1023
- * @param {any} fn
1024
- */
1025
-
1026
-
1027
- NCloudChat.prototype.bind = function (id, fn) {
1028
- return __awaiter(this, void 0, void 0, function () {
1029
- return __generator(this, function (_a) {
1030
- this.dp.off(id);
1031
- this.dp.on(id, fn);
1032
- return [2
1033
- /*return*/
1034
- ];
1035
- });
1036
- });
1037
- };
1038
- /**
1039
- * Unbind fn event handlers.
1040
- *
1041
- * @async
1042
- * @function unbind
1043
- * @param {string} id
1044
- * @param {any} fn
1045
- */
1046
-
1047
-
1048
- NCloudChat.prototype.unbind = function (id) {
1049
- return __awaiter(this, void 0, void 0, function () {
1050
- return __generator(this, function (_a) {
1051
- this.dp.off(id);
1052
- return [2
1053
- /*return*/
1054
- ];
1055
- });
1056
- });
1057
- };
1058
- /**
1059
- * Unbind all event handlers.
1060
- * @param id
1061
- */
1062
-
1063
-
1064
- NCloudChat.prototype.unbindall = function (id) {
1065
- return __awaiter(this, void 0, void 0, function () {
1066
- return __generator(this, function (_a) {
1067
- this.dp.offall(id);
1068
- return [2
1069
- /*return*/
1070
- ];
1071
- });
1072
- });
1073
- };
1074
- /**
1075
- * Decodes a base-64 encoded string.
1076
- *
1077
- * @function ObjectId
1078
- * @param {string} id - An encoded string to be decoded.
1079
- * @returns {string} decoded string.
1080
- */
1081
-
1082
-
1083
- NCloudChat.prototype.ObjectId = function (id) {
1084
- if (!id) return "";
1085
- return atob(id).split(":")[1];
1086
- };
1087
- /**
1088
- * Get current friends list of all status.
1089
- *
1090
- * @async
1091
- * @function getFriendships
1092
- * @param {string} filter - Field value for filter.
1093
- * @param {string} sort - Field value for sorting.
1094
- * @param {string} option - Optional option: ex) offset, per_page.
1095
- * @returns {Promise<any>}
1096
- */
1097
-
1098
-
1099
- NCloudChat.prototype.getFriendships = function (filter, sort, option) {
1100
- if (sort === void 0) {
1101
- sort = {};
1102
- }
1103
-
1104
- if (option === void 0) {
1105
- option = {};
1106
- }
1107
-
1108
- return __awaiter(this, void 0, void 0, function () {
1109
- var entries, friends, e_9;
1110
-
1111
- var _this = this;
1112
-
1113
- return __generator(this, function (_a) {
1114
- switch (_a.label) {
1115
- case 0:
1116
- this.inputValidation({});
1117
- _a.label = 1;
1118
-
1119
- case 1:
1120
- _a.trys.push([1, 3,, 4]);
1121
-
1122
- return [4
1123
- /*yield*/
1124
- , (0, _queries.getFriendships)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
1125
-
1126
- case 2:
1127
- entries = _a.sent();
1128
-
1129
- if (entries) {
1130
- friends = entries["edges"].map(function (item) {
1131
- item.node.friend.id = _this.ObjectId(item.node.friend.id);
1132
- item.node.user.id = _this.ObjectId(item.node.user.id);
1133
- return __assign(__assign({}, item.node), {
1134
- id: item.node.id
1135
- });
1136
- });
1137
- return [2
1138
- /*return*/
1139
- , friends];
1140
- }
1141
-
1142
- return [2
1143
- /*return*/
1144
- , entries["edges"]];
1145
-
1146
- case 3:
1147
- e_9 = _a.sent();
1148
- throw e_9;
1149
-
1150
- case 4:
1151
- return [2
1152
- /*return*/
1153
- ];
1154
- }
1155
- });
1156
- });
1157
- };
1158
- /**
1159
- * Get member blocks.
1160
- *
1161
- * @async
1162
- * @function getBannedUsers
1163
- * @param {string} filter - Field value for filter.
1164
- * @param {string} sort - Field value for sorting.
1165
- * @param {string} option - Optional option: ex) offset, per_page.
1166
- * @returns {Promise<any>}
1167
- */
1168
-
1169
-
1170
- NCloudChat.prototype.getBannedUsers = function (filter, sort, option) {
1171
- if (sort === void 0) {
1172
- sort = {};
1173
- }
1174
-
1175
- if (option === void 0) {
1176
- option = {};
1177
- }
1178
-
1179
- return __awaiter(this, void 0, void 0, function () {
1180
- var entries, members, e_10;
1181
-
1182
- var _this = this;
1183
-
1184
- return __generator(this, function (_a) {
1185
- switch (_a.label) {
1186
- case 0:
1187
- this.inputValidation({});
1188
- _a.label = 1;
1189
-
1190
- case 1:
1191
- _a.trys.push([1, 3,, 4]);
1192
-
1193
- return [4
1194
- /*yield*/
1195
- , (0, _queries.getMemberBlocks)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
1196
-
1197
- case 2:
1198
- entries = _a.sent();
1199
-
1200
- if (entries["edges"]) {
1201
- members = entries["edges"].map(function (item) {
1202
- return __assign(__assign({}, item.node), {
1203
- id: _this.ObjectId(item.node.id)
1204
- });
1205
- });
1206
- return [2
1207
- /*return*/
1208
- , members];
1209
- }
1210
-
1211
- return [2
1212
- /*return*/
1213
- , entries["edges"]];
1214
-
1215
- case 3:
1216
- e_10 = _a.sent();
1217
- throw e_10;
1218
-
1219
- case 4:
1220
- return [2
1221
- /*return*/
1222
- ];
1223
- }
1224
- });
1225
- });
1226
- };
1227
- /**
1228
- * Get information data of the member.
1229
- *
1230
- * @async
1231
- * @function getUsers
1232
- * @param {string} filter - Field value for filter.
1233
- * @param {string} sort - Field value for sorting.
1234
- * @param {string} option - Optional option: ex) offset, per_page.
1235
- * @returns {Promise<any>}
1236
- */
1237
-
1238
-
1239
- NCloudChat.prototype.getUsers = function (filter, sort, option) {
1240
- if (sort === void 0) {
1241
- sort = {};
1242
- }
1243
-
1244
- if (option === void 0) {
1245
- option = {};
1246
- }
1247
-
1248
- return __awaiter(this, void 0, void 0, function () {
1249
- var entries, members, e_11;
1250
-
1251
- var _this = this;
1252
-
1253
- return __generator(this, function (_a) {
1254
- switch (_a.label) {
1255
- case 0:
1256
- this.inputValidation({});
1257
- _a.label = 1;
1258
-
1259
- case 1:
1260
- _a.trys.push([1, 3,, 4]);
1261
-
1262
- return [4
1263
- /*yield*/
1264
- , (0, _queries.getMembers)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
1265
-
1266
- case 2:
1267
- entries = _a.sent();
1268
-
1269
- if (entries) {
1270
- members = entries['edges'].map(function (item) {
1271
- return __assign(__assign({}, item.node), {
1272
- id: _this.ObjectId(item.node.id)
1273
- });
1274
- });
1275
- return [2
1276
- /*return*/
1277
- , members];
1278
- }
1279
-
1280
- return [3
1281
- /*break*/
1282
- , 4];
1283
-
1284
- case 3:
1285
- e_11 = _a.sent();
1286
- throw e_11;
1287
-
1288
- case 4:
1289
- return [2
1290
- /*return*/
1291
- ];
1292
- }
1293
- });
1294
- });
1295
- };
1296
- /**
1297
- * Request a friendship to a user.
1298
- *
1299
- * @async
1300
- * @function requestFriend
1301
- * @param {string} friendId - An id of the friend to request.
1302
- * @returns {Promise<any>}
1303
- */
1304
-
1305
-
1306
- NCloudChat.prototype.requestFriend = function (friendId) {
1307
- return __awaiter(this, void 0, void 0, function () {
1308
- var result, e_12;
1309
- return __generator(this, function (_a) {
1310
- switch (_a.label) {
1311
- case 0:
1312
- this.inputValidation({
1313
- friendId: friendId
1314
- });
1315
- _a.label = 1;
1316
-
1317
- case 1:
1318
- _a.trys.push([1, 3,, 4]);
1319
-
1320
- return [4
1321
- /*yield*/
1322
- , (0, _mutations.requestFriend)(friendId)];
1323
-
1324
- case 2:
1325
- result = _a.sent();
1326
-
1327
- if (result["friendship"]) {
1328
- result["friendship"]["user"]["id"] = this.ObjectId(result["friendship"]["user"]["id"]);
1329
- result["friendship"]["friend"]["id"] = this.ObjectId(result["friendship"]["friend"]["id"]);
1330
- }
1331
-
1332
- return [2
1333
- /*return*/
1334
- , result["friendship"]];
1335
-
1336
- case 3:
1337
- e_12 = _a.sent();
1338
- throw e_12;
1339
-
1340
- case 4:
1341
- return [2
1342
- /*return*/
1343
- ];
1344
- }
1345
- });
1346
- });
1347
- };
1348
- /**
1349
- * Accept a friends request.
1350
- *
1351
- * @async
1352
- * @function acceptFriend
1353
- * @param {string} friendId - The id of the friend to accept the request.
1354
- * @returns {Promise<any>}
1355
- */
1356
-
1357
-
1358
- NCloudChat.prototype.acceptFriend = function (friendId) {
1359
- return __awaiter(this, void 0, void 0, function () {
1360
- var result, e_13;
1361
- return __generator(this, function (_a) {
1362
- switch (_a.label) {
1363
- case 0:
1364
- this.inputValidation({
1365
- friendId: friendId
1366
- });
1367
- _a.label = 1;
1368
-
1369
- case 1:
1370
- _a.trys.push([1, 3,, 4]);
1371
-
1372
- return [4
1373
- /*yield*/
1374
- , (0, _mutations.acceptFriend)(friendId)];
1375
-
1376
- case 2:
1377
- result = _a.sent();
1378
-
1379
- if (result["friendship"]) {
1380
- result["friendship"]["user"]["id"] = this.ObjectId(result["friendship"]["user"]["id"]);
1381
- result["friendship"]["friend"]["id"] = this.ObjectId(result["friendship"]["friend"]["id"]);
1382
- }
1383
-
1384
- return [2
1385
- /*return*/
1386
- , result["friendship"]];
1387
-
1388
- case 3:
1389
- e_13 = _a.sent();
1390
- throw e_13;
1391
-
1392
- case 4:
1393
- return [2
1394
- /*return*/
1395
- ];
1396
- }
1397
- });
1398
- });
1399
- };
1400
- /**
1401
- * Reject a friend request.
1402
- *
1403
- * @async
1404
- * @function rejectFriend
1405
- * @param {string} friendId - An id of the friend to be rejected.
1406
- * @returns {Promise<any>}
1407
- */
1408
-
1409
-
1410
- NCloudChat.prototype.rejectFriend = function (friendId) {
1411
- return __awaiter(this, void 0, void 0, function () {
1412
- var result, e_14;
1413
- return __generator(this, function (_a) {
1414
- switch (_a.label) {
1415
- case 0:
1416
- this.inputValidation({
1417
- friendId: friendId
1418
- });
1419
- _a.label = 1;
1420
-
1421
- case 1:
1422
- _a.trys.push([1, 3,, 4]);
1423
-
1424
- return [4
1425
- /*yield*/
1426
- , (0, _mutations.rejectFriend)(friendId)];
1427
-
1428
- case 2:
1429
- result = _a.sent();
1430
-
1431
- if (result["friendship"]) {
1432
- result["friendship"]["user"]["id"] = this.ObjectId(result["friendship"]["user"]["id"]);
1433
- result["friendship"]["friend"]["id"] = this.ObjectId(result["friendship"]["friend"]["id"]);
1434
- }
1435
-
1436
- return [2
1437
- /*return*/
1438
- , result["friendship"]];
1439
-
1440
- case 3:
1441
- e_14 = _a.sent();
1442
- throw e_14;
1443
-
1444
- case 4:
1445
- return [2
1446
- /*return*/
1447
- ];
1448
- }
1449
- });
1450
- });
1451
- };
1452
- /**
1453
- * Remove a friend.
1454
- *
1455
- * @async
1456
- * @function removeFriend
1457
- * @param {string} friendId - An id of the friend to be removed.
1458
- * @returns {Promise<any>}
1459
- */
1460
-
1461
-
1462
- NCloudChat.prototype.removeFriend = function (friendId) {
1463
- return __awaiter(this, void 0, void 0, function () {
1464
- var result, e_15;
1465
- return __generator(this, function (_a) {
1466
- switch (_a.label) {
1467
- case 0:
1468
- this.inputValidation({
1469
- friendId: friendId
1470
- });
1471
- _a.label = 1;
1472
-
1473
- case 1:
1474
- _a.trys.push([1, 3,, 4]);
1475
-
1476
- return [4
1477
- /*yield*/
1478
- , (0, _mutations.removeFriend)(friendId)];
1479
-
1480
- case 2:
1481
- result = _a.sent();
1482
-
1483
- if (result["friendship"]) {
1484
- result["friendship"]["user"]["id"] = this.ObjectId(result["friendship"]["user"]["id"]);
1485
- result["friendship"]["friend"]["id"] = this.ObjectId(result["friendship"]["friend"]["id"]);
1486
- }
1487
-
1488
- return [2
1489
- /*return*/
1490
- , result["friendship"]];
1491
-
1492
- case 3:
1493
- e_15 = _a.sent();
1494
- throw e_15;
1495
-
1496
- case 4:
1497
- return [2
1498
- /*return*/
1499
- ];
1500
- }
1501
- });
1502
- });
1503
- };
1504
- /**
1505
- * Get a count of unread messages of a channel.
1506
- *
1507
- * @async
1508
- * @function countUnread
1509
- * @param {string} channelId - The id of a channel.
1510
- * @returns {Promise<any>}
1511
- */
1512
-
1513
-
1514
- NCloudChat.prototype.countUnread = function (channelId) {
1515
- return __awaiter(this, void 0, void 0, function () {
1516
- var e_16;
1517
- return __generator(this, function (_a) {
1518
- switch (_a.label) {
1519
- case 0:
1520
- this.inputValidation({
1521
- channelId: channelId
1522
- });
1523
- _a.label = 1;
1524
-
1525
- case 1:
1526
- _a.trys.push([1, 3,, 4]);
1527
-
1528
- return [4
1529
- /*yield*/
1530
- , (0, _queries.unreadCount)(channelId)];
1531
-
1532
- case 2:
1533
- return [2
1534
- /*return*/
1535
- , _a.sent()];
1536
-
1537
- case 3:
1538
- e_16 = _a.sent();
1539
- throw e_16;
1540
-
1541
- case 4:
1542
- return [2
1543
- /*return*/
1544
- ];
1545
- }
1546
- });
1547
- });
1548
- };
1549
- /**
1550
- * Get subscription data of the user.
1551
- *
1552
- * @async
1553
- * @function getSubscription
1554
- * @param {string} channelId - The id of a channel.
1555
- * @param {string} id
1556
- * @returns {Promise<any>}
1557
- */
1558
-
1559
-
1560
- NCloudChat.prototype.getSubscription = function (channelId, id) {
1561
- return __awaiter(this, void 0, void 0, function () {
1562
- var subscription, e_17;
1563
- return __generator(this, function (_a) {
1564
- switch (_a.label) {
1565
- case 0:
1566
- this.inputValidation({
1567
- channelId: channelId,
1568
- subscriptionId: id
1569
- });
1570
- _a.label = 1;
1571
-
1572
- case 1:
1573
- _a.trys.push([1, 3,, 4]);
1574
-
1575
- return [4
1576
- /*yield*/
1577
- , (0, _queries.getSubscription)(channelId, id)];
1578
-
1579
- case 2:
1580
- subscription = _a.sent();
1581
- if (subscription) subscription["id"] = this.ObjectId(subscription["id"]);
1582
- return [2
1583
- /*return*/
1584
- , subscription];
1585
-
1586
- case 3:
1587
- e_17 = _a.sent();
1588
- throw e_17;
1589
-
1590
- case 4:
1591
- return [2
1592
- /*return*/
1593
- ];
1594
- }
1595
- });
1596
- });
1597
- };
1598
- /**
1599
- * Get data of a single channel from the endpoint.
1600
- *
1601
- * @async
1602
- * @function getChannel
1603
- * @param {string} channelId - An id of the channel.
1604
- * @returns {Promise<any>} The data of the channel.
1605
- */
1606
-
1607
-
1608
- NCloudChat.prototype.getChannel = function (channelId) {
1609
- return __awaiter(this, void 0, void 0, function () {
1610
- var result, e_18;
1611
- return __generator(this, function (_a) {
1612
- switch (_a.label) {
1613
- case 0:
1614
- this.inputValidation({
1615
- channelId: channelId
1616
- });
1617
- _a.label = 1;
1618
-
1619
- case 1:
1620
- _a.trys.push([1, 3,, 4]);
1621
-
1622
- return [4
1623
- /*yield*/
1624
- , (0, _queries.getChannel)(channelId)];
1625
-
1626
- case 2:
1627
- result = _a.sent();
1628
-
1629
- if (result) {
1630
- result.id = this.ObjectId(result.id);
1631
- result["user_id"]["id"] = this.ObjectId(result["user_id"]["id"]);
1632
- }
1633
-
1634
- return [2
1635
- /*return*/
1636
- , result];
1637
-
1638
- case 3:
1639
- e_18 = _a.sent();
1640
- throw e_18;
1641
-
1642
- case 4:
1643
- return [2
1644
- /*return*/
1645
- ];
1646
- }
1647
- });
1648
- });
1649
- };
1650
- /**
1651
- * Get data of multiple channels.
1652
- *
1653
- * @async
1654
- * @function getChannels
1655
- * @param {string} filter - Field value for filter.
1656
- * @param {string} sort - Field value for sorting.
1657
- * @param {string} option - Optional option: ex) offset, per_page.
1658
- * @returns {Promise<any[]>} An array of data of all channels.
1659
- */
1660
-
1661
-
1662
- NCloudChat.prototype.getChannels = function (filter, sort, option) {
1663
- if (sort === void 0) {
1664
- sort = {};
1665
- }
1666
-
1667
- if (option === void 0) {
1668
- option = {};
1669
- }
1670
-
1671
- return __awaiter(this, void 0, void 0, function () {
1672
- var entries, channels, e_19;
1673
-
1674
- var _this = this;
1675
-
1676
- return __generator(this, function (_a) {
1677
- switch (_a.label) {
1678
- case 0:
1679
- this.inputValidation({});
1680
- _a.label = 1;
1681
-
1682
- case 1:
1683
- _a.trys.push([1, 3,, 4]);
1684
-
1685
- return [4
1686
- /*yield*/
1687
- , (0, _queries.getChannels)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
1688
-
1689
- case 2:
1690
- entries = _a.sent();
1691
-
1692
- if (entries["edges"]) {
1693
- channels = entries["edges"].map(function (item) {
1694
- item.node.user_id.id = _this.ObjectId(item.node.user_id.id);
1695
- return __assign(__assign({}, item.node), {
1696
- id: _this.ObjectId(item.node.id)
1697
- });
1698
- });
1699
- return [2
1700
- /*return*/
1701
- , channels];
1702
- }
1703
-
1704
- return [2
1705
- /*return*/
1706
- , entries["edges"]];
1707
-
1708
- case 3:
1709
- e_19 = _a.sent();
1710
- throw e_19;
1711
-
1712
- case 4:
1713
- return [2
1714
- /*return*/
1715
- ];
1716
- }
1717
- });
1718
- });
1719
- };
1720
- /**
1721
- * @async
1722
- * @function getMessage
1723
- * @param {string} channelId - The id of a channel.
1724
- * @param {string} messageId - The id of a message.
1725
- * @returns {Promise<any>}
1726
- */
1727
-
1728
-
1729
- NCloudChat.prototype.getMessage = function (channelId, messageId) {
1730
- return __awaiter(this, void 0, void 0, function () {
1731
- var entry, e_20;
1732
- return __generator(this, function (_a) {
1733
- switch (_a.label) {
1734
- case 0:
1735
- this.inputValidation({
1736
- channelId: channelId,
1737
- messageId: messageId
1738
- });
1739
- _a.label = 1;
1740
-
1741
- case 1:
1742
- _a.trys.push([1, 3,, 4]);
1743
-
1744
- return [4
1745
- /*yield*/
1746
- , (0, _queries.getMessage)(channelId, messageId)];
1747
-
1748
- case 2:
1749
- entry = _a.sent();
1750
-
1751
- if (entry) {
1752
- entry.id = this.ObjectId(entry.id);
1753
- return [2
1754
- /*return*/
1755
- , entry];
1756
- }
1757
-
1758
- return [2
1759
- /*return*/
1760
- , entry];
1761
-
1762
- case 3:
1763
- e_20 = _a.sent();
1764
- throw e_20;
1765
-
1766
- case 4:
1767
- return [2
1768
- /*return*/
1769
- ];
1770
- }
1771
- });
1772
- });
1773
- };
1774
- /**
1775
- * Get data of the all messages.
1776
- *
1777
- * @async
1778
- * @function getMessages
1779
- * @param {string} filter - Field value for filter.
1780
- * @param {string} sort - Field value for sorting.
1781
- * @param {string} option - Optional option: ex) offset, per_page.
1782
- * @returns {Promise<any>}
1783
- */
1784
-
1785
-
1786
- NCloudChat.prototype.getMessages = function (filter, sort, option) {
1787
- return __awaiter(this, void 0, void 0, function () {
1788
- var entries, messages, e_21;
1789
-
1790
- var _this = this;
1791
-
1792
- return __generator(this, function (_a) {
1793
- switch (_a.label) {
1794
- case 0:
1795
- this.inputValidation({});
1796
- _a.label = 1;
1797
-
1798
- case 1:
1799
- _a.trys.push([1, 3,, 4]);
1800
-
1801
- return [4
1802
- /*yield*/
1803
- , (0, _queries.getMessages)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
1804
-
1805
- case 2:
1806
- entries = _a.sent();
1807
-
1808
- if (entries["edges"]) {
1809
- messages = entries["edges"].map(function (item) {
1810
- return __assign(__assign({}, item.node), {
1811
- id: _this.ObjectId(item.node.id)
1812
- });
1813
- });
1814
- return [2
1815
- /*return*/
1816
- , messages];
1817
- }
1818
-
1819
- return [2
1820
- /*return*/
1821
- , entries["edges"]];
1822
-
1823
- case 3:
1824
- e_21 = _a.sent();
1825
- throw e_21;
1826
-
1827
- case 4:
1828
- return [2
1829
- /*return*/
1830
- ];
1831
- }
1832
- });
1833
- });
1834
- };
1835
- /**
1836
- * Get a list of subscibed member of the channel.
1837
- * @param {string} filter - Field value for filter.
1838
- * @param {string} sort - Field value for sorting.
1839
- * @param {string} option - Optional option: ex) offset, per_page.
1840
- * @returns {Promise<any>}
1841
- */
1842
-
1843
-
1844
- NCloudChat.prototype.getSubscriptions = function (filter, sort, option) {
1845
- return __awaiter(this, void 0, void 0, function () {
1846
- var entries, subscribes, e_22;
1847
-
1848
- var _this = this;
1849
-
1850
- return __generator(this, function (_a) {
1851
- switch (_a.label) {
1852
- case 0:
1853
- this.inputValidation({});
1854
- _a.label = 1;
1855
-
1856
- case 1:
1857
- _a.trys.push([1, 3,, 4]);
1858
-
1859
- return [4
1860
- /*yield*/
1861
- , (0, _queries.getSubscriptions)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
1862
-
1863
- case 2:
1864
- entries = _a.sent();
1865
-
1866
- if (entries["edges"]) {
1867
- subscribes = entries["edges"].map(function (item) {
1868
- return __assign(__assign({}, item.node), {
1869
- id: _this.ObjectId(item.node.id)
1870
- });
1871
- });
1872
- return [2
1873
- /*return*/
1874
- , subscribes];
1875
- }
1876
-
1877
- return [2
1878
- /*return*/
1879
- , entries["edges"]];
1880
-
1881
- case 3:
1882
- e_22 = _a.sent();
1883
- throw e_22;
1884
-
1885
- case 4:
1886
- return [2
1887
- /*return*/
1888
- ];
1889
- }
1890
- });
1891
- });
1892
- };
1893
- /**
1894
- * Create a new channel.
1895
- *
1896
- * @async
1897
- * @function createChannel
1898
- * @param {ChannelInput} channel - Configuration options of the new channel.
1899
- * @returns {Promise<any>} The data of the newly created channel.
1900
- */
1901
-
1902
-
1903
- NCloudChat.prototype.createChannel = function (channel) {
1904
- return __awaiter(this, void 0, void 0, function () {
1905
- var result, e_23;
1906
- return __generator(this, function (_a) {
1907
- switch (_a.label) {
1908
- case 0:
1909
- this.inputValidation({
1910
- channelType: channel.type,
1911
- channelName: channel.name
1912
- });
1913
- _a.label = 1;
1914
-
1915
- case 1:
1916
- _a.trys.push([1, 3,, 4]);
1917
-
1918
- return [4
1919
- /*yield*/
1920
- , (0, _mutations.createChannel)(channel)];
1921
-
1922
- case 2:
1923
- result = _a.sent();
1924
-
1925
- if (result["channel"]) {
1926
- result["channel"]["id"] = this.ObjectId(result["channel"]["id"]);
1927
- result["channel"]["user_id"]["id"] = this.ObjectId(result["channel"]["user_id"]["id"]);
1928
- }
1929
-
1930
- return [2
1931
- /*return*/
1932
- , result["channel"]];
1933
-
1934
- case 3:
1935
- e_23 = _a.sent();
1936
- throw e_23;
1937
-
1938
- case 4:
1939
- return [2
1940
- /*return*/
1941
- ];
1942
- }
1943
- });
1944
- });
1945
- };
1946
- /**
1947
- * Update channel options.
1948
- *
1949
- * @async
1950
- * @function updateChannel
1951
- * @param {string} channelId - An id of the channel.
1952
- * @param {ChannelInput} channel - New options of the channel.
1953
- * @returns {Promise<any>} The data of the updated channel.
1954
- */
1955
-
1956
-
1957
- NCloudChat.prototype.updateChannel = function (channelId, channel) {
1958
- return __awaiter(this, void 0, void 0, function () {
1959
- var result, e_24;
1960
- return __generator(this, function (_a) {
1961
- switch (_a.label) {
1962
- case 0:
1963
- this.inputValidation({
1964
- channelId: channelId
1965
- });
1966
- if (!channel.name) throw Error("You need at least a channel name or a type.");
1967
- _a.label = 1;
1968
-
1969
- case 1:
1970
- _a.trys.push([1, 3,, 4]);
1971
-
1972
- return [4
1973
- /*yield*/
1974
- , (0, _mutations.updateChannel)(channelId, channel)];
1975
-
1976
- case 2:
1977
- result = _a.sent();
1978
-
1979
- if (result["channel"]) {
1980
- result["channel"]["id"] = this.ObjectId(result["channel"]["id"]);
1981
- result["channel"]["user_id"]["id"] = this.ObjectId(result["channel"]["user_id"]["id"]);
1982
- }
1983
-
1984
- return [2
1985
- /*return*/
1986
- , result["channel"]];
1987
-
1988
- case 3:
1989
- e_24 = _a.sent();
1990
- throw e_24;
1991
-
1992
- case 4:
1993
- return [2
1994
- /*return*/
1995
- ];
1996
- }
1997
- });
1998
- });
1999
- };
2000
- /**
2001
- * Delete a channel.
2002
- *
2003
- * @async
2004
- * @function deleteChannel
2005
- * @param {string} channelId - An channel id.
2006
- * @returns {Promise<any>}
2007
- */
2008
-
2009
-
2010
- NCloudChat.prototype.deleteChannel = function (channelId) {
2011
- return __awaiter(this, void 0, void 0, function () {
2012
- var result, e_25;
2013
- return __generator(this, function (_a) {
2014
- switch (_a.label) {
2015
- case 0:
2016
- this.inputValidation({
2017
- channelId: channelId
2018
- });
2019
- _a.label = 1;
2020
-
2021
- case 1:
2022
- _a.trys.push([1, 3,, 4]);
2023
-
2024
- return [4
2025
- /*yield*/
2026
- , (0, _mutations.deleteChannel)(channelId)];
2027
-
2028
- case 2:
2029
- result = _a.sent();
2030
-
2031
- if (result["channel"]) {
2032
- result["channel"]["id"] = this.ObjectId(result["channel"]["id"]);
2033
- result["channel"]["user_id"]["id"] = this.ObjectId(result["channel"]["user_id"]["id"]);
2034
- }
2035
-
2036
- return [2
2037
- /*return*/
2038
- , result["channel"]];
2039
-
2040
- case 3:
2041
- e_25 = _a.sent();
2042
- throw e_25;
2043
-
2044
- case 4:
2045
- return [2
2046
- /*return*/
2047
- ];
2048
- }
2049
- });
2050
- });
2051
- };
2052
- /**
2053
- * Update a subscription information, such as marking message read.
2054
- *
2055
- * @async
2056
- * @function markRead
2057
- * @param {string} channelId - The id of a channel.
2058
- * @param {MarkInput} mark
2059
- * @param {string} option
2060
- * @returns {Promise<any>}
2061
- */
2062
-
2063
-
2064
- NCloudChat.prototype.markRead = function (channelId, mark, option) {
2065
- if (option === void 0) {
2066
- option = null;
2067
- }
2068
-
2069
- return __awaiter(this, void 0, void 0, function () {
2070
- var result, e_26;
2071
- return __generator(this, function (_a) {
2072
- switch (_a.label) {
2073
- case 0:
2074
- this.inputValidation({
2075
- channelId: channelId,
2076
- userId: mark.userId,
2077
- messageId: mark.messageId,
2078
- sortId: mark.sortId
2079
- });
2080
- _a.label = 1;
2081
-
2082
- case 1:
2083
- _a.trys.push([1, 3,, 4]);
2084
-
2085
- return [4
2086
- /*yield*/
2087
- , (0, _mutations.updateSubscription)(channelId, mark, (0, _stringify["default"])(option))];
2088
-
2089
- case 2:
2090
- result = _a.sent();
2091
- return [2
2092
- /*return*/
2093
- , result["subscription"]];
2094
-
2095
- case 3:
2096
- e_26 = _a.sent();
2097
- throw e_26;
2098
-
2099
- case 4:
2100
- return [2
2101
- /*return*/
2102
- ];
2103
- }
2104
- });
2105
- });
2106
- };
2107
- /**
2108
- * Add members to the private channel.
2109
- *
2110
- * @async
2111
- * @function addUsers
2112
- * @param {string} channelId - An private channel id.
2113
- * @param {string[]} userIds - An array of member ids to be added.
2114
- * @param {any} options
2115
- * @returns {Promise<any>}
2116
- */
2117
-
2118
-
2119
- NCloudChat.prototype.addUsers = function (channelId, userIds, options) {
2120
- return __awaiter(this, void 0, void 0, function () {
2121
- var result, e_27;
2122
- return __generator(this, function (_a) {
2123
- switch (_a.label) {
2124
- case 0:
2125
- this.inputValidation({
2126
- channelId: channelId,
2127
- userIds: userIds
2128
- });
2129
- _a.label = 1;
2130
-
2131
- case 1:
2132
- _a.trys.push([1, 3,, 4]);
2133
-
2134
- return [4
2135
- /*yield*/
2136
- , (0, _mutations.addChannelMembers)(channelId, userIds, options)];
2137
-
2138
- case 2:
2139
- result = _a.sent();
2140
-
2141
- if (result["channel"]) {
2142
- result["channel"]["id"] = this.ObjectId(result["channel"]["id"]);
2143
- result["channel"]["user_id"]["id"] = this.ObjectId(result["channel"]["user_id"]["id"]);
2144
- }
2145
-
2146
- return [2
2147
- /*return*/
2148
- , result["channel"]];
2149
-
2150
- case 3:
2151
- e_27 = _a.sent();
2152
- throw e_27;
2153
-
2154
- case 4:
2155
- return [2
2156
- /*return*/
2157
- ];
2158
- }
2159
- });
2160
- });
2161
- };
2162
- /**
2163
- * Remove members from the private channel.
2164
- *
2165
- * @async
2166
- * @function removeUsers
2167
- * @param {string} channelId - An private channel id.
2168
- * @param {string[]} userIds - An array of the member ids to be deleted.
2169
- * @param {any} options
2170
- * @returns {Promise<any>}
2171
- */
2172
-
2173
-
2174
- NCloudChat.prototype.removeUsers = function (channelId, userIds, options) {
2175
- return __awaiter(this, void 0, void 0, function () {
2176
- var result, e_28;
2177
- return __generator(this, function (_a) {
2178
- switch (_a.label) {
2179
- case 0:
2180
- this.inputValidation({
2181
- channelId: channelId,
2182
- userIds: userIds
2183
- });
2184
- _a.label = 1;
2185
-
2186
- case 1:
2187
- _a.trys.push([1, 3,, 4]);
2188
-
2189
- return [4
2190
- /*yield*/
2191
- , (0, _mutations.removeChannelMembers)(channelId, userIds)];
2192
-
2193
- case 2:
2194
- result = _a.sent();
2195
-
2196
- if (result["channel"]) {
2197
- result["channel"]["id"] = this.ObjectId(result["channel"]["id"]);
2198
- result["channel"]["user_id"]["id"] = this.ObjectId(result["channel"]["user_id"]["id"]);
2199
- }
2200
-
2201
- return [2
2202
- /*return*/
2203
- , result["channel"]];
2204
-
2205
- case 3:
2206
- e_28 = _a.sent();
2207
- throw e_28;
2208
-
2209
- case 4:
2210
- return [2
2211
- /*return*/
2212
- ];
2213
- }
2214
- });
2215
- });
2216
- };
2217
- /**
2218
- * Emit "start typing" to a conneted socket.
2219
- *
2220
- * @async
2221
- * @function startTyping
2222
- * @param {string} channelId - The id of a channel that the typing is happening.
2223
- * @param {string} threadId - The id of a thread that the typing is happening.
2224
- * @returns {Promise<any>}
2225
- */
2226
-
2227
-
2228
- NCloudChat.prototype.startTyping = function (channelId, threadId) {
2229
- if (threadId === void 0) {
2230
- threadId = "";
2231
- }
2232
-
2233
- return __awaiter(this, void 0, void 0, function () {
2234
- var data;
2235
- return __generator(this, function (_a) {
2236
- if (!this.isConnected()) throw Error("You are not connected.");
2237
- this.inputValidation({
2238
- channelId: channelId,
2239
- threadId: threadId
2240
- });
2241
-
2242
- try {
2243
- data = {
2244
- channelId: channelId,
2245
- threadId: threadId
2246
- };
2247
- this.socket.emit("start typing", data);
2248
- return [2
2249
- /*return*/
2250
- , data];
2251
- } catch (e) {
2252
- throw e;
2253
- }
2254
-
2255
- return [2
2256
- /*return*/
2257
- ];
2258
- });
2259
- });
2260
- };
2261
- /**
2262
- * Emit "stop typing" to a connected socket.
2263
- *
2264
- * @async
2265
- * @function
2266
- * @param {string} channelId - The id of a channel that the typing is stopped.
2267
- * @param {string} threadId - The id of a thread that the typing is stopped.
2268
- * @returns {Promise<any>}
2269
- */
2270
-
2271
-
2272
- NCloudChat.prototype.stopTyping = function (channelId, threadId) {
2273
- if (threadId === void 0) {
2274
- threadId = "";
2275
- }
2276
-
2277
- return __awaiter(this, void 0, void 0, function () {
2278
- var data;
2279
- return __generator(this, function (_a) {
2280
- if (!this.isConnected()) throw Error("You are not connected.");
2281
- this.inputValidation({
2282
- channelId: channelId,
2283
- threadId: threadId
2284
- });
2285
-
2286
- try {
2287
- data = {
2288
- channelId: channelId,
2289
- threadId: threadId
2290
- };
2291
- this.socket.emit("stop typing", data);
2292
- return [2
2293
- /*return*/
2294
- , data];
2295
- } catch (e) {
2296
- throw e;
2297
- }
2298
-
2299
- return [2
2300
- /*return*/
2301
- ];
2302
- });
2303
- });
2304
- };
2305
- /**
2306
- * Ban a member from a channel.
2307
- *
2308
- * @async
2309
- * @function banUser
2310
- * @param {string} channelId - The id of a channel.
2311
- * @param {string} memberId - The id of a member.
2312
- * @param {any} options
2313
- * @returns {Promise<any>}
2314
- */
2315
-
2316
-
2317
- NCloudChat.prototype.banUser = function (channelId, memberId, options) {
2318
- if (options === void 0) {
2319
- options = {};
2320
- }
2321
-
2322
- return __awaiter(this, void 0, void 0, function () {
2323
- var memberBlock, e_29;
2324
- return __generator(this, function (_a) {
2325
- switch (_a.label) {
2326
- case 0:
2327
- this.inputValidation({
2328
- channelId: channelId,
2329
- memberId: memberId
2330
- });
2331
- _a.label = 1;
2332
-
2333
- case 1:
2334
- _a.trys.push([1, 3,, 4]);
2335
-
2336
- return [4
2337
- /*yield*/
2338
- , (0, _mutations.createMemberBlock)(channelId, memberId, (0, _stringify["default"])(options))];
2339
-
2340
- case 2:
2341
- memberBlock = _a.sent();
2342
- if (memberBlock["memberBlock"]) memberBlock["memberBlock"]["id"] = this.ObjectId(memberBlock["memberBlock"]["id"]);
2343
- return [2
2344
- /*return*/
2345
- , memberBlock["memberBlock"]];
2346
-
2347
- case 3:
2348
- e_29 = _a.sent();
2349
- throw e_29;
2350
-
2351
- case 4:
2352
- return [2
2353
- /*return*/
2354
- ];
2355
- }
2356
- });
2357
- });
2358
- };
2359
- /**
2360
- * Unban a member from a channel.
2361
- *
2362
- * @async
2363
- * @function unbanUser
2364
- * @param {string} channelId - The id of a channel.
2365
- * @param {string} memberId - The id of a member.
2366
- * @returns {Promise<any>}
2367
- */
2368
-
2369
-
2370
- NCloudChat.prototype.unbanUser = function (channelId, memberId) {
2371
- return __awaiter(this, void 0, void 0, function () {
2372
- var memberBlock, e_30;
2373
- return __generator(this, function (_a) {
2374
- switch (_a.label) {
2375
- case 0:
2376
- this.inputValidation({
2377
- channelId: channelId,
2378
- memberId: memberId
2379
- });
2380
- _a.label = 1;
2381
-
2382
- case 1:
2383
- _a.trys.push([1, 3,, 4]);
2384
-
2385
- return [4
2386
- /*yield*/
2387
- , (0, _mutations.deleteMemberBlock)(channelId, memberId)];
2388
-
2389
- case 2:
2390
- memberBlock = _a.sent();
2391
- if (memberBlock["memberBlock"]) memberBlock["memberBlock"]["id"] = this.ObjectId(memberBlock["memberBlock"]["id"]);
2392
- return [2
2393
- /*return*/
2394
- , memberBlock["memberBlock"]];
2395
-
2396
- case 3:
2397
- e_30 = _a.sent();
2398
- throw e_30;
2399
-
2400
- case 4:
2401
- return [2
2402
- /*return*/
2403
- ];
2404
- }
2405
- });
2406
- });
2407
- };
2408
- /**
2409
- * Get data of a single pin from the endpoint.
2410
- *
2411
- * @async
2412
- * @function getPin
2413
- * @param {string} channelId - An id of the channel.
2414
- * @param {string} id - An id of the pin.
2415
- * @returns {Promise<any>} The data of the pin.
2416
- */
2417
-
2418
-
2419
- NCloudChat.prototype.getPin = function (channelId, id) {
2420
- return __awaiter(this, void 0, void 0, function () {
2421
- var result, e_31;
2422
- return __generator(this, function (_a) {
2423
- switch (_a.label) {
2424
- case 0:
2425
- this.inputValidation({
2426
- channelId: channelId,
2427
- pinId: id
2428
- });
2429
- _a.label = 1;
2430
-
2431
- case 1:
2432
- _a.trys.push([1, 3,, 4]);
2433
-
2434
- return [4
2435
- /*yield*/
2436
- , (0, _queries.getPin)(channelId, id)];
2437
-
2438
- case 2:
2439
- result = _a.sent();
2440
-
2441
- if (result) {
2442
- result.id = this.ObjectId(result.id);
2443
-
2444
- if (result["user_id"]) {
2445
- result["user_id"]["id"] = this.ObjectId(result["user_id"]["id"]);
2446
- }
2447
- }
2448
-
2449
- return [2
2450
- /*return*/
2451
- , result];
2452
-
2453
- case 3:
2454
- e_31 = _a.sent();
2455
- throw e_31;
2456
-
2457
- case 4:
2458
- return [2
2459
- /*return*/
2460
- ];
2461
- }
2462
- });
2463
- });
2464
- };
2465
- /**
2466
- * Get data of multiple pins.
2467
- *
2468
- * @async
2469
- * @function getPins
2470
- * @param {string} channelId - An id of the channel.
2471
- * @param {string} filter - Field value for filter.
2472
- * @param {string} sort - Field value for sorting.
2473
- * @param {string} option - Optional option: ex) offset, per_page.
2474
- * @returns {Promise<any[]>} An array of data of all channels.
2475
- */
2476
-
2477
-
2478
- NCloudChat.prototype.getPins = function (channelId, filter, sort, option) {
2479
- if (sort === void 0) {
2480
- sort = {};
2481
- }
2482
-
2483
- if (option === void 0) {
2484
- option = {};
2485
- }
2486
-
2487
- return __awaiter(this, void 0, void 0, function () {
2488
- var entries, channels, e_32;
2489
-
2490
- var _this = this;
2491
-
2492
- return __generator(this, function (_a) {
2493
- switch (_a.label) {
2494
- case 0:
2495
- this.inputValidation({});
2496
- _a.label = 1;
2497
-
2498
- case 1:
2499
- _a.trys.push([1, 3,, 4]);
2500
-
2501
- return [4
2502
- /*yield*/
2503
- , (0, _queries.getPins)(channelId, (0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
2504
-
2505
- case 2:
2506
- entries = _a.sent();
2507
-
2508
- if (entries["edges"]) {
2509
- channels = entries["edges"].map(function (item) {
2510
- var _a, _b;
2511
-
2512
- if (item.node.user_id) item.node.user_id.id = _this.ObjectId((_b = (_a = item.node) === null || _a === void 0 ? void 0 : _a.user_id) === null || _b === void 0 ? void 0 : _b.id);
2513
- return __assign(__assign({}, item.node), {
2514
- id: _this.ObjectId(item.node.id)
2515
- });
2516
- });
2517
- return [2
2518
- /*return*/
2519
- , channels];
2520
- }
2521
-
2522
- return [2
2523
- /*return*/
2524
- , entries["edges"]];
2525
-
2526
- case 3:
2527
- e_32 = _a.sent();
2528
- throw e_32;
2529
-
2530
- case 4:
2531
- return [2
2532
- /*return*/
2533
- ];
2534
- }
2535
- });
2536
- });
2537
- };
2538
- /**
2539
- * Create a new pin.
2540
- *
2541
- * @async
2542
- * @function createPin
2543
- * @param {string} channelId - An id of the channel.
2544
- * @param {PinInput} pin - Configuration options of the new pin.
2545
- * @returns {Promise<any>} The data of the newly created pin.
2546
- */
2547
-
2548
-
2549
- NCloudChat.prototype.createPin = function (channelId, pin) {
2550
- return __awaiter(this, void 0, void 0, function () {
2551
- var result, e_33;
2552
- return __generator(this, function (_a) {
2553
- switch (_a.label) {
2554
- case 0:
2555
- this.inputValidation({
2556
- channelId: channelId,
2557
- pinned: pin.pinned
2558
- });
2559
- _a.label = 1;
2560
-
2561
- case 1:
2562
- _a.trys.push([1, 3,, 4]);
2563
-
2564
- return [4
2565
- /*yield*/
2566
- , (0, _mutations.createPin)(channelId, pin)];
2567
-
2568
- case 2:
2569
- result = _a.sent();
2570
-
2571
- if (result["pin"]) {
2572
- result["pin"]["id"] = this.ObjectId(result["pin"]["id"]);
2573
- result["pin"]["user_id"]["id"] = this.ObjectId(result["pin"]["user_id"]["id"]);
2574
- }
2575
-
2576
- return [2
2577
- /*return*/
2578
- , result["pin"]];
2579
-
2580
- case 3:
2581
- e_33 = _a.sent();
2582
- throw e_33;
2583
-
2584
- case 4:
2585
- return [2
2586
- /*return*/
2587
- ];
2588
- }
2589
- });
2590
- });
2591
- };
2592
- /**
2593
- * Update pin options.
2594
- *
2595
- * @async
2596
- * @function updatePin
2597
- * @param {string} channelId - An id of the channel.
2598
- * @param {PinInput} pin - New options of the pin.
2599
- * @returns {Promise<any>} The data of the updated pin.
2600
- */
2601
-
2602
-
2603
- NCloudChat.prototype.updatePin = function (pinId, channelId, pin) {
2604
- return __awaiter(this, void 0, void 0, function () {
2605
- var result, e_34;
2606
- return __generator(this, function (_a) {
2607
- switch (_a.label) {
2608
- case 0:
2609
- this.inputValidation({
2610
- channelId: channelId,
2611
- pinned: pin.pinned
2612
- });
2613
- _a.label = 1;
2614
-
2615
- case 1:
2616
- _a.trys.push([1, 3,, 4]);
2617
-
2618
- return [4
2619
- /*yield*/
2620
- , (0, _mutations.updatePin)(pinId, channelId, pin)];
2621
-
2622
- case 2:
2623
- result = _a.sent();
2624
-
2625
- if (result["pin"]) {
2626
- result["pin"]["id"] = this.ObjectId(result["pin"]["id"]);
2627
- result["pin"]["user_id"]["id"] = this.ObjectId(result["pin"]["user_id"]["id"]);
2628
- }
2629
-
2630
- return [2
2631
- /*return*/
2632
- , result["pin"]];
2633
-
2634
- case 3:
2635
- e_34 = _a.sent();
2636
- throw e_34;
2637
-
2638
- case 4:
2639
- return [2
2640
- /*return*/
2641
- ];
2642
- }
2643
- });
2644
- });
2645
- };
2646
-
2647
- NCloudChat.prototype.getServerUrl = function () {
2648
- return __awaiter(this, void 0, void 0, function () {
2649
- return __generator(this, function (_a) {
2650
- return [2
2651
- /*return*/
2652
- , _CoreManager["default"].get("SERVER_URL")];
2653
- });
2654
- });
2655
- };
2656
-
2657
- return NCloudChat;
2658
- }();
2659
-
2660
- var _default = NCloudChat;
2661
- exports["default"] = _default;