@twilio/conversations 1.3.0-rc8 → 2.0.0-rc.4

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 +210 -0
  2. package/README.md +22 -17
  3. package/dist/browser.js +7873 -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 +3394 -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 +3170 -0
  33. package/dist/docs/modules.html +3425 -0
  34. package/dist/lib.d.ts +1952 -0
  35. package/dist/lib.js +7873 -0
  36. package/dist/lib.js.map +1 -0
  37. package/dist/post-install.js +29 -0
  38. package/dist/react-native.js +4038 -0
  39. package/dist/react-native.js.map +1 -0
  40. package/dist/twilio-conversations.js +40912 -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 -632
  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 -35533
  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 -296
  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,1826 +0,0 @@
1
- "use strict";
2
-
3
- var _keys = require("babel-runtime/core-js/object/keys");
4
-
5
- var _keys2 = _interopRequireDefault(_keys);
6
-
7
- var _getIterator2 = require("babel-runtime/core-js/get-iterator");
8
-
9
- var _getIterator3 = _interopRequireDefault(_getIterator2);
10
-
11
- var _toConsumableArray2 = require("babel-runtime/helpers/toConsumableArray");
12
-
13
- var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
14
-
15
- var _set = require("babel-runtime/core-js/set");
16
-
17
- var _set2 = _interopRequireDefault(_set);
18
-
19
- var _promise = require("babel-runtime/core-js/promise");
20
-
21
- var _promise2 = _interopRequireDefault(_promise);
22
-
23
- var _stringify = require("babel-runtime/core-js/json/stringify");
24
-
25
- var _stringify2 = _interopRequireDefault(_stringify);
26
-
27
- var _isInteger = require("babel-runtime/core-js/number/is-integer");
28
-
29
- var _isInteger2 = _interopRequireDefault(_isInteger);
30
-
31
- var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");
32
-
33
- var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
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 _map = require("babel-runtime/core-js/map");
44
-
45
- var _map2 = _interopRequireDefault(_map);
46
-
47
- var _regenerator = require("babel-runtime/regenerator");
48
-
49
- var _regenerator2 = _interopRequireDefault(_regenerator);
50
-
51
- var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
52
-
53
- var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
54
-
55
- var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
56
-
57
- var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
58
-
59
- var _createClass2 = require("babel-runtime/helpers/createClass");
60
-
61
- var _createClass3 = _interopRequireDefault(_createClass2);
62
-
63
- var _metadata = require("babel-runtime/core-js/reflect/metadata");
64
-
65
- var _metadata2 = _interopRequireDefault(_metadata);
66
-
67
- var _defineProperty = require("babel-runtime/core-js/object/define-property");
68
-
69
- var _defineProperty2 = _interopRequireDefault(_defineProperty);
70
-
71
- var _typeof2 = require("babel-runtime/helpers/typeof");
72
-
73
- var _typeof3 = _interopRequireDefault(_typeof2);
74
-
75
- var _getOwnPropertyDescriptor = require("babel-runtime/core-js/object/get-own-property-descriptor");
76
-
77
- var _getOwnPropertyDescriptor2 = _interopRequireDefault(_getOwnPropertyDescriptor);
78
-
79
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
80
-
81
- var __decorate = undefined && undefined.__decorate || function (decorators, target, key, desc) {
82
- var c = arguments.length,
83
- r = c < 3 ? target : desc === null ? desc = (0, _getOwnPropertyDescriptor2.default)(target, key) : desc,
84
- d;
85
- if ((typeof Reflect === "undefined" ? "undefined" : (0, _typeof3.default)(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
86
- if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
87
- }return c > 3 && r && (0, _defineProperty2.default)(target, key, r), r;
88
- };
89
- var __metadata = undefined && undefined.__metadata || function (k, v) {
90
- if ((typeof Reflect === "undefined" ? "undefined" : (0, _typeof3.default)(Reflect)) === "object" && typeof _metadata2.default === "function") return (0, _metadata2.default)(k, v);
91
- };
92
- Object.defineProperty(exports, "__esModule", { value: true });
93
- var events_1 = require("events");
94
- var logger_1 = require("./logger");
95
- var participants_1 = require("./data/participants");
96
- var participant_1 = require("./participant");
97
- var messages_1 = require("./data/messages");
98
- var util_1 = require("./util");
99
- var twilio_sdk_type_validator_1 = require("twilio-sdk-type-validator");
100
- var log = logger_1.Logger.scope('Conversation');
101
- var fieldMappings = {
102
- lastMessage: 'lastMessage',
103
- attributes: 'attributes',
104
- createdBy: 'createdBy',
105
- dateCreated: 'dateCreated',
106
- dateUpdated: 'dateUpdated',
107
- friendlyName: 'friendlyName',
108
- lastConsumedMessageIndex: 'lastConsumedMessageIndex',
109
- notificationLevel: 'notificationLevel',
110
- sid: 'sid',
111
- status: 'status',
112
- uniqueName: 'uniqueName',
113
- state: 'state',
114
- bindings: 'bindings'
115
- };
116
- function parseTime(timeString) {
117
- try {
118
- return new Date(timeString);
119
- } catch (e) {
120
- return null;
121
- }
122
- }
123
-
124
- var UnsentMessage = function () {
125
- function UnsentMessage(messagesEntity) {
126
- (0, _classCallCheck3.default)(this, UnsentMessage);
127
-
128
- this.messagesEntity = messagesEntity;
129
- this.attributes = {};
130
- this.mediaContent = [];
131
- this.emailOptions = {};
132
- }
133
- /**
134
- * Send the prepared message to the conversation.
135
- * @returns {Promise<number>} new Message's index in the Conversation's messages list
136
- */
137
-
138
-
139
- (0, _createClass3.default)(UnsentMessage, [{
140
- key: "send",
141
- value: function () {
142
- var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
143
- var response;
144
- return _regenerator2.default.wrap(function _callee$(_context) {
145
- while (1) {
146
- switch (_context.prev = _context.next) {
147
- case 0:
148
- _context.next = 2;
149
- return this.messagesEntity.sendV2(this);
150
-
151
- case 2:
152
- response = _context.sent;
153
- return _context.abrupt("return", util_1.parseToNumber(response.messageId));
154
-
155
- case 4:
156
- case "end":
157
- return _context.stop();
158
- }
159
- }
160
- }, _callee, this);
161
- }));
162
-
163
- function send() {
164
- return _ref.apply(this, arguments);
165
- }
166
-
167
- return send;
168
- }()
169
- }]);
170
- return UnsentMessage;
171
- }();
172
-
173
- exports.UnsentMessage = UnsentMessage;
174
-
175
- var MessageBuilder = function () {
176
- function MessageBuilder(limits, messagesEntity) {
177
- (0, _classCallCheck3.default)(this, MessageBuilder);
178
-
179
- this.limits = limits;
180
- this.message = new UnsentMessage(messagesEntity);
181
- this.emailBodies = new _map2.default();
182
- this.emailHistories = new _map2.default();
183
- }
184
-
185
- (0, _createClass3.default)(MessageBuilder, [{
186
- key: "setBody",
187
- value: function setBody(text) {
188
- this.message.text = text;
189
- return this;
190
- }
191
- }, {
192
- key: "setSubject",
193
- value: function setSubject(subject) {
194
- this.message.emailOptions.subject = subject;
195
- return this;
196
- }
197
- }, {
198
- key: "setAttributes",
199
- value: function setAttributes(attributes) {
200
- this.message.attributes = attributes;
201
- return this;
202
- }
203
- }, {
204
- key: "setEmailBody",
205
- value: function setEmailBody(mimeType, body) {
206
- this.emailBodies.set(mimeType, body);
207
- return this;
208
- }
209
- }, {
210
- key: "setEmailHistory",
211
- value: function setEmailHistory(mimeType, history) {
212
- this.emailHistories.set(mimeType, history);
213
- return this;
214
- }
215
- }, {
216
- key: "addMedia",
217
- value: function addMedia(payload) {
218
- this.message.mediaContent.push(['media', payload]);
219
- return this;
220
- }
221
- }, {
222
- key: "build",
223
- value: function build() {
224
- var _this = this;
225
-
226
- this.emailBodies.forEach(function (_, key) {
227
- if (!_this.limits.emailBodiesAllowedMimeTypes.includes(key)) {
228
- throw new Error("Unsupported email body MIME type " + key);
229
- }
230
- });
231
- this.emailHistories.forEach(function (_, key) {
232
- if (!_this.limits.emailHistoriesAllowedMimeTypes.includes(key)) {
233
- throw new Error("Unsupported email history MIME type " + key);
234
- }
235
- });
236
- if (this.emailBodies.size > this.limits.emailBodiesAllowedMimeTypes.length) {
237
- throw new Error("Email bodies set is too large");
238
- }
239
- if (this.emailHistories.size > this.limits.emailHistoriesAllowedMimeTypes.length) {
240
- throw new Error("Email histories set is too large");
241
- }
242
- if (this.message.mediaContent.length > this.limits.mediaAttachmentsCountLimit) {
243
- throw new Error("Too many media attachments in the message (" + this.message.mediaContent.length + " > " + this.limits.mediaAttachmentsCountLimit + ")");
244
- }
245
- // @todo we don't know the sizes of the attachments in FormData
246
- // @todo insertion below makes build() method non-repeatable - probably move to UnsentMessage.send() or even sendV2()?
247
- // @todo specify CATEGORY
248
- this.emailBodies.forEach(function (body) {
249
- _this.message.mediaContent.push(['body', body]);
250
- });
251
- this.emailHistories.forEach(function (body) {
252
- _this.message.mediaContent.push(['history', body]);
253
- });
254
- return this.message;
255
- }
256
- }, {
257
- key: "getPayloadContentType",
258
- value: function getPayloadContentType(payload) {
259
- if (typeof FormData !== 'undefined' && payload instanceof FormData) {
260
- return payload.get('Content-Type');
261
- }
262
- return payload.contentType;
263
- }
264
- }]);
265
- return MessageBuilder;
266
- }();
267
- /**
268
- * @classdesc A Conversation represents communication between multiple Conversations Clients
269
- * @property {any} attributes - The Conversation's custom attributes
270
- * @property {String} createdBy - The identity of the User that created this Conversation
271
- * @property {Date} dateCreated - The Date this Conversation was created
272
- * @property {Date} dateUpdated - The Date this Conversation was last updated
273
- * @property {String} [friendlyName] - The Conversation's name
274
- * @property {Number|null} lastReadMessageIndex - Index of the last Message the User has read in this Conversation
275
- * @property {Conversation#LastMessage} lastMessage - Last Message sent to this Conversation
276
- * @property {Conversation#NotificationLevel} notificationLevel - User Notification level for this Conversation
277
- * @property {String} sid - The Conversation's unique system identifier
278
- * @property {Conversation#Status} status - The Conversation's status
279
- * @property {Conversation#State} state - The Conversation's state
280
- * @property {String} uniqueName - The Conversation's unique name
281
- * @fires Conversation#participantJoined
282
- * @fires Conversation#participantLeft
283
- * @fires Conversation#participantUpdated
284
- * @fires Conversation#messageAdded
285
- * @fires Conversation#messageRemoved
286
- * @fires Conversation#messageUpdated
287
- * @fires Conversation#typingEnded
288
- * @fires Conversation#typingStarted
289
- * @fires Conversation#updated
290
- * @fires Conversation#removed
291
- */
292
-
293
-
294
- var Conversation = function (_events_1$EventEmitte) {
295
- (0, _inherits3.default)(Conversation, _events_1$EventEmitte);
296
-
297
- function Conversation(services, descriptor, sid) {
298
- (0, _classCallCheck3.default)(this, Conversation);
299
-
300
- var _a;
301
-
302
- var _this2 = (0, _possibleConstructorReturn3.default)(this, (Conversation.__proto__ || (0, _getPrototypeOf2.default)(Conversation)).call(this));
303
-
304
- _this2.services = services;
305
- var attributes = descriptor.attributes || {};
306
- var createdBy = descriptor.createdBy;
307
- var dateCreated = parseTime(descriptor.dateCreated);
308
- var dateUpdated = parseTime(descriptor.dateUpdated);
309
- var friendlyName = descriptor.friendlyName || null;
310
- var lastReadMessageIndex = (0, _isInteger2.default)(descriptor.lastConsumedMessageIndex) ? descriptor.lastConsumedMessageIndex : null;
311
- var uniqueName = descriptor.uniqueName || null;
312
- try {
313
- (0, _stringify2.default)(attributes);
314
- } catch (e) {
315
- throw new Error('Attributes must be a valid JSON object.');
316
- }
317
- _this2.sid = sid;
318
- _this2.entityName = descriptor.channel;
319
- _this2.channelState = {
320
- uniqueName: uniqueName,
321
- status: 'notParticipating',
322
- attributes: attributes,
323
- createdBy: createdBy,
324
- dateCreated: dateCreated,
325
- dateUpdated: dateUpdated,
326
- friendlyName: friendlyName,
327
- lastReadMessageIndex: lastReadMessageIndex,
328
- bindings: (_a = descriptor.bindings, _a !== null && _a !== void 0 ? _a : {})
329
- };
330
- if (descriptor.notificationLevel) {
331
- _this2.channelState.notificationLevel = descriptor.notificationLevel;
332
- }
333
- _this2.participants = new _map2.default();
334
- _this2.participantsEntity = new participants_1.Participants(_this2, _this2.services, _this2.participants);
335
- _this2.participantsEntity.on('participantJoined', _this2.emit.bind(_this2, 'participantJoined'));
336
- _this2.participantsEntity.on('participantLeft', _this2.emit.bind(_this2, 'participantLeft'));
337
- _this2.participantsEntity.on('participantUpdated', function (args) {
338
- return _this2.emit('participantUpdated', args);
339
- });
340
- _this2.messagesEntity = new messages_1.Messages(_this2, services);
341
- _this2.messagesEntity.on('messageAdded', function (message) {
342
- return _this2._onMessageAdded(message);
343
- });
344
- _this2.messagesEntity.on('messageUpdated', function (args) {
345
- return _this2.emit('messageUpdated', args);
346
- });
347
- _this2.messagesEntity.on('messageRemoved', _this2.emit.bind(_this2, 'messageRemoved'));
348
- return _this2;
349
- }
350
- /**
351
- * These options can be passed to {@link Conversation#sendMessage}.
352
- * @typedef {Object} Conversation#SendMediaOptions
353
- * @property {String} contentType - content type of media
354
- * @property {String | Buffer} media - content to post
355
- */
356
- /**
357
- * These options can be passed to {@link Conversation#sendMessage}.
358
- * @typedef {Object} Conversation#SendEmailOptions
359
- * @property {String} subject - subject for the message. Ignored for media messages.
360
- */
361
- /**
362
- * The update reason for <code>updated</code> event emitted on Conversation
363
- * @typedef {('attributes' | 'createdBy' | 'dateCreated' | 'dateUpdated' |
364
- 'friendlyName' | 'lastReadMessageIndex' | 'state' | 'status' | 'uniqueName' | 'lastMessage' |
365
- 'notificationLevel' | 'bindings')} Conversation#UpdateReason
366
- */
367
- /**
368
- * The status of the Conversation, relative to the Client: whether the Conversation has been <code>joined</code> or the Client is
369
- * <code>notParticipating</code> in the Conversation.
370
- * @typedef {('notParticipating' | 'joined')} Conversation#Status
371
- */
372
- /**
373
- * The User's Notification level for Conversation, determines whether the currently logged-in User will receive
374
- * pushes for events in this Conversation. Can be either <code>muted</code> or <code>default</code>,
375
- * where <code>default</code> defers to global Service push configuration.
376
- * @typedef {('default' | 'muted')} Conversation#NotificationLevel
377
- */
378
- /**
379
- * The Conversation's state.
380
- * @typedef {Object} Conversation#State
381
- * @property {('active' | 'inactive' | 'closed')} current - the current state
382
- * @property {Date} dateUpdated - date at which the latest conversation state update happened
383
- */
384
-
385
-
386
- (0, _createClass3.default)(Conversation, [{
387
- key: "_subscribe",
388
-
389
- /**
390
- * The Conversation's last message's information.
391
- * @typedef {Object} Conversation#LastMessage
392
- * @property {Number} index - Message's index
393
- * @property {Date} dateCreated - Message's creation date
394
- */
395
- /**
396
- * Load and Subscribe to this Conversation and do not subscribe to its Participants and Messages.
397
- * This or _subscribeStreams will need to be called before any events on Conversation will fire.
398
- * @returns {Promise}
399
- * @private
400
- */
401
- value: function _subscribe() {
402
- var _this3 = this;
403
-
404
- var _a;
405
- return this.entityPromise = (_a = this.entityPromise, _a !== null && _a !== void 0 ? _a : this.services.syncClient.document({ id: this.entityName, mode: 'open_existing' }).then(function (entity) {
406
- _this3.entity = entity;
407
- _this3.entity.on('updated', function (args) {
408
- _this3._update(args.data);
409
- });
410
- _this3.entity.on('removed', function () {
411
- return _this3.emit('removed', _this3);
412
- });
413
- _this3._update(_this3.entity.data);
414
- return entity;
415
- }).catch(function (err) {
416
- _this3.entity = null;
417
- _this3.entityPromise = null;
418
- if (_this3.services.syncClient.connectionState != 'disconnected') {
419
- log.error('Failed to get conversation object', err);
420
- }
421
- log.debug('ERROR: Failed to get conversation object', err);
422
- throw err;
423
- }));
424
- }
425
- /**
426
- * Load the attributes of this Conversation and instantiate its Participants and Messages.
427
- * This or _subscribe will need to be called before any events on Conversation will fire.
428
- * This will need to be called before any events on Participants or Messages will fire
429
- * @returns {Promise}
430
- * @private
431
- */
432
-
433
- }, {
434
- key: "_subscribeStreams",
435
- value: function () {
436
- var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
437
- var messagesObjectName, rosterObjectName;
438
- return _regenerator2.default.wrap(function _callee2$(_context2) {
439
- while (1) {
440
- switch (_context2.prev = _context2.next) {
441
- case 0:
442
- _context2.prev = 0;
443
- _context2.next = 3;
444
- return this._subscribe();
445
-
446
- case 3:
447
- log.trace('_subscribeStreams, this.entity.data=', this.entity.data);
448
- messagesObjectName = this.entity.data.messages;
449
- rosterObjectName = this.entity.data.roster;
450
- _context2.next = 8;
451
- return _promise2.default.all([this.messagesEntity.subscribe(messagesObjectName), this.participantsEntity.subscribe(rosterObjectName)]);
452
-
453
- case 8:
454
- _context2.next = 15;
455
- break;
456
-
457
- case 10:
458
- _context2.prev = 10;
459
- _context2.t0 = _context2["catch"](0);
460
-
461
- if (this.services.syncClient.connectionState !== 'disconnected') {
462
- log.error('Failed to subscribe on conversation objects', this.sid, _context2.t0);
463
- }
464
- log.debug('ERROR: Failed to subscribe on conversation objects', this.sid, _context2.t0);
465
- throw _context2.t0;
466
-
467
- case 15:
468
- case "end":
469
- return _context2.stop();
470
- }
471
- }
472
- }, _callee2, this, [[0, 10]]);
473
- }));
474
-
475
- function _subscribeStreams() {
476
- return _ref2.apply(this, arguments);
477
- }
478
-
479
- return _subscribeStreams;
480
- }()
481
- /**
482
- * Stop listening for and firing events on this Conversation.
483
- * @returns {Promise}
484
- * @private
485
- */
486
-
487
- }, {
488
- key: "_unsubscribe",
489
- value: function () {
490
- var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3() {
491
- return _regenerator2.default.wrap(function _callee3$(_context3) {
492
- while (1) {
493
- switch (_context3.prev = _context3.next) {
494
- case 0:
495
- if (!this.entity) {
496
- _context3.next = 5;
497
- break;
498
- }
499
-
500
- _context3.next = 3;
501
- return this.entity.close();
502
-
503
- case 3:
504
- this.entity = null;
505
- this.entityPromise = null;
506
-
507
- case 5:
508
- return _context3.abrupt("return", _promise2.default.all([this.participantsEntity.unsubscribe(), this.messagesEntity.unsubscribe()]));
509
-
510
- case 6:
511
- case "end":
512
- return _context3.stop();
513
- }
514
- }
515
- }, _callee3, this);
516
- }));
517
-
518
- function _unsubscribe() {
519
- return _ref3.apply(this, arguments);
520
- }
521
-
522
- return _unsubscribe;
523
- }()
524
- /**
525
- * Set conversation status
526
- * @private
527
- */
528
-
529
- }, {
530
- key: "_setStatus",
531
- value: function _setStatus(status, source) {
532
- var _this4 = this;
533
-
534
- this.statusSource = source;
535
- if (this.channelState.status === status) {
536
- return;
537
- }
538
- this.channelState.status = status;
539
- if (status === 'joined') {
540
- this._subscribeStreams().catch(function (err) {
541
- log.debug('ERROR while setting conversation status ' + status, err);
542
- if (_this4.services.syncClient.connectionState !== 'disconnected') {
543
- throw err;
544
- }
545
- });
546
- } else if (this.entityPromise) {
547
- this._unsubscribe().catch(function (err) {
548
- log.debug('ERROR while setting conversation status ' + status, err);
549
- if (_this4.services.syncClient.connectionState !== 'disconnected') {
550
- throw err;
551
- }
552
- });
553
- }
554
- }
555
- /**
556
- * If conversation's status update source
557
- * @private
558
- * @return {Conversations.DataSource}
559
- */
560
-
561
- }, {
562
- key: "_statusSource",
563
- value: function _statusSource() {
564
- return this.statusSource;
565
- }
566
- }, {
567
- key: "_update",
568
-
569
- /**
570
- * Updates local conversation object with new values
571
- * @private
572
- */
573
- value: function _update(update) {
574
- var _a, _b, _c, _d, _e;
575
- log.trace('_update', update);
576
- Conversation.preprocessUpdate(update, this.sid);
577
- var updateReasons = new _set2.default();
578
- var _iteratorNormalCompletion = true;
579
- var _didIteratorError = false;
580
- var _iteratorError = undefined;
581
-
582
- try {
583
- for (var _iterator = (0, _getIterator3.default)((0, _keys2.default)(update)), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
584
- var key = _step.value;
585
-
586
- var localKey = fieldMappings[key];
587
- if (!localKey) {
588
- continue;
589
- }
590
- switch (localKey) {
591
- case fieldMappings.status:
592
- if (!update.status || update.status === 'unknown' || this.channelState.status === update.status) {
593
- break;
594
- }
595
- this.channelState.status = update.status;
596
- updateReasons.add(localKey);
597
- break;
598
- case fieldMappings.attributes:
599
- if (util_1.isDeepEqual(this.channelState.attributes, update.attributes)) {
600
- break;
601
- }
602
- this.channelState.attributes = update.attributes;
603
- updateReasons.add(localKey);
604
- break;
605
- case fieldMappings.lastConsumedMessageIndex:
606
- if (update.lastConsumedMessageIndex === undefined || update.lastConsumedMessageIndex === this.channelState.lastReadMessageIndex) {
607
- break;
608
- }
609
- this.channelState.lastReadMessageIndex = update.lastConsumedMessageIndex;
610
- updateReasons.add('lastReadMessageIndex');
611
- break;
612
- case fieldMappings.lastMessage:
613
- if (this.channelState.lastMessage && !update.lastMessage) {
614
- delete this.channelState.lastMessage;
615
- updateReasons.add(localKey);
616
- break;
617
- }
618
- this.channelState.lastMessage = this.channelState.lastMessage || {};
619
- if (((_a = update.lastMessage) === null || _a === void 0 ? void 0 : _a.index) !== undefined && update.lastMessage.index !== this.channelState.lastMessage.index) {
620
- this.channelState.lastMessage.index = update.lastMessage.index;
621
- updateReasons.add(localKey);
622
- }
623
- if (((_b = update.lastMessage) === null || _b === void 0 ? void 0 : _b.timestamp) !== undefined && ((_d = (_c = this.channelState.lastMessage) === null || _c === void 0 ? void 0 : _c.dateCreated) === null || _d === void 0 ? void 0 : _d.getTime()) !== update.lastMessage.timestamp.getTime()) {
624
- this.channelState.lastMessage.dateCreated = update.lastMessage.timestamp;
625
- updateReasons.add(localKey);
626
- }
627
- if (util_1.isDeepEqual(this.channelState.lastMessage, {})) {
628
- delete this.channelState.lastMessage;
629
- }
630
- break;
631
- case fieldMappings.state:
632
- var state = update.state || undefined;
633
- if (state !== undefined) {
634
- state.dateUpdated = new Date(state.dateUpdated);
635
- }
636
- if (util_1.isDeepEqual(this.channelState.state, state)) {
637
- break;
638
- }
639
- this.channelState.state = state;
640
- updateReasons.add(localKey);
641
- break;
642
- case fieldMappings.bindings:
643
- if (util_1.isDeepEqual(this.channelState.bindings, update.bindings)) {
644
- break;
645
- }
646
- this.channelState.bindings = update.bindings;
647
- updateReasons.add(localKey);
648
- break;
649
- default:
650
- var isDate = update[key] instanceof Date;
651
- var keysMatchAsDates = isDate && ((_e = this.channelState[localKey]) === null || _e === void 0 ? void 0 : _e.getTime()) === update[key].getTime();
652
- var keysMatchAsNonDates = !isDate && this[localKey] === update[key];
653
- if (keysMatchAsDates || keysMatchAsNonDates) {
654
- break;
655
- }
656
- this.channelState[localKey] = update[key];
657
- updateReasons.add(localKey);
658
- }
659
- }
660
- } catch (err) {
661
- _didIteratorError = true;
662
- _iteratorError = err;
663
- } finally {
664
- try {
665
- if (!_iteratorNormalCompletion && _iterator.return) {
666
- _iterator.return();
667
- }
668
- } finally {
669
- if (_didIteratorError) {
670
- throw _iteratorError;
671
- }
672
- }
673
- }
674
-
675
- if (updateReasons.size > 0) {
676
- this.emit('updated', { conversation: this, updateReasons: [].concat((0, _toConsumableArray3.default)(updateReasons)) });
677
- }
678
- }
679
- /**
680
- * @private
681
- */
682
-
683
- }, {
684
- key: "_onMessageAdded",
685
- value: function _onMessageAdded(message) {
686
- var _iteratorNormalCompletion2 = true;
687
- var _didIteratorError2 = false;
688
- var _iteratorError2 = undefined;
689
-
690
- try {
691
- for (var _iterator2 = (0, _getIterator3.default)(this.participants.values()), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
692
- var participant = _step2.value;
693
-
694
- if (participant.identity === message.author) {
695
- participant._endTyping();
696
- break;
697
- }
698
- }
699
- } catch (err) {
700
- _didIteratorError2 = true;
701
- _iteratorError2 = err;
702
- } finally {
703
- try {
704
- if (!_iteratorNormalCompletion2 && _iterator2.return) {
705
- _iterator2.return();
706
- }
707
- } finally {
708
- if (_didIteratorError2) {
709
- throw _iteratorError2;
710
- }
711
- }
712
- }
713
-
714
- this.emit('messageAdded', message);
715
- }
716
- /**
717
- * Add a participant to the Conversation by its Identity.
718
- * @param {String} identity - Identity of the Client to add
719
- * @param {any} [attributes] Attributes to be attached to the participant
720
- * @returns {Promise<void>}
721
- */
722
-
723
- }, {
724
- key: "add",
725
- value: function () {
726
- var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(identity, attributes) {
727
- return _regenerator2.default.wrap(function _callee4$(_context4) {
728
- while (1) {
729
- switch (_context4.prev = _context4.next) {
730
- case 0:
731
- return _context4.abrupt("return", this.participantsEntity.add(identity, attributes));
732
-
733
- case 1:
734
- case "end":
735
- return _context4.stop();
736
- }
737
- }
738
- }, _callee4, this);
739
- }));
740
-
741
- function add(_x, _x2) {
742
- return _ref4.apply(this, arguments);
743
- }
744
-
745
- return add;
746
- }()
747
- /**
748
- * Add a non-chat participant to the Conversation.
749
- *
750
- * @param {String} proxyAddress Proxy (Twilio) address of the participant
751
- * @param {String} address User address of the participant
752
- * @param {any} [attributes] Attributes to be attached to the participant
753
- * @returns {Promise<void>}
754
- */
755
-
756
- }, {
757
- key: "addNonChatParticipant",
758
- value: function () {
759
- var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(proxyAddress, address) {
760
- var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
761
- return _regenerator2.default.wrap(function _callee5$(_context5) {
762
- while (1) {
763
- switch (_context5.prev = _context5.next) {
764
- case 0:
765
- return _context5.abrupt("return", this.participantsEntity.addNonChatParticipant(proxyAddress, address, attributes));
766
-
767
- case 1:
768
- case "end":
769
- return _context5.stop();
770
- }
771
- }
772
- }, _callee5, this);
773
- }));
774
-
775
- function addNonChatParticipant(_x4, _x5) {
776
- return _ref5.apply(this, arguments);
777
- }
778
-
779
- return addNonChatParticipant;
780
- }()
781
- /**
782
- * Advance Conversation's last read Message index to current read horizon.
783
- * Rejects if User is not Participant of Conversation.
784
- * Last read Message index is updated only if new index value is higher than previous.
785
- * @param {Number} index - Message index to advance to as last read
786
- * @returns {Promise<number>} resulting unread messages count in the conversation
787
- */
788
-
789
- }, {
790
- key: "advanceLastReadMessageIndex",
791
- value: function () {
792
- var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(index) {
793
- return _regenerator2.default.wrap(function _callee6$(_context6) {
794
- while (1) {
795
- switch (_context6.prev = _context6.next) {
796
- case 0:
797
- _context6.next = 2;
798
- return this._subscribeStreams();
799
-
800
- case 2:
801
- return _context6.abrupt("return", this.services.readHorizon.advanceLastReadMessageIndexForConversation(this.sid, index, this.lastReadMessageIndex));
802
-
803
- case 3:
804
- case "end":
805
- return _context6.stop();
806
- }
807
- }
808
- }, _callee6, this);
809
- }));
810
-
811
- function advanceLastReadMessageIndex(_x6) {
812
- return _ref6.apply(this, arguments);
813
- }
814
-
815
- return advanceLastReadMessageIndex;
816
- }()
817
- /**
818
- * Delete the Conversation and unsubscribe from its events.
819
- * @returns {Promise<Conversation>}
820
- */
821
-
822
- }, {
823
- key: "delete",
824
- value: function () {
825
- var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7() {
826
- return _regenerator2.default.wrap(function _callee7$(_context7) {
827
- while (1) {
828
- switch (_context7.prev = _context7.next) {
829
- case 0:
830
- _context7.next = 2;
831
- return this.services.session.addCommand('destroyChannel', {
832
- channelSid: this.sid
833
- });
834
-
835
- case 2:
836
- return _context7.abrupt("return", this);
837
-
838
- case 3:
839
- case "end":
840
- return _context7.stop();
841
- }
842
- }
843
- }, _callee7, this);
844
- }));
845
-
846
- function _delete() {
847
- return _ref7.apply(this, arguments);
848
- }
849
-
850
- return _delete;
851
- }()
852
- /**
853
- * Get the custom attributes of this Conversation.
854
- * @returns {Promise<any>} attributes of this Conversation
855
- */
856
-
857
- }, {
858
- key: "getAttributes",
859
- value: function () {
860
- var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8() {
861
- return _regenerator2.default.wrap(function _callee8$(_context8) {
862
- while (1) {
863
- switch (_context8.prev = _context8.next) {
864
- case 0:
865
- _context8.next = 2;
866
- return this._subscribe();
867
-
868
- case 2:
869
- return _context8.abrupt("return", this.attributes);
870
-
871
- case 3:
872
- case "end":
873
- return _context8.stop();
874
- }
875
- }
876
- }, _callee8, this);
877
- }));
878
-
879
- function getAttributes() {
880
- return _ref8.apply(this, arguments);
881
- }
882
-
883
- return getAttributes;
884
- }()
885
- /**
886
- * Returns messages from conversation using paginator interface.
887
- * @param {Number} [pageSize=30] Number of messages to return in single chunk
888
- * @param {Number} [anchor] - Index of newest Message to fetch. From the end by default
889
- * @param {('backwards'|'forward')} [direction=backwards] - Query direction. By default it query backwards
890
- * from newer to older. 'forward' will query in opposite direction
891
- * @returns {Promise<Paginator<Message>>} page of messages
892
- */
893
-
894
- }, {
895
- key: "getMessages",
896
- value: function () {
897
- var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(pageSize, anchor, direction) {
898
- return _regenerator2.default.wrap(function _callee9$(_context9) {
899
- while (1) {
900
- switch (_context9.prev = _context9.next) {
901
- case 0:
902
- _context9.next = 2;
903
- return this._subscribeStreams();
904
-
905
- case 2:
906
- return _context9.abrupt("return", this.messagesEntity.getMessages(pageSize, anchor, direction));
907
-
908
- case 3:
909
- case "end":
910
- return _context9.stop();
911
- }
912
- }
913
- }, _callee9, this);
914
- }));
915
-
916
- function getMessages(_x7, _x8, _x9) {
917
- return _ref9.apply(this, arguments);
918
- }
919
-
920
- return getMessages;
921
- }()
922
- /**
923
- * Get a list of all Participants joined to this Conversation.
924
- * @returns {Promise<Participant[]>}
925
- */
926
-
927
- }, {
928
- key: "getParticipants",
929
- value: function () {
930
- var _ref10 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10() {
931
- return _regenerator2.default.wrap(function _callee10$(_context10) {
932
- while (1) {
933
- switch (_context10.prev = _context10.next) {
934
- case 0:
935
- _context10.next = 2;
936
- return this._subscribeStreams();
937
-
938
- case 2:
939
- return _context10.abrupt("return", this.participantsEntity.getParticipants());
940
-
941
- case 3:
942
- case "end":
943
- return _context10.stop();
944
- }
945
- }
946
- }, _callee10, this);
947
- }));
948
-
949
- function getParticipants() {
950
- return _ref10.apply(this, arguments);
951
- }
952
-
953
- return getParticipants;
954
- }()
955
- /**
956
- * Get conversation participants count.
957
- * <br/>
958
- * This method is semi-realtime. This means that this data will be eventually correct,
959
- * but will also possibly be incorrect for a few seconds. The Conversation system does not
960
- * provide real time events for counter values changes.
961
- * <br/>
962
- * So this is quite useful for any UI badges, but is not recommended
963
- * to build any core application logic based on these counters being accurate in real time.
964
- * @returns {Promise<number>}
965
- */
966
-
967
- }, {
968
- key: "getParticipantsCount",
969
- value: function () {
970
- var _ref11 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11() {
971
- var links, url, response;
972
- return _regenerator2.default.wrap(function _callee11$(_context11) {
973
- while (1) {
974
- switch (_context11.prev = _context11.next) {
975
- case 0:
976
- _context11.next = 2;
977
- return this.services.session.getSessionLinks();
978
-
979
- case 2:
980
- links = _context11.sent;
981
- url = new util_1.UriBuilder(links.publicChannelsUrl).path(this.sid).build();
982
- _context11.next = 6;
983
- return this.services.network.get(url);
984
-
985
- case 6:
986
- response = _context11.sent;
987
- return _context11.abrupt("return", response.body.members_count);
988
-
989
- case 8:
990
- case "end":
991
- return _context11.stop();
992
- }
993
- }
994
- }, _callee11, this);
995
- }));
996
-
997
- function getParticipantsCount() {
998
- return _ref11.apply(this, arguments);
999
- }
1000
-
1001
- return getParticipantsCount;
1002
- }()
1003
- /**
1004
- * Get a Participant by its SID.
1005
- * @param {String} participantSid - Participant sid
1006
- * @returns {Promise<Participant>}
1007
- */
1008
-
1009
- }, {
1010
- key: "getParticipantBySid",
1011
- value: function () {
1012
- var _ref12 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12(participantSid) {
1013
- return _regenerator2.default.wrap(function _callee12$(_context12) {
1014
- while (1) {
1015
- switch (_context12.prev = _context12.next) {
1016
- case 0:
1017
- return _context12.abrupt("return", this.participantsEntity.getParticipantBySid(participantSid));
1018
-
1019
- case 1:
1020
- case "end":
1021
- return _context12.stop();
1022
- }
1023
- }
1024
- }, _callee12, this);
1025
- }));
1026
-
1027
- function getParticipantBySid(_x10) {
1028
- return _ref12.apply(this, arguments);
1029
- }
1030
-
1031
- return getParticipantBySid;
1032
- }()
1033
- /**
1034
- * Get a Participant by its identity.
1035
- * @param {String} identity - Participant identity
1036
- * @returns {Promise<Participant>}
1037
- */
1038
-
1039
- }, {
1040
- key: "getParticipantByIdentity",
1041
- value: function () {
1042
- var _ref13 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee13(identity) {
1043
- return _regenerator2.default.wrap(function _callee13$(_context13) {
1044
- while (1) {
1045
- switch (_context13.prev = _context13.next) {
1046
- case 0:
1047
- return _context13.abrupt("return", this.participantsEntity.getParticipantByIdentity(identity));
1048
-
1049
- case 1:
1050
- case "end":
1051
- return _context13.stop();
1052
- }
1053
- }
1054
- }, _callee13, this);
1055
- }));
1056
-
1057
- function getParticipantByIdentity(_x11) {
1058
- return _ref13.apply(this, arguments);
1059
- }
1060
-
1061
- return getParticipantByIdentity;
1062
- }()
1063
- /**
1064
- * Get total message count in a conversation.
1065
- * <br/>
1066
- * This method is semi-realtime. This means that this data will be eventually correct,
1067
- * but will also possibly be incorrect for a few seconds. The Conversations system does not
1068
- * provide real time events for counter values changes.
1069
- * <br/>
1070
- * So this is quite useful for any UI badges, but is not recommended
1071
- * to build any core application logic based on these counters being accurate in real time.
1072
- * @returns {Promise<number>}
1073
- */
1074
-
1075
- }, {
1076
- key: "getMessagesCount",
1077
- value: function () {
1078
- var _ref14 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee14() {
1079
- var links, url, response;
1080
- return _regenerator2.default.wrap(function _callee14$(_context14) {
1081
- while (1) {
1082
- switch (_context14.prev = _context14.next) {
1083
- case 0:
1084
- _context14.next = 2;
1085
- return this.services.session.getSessionLinks();
1086
-
1087
- case 2:
1088
- links = _context14.sent;
1089
- url = new util_1.UriBuilder(links.publicChannelsUrl).path(this.sid).build();
1090
- _context14.next = 6;
1091
- return this.services.network.get(url);
1092
-
1093
- case 6:
1094
- response = _context14.sent;
1095
- return _context14.abrupt("return", response.body.messages_count);
1096
-
1097
- case 8:
1098
- case "end":
1099
- return _context14.stop();
1100
- }
1101
- }
1102
- }, _callee14, this);
1103
- }));
1104
-
1105
- function getMessagesCount() {
1106
- return _ref14.apply(this, arguments);
1107
- }
1108
-
1109
- return getMessagesCount;
1110
- }()
1111
- /**
1112
- * Get unread messages count for the User if they are a Participant of this Conversation.
1113
- * Rejects if the User is not a Participant of the Conversation.
1114
- * <br/>
1115
- * Use this method to obtain the number of unread messages together with
1116
- * updateLastReadMessageIndex() instead of relying on the
1117
- * Message indices which may have gaps. See Message.index for details.
1118
- * <br/>
1119
- * This method is semi-realtime. This means that this data will be eventually correct,
1120
- * but will also possibly be incorrect for a few seconds. The Chat system does not
1121
- * provide real time events for counter values changes.
1122
- * <br/>
1123
- * This is quite useful for any “unread messages count” badges, but is not recommended
1124
- * to build any core application logic based on these counters being accurate in real time.
1125
- * @returns {Promise<number|null>}
1126
- */
1127
-
1128
- }, {
1129
- key: "getUnreadMessagesCount",
1130
- value: function () {
1131
- var _ref15 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee15() {
1132
- var links, url, response;
1133
- return _regenerator2.default.wrap(function _callee15$(_context15) {
1134
- while (1) {
1135
- switch (_context15.prev = _context15.next) {
1136
- case 0:
1137
- _context15.next = 2;
1138
- return this.services.session.getSessionLinks();
1139
-
1140
- case 2:
1141
- links = _context15.sent;
1142
- url = new util_1.UriBuilder(links.myChannelsUrl).arg('ChannelSid', this.sid).build();
1143
- _context15.next = 6;
1144
- return this.services.network.get(url);
1145
-
1146
- case 6:
1147
- response = _context15.sent;
1148
-
1149
- if (!(response.body.channels.length && response.body.channels[0].channel_sid == this.sid)) {
1150
- _context15.next = 11;
1151
- break;
1152
- }
1153
-
1154
- if (!(typeof response.body.channels[0].unread_messages_count !== 'undefined' && response.body.channels[0].unread_messages_count != null)) {
1155
- _context15.next = 10;
1156
- break;
1157
- }
1158
-
1159
- return _context15.abrupt("return", response.body.channels[0].unread_messages_count);
1160
-
1161
- case 10:
1162
- return _context15.abrupt("return", null);
1163
-
1164
- case 11:
1165
- throw new Error('Conversation is not in user conversations list');
1166
-
1167
- case 12:
1168
- case "end":
1169
- return _context15.stop();
1170
- }
1171
- }
1172
- }, _callee15, this);
1173
- }));
1174
-
1175
- function getUnreadMessagesCount() {
1176
- return _ref15.apply(this, arguments);
1177
- }
1178
-
1179
- return getUnreadMessagesCount;
1180
- }()
1181
- /**
1182
- * Join the Conversation and subscribe to its events.
1183
- * @returns {Promise<Conversation>}
1184
- */
1185
-
1186
- }, {
1187
- key: "join",
1188
- value: function () {
1189
- var _ref16 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee16() {
1190
- return _regenerator2.default.wrap(function _callee16$(_context16) {
1191
- while (1) {
1192
- switch (_context16.prev = _context16.next) {
1193
- case 0:
1194
- _context16.next = 2;
1195
- return this.services.session.addCommand('joinChannelV2', { channelSid: this.sid });
1196
-
1197
- case 2:
1198
- return _context16.abrupt("return", this);
1199
-
1200
- case 3:
1201
- case "end":
1202
- return _context16.stop();
1203
- }
1204
- }
1205
- }, _callee16, this);
1206
- }));
1207
-
1208
- function join() {
1209
- return _ref16.apply(this, arguments);
1210
- }
1211
-
1212
- return join;
1213
- }()
1214
- /**
1215
- * Leave the Conversation.
1216
- * @returns {Promise<Conversation>}
1217
- */
1218
-
1219
- }, {
1220
- key: "leave",
1221
- value: function () {
1222
- var _ref17 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee17() {
1223
- return _regenerator2.default.wrap(function _callee17$(_context17) {
1224
- while (1) {
1225
- switch (_context17.prev = _context17.next) {
1226
- case 0:
1227
- if (!(this.channelState.status === 'joined')) {
1228
- _context17.next = 3;
1229
- break;
1230
- }
1231
-
1232
- _context17.next = 3;
1233
- return this.services.session.addCommand('leaveChannel', { channelSid: this.sid });
1234
-
1235
- case 3:
1236
- return _context17.abrupt("return", this);
1237
-
1238
- case 4:
1239
- case "end":
1240
- return _context17.stop();
1241
- }
1242
- }
1243
- }, _callee17, this);
1244
- }));
1245
-
1246
- function leave() {
1247
- return _ref17.apply(this, arguments);
1248
- }
1249
-
1250
- return leave;
1251
- }()
1252
- /**
1253
- * Remove a Participant from the Conversation. When a string is passed as the argument, it will assume that the string is an identity.
1254
- * @param {String|Participant} participant - identity or participant object to remove
1255
- * @returns {Promise<void>}
1256
- */
1257
-
1258
- }, {
1259
- key: "removeParticipant",
1260
- value: function () {
1261
- var _ref18 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee18(participant) {
1262
- return _regenerator2.default.wrap(function _callee18$(_context18) {
1263
- while (1) {
1264
- switch (_context18.prev = _context18.next) {
1265
- case 0:
1266
- if (!(participant instanceof participant_1.Participant)) {
1267
- _context18.next = 4;
1268
- break;
1269
- }
1270
-
1271
- _context18.next = 3;
1272
- return this.participantsEntity.removeBySid(participant.sid);
1273
-
1274
- case 3:
1275
- return _context18.abrupt("return");
1276
-
1277
- case 4:
1278
- _context18.next = 6;
1279
- return this.participantsEntity.removeByIdentity(participant);
1280
-
1281
- case 6:
1282
- case "end":
1283
- return _context18.stop();
1284
- }
1285
- }
1286
- }, _callee18, this);
1287
- }));
1288
-
1289
- function removeParticipant(_x12) {
1290
- return _ref18.apply(this, arguments);
1291
- }
1292
-
1293
- return removeParticipant;
1294
- }()
1295
- /**
1296
- * Send a Message in the Conversation.
1297
- * @param {String|FormData|Conversation#SendMediaOptions|null} message - The message body for text message,
1298
- * FormData or MediaOptions for media content. Sending FormData supported only with browser engine
1299
- * @param {any} [messageAttributes] - attributes for the message
1300
- * @param {Conversation#SendEmailOptions} [emailOptions] - email options for the message
1301
- * @returns {Promise<number>} new Message's index in the Conversation's messages list
1302
- */
1303
-
1304
- }, {
1305
- key: "sendMessage",
1306
- value: function () {
1307
- var _ref19 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee19(message, messageAttributes, emailOptions) {
1308
- var _response, response;
1309
-
1310
- return _regenerator2.default.wrap(function _callee19$(_context19) {
1311
- while (1) {
1312
- switch (_context19.prev = _context19.next) {
1313
- case 0:
1314
- if (!(typeof message === 'string' || message === null)) {
1315
- _context19.next = 5;
1316
- break;
1317
- }
1318
-
1319
- _context19.next = 3;
1320
- return this.messagesEntity.send(message, messageAttributes, emailOptions);
1321
-
1322
- case 3:
1323
- _response = _context19.sent;
1324
- return _context19.abrupt("return", util_1.parseToNumber(_response.messageId));
1325
-
1326
- case 5:
1327
- _context19.next = 7;
1328
- return this.messagesEntity.sendMedia(message, messageAttributes, emailOptions);
1329
-
1330
- case 7:
1331
- response = _context19.sent;
1332
- return _context19.abrupt("return", util_1.parseToNumber(response.messageId));
1333
-
1334
- case 9:
1335
- case "end":
1336
- return _context19.stop();
1337
- }
1338
- }
1339
- }, _callee19, this);
1340
- }));
1341
-
1342
- function sendMessage(_x13, _x14, _x15) {
1343
- return _ref19.apply(this, arguments);
1344
- }
1345
-
1346
- return sendMessage;
1347
- }()
1348
- }, {
1349
- key: "prepareMessage",
1350
- value: function prepareMessage() {
1351
- return new MessageBuilder(this.limits, this.messagesEntity);
1352
- }
1353
- /**
1354
- * Set last read Conversation's Message index to last known Message's index in this Conversation.
1355
- * @returns {Promise<number>} resulting unread messages count in the conversation
1356
- */
1357
-
1358
- }, {
1359
- key: "setAllMessagesRead",
1360
- value: function () {
1361
- var _ref20 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee20() {
1362
- var messagesPage;
1363
- return _regenerator2.default.wrap(function _callee20$(_context20) {
1364
- while (1) {
1365
- switch (_context20.prev = _context20.next) {
1366
- case 0:
1367
- _context20.next = 2;
1368
- return this._subscribeStreams();
1369
-
1370
- case 2:
1371
- _context20.next = 4;
1372
- return this.getMessages(1);
1373
-
1374
- case 4:
1375
- messagesPage = _context20.sent;
1376
-
1377
- if (!(messagesPage.items.length > 0)) {
1378
- _context20.next = 7;
1379
- break;
1380
- }
1381
-
1382
- return _context20.abrupt("return", this.advanceLastReadMessageIndex(messagesPage.items[0].index));
1383
-
1384
- case 7:
1385
- return _context20.abrupt("return", _promise2.default.resolve(0));
1386
-
1387
- case 8:
1388
- case "end":
1389
- return _context20.stop();
1390
- }
1391
- }
1392
- }, _callee20, this);
1393
- }));
1394
-
1395
- function setAllMessagesRead() {
1396
- return _ref20.apply(this, arguments);
1397
- }
1398
-
1399
- return setAllMessagesRead;
1400
- }()
1401
- /**
1402
- * Set all messages in the conversation unread.
1403
- * @returns {Promise<number>} resulting unread messages count in the conversation
1404
- */
1405
-
1406
- }, {
1407
- key: "setAllMessagesUnread",
1408
- value: function () {
1409
- var _ref21 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee21() {
1410
- return _regenerator2.default.wrap(function _callee21$(_context21) {
1411
- while (1) {
1412
- switch (_context21.prev = _context21.next) {
1413
- case 0:
1414
- _context21.next = 2;
1415
- return this._subscribeStreams();
1416
-
1417
- case 2:
1418
- return _context21.abrupt("return", this.services.readHorizon.updateLastReadMessageIndexForConversation(this.sid, null));
1419
-
1420
- case 3:
1421
- case "end":
1422
- return _context21.stop();
1423
- }
1424
- }
1425
- }, _callee21, this);
1426
- }));
1427
-
1428
- function setAllMessagesUnread() {
1429
- return _ref21.apply(this, arguments);
1430
- }
1431
-
1432
- return setAllMessagesUnread;
1433
- }()
1434
- /**
1435
- * Set User Notification level for this conversation.
1436
- * @param {Conversation#NotificationLevel} notificationLevel - The new user notification level
1437
- * @returns {Promise<void>}
1438
- */
1439
-
1440
- }, {
1441
- key: "setUserNotificationLevel",
1442
- value: function () {
1443
- var _ref22 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee22(notificationLevel) {
1444
- return _regenerator2.default.wrap(function _callee22$(_context22) {
1445
- while (1) {
1446
- switch (_context22.prev = _context22.next) {
1447
- case 0:
1448
- _context22.next = 2;
1449
- return this.services.session.addCommand('editNotificationLevel', { channelSid: this.sid, notificationLevel: notificationLevel });
1450
-
1451
- case 2:
1452
- case "end":
1453
- return _context22.stop();
1454
- }
1455
- }
1456
- }, _callee22, this);
1457
- }));
1458
-
1459
- function setUserNotificationLevel(_x16) {
1460
- return _ref22.apply(this, arguments);
1461
- }
1462
-
1463
- return setUserNotificationLevel;
1464
- }()
1465
- /**
1466
- * Send a notification to the server indicating that this Client is currently typing in this Conversation.
1467
- * Typing ended notification is sent after a while automatically, but by calling again this method you ensure typing ended is not received.
1468
- * @returns {Promise<void>}
1469
- */
1470
-
1471
- }, {
1472
- key: "typing",
1473
- value: function typing() {
1474
- return this.services.typingIndicator.send(this.sid);
1475
- }
1476
- /**
1477
- * Update the Conversation's attributes.
1478
- * @param {any} attributes - The new attributes object
1479
- * @returns {Promise<Conversation>}
1480
- */
1481
-
1482
- }, {
1483
- key: "updateAttributes",
1484
- value: function () {
1485
- var _ref23 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee23(attributes) {
1486
- return _regenerator2.default.wrap(function _callee23$(_context23) {
1487
- while (1) {
1488
- switch (_context23.prev = _context23.next) {
1489
- case 0:
1490
- _context23.next = 2;
1491
- return this.services.session.addCommand('editAttributes', {
1492
- channelSid: this.sid,
1493
- attributes: (0, _stringify2.default)(attributes)
1494
- });
1495
-
1496
- case 2:
1497
- return _context23.abrupt("return", this);
1498
-
1499
- case 3:
1500
- case "end":
1501
- return _context23.stop();
1502
- }
1503
- }
1504
- }, _callee23, this);
1505
- }));
1506
-
1507
- function updateAttributes(_x17) {
1508
- return _ref23.apply(this, arguments);
1509
- }
1510
-
1511
- return updateAttributes;
1512
- }()
1513
- /**
1514
- * Update the Conversation's friendlyName.
1515
- * @param {String|null} name - The new Conversation friendlyName
1516
- * @returns {Promise<Conversation>}
1517
- */
1518
-
1519
- }, {
1520
- key: "updateFriendlyName",
1521
- value: function () {
1522
- var _ref24 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee24(name) {
1523
- return _regenerator2.default.wrap(function _callee24$(_context24) {
1524
- while (1) {
1525
- switch (_context24.prev = _context24.next) {
1526
- case 0:
1527
- if (!(this.channelState.friendlyName !== name)) {
1528
- _context24.next = 3;
1529
- break;
1530
- }
1531
-
1532
- _context24.next = 3;
1533
- return this.services.session.addCommand('editFriendlyName', {
1534
- channelSid: this.sid,
1535
- friendlyName: name
1536
- });
1537
-
1538
- case 3:
1539
- return _context24.abrupt("return", this);
1540
-
1541
- case 4:
1542
- case "end":
1543
- return _context24.stop();
1544
- }
1545
- }
1546
- }, _callee24, this);
1547
- }));
1548
-
1549
- function updateFriendlyName(_x18) {
1550
- return _ref24.apply(this, arguments);
1551
- }
1552
-
1553
- return updateFriendlyName;
1554
- }()
1555
- /**
1556
- * Set Conversation's last read Message index to current read horizon.
1557
- * @param {Number|null} index - Message index to set as last read.
1558
- * If null provided, then the behavior is identical to {@link Conversation#setAllMessagesUnread}
1559
- * @returns {Promise<number>} resulting unread messages count in the conversation
1560
- */
1561
-
1562
- }, {
1563
- key: "updateLastReadMessageIndex",
1564
- value: function () {
1565
- var _ref25 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee25(index) {
1566
- return _regenerator2.default.wrap(function _callee25$(_context25) {
1567
- while (1) {
1568
- switch (_context25.prev = _context25.next) {
1569
- case 0:
1570
- _context25.next = 2;
1571
- return this._subscribeStreams();
1572
-
1573
- case 2:
1574
- return _context25.abrupt("return", this.services.readHorizon.updateLastReadMessageIndexForConversation(this.sid, index));
1575
-
1576
- case 3:
1577
- case "end":
1578
- return _context25.stop();
1579
- }
1580
- }
1581
- }, _callee25, this);
1582
- }));
1583
-
1584
- function updateLastReadMessageIndex(_x19) {
1585
- return _ref25.apply(this, arguments);
1586
- }
1587
-
1588
- return updateLastReadMessageIndex;
1589
- }()
1590
- /**
1591
- * Update the Conversation's unique name.
1592
- * @param {String|null} uniqueName - New unique name for the Conversation. Setting unique name to null removes it.
1593
- * @returns {Promise<Conversation>}
1594
- */
1595
-
1596
- }, {
1597
- key: "updateUniqueName",
1598
- value: function () {
1599
- var _ref26 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee26(uniqueName) {
1600
- return _regenerator2.default.wrap(function _callee26$(_context26) {
1601
- while (1) {
1602
- switch (_context26.prev = _context26.next) {
1603
- case 0:
1604
- if (!(this.channelState.uniqueName !== uniqueName)) {
1605
- _context26.next = 4;
1606
- break;
1607
- }
1608
-
1609
- if (!uniqueName) {
1610
- uniqueName = '';
1611
- }
1612
- _context26.next = 4;
1613
- return this.services.session.addCommand('editUniqueName', {
1614
- channelSid: this.sid,
1615
- uniqueName: uniqueName
1616
- });
1617
-
1618
- case 4:
1619
- return _context26.abrupt("return", this);
1620
-
1621
- case 5:
1622
- case "end":
1623
- return _context26.stop();
1624
- }
1625
- }
1626
- }, _callee26, this);
1627
- }));
1628
-
1629
- function updateUniqueName(_x20) {
1630
- return _ref26.apply(this, arguments);
1631
- }
1632
-
1633
- return updateUniqueName;
1634
- }()
1635
- }, {
1636
- key: "uniqueName",
1637
- get: function get() {
1638
- return this.channelState.uniqueName;
1639
- }
1640
- }, {
1641
- key: "status",
1642
- get: function get() {
1643
- return this.channelState.status;
1644
- }
1645
- }, {
1646
- key: "friendlyName",
1647
- get: function get() {
1648
- return this.channelState.friendlyName;
1649
- }
1650
- }, {
1651
- key: "dateUpdated",
1652
- get: function get() {
1653
- return this.channelState.dateUpdated;
1654
- }
1655
- }, {
1656
- key: "dateCreated",
1657
- get: function get() {
1658
- return this.channelState.dateCreated;
1659
- }
1660
- }, {
1661
- key: "createdBy",
1662
- get: function get() {
1663
- return this.channelState.createdBy;
1664
- }
1665
- }, {
1666
- key: "attributes",
1667
- get: function get() {
1668
- return this.channelState.attributes;
1669
- }
1670
- }, {
1671
- key: "lastReadMessageIndex",
1672
- get: function get() {
1673
- return this.channelState.lastReadMessageIndex;
1674
- }
1675
- }, {
1676
- key: "lastMessage",
1677
- get: function get() {
1678
- return this.channelState.lastMessage;
1679
- }
1680
- }, {
1681
- key: "notificationLevel",
1682
- get: function get() {
1683
- return this.channelState.notificationLevel;
1684
- }
1685
- }, {
1686
- key: "state",
1687
- get: function get() {
1688
- return this.channelState.state;
1689
- }
1690
- }, {
1691
- key: "bindings",
1692
- get: function get() {
1693
- return this.channelState.bindings;
1694
- }
1695
- }, {
1696
- key: "limits",
1697
- get: function get() {
1698
- return this.services.limits;
1699
- }
1700
- }], [{
1701
- key: "preprocessUpdate",
1702
- value: function preprocessUpdate(update, conversationSid) {
1703
- try {
1704
- if (typeof update.attributes === 'string') {
1705
- update.attributes = JSON.parse(update.attributes);
1706
- } else if (update.attributes) {
1707
- (0, _stringify2.default)(update.attributes);
1708
- }
1709
- } catch (e) {
1710
- log.warn('Retrieved malformed attributes from the server for conversation: ' + conversationSid);
1711
- update.attributes = {};
1712
- }
1713
- try {
1714
- if (update.dateCreated) {
1715
- update.dateCreated = new Date(update.dateCreated);
1716
- }
1717
- } catch (e) {
1718
- log.warn('Retrieved malformed dateCreated from the server for conversation: ' + conversationSid);
1719
- delete update.dateCreated;
1720
- }
1721
- try {
1722
- if (update.dateUpdated) {
1723
- update.dateUpdated = new Date(update.dateUpdated);
1724
- }
1725
- } catch (e) {
1726
- log.warn('Retrieved malformed dateUpdated from the server for conversation: ' + conversationSid);
1727
- delete update.dateUpdated;
1728
- }
1729
- try {
1730
- if (update.lastMessage && update.lastMessage.timestamp) {
1731
- update.lastMessage.timestamp = new Date(update.lastMessage.timestamp);
1732
- }
1733
- } catch (e) {
1734
- log.warn('Retrieved malformed lastMessage.timestamp from the server for conversation: ' + conversationSid);
1735
- delete update.lastMessage.timestamp;
1736
- }
1737
- }
1738
- }]);
1739
- return Conversation;
1740
- }(events_1.EventEmitter);
1741
-
1742
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonEmptyString, ['undefined', 'string', 'number', 'boolean', 'object', twilio_sdk_type_validator_1.literal(null)]), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "add", null);
1743
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonEmptyString, twilio_sdk_type_validator_1.nonEmptyString, ['undefined', 'object']), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, Object]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "addNonChatParticipant", null);
1744
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonNegativeInteger), __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "advanceLastReadMessageIndex", null);
1745
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync(['undefined', twilio_sdk_type_validator_1.nonNegativeInteger], ['undefined', twilio_sdk_type_validator_1.nonNegativeInteger], ['undefined', twilio_sdk_type_validator_1.literal('backwards', 'forward')]), __metadata("design:type", Function), __metadata("design:paramtypes", [Number, Number, String]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "getMessages", null);
1746
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "getParticipantBySid", null);
1747
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "getParticipantByIdentity", null);
1748
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync([twilio_sdk_type_validator_1.nonEmptyString, participant_1.Participant]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "removeParticipant", null);
1749
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync(['string', twilio_sdk_type_validator_1.literal(null),
1750
- // Wrapping it into a custom rule is necessary because the FormData class is not available on initialization.
1751
- twilio_sdk_type_validator_1.custom(function (value) {
1752
- return [value instanceof FormData, 'an instance of FormData'];
1753
- }), twilio_sdk_type_validator_1.objectSchema('media options', {
1754
- contentType: twilio_sdk_type_validator_1.nonEmptyString,
1755
- media: twilio_sdk_type_validator_1.custom(function (value) {
1756
- var isValid = typeof value === 'string' && value.length > 0 || value instanceof Uint8Array || value instanceof ArrayBuffer;
1757
- if (typeof Blob === 'function') {
1758
- isValid = isValid || value instanceof Blob;
1759
- }
1760
- return [isValid, 'a non-empty string, an instance of Buffer or an instance of Blob'];
1761
- })
1762
- })], ['undefined', 'string', 'number', 'boolean', 'object', twilio_sdk_type_validator_1.literal(null)], ['undefined', twilio_sdk_type_validator_1.literal(null), twilio_sdk_type_validator_1.objectSchema('email attributes', {
1763
- subject: [twilio_sdk_type_validator_1.nonEmptyString, 'undefined']
1764
- })]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, Object]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "sendMessage", null);
1765
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.literal('default', 'muted')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "setUserNotificationLevel", null);
1766
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync(['string', 'number', 'boolean', 'object', twilio_sdk_type_validator_1.literal(null)]), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "updateAttributes", null);
1767
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync(['string', twilio_sdk_type_validator_1.literal(null)]), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "updateFriendlyName", null);
1768
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync([twilio_sdk_type_validator_1.literal(null), twilio_sdk_type_validator_1.nonNegativeInteger]), __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "updateLastReadMessageIndex", null);
1769
- __decorate([twilio_sdk_type_validator_1.validateTypesAsync(['string', twilio_sdk_type_validator_1.literal(null)]), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", _promise2.default)], Conversation.prototype, "updateUniqueName", null);
1770
- exports.Conversation = Conversation;
1771
- /**
1772
- * Fired when a Participant has joined the Conversation.
1773
- * @event Conversation#participantJoined
1774
- * @type {Participant}
1775
- */
1776
- /**
1777
- * Fired when a Participant has left the Conversation.
1778
- * @event Conversation#participantLeft
1779
- * @type {Participant}
1780
- */
1781
- /**
1782
- * Fired when a Participant's fields has been updated.
1783
- * @event Conversation#participantUpdated
1784
- * @type {Object}
1785
- * @property {Participant} participant - Updated Participant
1786
- * @property {Participant#UpdateReason[]} updateReasons - Array of Participant's updated event reasons
1787
- */
1788
- /**
1789
- * Fired when a new Message has been added to the Conversation.
1790
- * @event Conversation#messageAdded
1791
- * @type {Message}
1792
- */
1793
- /**
1794
- * Fired when Message is removed from Conversation's message list.
1795
- * @event Conversation#messageRemoved
1796
- * @type {Message}
1797
- */
1798
- /**
1799
- * Fired when an existing Message's fields are updated with new values.
1800
- * @event Conversation#messageUpdated
1801
- * @type {Object}
1802
- * @property {Message} message - Updated Message
1803
- * @property {Message#UpdateReason[]} updateReasons - Array of Message's updated event reasons
1804
- */
1805
- /**
1806
- * Fired when a Participant has stopped typing.
1807
- * @event Conversation#typingEnded
1808
- * @type {Participant}
1809
- */
1810
- /**
1811
- * Fired when a Participant has started typing.
1812
- * @event Conversation#typingStarted
1813
- * @type {Participant}
1814
- */
1815
- /**
1816
- * Fired when a Conversation's attributes or metadata have been updated.
1817
- * @event Conversation#updated
1818
- * @type {Object}
1819
- * @property {Conversation} conversation - Updated Conversation
1820
- * @property {Conversation#UpdateReason[]} updateReasons - Array of Conversation's updated event reasons
1821
- */
1822
- /**
1823
- * Fired when the Conversation was destroyed or currently logged in User has left private Conversation
1824
- * @event Conversation#removed
1825
- * @type {Conversation}
1826
- */