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