ncloudchat 0.0.23-beta → 0.0.26-beta

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.
package/lib/CloudChat.js CHANGED
@@ -258,9 +258,13 @@ function () {
258
258
  _CoreManager["default"].set("USER", user);
259
259
  };
260
260
 
261
- NCloudChat.prototype.connect = function (user_id, callback) {
261
+ NCloudChat.prototype.connect = function (user, userToken) {
262
+ if (userToken === void 0) {
263
+ userToken = "";
264
+ }
265
+
262
266
  return __awaiter(this, void 0, void 0, function () {
263
- var url, project_id, user, image, name, lang, token, e_1, options;
267
+ var url, project_id, image, name, lang, e_1, options;
264
268
 
265
269
  var _this = this;
266
270
 
@@ -285,19 +289,17 @@ function () {
285
289
 
286
290
  if (!project_id) {
287
291
  throw Error("Project ID not found");
288
- }
292
+ } // const user = CoreManager.get("USER");
293
+ // if (!user.id && user.id) user_id = user.id;
289
294
 
290
- user = _CoreManager["default"].get("USER");
291
- if (!user_id && user.id) user_id = user.id;
292
295
 
293
- if (!user_id) {
296
+ if (!user.id) {
294
297
  throw Error("UserID not found");
295
298
  }
296
299
 
297
- image = user.image;
300
+ image = user.profile;
298
301
  name = user.name;
299
302
  lang = this.getLang();
300
- token = null;
301
303
  _a.label = 3;
302
304
 
303
305
  case 3:
@@ -305,10 +307,10 @@ function () {
305
307
 
306
308
  return [4
307
309
  /*yield*/
308
- , (0, _mutations.login)(user_id)];
310
+ , (0, _mutations.login)(user.id, name, image, userToken)];
309
311
 
310
312
  case 4:
311
- token = _a.sent();
313
+ userToken = _a.sent();
312
314
  return [3
313
315
  /*break*/
314
316
  , 6];
@@ -318,11 +320,11 @@ function () {
318
320
  throw e_1;
319
321
 
320
322
  case 6:
321
- if (token == false) {
322
- throw Error("token is not found");
323
+ if (!userToken) {
324
+ throw Error("Token is not found");
323
325
  }
324
326
 
325
- _CoreManager["default"].set("TOKEN", token);
327
+ _CoreManager["default"].set("TOKEN", userToken);
326
328
 
327
329
  options = {
328
330
  transports: ["websocket"],
@@ -333,7 +335,7 @@ function () {
333
335
  randomizationFactor: 0.5,
334
336
  query: {
335
337
  project_id: project_id,
336
- token: token,
338
+ user_id: user.id,
337
339
  lang: lang,
338
340
  image: image,
339
341
  name: name
@@ -509,7 +511,7 @@ function () {
509
511
  });
510
512
  };
511
513
 
512
- NCloudChat.prototype.translateMessage = function (source, target, message) {
514
+ NCloudChat.prototype.translateMessage = function (channelId, source, target, message) {
513
515
  return __awaiter(this, void 0, void 0, function () {
514
516
  var user, result, e_5;
515
517
  return __generator(this, function (_a) {
@@ -527,7 +529,7 @@ function () {
527
529
  user = _CoreManager["default"].get("USER");
528
530
  return [4
529
531
  /*yield*/
530
- , (0, _mutations.translate)(source, target, message)];
532
+ , (0, _mutations.translate)(channelId, source, target, message)];
531
533
 
532
534
  case 2:
533
535
  result = _a.sent();
@@ -537,7 +539,7 @@ function () {
537
539
 
538
540
  case 3:
539
541
  e_5 = _a.sent();
540
- throw e_5;
542
+ throw Error(e_5.message);
541
543
 
542
544
  case 4:
543
545
  return [2
@@ -693,6 +695,64 @@ function () {
693
695
  return atob(id).split(":")[1];
694
696
  };
695
697
 
698
+ NCloudChat.prototype.getFriendships = function (filter, sort, option) {
699
+ if (sort === void 0) {
700
+ sort = {};
701
+ }
702
+
703
+ if (option === void 0) {
704
+ option = {};
705
+ }
706
+
707
+ return __awaiter(this, void 0, void 0, function () {
708
+ var entries, friends, e_6;
709
+ return __generator(this, function (_a) {
710
+ switch (_a.label) {
711
+ case 0:
712
+ if (!this.isConnected()) {
713
+ throw Error("You are not connected.");
714
+ }
715
+
716
+ _a.label = 1;
717
+
718
+ case 1:
719
+ _a.trys.push([1, 3,, 4]);
720
+
721
+ return [4
722
+ /*yield*/
723
+ , (0, _queries.getFriendships)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
724
+
725
+ case 2:
726
+ entries = _a.sent();
727
+
728
+ if (entries) {
729
+ friends = entries.map(function (item) {
730
+ return __assign(__assign({}, item.node), {
731
+ id: item.node.id
732
+ });
733
+ });
734
+ return [2
735
+ /*return*/
736
+ , friends];
737
+ }
738
+
739
+ return [2
740
+ /*return*/
741
+ , entries];
742
+
743
+ case 3:
744
+ e_6 = _a.sent();
745
+ throw e_6;
746
+
747
+ case 4:
748
+ return [2
749
+ /*return*/
750
+ ];
751
+ }
752
+ });
753
+ });
754
+ };
755
+
696
756
  NCloudChat.prototype.getMembers = function (filter, sort, option) {
697
757
  if (sort === void 0) {
698
758
  sort = {};
@@ -703,7 +763,7 @@ function () {
703
763
  }
704
764
 
705
765
  return __awaiter(this, void 0, void 0, function () {
706
- var entries, members, e_6;
766
+ var entries, members, e_7;
707
767
 
708
768
  var _this = this;
709
769
 
@@ -742,8 +802,8 @@ function () {
742
802
  , entries];
743
803
 
744
804
  case 3:
745
- e_6 = _a.sent();
746
- throw e_6;
805
+ e_7 = _a.sent();
806
+ throw e_7;
747
807
 
748
808
  case 4:
749
809
  return [2
@@ -764,7 +824,7 @@ function () {
764
824
  }
765
825
 
766
826
  return __awaiter(this, void 0, void 0, function () {
767
- var entries, channels, e_7;
827
+ var entries, channels, e_8;
768
828
 
769
829
  var _this = this;
770
830
 
@@ -803,8 +863,156 @@ function () {
803
863
  , entries];
804
864
 
805
865
  case 3:
806
- e_7 = _a.sent();
807
- throw e_7;
866
+ e_8 = _a.sent();
867
+ throw e_8;
868
+
869
+ case 4:
870
+ return [2
871
+ /*return*/
872
+ ];
873
+ }
874
+ });
875
+ });
876
+ };
877
+
878
+ NCloudChat.prototype.requestFriend = function (friendId) {
879
+ return __awaiter(this, void 0, void 0, function () {
880
+ var e_9;
881
+ return __generator(this, function (_a) {
882
+ switch (_a.label) {
883
+ case 0:
884
+ if (!this.isConnected()) {
885
+ throw Error("You are not connected.");
886
+ }
887
+
888
+ _a.label = 1;
889
+
890
+ case 1:
891
+ _a.trys.push([1, 3,, 4]);
892
+
893
+ return [4
894
+ /*yield*/
895
+ , (0, _mutations.requestFriend)(friendId)];
896
+
897
+ case 2:
898
+ return [2
899
+ /*return*/
900
+ , _a.sent()];
901
+
902
+ case 3:
903
+ e_9 = _a.sent();
904
+ throw e_9;
905
+
906
+ case 4:
907
+ return [2
908
+ /*return*/
909
+ ];
910
+ }
911
+ });
912
+ });
913
+ };
914
+
915
+ NCloudChat.prototype.acceptFriend = function (friendId) {
916
+ return __awaiter(this, void 0, void 0, function () {
917
+ var e_10;
918
+ return __generator(this, function (_a) {
919
+ switch (_a.label) {
920
+ case 0:
921
+ if (!this.isConnected()) {
922
+ throw Error("You are not connected.");
923
+ }
924
+
925
+ _a.label = 1;
926
+
927
+ case 1:
928
+ _a.trys.push([1, 3,, 4]);
929
+
930
+ return [4
931
+ /*yield*/
932
+ , (0, _mutations.acceptFriend)(friendId)];
933
+
934
+ case 2:
935
+ return [2
936
+ /*return*/
937
+ , _a.sent()];
938
+
939
+ case 3:
940
+ e_10 = _a.sent();
941
+ throw e_10;
942
+
943
+ case 4:
944
+ return [2
945
+ /*return*/
946
+ ];
947
+ }
948
+ });
949
+ });
950
+ };
951
+
952
+ NCloudChat.prototype.rejectFriend = function (friendId) {
953
+ return __awaiter(this, void 0, void 0, function () {
954
+ var e_11;
955
+ return __generator(this, function (_a) {
956
+ switch (_a.label) {
957
+ case 0:
958
+ if (!this.isConnected()) {
959
+ throw Error("You are not connected.");
960
+ }
961
+
962
+ _a.label = 1;
963
+
964
+ case 1:
965
+ _a.trys.push([1, 3,, 4]);
966
+
967
+ return [4
968
+ /*yield*/
969
+ , (0, _mutations.rejectFriend)(friendId)];
970
+
971
+ case 2:
972
+ return [2
973
+ /*return*/
974
+ , _a.sent()];
975
+
976
+ case 3:
977
+ e_11 = _a.sent();
978
+ throw e_11;
979
+
980
+ case 4:
981
+ return [2
982
+ /*return*/
983
+ ];
984
+ }
985
+ });
986
+ });
987
+ };
988
+
989
+ NCloudChat.prototype.removeFriend = function (friendId) {
990
+ return __awaiter(this, void 0, void 0, function () {
991
+ var e_12;
992
+ return __generator(this, function (_a) {
993
+ switch (_a.label) {
994
+ case 0:
995
+ if (!this.isConnected()) {
996
+ throw Error("You are not connected.");
997
+ }
998
+
999
+ _a.label = 1;
1000
+
1001
+ case 1:
1002
+ _a.trys.push([1, 3,, 4]);
1003
+
1004
+ return [4
1005
+ /*yield*/
1006
+ , (0, _mutations.removeFriend)(friendId)];
1007
+
1008
+ case 2:
1009
+ return [2
1010
+ /*return*/
1011
+ , _a.sent()];
1012
+
1013
+ case 3:
1014
+ e_12 = _a.sent();
1015
+ throw e_12;
808
1016
 
809
1017
  case 4:
810
1018
  return [2
@@ -817,7 +1025,7 @@ function () {
817
1025
 
818
1026
  NCloudChat.prototype.countUnread = function (channelId) {
819
1027
  return __awaiter(this, void 0, void 0, function () {
820
- var e_8;
1028
+ var e_13;
821
1029
  return __generator(this, function (_a) {
822
1030
  switch (_a.label) {
823
1031
  case 0:
@@ -840,13 +1048,13 @@ function () {
840
1048
  , _a.sent()];
841
1049
 
842
1050
  case 3:
843
- e_8 = _a.sent();
844
- throw e_8;
1051
+ e_13 = _a.sent();
1052
+ throw e_13;
845
1053
 
846
1054
  case 4:
847
1055
  return [2
848
1056
  /*return*/
849
- , null];
1057
+ ];
850
1058
  }
851
1059
  });
852
1060
  });
@@ -854,7 +1062,7 @@ function () {
854
1062
 
855
1063
  NCloudChat.prototype.getSubscription = function (channelId, id) {
856
1064
  return __awaiter(this, void 0, void 0, function () {
857
- var e_9;
1065
+ var e_14;
858
1066
  return __generator(this, function (_a) {
859
1067
  switch (_a.label) {
860
1068
  case 0:
@@ -877,8 +1085,8 @@ function () {
877
1085
  , _a.sent()];
878
1086
 
879
1087
  case 3:
880
- e_9 = _a.sent();
881
- throw e_9;
1088
+ e_14 = _a.sent();
1089
+ throw e_14;
882
1090
 
883
1091
  case 4:
884
1092
  return [2
@@ -891,7 +1099,7 @@ function () {
891
1099
 
892
1100
  NCloudChat.prototype.getChannel = function (channelId) {
893
1101
  return __awaiter(this, void 0, void 0, function () {
894
- var e_10;
1102
+ var e_15;
895
1103
  return __generator(this, function (_a) {
896
1104
  switch (_a.label) {
897
1105
  case 0:
@@ -914,8 +1122,8 @@ function () {
914
1122
  , _a.sent()];
915
1123
 
916
1124
  case 3:
917
- e_10 = _a.sent();
918
- throw e_10;
1125
+ e_15 = _a.sent();
1126
+ throw e_15;
919
1127
 
920
1128
  case 4:
921
1129
  return [2
@@ -928,7 +1136,7 @@ function () {
928
1136
 
929
1137
  NCloudChat.prototype.getMessage = function (channelId, messageId) {
930
1138
  return __awaiter(this, void 0, void 0, function () {
931
- var entry, e_11;
1139
+ var entry, e_16;
932
1140
  return __generator(this, function (_a) {
933
1141
  switch (_a.label) {
934
1142
  case 0:
@@ -960,8 +1168,8 @@ function () {
960
1168
  , null];
961
1169
 
962
1170
  case 3:
963
- e_11 = _a.sent();
964
- throw e_11;
1171
+ e_16 = _a.sent();
1172
+ throw e_16;
965
1173
 
966
1174
  case 4:
967
1175
  return [2
@@ -974,7 +1182,7 @@ function () {
974
1182
 
975
1183
  NCloudChat.prototype.getMessages = function (filter, sort, option) {
976
1184
  return __awaiter(this, void 0, void 0, function () {
977
- var entries, messages, e_12;
1185
+ var entries, messages, e_17;
978
1186
 
979
1187
  var _this = this;
980
1188
 
@@ -1013,8 +1221,8 @@ function () {
1013
1221
  , entries];
1014
1222
 
1015
1223
  case 3:
1016
- e_12 = _a.sent();
1017
- throw e_12;
1224
+ e_17 = _a.sent();
1225
+ throw e_17;
1018
1226
 
1019
1227
  case 4:
1020
1228
  return [2
@@ -1027,7 +1235,7 @@ function () {
1027
1235
 
1028
1236
  NCloudChat.prototype.getSubscriptions = function (filter, sort, option) {
1029
1237
  return __awaiter(this, void 0, void 0, function () {
1030
- var entries, subscribes, e_13;
1238
+ var entries, subscribes, e_18;
1031
1239
 
1032
1240
  var _this = this;
1033
1241
 
@@ -1066,8 +1274,8 @@ function () {
1066
1274
  , entries];
1067
1275
 
1068
1276
  case 3:
1069
- e_13 = _a.sent();
1070
- throw e_13;
1277
+ e_18 = _a.sent();
1278
+ throw e_18;
1071
1279
 
1072
1280
  case 4:
1073
1281
  return [2
@@ -1080,7 +1288,7 @@ function () {
1080
1288
 
1081
1289
  NCloudChat.prototype.createChannel = function (channel) {
1082
1290
  return __awaiter(this, void 0, void 0, function () {
1083
- var e_14;
1291
+ var e_19;
1084
1292
  return __generator(this, function (_a) {
1085
1293
  switch (_a.label) {
1086
1294
  case 0:
@@ -1103,8 +1311,8 @@ function () {
1103
1311
  , _a.sent()];
1104
1312
 
1105
1313
  case 3:
1106
- e_14 = _a.sent();
1107
- throw e_14;
1314
+ e_19 = _a.sent();
1315
+ throw e_19;
1108
1316
 
1109
1317
  case 4:
1110
1318
  return [2
@@ -1117,7 +1325,7 @@ function () {
1117
1325
 
1118
1326
  NCloudChat.prototype.updateChannel = function (channelId, channel) {
1119
1327
  return __awaiter(this, void 0, void 0, function () {
1120
- var e_15;
1328
+ var e_20;
1121
1329
  return __generator(this, function (_a) {
1122
1330
  switch (_a.label) {
1123
1331
  case 0:
@@ -1140,8 +1348,8 @@ function () {
1140
1348
  , _a.sent()];
1141
1349
 
1142
1350
  case 3:
1143
- e_15 = _a.sent();
1144
- throw e_15;
1351
+ e_20 = _a.sent();
1352
+ throw e_20;
1145
1353
 
1146
1354
  case 4:
1147
1355
  return [2
@@ -1154,7 +1362,7 @@ function () {
1154
1362
 
1155
1363
  NCloudChat.prototype.deleteChannel = function (channelId) {
1156
1364
  return __awaiter(this, void 0, void 0, function () {
1157
- var e_16;
1365
+ var e_21;
1158
1366
  return __generator(this, function (_a) {
1159
1367
  switch (_a.label) {
1160
1368
  case 0:
@@ -1177,8 +1385,8 @@ function () {
1177
1385
  , _a.sent()];
1178
1386
 
1179
1387
  case 3:
1180
- e_16 = _a.sent();
1181
- throw e_16;
1388
+ e_21 = _a.sent();
1389
+ throw e_21;
1182
1390
 
1183
1391
  case 4:
1184
1392
  return [2
@@ -1191,7 +1399,7 @@ function () {
1191
1399
 
1192
1400
  NCloudChat.prototype.markRead = function (channelId, mark) {
1193
1401
  return __awaiter(this, void 0, void 0, function () {
1194
- var e_17;
1402
+ var e_22;
1195
1403
  return __generator(this, function (_a) {
1196
1404
  switch (_a.label) {
1197
1405
  case 0:
@@ -1214,8 +1422,8 @@ function () {
1214
1422
  , _a.sent()];
1215
1423
 
1216
1424
  case 3:
1217
- e_17 = _a.sent();
1218
- throw e_17;
1425
+ e_22 = _a.sent();
1426
+ throw e_22;
1219
1427
 
1220
1428
  case 4:
1221
1429
  return [2