@twilio/conversations 1.3.0-rc7 → 2.0.0-rc.3

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 (282) hide show
  1. package/CHANGELOG.md +201 -0
  2. package/README.md +5 -5
  3. package/dist/browser.js +7866 -0
  4. package/dist/browser.js.map +1 -0
  5. package/dist/docs/assets/css/main.css +2660 -0
  6. package/dist/docs/assets/images/icons.png +0 -0
  7. package/dist/docs/assets/images/icons@2x.png +0 -0
  8. package/dist/docs/assets/images/widgets.png +0 -0
  9. package/dist/docs/assets/images/widgets@2x.png +0 -0
  10. package/dist/docs/assets/js/main.js +248 -0
  11. package/dist/docs/assets/js/search.js +1 -0
  12. package/dist/docs/classes/AggregatedDeliveryReceipt.html +3286 -0
  13. package/dist/docs/classes/Client.html +4181 -0
  14. package/dist/docs/classes/Conversation.html +4397 -0
  15. package/dist/docs/classes/DetailedDeliveryReceipt.html +3265 -0
  16. package/dist/docs/classes/Media.html +3295 -0
  17. package/dist/docs/classes/Message.html +3713 -0
  18. package/dist/docs/classes/MessageBuilder.html +3280 -0
  19. package/dist/docs/classes/Participant.html +3517 -0
  20. package/dist/docs/classes/PushNotification.html +3232 -0
  21. package/dist/docs/classes/RestPaginator.html +3262 -0
  22. package/dist/docs/classes/UnsentMessage.html +3144 -0
  23. package/dist/docs/classes/User.html +3451 -0
  24. package/dist/docs/index.html +3387 -212
  25. package/dist/docs/interfaces/ClientOptions.html +3136 -0
  26. package/dist/docs/interfaces/ConversationState.html +3152 -0
  27. package/dist/docs/interfaces/CreateConversationOptions.html +3168 -0
  28. package/dist/docs/interfaces/LastMessage.html +3152 -0
  29. package/dist/docs/interfaces/Paginator.html +3243 -0
  30. package/dist/docs/interfaces/PushNotificationData.html +3168 -0
  31. package/dist/docs/interfaces/SendEmailOptions.html +3136 -0
  32. package/dist/docs/interfaces/SendMediaOptions.html +3169 -0
  33. package/dist/docs/modules.html +3418 -0
  34. package/dist/lib.d.ts +1944 -0
  35. package/dist/lib.js +7866 -0
  36. package/dist/lib.js.map +1 -0
  37. package/dist/post-install.js +29 -0
  38. package/dist/react-native.js +4031 -0
  39. package/dist/react-native.js.map +1 -0
  40. package/dist/twilio-conversations.js +40905 -0
  41. package/dist/twilio-conversations.min.js +156 -0
  42. package/package.json +59 -48
  43. package/.circleci/config.yml +0 -650
  44. package/.deepsource.toml +0 -6
  45. package/.env.example +0 -13
  46. package/browser/aggregateddeliveryreceipt.js +0 -152
  47. package/browser/client.js +0 -991
  48. package/browser/configuration.js +0 -80
  49. package/browser/conversation.js +0 -1826
  50. package/browser/data/conversations.js +0 -665
  51. package/browser/data/messages.js +0 -522
  52. package/browser/data/participants.js +0 -411
  53. package/browser/data/users.js +0 -281
  54. package/browser/detaileddeliveryreceipt.js +0 -44
  55. package/browser/index.js +0 -4
  56. package/browser/interfaces/limits.js +0 -3
  57. package/browser/interfaces/notificationtypes.js +0 -21
  58. package/browser/interfaces/paginator.js +0 -53
  59. package/browser/interfaces/responsecodes.js +0 -20
  60. package/browser/interfaces/transport.js +0 -3
  61. package/browser/logger.js +0 -141
  62. package/browser/media.js +0 -198
  63. package/browser/message.js +0 -685
  64. package/browser/participant.js +0 -415
  65. package/browser/pushnotification.js +0 -49
  66. package/browser/restpaginator.js +0 -74
  67. package/browser/services/network.js +0 -223
  68. package/browser/services/readhorizon.js +0 -181
  69. package/browser/services/typingindicator.js +0 -142
  70. package/browser/session.js +0 -505
  71. package/browser/sessionerror.js +0 -93
  72. package/browser/sri.json +0 -1
  73. package/browser/synclist.js +0 -90
  74. package/browser/synclistdescriptor.js +0 -29
  75. package/browser/syncpaginator.js +0 -63
  76. package/browser/user.js +0 -431
  77. package/browser/util/deferred.js +0 -56
  78. package/browser/util/index.js +0 -108
  79. package/dist/@twilio/conversations.js +0 -35565
  80. package/dist/@twilio/conversations.min.js +0 -204
  81. package/dist/docs/AggregatedDeliveryReceipt.html +0 -948
  82. package/dist/docs/Client.html +0 -5075
  83. package/dist/docs/Conversation.html +0 -6018
  84. package/dist/docs/DetailedDeliveryReceipt.html +0 -641
  85. package/dist/docs/Media.html +0 -694
  86. package/dist/docs/Message.html +0 -1934
  87. package/dist/docs/Paginator.html +0 -605
  88. package/dist/docs/Participant.html +0 -1510
  89. package/dist/docs/PushNotification.html +0 -836
  90. package/dist/docs/SessionError.html +0 -379
  91. package/dist/docs/User.html +0 -1315
  92. package/dist/docs/classes.list.html +0 -4431
  93. package/dist/docs/fonts/glyphicons-halflings-regular.eot +0 -0
  94. package/dist/docs/fonts/glyphicons-halflings-regular.svg +0 -288
  95. package/dist/docs/fonts/glyphicons-halflings-regular.ttf +0 -0
  96. package/dist/docs/fonts/glyphicons-halflings-regular.woff +0 -0
  97. package/dist/docs/fonts/glyphicons-halflings-regular.woff2 +0 -0
  98. package/dist/docs/img/glyphicons-halflings-white.png +0 -0
  99. package/dist/docs/img/glyphicons-halflings.png +0 -0
  100. package/dist/docs/quicksearch.html +0 -31
  101. package/dist/docs/scripts/docstrap.lib.js +0 -11
  102. package/dist/docs/scripts/fulltext-search-ui.js +0 -89
  103. package/dist/docs/scripts/fulltext-search.js +0 -36
  104. package/dist/docs/scripts/lunr.min.js +0 -6
  105. package/dist/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
  106. package/dist/docs/scripts/prettify/jquery.min.js +0 -6
  107. package/dist/docs/scripts/prettify/lang-css.js +0 -21
  108. package/dist/docs/scripts/prettify/prettify.js +0 -496
  109. package/dist/docs/scripts/sunlight.js +0 -1157
  110. package/dist/docs/scripts/toc.js +0 -203
  111. package/dist/docs/styles/darkstrap.css +0 -960
  112. package/dist/docs/styles/prettify-tomorrow.css +0 -132
  113. package/dist/docs/styles/site.cerulean.css +0 -7008
  114. package/dist/docs/styles/site.cosmo.css +0 -7061
  115. package/dist/docs/styles/site.cyborg.css +0 -7048
  116. package/dist/docs/styles/site.darkly.css +0 -7171
  117. package/dist/docs/styles/site.darkstrap.css +0 -5638
  118. package/dist/docs/styles/site.dibs-bootstrap.css +0 -5899
  119. package/dist/docs/styles/site.flatly.css +0 -7147
  120. package/dist/docs/styles/site.journal.css +0 -6973
  121. package/dist/docs/styles/site.lumen.css +0 -7298
  122. package/dist/docs/styles/site.paper.css +0 -7623
  123. package/dist/docs/styles/site.readable.css +0 -6997
  124. package/dist/docs/styles/site.sandstone.css +0 -7035
  125. package/dist/docs/styles/site.simplex.css +0 -7023
  126. package/dist/docs/styles/site.slate.css +0 -7343
  127. package/dist/docs/styles/site.spacelab.css +0 -7055
  128. package/dist/docs/styles/site.superhero.css +0 -7131
  129. package/dist/docs/styles/site.united.css +0 -6895
  130. package/dist/docs/styles/site.yeti.css +0 -7195
  131. package/dist/docs/styles/sunlight.dark.css +0 -345
  132. package/dist/docs/styles/sunlight.default.css +0 -344
  133. package/dist/sri.json +0 -1
  134. package/lib/aggregateddeliveryreceipt.d.ts +0 -98
  135. package/lib/aggregateddeliveryreceipt.js +0 -112
  136. package/lib/client.d.ts +0 -317
  137. package/lib/client.js +0 -633
  138. package/lib/configuration.d.ts +0 -21
  139. package/lib/configuration.js +0 -41
  140. package/lib/conversation.d.ts +0 -460
  141. package/lib/conversation.js +0 -940
  142. package/lib/data/conversations.d.ts +0 -57
  143. package/lib/data/conversations.js +0 -318
  144. package/lib/data/messages.d.ts +0 -75
  145. package/lib/data/messages.js +0 -208
  146. package/lib/data/participants.d.ts +0 -94
  147. package/lib/data/participants.js +0 -204
  148. package/lib/data/users.d.ts +0 -42
  149. package/lib/data/users.js +0 -113
  150. package/lib/detaileddeliveryreceipt.d.ts +0 -45
  151. package/lib/detaileddeliveryreceipt.js +0 -34
  152. package/lib/index.d.ts +0 -1
  153. package/lib/index.js +0 -3
  154. package/lib/interfaces/limits.d.ts +0 -8
  155. package/lib/interfaces/limits.js +0 -2
  156. package/lib/interfaces/notificationtypes.d.ts +0 -8
  157. package/lib/interfaces/notificationtypes.js +0 -11
  158. package/lib/interfaces/paginator.d.ts +0 -52
  159. package/lib/interfaces/paginator.js +0 -28
  160. package/lib/interfaces/responsecodes.d.ts +0 -8
  161. package/lib/interfaces/responsecodes.js +0 -10
  162. package/lib/interfaces/transport.d.ts +0 -13
  163. package/lib/interfaces/transport.js +0 -2
  164. package/lib/logger.d.ts +0 -18
  165. package/lib/logger.js +0 -35
  166. package/lib/media.d.ts +0 -52
  167. package/lib/media.js +0 -69
  168. package/lib/message.d.ts +0 -136
  169. package/lib/message.js +0 -305
  170. package/lib/participant.d.ts +0 -142
  171. package/lib/participant.js +0 -219
  172. package/lib/pushnotification.d.ts +0 -48
  173. package/lib/pushnotification.js +0 -39
  174. package/lib/restpaginator.d.ts +0 -19
  175. package/lib/restpaginator.js +0 -36
  176. package/lib/services/network.d.ts +0 -22
  177. package/lib/services/network.js +0 -87
  178. package/lib/services/readhorizon.d.ts +0 -28
  179. package/lib/services/readhorizon.js +0 -112
  180. package/lib/services/typingindicator.d.ts +0 -50
  181. package/lib/services/typingindicator.js +0 -102
  182. package/lib/session.d.ts +0 -63
  183. package/lib/session.js +0 -213
  184. package/lib/sessionerror.d.ts +0 -12
  185. package/lib/sessionerror.js +0 -24
  186. package/lib/sri.json +0 -1
  187. package/lib/synclist.d.ts +0 -24
  188. package/lib/synclist.js +0 -28
  189. package/lib/synclistdescriptor.d.ts +0 -27
  190. package/lib/synclistdescriptor.js +0 -19
  191. package/lib/syncpaginator.d.ts +0 -22
  192. package/lib/syncpaginator.js +0 -37
  193. package/lib/user.d.ts +0 -98
  194. package/lib/user.js +0 -219
  195. package/lib/util/deferred.d.ts +0 -12
  196. package/lib/util/deferred.js +0 -22
  197. package/lib/util/index.d.ts +0 -28
  198. package/lib/util/index.js +0 -82
  199. package/tools/rtd-sdk-cdn-pin/.gitrepo +0 -12
  200. package/tools/rtd-sdk-cdn-pin/README.md +0 -54
  201. package/tools/rtd-sdk-cdn-pin/bintray-settings.xml.template +0 -16
  202. package/tools/rtd-sdk-cdn-pin/cdn-common/cdn-prepare.sh +0 -67
  203. package/tools/rtd-sdk-cdn-pin/cdn-pin-latest.sh +0 -19
  204. package/tools/rtd-sdk-cdn-pin/cdn-pin.sh +0 -19
  205. package/tools/rtd-sdk-cdn-pin/cdn-upload.sh +0 -13
  206. package/tools/rtd-sdk-cdn-pin/fetch/common/fetch-bintray-android.sh +0 -34
  207. package/tools/rtd-sdk-cdn-pin/fetch/common/fetch-npm.sh +0 -18
  208. package/tools/rtd-sdk-cdn-pin/fetch/twilio-chat-android.sh +0 -5
  209. package/tools/rtd-sdk-cdn-pin/fetch/twilio-chat-js.sh +0 -5
  210. package/tools/rtd-sdk-cdn-pin/fetch/twilio-conversations-android.sh +0 -6
  211. package/tools/rtd-sdk-cdn-pin/fetch/twilio-conversations-js.sh +0 -5
  212. package/tools/rtd-sdk-cdn-pin/fetch/twilio-sync-android.sh +0 -5
  213. package/tools/rtd-sdk-cdn-pin/fetch/twilio-sync-js.sh +0 -5
  214. package/tools/rtd-sdk-cdn-pin/fetch-artifact.sh +0 -26
  215. package/tools/sdk-release-tool/.gitrepo +0 -12
  216. package/tools/sdk-release-tool/Makefile +0 -49
  217. package/tools/sdk-release-tool/README.md +0 -275
  218. package/tools/sdk-release-tool/delete +0 -3
  219. package/tools/sdk-release-tool/download +0 -3
  220. package/tools/sdk-release-tool/get-cors +0 -3
  221. package/tools/sdk-release-tool/list +0 -3
  222. package/tools/sdk-release-tool/pin +0 -3
  223. package/tools/sdk-release-tool/pin-latest +0 -3
  224. package/tools/sdk-release-tool/requirements.txt +0 -4
  225. package/tools/sdk-release-tool/sdk-release-tool +0 -3
  226. package/tools/sdk-release-tool/sdk_release_tools/__init__.py +0 -0
  227. package/tools/sdk-release-tool/sdk_release_tools/__main__.py +0 -110
  228. package/tools/sdk-release-tool/sdk_release_tools/aws.py +0 -70
  229. package/tools/sdk-release-tool/sdk_release_tools/cli.py +0 -181
  230. package/tools/sdk-release-tool/sdk_release_tools/log.py +0 -24
  231. package/tools/sdk-release-tool/sdk_release_tools/ops.py +0 -295
  232. package/tools/sdk-release-tool/sdk_release_tools/rpm.py +0 -28
  233. package/tools/sdk-release-tool/sdk_release_tools/util.py +0 -186
  234. package/tools/sdk-release-tool/sdk_release_tools/versions.py +0 -362
  235. package/tools/sdk-release-tool/signal-sdk-js.json +0 -28
  236. package/tools/sdk-release-tool/tests/test_versions.py +0 -94
  237. package/tools/sdk-release-tool/twilio-accessmanager-android.json +0 -19
  238. package/tools/sdk-release-tool/twilio-accessmanager-ios.json +0 -26
  239. package/tools/sdk-release-tool/twilio-auth-ios.json +0 -29
  240. package/tools/sdk-release-tool/twilio-authenticator-ios.json +0 -29
  241. package/tools/sdk-release-tool/twilio-chat-android-2.json +0 -19
  242. package/tools/sdk-release-tool/twilio-chat-android.json +0 -22
  243. package/tools/sdk-release-tool/twilio-chat-ios.json +0 -26
  244. package/tools/sdk-release-tool/twilio-chat-js.json +0 -27
  245. package/tools/sdk-release-tool/twilio-client-android-aar.json +0 -22
  246. package/tools/sdk-release-tool/twilio-client-android.json +0 -22
  247. package/tools/sdk-release-tool/twilio-client-ios.json +0 -20
  248. package/tools/sdk-release-tool/twilio-client-js.json +0 -17
  249. package/tools/sdk-release-tool/twilio-client-sounds-js.json +0 -14
  250. package/tools/sdk-release-tool/twilio-common-android-maven.json +0 -16
  251. package/tools/sdk-release-tool/twilio-common-android.json +0 -22
  252. package/tools/sdk-release-tool/twilio-common-ios-rtc.json +0 -25
  253. package/tools/sdk-release-tool/twilio-common-ios.json +0 -25
  254. package/tools/sdk-release-tool/twilio-common-js.json +0 -19
  255. package/tools/sdk-release-tool/twilio-conversations-android.json +0 -22
  256. package/tools/sdk-release-tool/twilio-conversations-ios.json +0 -26
  257. package/tools/sdk-release-tool/twilio-conversations-js.json +0 -27
  258. package/tools/sdk-release-tool/twilio-flex-js.json +0 -20
  259. package/tools/sdk-release-tool/twilio-flex-webchat-js.json +0 -16
  260. package/tools/sdk-release-tool/twilio-frame-chat-android.json +0 -22
  261. package/tools/sdk-release-tool/twilio-frame-chat-ios.json +0 -23
  262. package/tools/sdk-release-tool/twilio-frame-chat-js.json +0 -23
  263. package/tools/sdk-release-tool/twilio-ip-messaging-android-maven.json +0 -16
  264. package/tools/sdk-release-tool/twilio-ip-messaging-android.json +0 -22
  265. package/tools/sdk-release-tool/twilio-ip-messaging-ios.json +0 -25
  266. package/tools/sdk-release-tool/twilio-ip-messaging-js.json +0 -21
  267. package/tools/sdk-release-tool/twilio-sync-android.json +0 -22
  268. package/tools/sdk-release-tool/twilio-sync-ios.json +0 -26
  269. package/tools/sdk-release-tool/twilio-sync-js.json +0 -39
  270. package/tools/sdk-release-tool/twilio-taskrouter-js.json +0 -17
  271. package/tools/sdk-release-tool/twilio-video-android.json +0 -22
  272. package/tools/sdk-release-tool/twilio-video-cpp-linux-cross-rootfs.json +0 -13
  273. package/tools/sdk-release-tool/twilio-video-cpp.json +0 -33
  274. package/tools/sdk-release-tool/twilio-video-ios.json +0 -25
  275. package/tools/sdk-release-tool/twilio-video-js.json +0 -19
  276. package/tools/sdk-release-tool/twilio-video-jsdocs.json +0 -14
  277. package/tools/sdk-release-tool/twilio-voice-android.json +0 -22
  278. package/tools/sdk-release-tool/twilio-voice-ios.json +0 -29
  279. package/tools/sdk-release-tool/unpin +0 -3
  280. package/tools/sdk-release-tool/unpin-latest +0 -3
  281. package/tools/sdk-release-tool/upload +0 -3
  282. package/twilio-chat.js.iml +0 -9
@@ -1,665 +0,0 @@
1
- "use strict";
2
-
3
- var _typeof2 = require("babel-runtime/helpers/typeof");
4
-
5
- var _typeof3 = _interopRequireDefault(_typeof2);
6
-
7
- var _promise = require("babel-runtime/core-js/promise");
8
-
9
- var _promise2 = _interopRequireDefault(_promise);
10
-
11
- var _stringify = require("babel-runtime/core-js/json/stringify");
12
-
13
- var _stringify2 = _interopRequireDefault(_stringify);
14
-
15
- var _set = require("babel-runtime/core-js/set");
16
-
17
- var _set2 = _interopRequireDefault(_set);
18
-
19
- var _map = require("babel-runtime/core-js/map");
20
-
21
- var _map2 = _interopRequireDefault(_map);
22
-
23
- var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");
24
-
25
- var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
26
-
27
- var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
28
-
29
- var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
30
-
31
- var _createClass2 = require("babel-runtime/helpers/createClass");
32
-
33
- var _createClass3 = _interopRequireDefault(_createClass2);
34
-
35
- var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
36
-
37
- var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
38
-
39
- var _inherits2 = require("babel-runtime/helpers/inherits");
40
-
41
- var _inherits3 = _interopRequireDefault(_inherits2);
42
-
43
- var _regenerator = require("babel-runtime/regenerator");
44
-
45
- var _regenerator2 = _interopRequireDefault(_regenerator);
46
-
47
- var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
48
-
49
- var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
50
-
51
- var wrapService = function () {
52
- var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(services) {
53
- return _regenerator2.default.wrap(function _callee$(_context) {
54
- while (1) {
55
- switch (_context.prev = _context.next) {
56
- case 0:
57
- _context.next = 2;
58
- return services.session.getMediaLimits();
59
-
60
- case 2:
61
- _context.t0 = _context.sent;
62
- _context.t1 = services.session;
63
- _context.t2 = services.syncClient;
64
- _context.t3 = services.users;
65
- _context.t4 = services.typingIndicator;
66
- _context.t5 = services.readHorizon;
67
- _context.t6 = services.network;
68
- _context.t7 = services.mcsClient;
69
- return _context.abrupt("return", {
70
- limits: _context.t0,
71
- session: _context.t1,
72
- syncClient: _context.t2,
73
- users: _context.t3,
74
- typingIndicator: _context.t4,
75
- readHorizon: _context.t5,
76
- network: _context.t6,
77
- mcsClient: _context.t7
78
- });
79
-
80
- case 11:
81
- case "end":
82
- return _context.stop();
83
- }
84
- }
85
- }, _callee, this);
86
- }));
87
-
88
- return function wrapService(_x) {
89
- return _ref.apply(this, arguments);
90
- };
91
- }();
92
- /**
93
- * Represents conversations collection
94
- * {@see Conversation}
95
- */
96
-
97
-
98
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
99
-
100
- Object.defineProperty(exports, "__esModule", { value: true });
101
- var events_1 = require("events");
102
- var logger_1 = require("../logger");
103
- var conversation_1 = require("../conversation");
104
- exports.Conversation = conversation_1.Conversation;
105
- var deferred_1 = require("../util/deferred");
106
- var util_1 = require("../util");
107
- var log = logger_1.Logger.scope('Conversations');
108
-
109
- var Conversations = function (_events_1$EventEmitte) {
110
- (0, _inherits3.default)(Conversations, _events_1$EventEmitte);
111
-
112
- function Conversations(services) {
113
- (0, _classCallCheck3.default)(this, Conversations);
114
-
115
- var _this = (0, _possibleConstructorReturn3.default)(this, (Conversations.__proto__ || (0, _getPrototypeOf2.default)(Conversations)).call(this));
116
-
117
- _this.services = services;
118
- _this.conversations = new _map2.default();
119
- _this.tombstones = new _set2.default();
120
- _this.syncListFetched = false;
121
- _this.syncListRead = new deferred_1.Deferred();
122
- return _this;
123
- }
124
-
125
- (0, _createClass3.default)(Conversations, [{
126
- key: "getMap",
127
- value: function getMap() {
128
- var _this2 = this;
129
-
130
- return this.services.session.getMyConversationsId().then(function (name) {
131
- return _this2.services.syncClient.map({ id: name, mode: 'open_existing' });
132
- });
133
- }
134
- /**
135
- * Add conversation to server
136
- * @private
137
- * @returns {Promise<Conversation>} Conversation
138
- */
139
-
140
- }, {
141
- key: "addConversation",
142
- value: function () {
143
- var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(options) {
144
- var attributes, response, conversationSid, conversationDocument, existingConversation, conversation;
145
- return _regenerator2.default.wrap(function _callee2$(_context2) {
146
- while (1) {
147
- switch (_context2.prev = _context2.next) {
148
- case 0:
149
- attributes = void 0;
150
-
151
- if (typeof options.attributes === 'undefined') {
152
- attributes = {};
153
- } else {
154
- attributes = options.attributes;
155
- }
156
- _context2.next = 4;
157
- return this.services.session.addCommand('createConversation', {
158
- friendlyName: options.friendlyName,
159
- uniqueName: options.uniqueName,
160
- attributes: (0, _stringify2.default)(attributes)
161
- });
162
-
163
- case 4:
164
- response = _context2.sent;
165
- conversationSid = 'conversationSid' in response ? response['conversationSid'] : null;
166
- conversationDocument = 'conversation' in response ? response['conversation'] : null;
167
- existingConversation = this.conversations.get(conversationSid);
168
-
169
- if (!existingConversation) {
170
- _context2.next = 12;
171
- break;
172
- }
173
-
174
- _context2.next = 11;
175
- return existingConversation._subscribe();
176
-
177
- case 11:
178
- return _context2.abrupt("return", existingConversation);
179
-
180
- case 12:
181
- _context2.t0 = conversation_1.Conversation;
182
- _context2.next = 15;
183
- return wrapService(this.services);
184
-
185
- case 15:
186
- _context2.t1 = _context2.sent;
187
- _context2.t2 = {
188
- channel: conversationDocument,
189
- entityName: null,
190
- uniqueName: null,
191
- attributes: null,
192
- createdBy: null,
193
- friendlyName: null,
194
- lastConsumedMessageIndex: null,
195
- dateCreated: null,
196
- dateUpdated: null
197
- };
198
- _context2.t3 = conversationSid;
199
- conversation = new _context2.t0(_context2.t1, _context2.t2, _context2.t3);
200
-
201
- this.conversations.set(conversation.sid, conversation);
202
- this.registerForEvents(conversation);
203
- _context2.next = 23;
204
- return conversation._subscribe();
205
-
206
- case 23:
207
- this.emit('conversationAdded', conversation);
208
- return _context2.abrupt("return", conversation);
209
-
210
- case 25:
211
- case "end":
212
- return _context2.stop();
213
- }
214
- }
215
- }, _callee2, this);
216
- }));
217
-
218
- function addConversation(_x2) {
219
- return _ref2.apply(this, arguments);
220
- }
221
-
222
- return addConversation;
223
- }()
224
- /**
225
- * Fetch conversations list and instantiate all necessary objects
226
- */
227
-
228
- }, {
229
- key: "fetchConversations",
230
- value: function fetchConversations() {
231
- var _this3 = this;
232
-
233
- this.getMap().then(function () {
234
- var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(map) {
235
- var upserts, paginator, items;
236
- return _regenerator2.default.wrap(function _callee3$(_context3) {
237
- while (1) {
238
- switch (_context3.prev = _context3.next) {
239
- case 0:
240
- map.on('itemAdded', function (args) {
241
- log.debug('itemAdded: ' + args.item.key);
242
- _this3.upsertConversation('sync', args.item.key, args.item.data);
243
- });
244
- map.on('itemRemoved', function (args) {
245
- log.debug('itemRemoved: ' + args.key);
246
- var sid = args.key;
247
- if (!_this3.syncListFetched) {
248
- _this3.tombstones.add(sid);
249
- }
250
- var conversation = _this3.conversations.get(sid);
251
- if (conversation) {
252
- if (conversation && conversation.status === 'joined' /*|| conversation.status === 'invited'*/) {
253
- conversation._setStatus('notParticipating', 'sync');
254
- _this3.emit('conversationLeft', conversation);
255
- }
256
- _this3.conversations.delete(sid);
257
- _this3.emit('conversationRemoved', conversation);
258
- conversation.emit('removed', conversation);
259
- }
260
- });
261
- map.on('itemUpdated', function (args) {
262
- log.debug('itemUpdated: ' + args.item.key);
263
- _this3.upsertConversation('sync', args.item.key, args.item.data);
264
- });
265
- upserts = [];
266
- _context3.next = 6;
267
- return _this3.services.syncList.getPage();
268
-
269
- case 6:
270
- paginator = _context3.sent;
271
- items = paginator.items;
272
-
273
- items.forEach(function (item) {
274
- upserts.push(_this3.upsertConversation('synclist', item.channel_sid, item));
275
- });
276
-
277
- case 9:
278
- if (!paginator.hasNextPage) {
279
- _context3.next = 16;
280
- break;
281
- }
282
-
283
- _context3.next = 12;
284
- return paginator.nextPage();
285
-
286
- case 12:
287
- paginator = _context3.sent;
288
-
289
- paginator.items.forEach(function (item) {
290
- upserts.push(_this3.upsertConversation('synclist', item.channel_sid, item));
291
- });
292
- _context3.next = 9;
293
- break;
294
-
295
- case 16:
296
- _this3.syncListRead.set(true);
297
- return _context3.abrupt("return", _promise2.default.all(upserts));
298
-
299
- case 18:
300
- case "end":
301
- return _context3.stop();
302
- }
303
- }
304
- }, _callee3, _this3);
305
- }));
306
-
307
- return function (_x3) {
308
- return _ref3.apply(this, arguments);
309
- };
310
- }()).then(function () {
311
- _this3.syncListFetched = true;
312
- _this3.tombstones.clear();
313
- log.debug('Conversations list fetched');
314
- }).then(function () {
315
- return _this3;
316
- }).catch(function (e) {
317
- if (_this3.services.syncClient.connectionState != 'disconnected') {
318
- log.error('Failed to get conversations list', e);
319
- }
320
- log.debug('ERROR: Failed to get conversations list', e);
321
- throw e;
322
- });
323
- }
324
- }, {
325
- key: "_wrapPaginator",
326
- value: function _wrapPaginator(page, op) {
327
- var _this4 = this;
328
-
329
- return op(page.items).then(function (items) {
330
- return {
331
- items: items,
332
- hasNextPage: page.hasNextPage,
333
- hasPrevPage: page.hasPrevPage,
334
- nextPage: function nextPage() {
335
- return page.nextPage().then(function (x) {
336
- return _this4._wrapPaginator(x, op);
337
- });
338
- },
339
- prevPage: function prevPage() {
340
- return page.prevPage().then(function (x) {
341
- return _this4._wrapPaginator(x, op);
342
- });
343
- }
344
- };
345
- });
346
- }
347
- }, {
348
- key: "getConversations",
349
- value: function getConversations(args) {
350
- var _this5 = this;
351
-
352
- return this.getMap().then(function (conversationsMap) {
353
- return conversationsMap.getItems(args);
354
- }).then(function (page) {
355
- return _this5._wrapPaginator(page, function (items) {
356
- return _promise2.default.all(items.map(function (item) {
357
- return _this5.upsertConversation('sync', item.key, item.data);
358
- }));
359
- });
360
- });
361
- }
362
- }, {
363
- key: "getConversation",
364
- value: function getConversation(sid) {
365
- var _this6 = this;
366
-
367
- return this.getMap().then(function (conversationsMap) {
368
- return conversationsMap.getItems({ key: sid });
369
- }).then(function (page) {
370
- return page.items.map(function (item) {
371
- return _this6.upsertConversation('sync', item.key, item.data);
372
- });
373
- }).then(function (items) {
374
- return items.length > 0 ? items[0] : null;
375
- });
376
- }
377
- }, {
378
- key: "getConversationByUniqueName",
379
- value: function () {
380
- var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(uniqueName) {
381
- var _a, _b, links, url, response, body, sid, data;
382
-
383
- return _regenerator2.default.wrap(function _callee4$(_context4) {
384
- while (1) {
385
- switch (_context4.prev = _context4.next) {
386
- case 0:
387
- _context4.next = 2;
388
- return this.services.session.getSessionLinks();
389
-
390
- case 2:
391
- links = _context4.sent;
392
- url = new util_1.UriBuilder(links.myChannelsUrl).path(uniqueName).build();
393
- _context4.next = 6;
394
- return this.services.network.get(url);
395
-
396
- case 6:
397
- response = _context4.sent;
398
- body = response.body;
399
- sid = body.channel_sid;
400
- data = {
401
- entityName: null,
402
- lastConsumedMessageIndex: body.last_consumed_message_index,
403
- status: ((_a = body) === null || _a === void 0 ? void 0 : _a.status) || 'unknown',
404
- friendlyName: body.friendly_name,
405
- dateUpdated: body.date_updated,
406
- dateCreated: body.date_created,
407
- uniqueName: body.unique_name,
408
- createdBy: body.created_by,
409
- attributes: body.attributes,
410
- channel: sid + ".channel",
411
- notificationLevel: (_b = body) === null || _b === void 0 ? void 0 : _b.notification_level,
412
- sid: sid
413
- };
414
- return _context4.abrupt("return", this.upsertConversation('sync', sid, data));
415
-
416
- case 11:
417
- case "end":
418
- return _context4.stop();
419
- }
420
- }
421
- }, _callee4, this);
422
- }));
423
-
424
- function getConversationByUniqueName(_x4) {
425
- return _ref4.apply(this, arguments);
426
- }
427
-
428
- return getConversationByUniqueName;
429
- }()
430
- }, {
431
- key: "getWhisperConversation",
432
- value: function () {
433
- var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(sid) {
434
- var _a, _b, _c, _d, links, url, response, body, state, data;
435
-
436
- return _regenerator2.default.wrap(function _callee5$(_context5) {
437
- while (1) {
438
- switch (_context5.prev = _context5.next) {
439
- case 0:
440
- _context5.next = 2;
441
- return this.services.session.getSessionLinks();
442
-
443
- case 2:
444
- links = _context5.sent;
445
- url = new util_1.UriBuilder(links.publicChannelsUrl).path(sid).build();
446
- _context5.next = 6;
447
- return this.services.network.get(url);
448
-
449
- case 6:
450
- response = _context5.sent;
451
- body = response.body;
452
-
453
- if (!(body.type !== 'private')) {
454
- _context5.next = 10;
455
- break;
456
- }
457
-
458
- return _context5.abrupt("return");
459
-
460
- case 10:
461
- // todo: refactor this after the back-end change.
462
- // Currently, a conversation that is created using a non-conversations-specific
463
- // endpoint (i.e., a chat-specific endpoint) will not have a state property set.
464
- // The back-end team will fix this, but only when they get some more time to work
465
- // on this. For now, the SDK will assume that the default state is active when
466
- // the property is absent from the REST response. The back-end team also mentioned
467
- // that the state property will become a proper JSON object, as opposed to a JSON
468
- // string, which is also covered in the following code.
469
- state = void 0;
470
- // If the state property is a string, it's expected to be a string that represents
471
- // a JSON object.
472
-
473
- if (typeof body.state === 'string') {
474
- state = JSON.parse(body.state);
475
- }
476
- // If the state property is already a non-nullable object, then no JSON parsing is
477
- // required.
478
- if ((0, _typeof3.default)(body.state) === 'object' && body.state !== null) {
479
- state = body.state;
480
- }
481
-
482
- if (!(((_b = (_a = state) === null || _a === void 0 ? void 0 : _a['state.v1']) === null || _b === void 0 ? void 0 : _b.current) === 'closed')) {
483
- _context5.next = 15;
484
- break;
485
- }
486
-
487
- return _context5.abrupt("return");
488
-
489
- case 15:
490
- data = {
491
- entityName: null,
492
- lastConsumedMessageIndex: body.last_consumed_message_index,
493
- status: ((_c = body) === null || _c === void 0 ? void 0 : _c.status) || 'unknown',
494
- friendlyName: body.friendly_name,
495
- dateUpdated: body.date_updated,
496
- dateCreated: body.date_created,
497
- uniqueName: body.unique_name,
498
- createdBy: body.created_by,
499
- attributes: body.attributes,
500
- channel: sid + ".channel",
501
- notificationLevel: (_d = body) === null || _d === void 0 ? void 0 : _d.notification_level,
502
- sid: sid
503
- };
504
- return _context5.abrupt("return", this.upsertConversation('sync', sid, data));
505
-
506
- case 17:
507
- case "end":
508
- return _context5.stop();
509
- }
510
- }
511
- }, _callee5, this);
512
- }));
513
-
514
- function getWhisperConversation(_x5) {
515
- return _ref5.apply(this, arguments);
516
- }
517
-
518
- return getWhisperConversation;
519
- }()
520
- }, {
521
- key: "upsertConversation",
522
- value: function () {
523
- var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(source, sid, data) {
524
- var _this7 = this;
525
-
526
- var conversation, updateData;
527
- return _regenerator2.default.wrap(function _callee6$(_context6) {
528
- while (1) {
529
- switch (_context6.prev = _context6.next) {
530
- case 0:
531
- log.trace('upsertConversation(sid=' + sid + ', data=', data);
532
- conversation = this.conversations.get(sid);
533
- // Update the Conversation's status if we know about it
534
-
535
- if (!conversation) {
536
- _context6.next = 6;
537
- break;
538
- }
539
-
540
- log.trace('upsertConversation: conversation ' + sid + ' is known and it\'s' + ' status is known from source ' + conversation._statusSource() + ' and update came from source ' + source, conversation);
541
- if (typeof conversation._statusSource() === 'undefined' || source === conversation._statusSource() || source === 'synclist' && conversation._statusSource() !== 'sync' || source === 'sync') {
542
- if (data.status === 'joined' && conversation.status !== 'joined') {
543
- conversation._setStatus('joined', source);
544
- updateData = {};
545
-
546
- if (typeof data.notificationLevel !== 'undefined') {
547
- updateData.notificationLevel = data.notificationLevel;
548
- }
549
- if (typeof data.lastConsumedMessageIndex !== 'undefined') {
550
- updateData.lastConsumedMessageIndex = data.lastConsumedMessageIndex;
551
- }
552
- if (!util_1.isDeepEqual(updateData, {})) {
553
- conversation._update(updateData);
554
- }
555
- conversation._subscribe().then(function () {
556
- _this7.emit('conversationJoined', conversation);
557
- });
558
- } else if (data.status === 'notParticipating' && conversation.status === 'joined') {
559
- conversation._setStatus('notParticipating', source);
560
- conversation._update(data);
561
- conversation._subscribe().then(function () {
562
- _this7.emit('conversationLeft', conversation);
563
- });
564
- } else if (data.status === 'notParticipating') {
565
- conversation._subscribe();
566
- } else {
567
- conversation._update(data);
568
- }
569
- } else {
570
- log.trace('upsertConversation: conversation is known from sync and came from chat, ignoring', {
571
- sid: sid,
572
- data: data.status,
573
- conversation: conversation.status
574
- });
575
- }
576
- return _context6.abrupt("return", conversation._subscribe().then(function () {
577
- return conversation;
578
- }));
579
-
580
- case 6:
581
- if (!((source === 'chat' || source === 'synclist') && this.tombstones.has(sid))) {
582
- _context6.next = 9;
583
- break;
584
- }
585
-
586
- // if conversation was deleted, we ignore it
587
- log.trace('upsertConversation: conversation is deleted and came again from chat, ignoring', sid);
588
- return _context6.abrupt("return");
589
-
590
- case 9:
591
- // Fetch the Conversation if we don't know about it
592
- log.trace('upsertConversation: creating local conversation object with sid ' + sid, data);
593
- _context6.t0 = conversation_1.Conversation;
594
- _context6.next = 13;
595
- return wrapService(this.services);
596
-
597
- case 13:
598
- _context6.t1 = _context6.sent;
599
- _context6.t2 = data;
600
- _context6.t3 = sid;
601
- conversation = new _context6.t0(_context6.t1, _context6.t2, _context6.t3);
602
-
603
- this.conversations.set(sid, conversation);
604
- return _context6.abrupt("return", conversation._subscribe().then(function () {
605
- _this7.registerForEvents(conversation);
606
- _this7.emit('conversationAdded', conversation);
607
- if (data.status === 'joined') {
608
- conversation._setStatus('joined', source);
609
- _this7.emit('conversationJoined', conversation);
610
- }
611
- return conversation;
612
- }));
613
-
614
- case 19:
615
- case "end":
616
- return _context6.stop();
617
- }
618
- }
619
- }, _callee6, this);
620
- }));
621
-
622
- function upsertConversation(_x6, _x7, _x8) {
623
- return _ref6.apply(this, arguments);
624
- }
625
-
626
- return upsertConversation;
627
- }()
628
- }, {
629
- key: "onConversationRemoved",
630
- value: function onConversationRemoved(sid) {
631
- var conversation = this.conversations.get(sid);
632
- if (conversation) {
633
- this.conversations.delete(sid);
634
- this.emit('conversationRemoved', conversation);
635
- }
636
- }
637
- }, {
638
- key: "registerForEvents",
639
- value: function registerForEvents(conversation) {
640
- var _this8 = this;
641
-
642
- conversation.on('removed', function () {
643
- return _this8.onConversationRemoved(conversation.sid);
644
- });
645
- conversation.on('updated', function (args) {
646
- return _this8.emit('conversationUpdated', args);
647
- });
648
- conversation.on('participantJoined', this.emit.bind(this, 'participantJoined'));
649
- conversation.on('participantLeft', this.emit.bind(this, 'participantLeft'));
650
- conversation.on('participantUpdated', function (args) {
651
- return _this8.emit('participantUpdated', args);
652
- });
653
- conversation.on('messageAdded', this.emit.bind(this, 'messageAdded'));
654
- conversation.on('messageUpdated', function (args) {
655
- return _this8.emit('messageUpdated', args);
656
- });
657
- conversation.on('messageRemoved', this.emit.bind(this, 'messageRemoved'));
658
- conversation.on('typingStarted', this.emit.bind(this, 'typingStarted'));
659
- conversation.on('typingEnded', this.emit.bind(this, 'typingEnded'));
660
- }
661
- }]);
662
- return Conversations;
663
- }(events_1.EventEmitter);
664
-
665
- exports.Conversations = Conversations;