ncloudchat 1.0.31 → 1.0.35

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