1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6 |
|
7 | var protobufLight = _interopDefault(require('protobufjs/dist/protobuf-light'));
|
8 | var EventEmitter = _interopDefault(require('eventemitter3'));
|
9 | var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator'));
|
10 | var d = _interopDefault(require('debug'));
|
11 | var superagent = _interopDefault(require('superagent'));
|
12 | var shuffle = _interopDefault(require('lodash/shuffle'));
|
13 | var StateMachine = _interopDefault(require('javascript-state-machine'));
|
14 | var WebSocket = _interopDefault(require('ws'));
|
15 | var isPlainObject = _interopDefault(require('lodash/isPlainObject'));
|
16 | var uuid = _interopDefault(require('uuid/v4'));
|
17 | var base64Arraybuffer = require('base64-arraybuffer');
|
18 | var remove = _interopDefault(require('lodash/remove'));
|
19 | var values = _interopDefault(require('lodash/values'));
|
20 | var isEmpty = _interopDefault(require('lodash/isEmpty'));
|
21 | var cloneDeep = _interopDefault(require('lodash/cloneDeep'));
|
22 | var find = _interopDefault(require('lodash/find'));
|
23 |
|
24 | function _typeof(obj) {
|
25 | if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
26 | _typeof = function (obj) {
|
27 | return typeof obj;
|
28 | };
|
29 | } else {
|
30 | _typeof = function (obj) {
|
31 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
32 | };
|
33 | }
|
34 |
|
35 | return _typeof(obj);
|
36 | }
|
37 |
|
38 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
39 | try {
|
40 | var info = gen[key](arg);
|
41 | var value = info.value;
|
42 | } catch (error) {
|
43 | reject(error);
|
44 | return;
|
45 | }
|
46 |
|
47 | if (info.done) {
|
48 | resolve(value);
|
49 | } else {
|
50 | Promise.resolve(value).then(_next, _throw);
|
51 | }
|
52 | }
|
53 |
|
54 | function _asyncToGenerator(fn) {
|
55 | return function () {
|
56 | var self = this,
|
57 | args = arguments;
|
58 | return new Promise(function (resolve, reject) {
|
59 | var gen = fn.apply(self, args);
|
60 |
|
61 | function _next(value) {
|
62 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
63 | }
|
64 |
|
65 | function _throw(err) {
|
66 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
67 | }
|
68 |
|
69 | _next(undefined);
|
70 | });
|
71 | };
|
72 | }
|
73 |
|
74 | function _defineProperties(target, props) {
|
75 | for (var i = 0; i < props.length; i++) {
|
76 | var descriptor = props[i];
|
77 | descriptor.enumerable = descriptor.enumerable || false;
|
78 | descriptor.configurable = true;
|
79 | if ("value" in descriptor) descriptor.writable = true;
|
80 | Object.defineProperty(target, descriptor.key, descriptor);
|
81 | }
|
82 | }
|
83 |
|
84 | function _createClass(Constructor, protoProps, staticProps) {
|
85 | if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
86 | if (staticProps) _defineProperties(Constructor, staticProps);
|
87 | return Constructor;
|
88 | }
|
89 |
|
90 | function _defineProperty(obj, key, value) {
|
91 | if (key in obj) {
|
92 | Object.defineProperty(obj, key, {
|
93 | value: value,
|
94 | enumerable: true,
|
95 | configurable: true,
|
96 | writable: true
|
97 | });
|
98 | } else {
|
99 | obj[key] = value;
|
100 | }
|
101 |
|
102 | return obj;
|
103 | }
|
104 |
|
105 | function _objectSpread(target) {
|
106 | for (var i = 1; i < arguments.length; i++) {
|
107 | var source = arguments[i] != null ? arguments[i] : {};
|
108 | var ownKeys = Object.keys(source);
|
109 |
|
110 | if (typeof Object.getOwnPropertySymbols === 'function') {
|
111 | ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
|
112 | return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
113 | }));
|
114 | }
|
115 |
|
116 | ownKeys.forEach(function (key) {
|
117 | _defineProperty(target, key, source[key]);
|
118 | });
|
119 | }
|
120 |
|
121 | return target;
|
122 | }
|
123 |
|
124 | function _inheritsLoose(subClass, superClass) {
|
125 | subClass.prototype = Object.create(superClass.prototype);
|
126 | subClass.prototype.constructor = subClass;
|
127 | subClass.__proto__ = superClass;
|
128 | }
|
129 |
|
130 | function _objectWithoutPropertiesLoose(source, excluded) {
|
131 | if (source == null) return {};
|
132 | var target = {};
|
133 | var sourceKeys = Object.keys(source);
|
134 | var key, i;
|
135 |
|
136 | for (i = 0; i < sourceKeys.length; i++) {
|
137 | key = sourceKeys[i];
|
138 | if (excluded.indexOf(key) >= 0) continue;
|
139 | target[key] = source[key];
|
140 | }
|
141 |
|
142 | return target;
|
143 | }
|
144 |
|
145 | function _objectWithoutProperties(source, excluded) {
|
146 | if (source == null) return {};
|
147 |
|
148 | var target = _objectWithoutPropertiesLoose(source, excluded);
|
149 |
|
150 | var key, i;
|
151 |
|
152 | if (Object.getOwnPropertySymbols) {
|
153 | var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
154 |
|
155 | for (i = 0; i < sourceSymbolKeys.length; i++) {
|
156 | key = sourceSymbolKeys[i];
|
157 | if (excluded.indexOf(key) >= 0) continue;
|
158 | if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
159 | target[key] = source[key];
|
160 | }
|
161 | }
|
162 |
|
163 | return target;
|
164 | }
|
165 |
|
166 | function _assertThisInitialized(self) {
|
167 | if (self === void 0) {
|
168 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
169 | }
|
170 |
|
171 | return self;
|
172 | }
|
173 |
|
174 | function _slicedToArray(arr, i) {
|
175 | return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
|
176 | }
|
177 |
|
178 | function _toArray(arr) {
|
179 | return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest();
|
180 | }
|
181 |
|
182 | function _toConsumableArray(arr) {
|
183 | return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
|
184 | }
|
185 |
|
186 | function _arrayWithoutHoles(arr) {
|
187 | if (Array.isArray(arr)) {
|
188 | for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
189 |
|
190 | return arr2;
|
191 | }
|
192 | }
|
193 |
|
194 | function _arrayWithHoles(arr) {
|
195 | if (Array.isArray(arr)) return arr;
|
196 | }
|
197 |
|
198 | function _iterableToArray(iter) {
|
199 | if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
200 | }
|
201 |
|
202 | function _iterableToArrayLimit(arr, i) {
|
203 | var _arr = [];
|
204 | var _n = true;
|
205 | var _d = false;
|
206 | var _e = undefined;
|
207 |
|
208 | try {
|
209 | for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
210 | _arr.push(_s.value);
|
211 |
|
212 | if (i && _arr.length === i) break;
|
213 | }
|
214 | } catch (err) {
|
215 | _d = true;
|
216 | _e = err;
|
217 | } finally {
|
218 | try {
|
219 | if (!_n && _i["return"] != null) _i["return"]();
|
220 | } finally {
|
221 | if (_d) throw _e;
|
222 | }
|
223 | }
|
224 |
|
225 | return _arr;
|
226 | }
|
227 |
|
228 | function _nonIterableSpread() {
|
229 | throw new TypeError("Invalid attempt to spread non-iterable instance");
|
230 | }
|
231 |
|
232 | function _nonIterableRest() {
|
233 | throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
234 | }
|
235 |
|
236 | function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
|
237 | var desc = {};
|
238 | Object['ke' + 'ys'](descriptor).forEach(function (key) {
|
239 | desc[key] = descriptor[key];
|
240 | });
|
241 | desc.enumerable = !!desc.enumerable;
|
242 | desc.configurable = !!desc.configurable;
|
243 |
|
244 | if ('value' in desc || desc.initializer) {
|
245 | desc.writable = true;
|
246 | }
|
247 |
|
248 | desc = decorators.slice().reverse().reduce(function (desc, decorator) {
|
249 | return decorator(target, property, desc) || desc;
|
250 | }, desc);
|
251 |
|
252 | if (context && desc.initializer !== void 0) {
|
253 | desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
|
254 | desc.initializer = undefined;
|
255 | }
|
256 |
|
257 | if (desc.initializer === void 0) {
|
258 | Object['define' + 'Property'](target, property, desc);
|
259 | desc = null;
|
260 | }
|
261 |
|
262 | return desc;
|
263 | }
|
264 |
|
265 | var messageCompiled = protobufLight.newBuilder({})['import']({
|
266 | package: 'push_server.messages2',
|
267 | syntax: 'proto2',
|
268 | options: {
|
269 | objc_class_prefix: 'AVIM'
|
270 | },
|
271 | messages: [{
|
272 | name: 'JsonObjectMessage',
|
273 | syntax: 'proto2',
|
274 | fields: [{
|
275 | rule: 'required',
|
276 | type: 'string',
|
277 | name: 'data',
|
278 | id: 1
|
279 | }]
|
280 | }, {
|
281 | name: 'UnreadTuple',
|
282 | syntax: 'proto2',
|
283 | fields: [{
|
284 | rule: 'required',
|
285 | type: 'string',
|
286 | name: 'cid',
|
287 | id: 1
|
288 | }, {
|
289 | rule: 'required',
|
290 | type: 'int32',
|
291 | name: 'unread',
|
292 | id: 2
|
293 | }, {
|
294 | rule: 'optional',
|
295 | type: 'string',
|
296 | name: 'mid',
|
297 | id: 3
|
298 | }, {
|
299 | rule: 'optional',
|
300 | type: 'int64',
|
301 | name: 'timestamp',
|
302 | id: 4
|
303 | }, {
|
304 | rule: 'optional',
|
305 | type: 'string',
|
306 | name: 'from',
|
307 | id: 5
|
308 | }, {
|
309 | rule: 'optional',
|
310 | type: 'string',
|
311 | name: 'data',
|
312 | id: 6
|
313 | }, {
|
314 | rule: 'optional',
|
315 | type: 'int64',
|
316 | name: 'patchTimestamp',
|
317 | id: 7
|
318 | }, {
|
319 | rule: 'optional',
|
320 | type: 'bool',
|
321 | name: 'mentioned',
|
322 | id: 8
|
323 | }, {
|
324 | rule: 'optional',
|
325 | type: 'bytes',
|
326 | name: 'binaryMsg',
|
327 | id: 9
|
328 | }, {
|
329 | rule: 'optional',
|
330 | type: 'int32',
|
331 | name: 'convType',
|
332 | id: 10
|
333 | }]
|
334 | }, {
|
335 | name: 'LogItem',
|
336 | syntax: 'proto2',
|
337 | fields: [{
|
338 | rule: 'optional',
|
339 | type: 'string',
|
340 | name: 'from',
|
341 | id: 1
|
342 | }, {
|
343 | rule: 'optional',
|
344 | type: 'string',
|
345 | name: 'data',
|
346 | id: 2
|
347 | }, {
|
348 | rule: 'optional',
|
349 | type: 'int64',
|
350 | name: 'timestamp',
|
351 | id: 3
|
352 | }, {
|
353 | rule: 'optional',
|
354 | type: 'string',
|
355 | name: 'msgId',
|
356 | id: 4
|
357 | }, {
|
358 | rule: 'optional',
|
359 | type: 'int64',
|
360 | name: 'ackAt',
|
361 | id: 5
|
362 | }, {
|
363 | rule: 'optional',
|
364 | type: 'int64',
|
365 | name: 'readAt',
|
366 | id: 6
|
367 | }, {
|
368 | rule: 'optional',
|
369 | type: 'int64',
|
370 | name: 'patchTimestamp',
|
371 | id: 7
|
372 | }, {
|
373 | rule: 'optional',
|
374 | type: 'bool',
|
375 | name: 'mentionAll',
|
376 | id: 8
|
377 | }, {
|
378 | rule: 'repeated',
|
379 | type: 'string',
|
380 | name: 'mentionPids',
|
381 | id: 9
|
382 | }, {
|
383 | rule: 'optional',
|
384 | type: 'bool',
|
385 | name: 'bin',
|
386 | id: 10
|
387 | }, {
|
388 | rule: 'optional',
|
389 | type: 'int32',
|
390 | name: 'convType',
|
391 | id: 11
|
392 | }]
|
393 | }, {
|
394 | name: 'ConvMemberInfo',
|
395 | syntax: 'proto2',
|
396 | fields: [{
|
397 | rule: 'optional',
|
398 | type: 'string',
|
399 | name: 'pid',
|
400 | id: 1
|
401 | }, {
|
402 | rule: 'optional',
|
403 | type: 'string',
|
404 | name: 'role',
|
405 | id: 2
|
406 | }, {
|
407 | rule: 'optional',
|
408 | type: 'string',
|
409 | name: 'infoId',
|
410 | id: 3
|
411 | }]
|
412 | }, {
|
413 | name: 'DataCommand',
|
414 | syntax: 'proto2',
|
415 | fields: [{
|
416 | rule: 'repeated',
|
417 | type: 'string',
|
418 | name: 'ids',
|
419 | id: 1
|
420 | }, {
|
421 | rule: 'repeated',
|
422 | type: 'JsonObjectMessage',
|
423 | name: 'msg',
|
424 | id: 2
|
425 | }, {
|
426 | rule: 'optional',
|
427 | type: 'bool',
|
428 | name: 'offline',
|
429 | id: 3
|
430 | }]
|
431 | }, {
|
432 | name: 'SessionCommand',
|
433 | syntax: 'proto2',
|
434 | fields: [{
|
435 | rule: 'optional',
|
436 | type: 'int64',
|
437 | name: 't',
|
438 | id: 1
|
439 | }, {
|
440 | rule: 'optional',
|
441 | type: 'string',
|
442 | name: 'n',
|
443 | id: 2
|
444 | }, {
|
445 | rule: 'optional',
|
446 | type: 'string',
|
447 | name: 's',
|
448 | id: 3
|
449 | }, {
|
450 | rule: 'optional',
|
451 | type: 'string',
|
452 | name: 'ua',
|
453 | id: 4
|
454 | }, {
|
455 | rule: 'optional',
|
456 | type: 'bool',
|
457 | name: 'r',
|
458 | id: 5
|
459 | }, {
|
460 | rule: 'optional',
|
461 | type: 'string',
|
462 | name: 'tag',
|
463 | id: 6
|
464 | }, {
|
465 | rule: 'optional',
|
466 | type: 'string',
|
467 | name: 'deviceId',
|
468 | id: 7
|
469 | }, {
|
470 | rule: 'repeated',
|
471 | type: 'string',
|
472 | name: 'sessionPeerIds',
|
473 | id: 8
|
474 | }, {
|
475 | rule: 'repeated',
|
476 | type: 'string',
|
477 | name: 'onlineSessionPeerIds',
|
478 | id: 9
|
479 | }, {
|
480 | rule: 'optional',
|
481 | type: 'string',
|
482 | name: 'st',
|
483 | id: 10
|
484 | }, {
|
485 | rule: 'optional',
|
486 | type: 'int32',
|
487 | name: 'stTtl',
|
488 | id: 11
|
489 | }, {
|
490 | rule: 'optional',
|
491 | type: 'int32',
|
492 | name: 'code',
|
493 | id: 12
|
494 | }, {
|
495 | rule: 'optional',
|
496 | type: 'string',
|
497 | name: 'reason',
|
498 | id: 13
|
499 | }, {
|
500 | rule: 'optional',
|
501 | type: 'string',
|
502 | name: 'deviceToken',
|
503 | id: 14
|
504 | }, {
|
505 | rule: 'optional',
|
506 | type: 'bool',
|
507 | name: 'sp',
|
508 | id: 15
|
509 | }, {
|
510 | rule: 'optional',
|
511 | type: 'string',
|
512 | name: 'detail',
|
513 | id: 16
|
514 | }, {
|
515 | rule: 'optional',
|
516 | type: 'int64',
|
517 | name: 'lastUnreadNotifTime',
|
518 | id: 17
|
519 | }, {
|
520 | rule: 'optional',
|
521 | type: 'int64',
|
522 | name: 'lastPatchTime',
|
523 | id: 18
|
524 | }, {
|
525 | rule: 'optional',
|
526 | type: 'int64',
|
527 | name: 'configBitmap',
|
528 | id: 19
|
529 | }]
|
530 | }, {
|
531 | name: 'ErrorCommand',
|
532 | syntax: 'proto2',
|
533 | fields: [{
|
534 | rule: 'required',
|
535 | type: 'int32',
|
536 | name: 'code',
|
537 | id: 1
|
538 | }, {
|
539 | rule: 'required',
|
540 | type: 'string',
|
541 | name: 'reason',
|
542 | id: 2
|
543 | }, {
|
544 | rule: 'optional',
|
545 | type: 'int32',
|
546 | name: 'appCode',
|
547 | id: 3
|
548 | }, {
|
549 | rule: 'optional',
|
550 | type: 'string',
|
551 | name: 'detail',
|
552 | id: 4
|
553 | }, {
|
554 | rule: 'repeated',
|
555 | type: 'string',
|
556 | name: 'pids',
|
557 | id: 5
|
558 | }, {
|
559 | rule: 'optional',
|
560 | type: 'string',
|
561 | name: 'appMsg',
|
562 | id: 6
|
563 | }]
|
564 | }, {
|
565 | name: 'DirectCommand',
|
566 | syntax: 'proto2',
|
567 | fields: [{
|
568 | rule: 'optional',
|
569 | type: 'string',
|
570 | name: 'msg',
|
571 | id: 1
|
572 | }, {
|
573 | rule: 'optional',
|
574 | type: 'string',
|
575 | name: 'uid',
|
576 | id: 2
|
577 | }, {
|
578 | rule: 'optional',
|
579 | type: 'string',
|
580 | name: 'fromPeerId',
|
581 | id: 3
|
582 | }, {
|
583 | rule: 'optional',
|
584 | type: 'int64',
|
585 | name: 'timestamp',
|
586 | id: 4
|
587 | }, {
|
588 | rule: 'optional',
|
589 | type: 'bool',
|
590 | name: 'offline',
|
591 | id: 5
|
592 | }, {
|
593 | rule: 'optional',
|
594 | type: 'bool',
|
595 | name: 'hasMore',
|
596 | id: 6
|
597 | }, {
|
598 | rule: 'repeated',
|
599 | type: 'string',
|
600 | name: 'toPeerIds',
|
601 | id: 7
|
602 | }, {
|
603 | rule: 'optional',
|
604 | type: 'bool',
|
605 | name: 'r',
|
606 | id: 10
|
607 | }, {
|
608 | rule: 'optional',
|
609 | type: 'string',
|
610 | name: 'cid',
|
611 | id: 11
|
612 | }, {
|
613 | rule: 'optional',
|
614 | type: 'string',
|
615 | name: 'id',
|
616 | id: 12
|
617 | }, {
|
618 | rule: 'optional',
|
619 | type: 'bool',
|
620 | name: 'transient',
|
621 | id: 13
|
622 | }, {
|
623 | rule: 'optional',
|
624 | type: 'string',
|
625 | name: 'dt',
|
626 | id: 14
|
627 | }, {
|
628 | rule: 'optional',
|
629 | type: 'string',
|
630 | name: 'roomId',
|
631 | id: 15
|
632 | }, {
|
633 | rule: 'optional',
|
634 | type: 'string',
|
635 | name: 'pushData',
|
636 | id: 16
|
637 | }, {
|
638 | rule: 'optional',
|
639 | type: 'bool',
|
640 | name: 'will',
|
641 | id: 17
|
642 | }, {
|
643 | rule: 'optional',
|
644 | type: 'int64',
|
645 | name: 'patchTimestamp',
|
646 | id: 18
|
647 | }, {
|
648 | rule: 'optional',
|
649 | type: 'bytes',
|
650 | name: 'binaryMsg',
|
651 | id: 19
|
652 | }, {
|
653 | rule: 'repeated',
|
654 | type: 'string',
|
655 | name: 'mentionPids',
|
656 | id: 20
|
657 | }, {
|
658 | rule: 'optional',
|
659 | type: 'bool',
|
660 | name: 'mentionAll',
|
661 | id: 21
|
662 | }, {
|
663 | rule: 'optional',
|
664 | type: 'int32',
|
665 | name: 'convType',
|
666 | id: 22
|
667 | }]
|
668 | }, {
|
669 | name: 'AckCommand',
|
670 | syntax: 'proto2',
|
671 | fields: [{
|
672 | rule: 'optional',
|
673 | type: 'int32',
|
674 | name: 'code',
|
675 | id: 1
|
676 | }, {
|
677 | rule: 'optional',
|
678 | type: 'string',
|
679 | name: 'reason',
|
680 | id: 2
|
681 | }, {
|
682 | rule: 'optional',
|
683 | type: 'string',
|
684 | name: 'mid',
|
685 | id: 3
|
686 | }, {
|
687 | rule: 'optional',
|
688 | type: 'string',
|
689 | name: 'cid',
|
690 | id: 4
|
691 | }, {
|
692 | rule: 'optional',
|
693 | type: 'int64',
|
694 | name: 't',
|
695 | id: 5
|
696 | }, {
|
697 | rule: 'optional',
|
698 | type: 'string',
|
699 | name: 'uid',
|
700 | id: 6
|
701 | }, {
|
702 | rule: 'optional',
|
703 | type: 'int64',
|
704 | name: 'fromts',
|
705 | id: 7
|
706 | }, {
|
707 | rule: 'optional',
|
708 | type: 'int64',
|
709 | name: 'tots',
|
710 | id: 8
|
711 | }, {
|
712 | rule: 'optional',
|
713 | type: 'string',
|
714 | name: 'type',
|
715 | id: 9
|
716 | }, {
|
717 | rule: 'repeated',
|
718 | type: 'string',
|
719 | name: 'ids',
|
720 | id: 10
|
721 | }, {
|
722 | rule: 'optional',
|
723 | type: 'int32',
|
724 | name: 'appCode',
|
725 | id: 11
|
726 | }, {
|
727 | rule: 'optional',
|
728 | type: 'string',
|
729 | name: 'appMsg',
|
730 | id: 12
|
731 | }]
|
732 | }, {
|
733 | name: 'UnreadCommand',
|
734 | syntax: 'proto2',
|
735 | fields: [{
|
736 | rule: 'repeated',
|
737 | type: 'UnreadTuple',
|
738 | name: 'convs',
|
739 | id: 1
|
740 | }, {
|
741 | rule: 'optional',
|
742 | type: 'int64',
|
743 | name: 'notifTime',
|
744 | id: 2
|
745 | }]
|
746 | }, {
|
747 | name: 'ConvCommand',
|
748 | syntax: 'proto2',
|
749 | fields: [{
|
750 | rule: 'repeated',
|
751 | type: 'string',
|
752 | name: 'm',
|
753 | id: 1
|
754 | }, {
|
755 | rule: 'optional',
|
756 | type: 'bool',
|
757 | name: 'transient',
|
758 | id: 2
|
759 | }, {
|
760 | rule: 'optional',
|
761 | type: 'bool',
|
762 | name: 'unique',
|
763 | id: 3
|
764 | }, {
|
765 | rule: 'optional',
|
766 | type: 'string',
|
767 | name: 'cid',
|
768 | id: 4
|
769 | }, {
|
770 | rule: 'optional',
|
771 | type: 'string',
|
772 | name: 'cdate',
|
773 | id: 5
|
774 | }, {
|
775 | rule: 'optional',
|
776 | type: 'string',
|
777 | name: 'initBy',
|
778 | id: 6
|
779 | }, {
|
780 | rule: 'optional',
|
781 | type: 'string',
|
782 | name: 'sort',
|
783 | id: 7
|
784 | }, {
|
785 | rule: 'optional',
|
786 | type: 'int32',
|
787 | name: 'limit',
|
788 | id: 8
|
789 | }, {
|
790 | rule: 'optional',
|
791 | type: 'int32',
|
792 | name: 'skip',
|
793 | id: 9
|
794 | }, {
|
795 | rule: 'optional',
|
796 | type: 'int32',
|
797 | name: 'flag',
|
798 | id: 10
|
799 | }, {
|
800 | rule: 'optional',
|
801 | type: 'int32',
|
802 | name: 'count',
|
803 | id: 11
|
804 | }, {
|
805 | rule: 'optional',
|
806 | type: 'string',
|
807 | name: 'udate',
|
808 | id: 12
|
809 | }, {
|
810 | rule: 'optional',
|
811 | type: 'int64',
|
812 | name: 't',
|
813 | id: 13
|
814 | }, {
|
815 | rule: 'optional',
|
816 | type: 'string',
|
817 | name: 'n',
|
818 | id: 14
|
819 | }, {
|
820 | rule: 'optional',
|
821 | type: 'string',
|
822 | name: 's',
|
823 | id: 15
|
824 | }, {
|
825 | rule: 'optional',
|
826 | type: 'bool',
|
827 | name: 'statusSub',
|
828 | id: 16
|
829 | }, {
|
830 | rule: 'optional',
|
831 | type: 'bool',
|
832 | name: 'statusPub',
|
833 | id: 17
|
834 | }, {
|
835 | rule: 'optional',
|
836 | type: 'int32',
|
837 | name: 'statusTTL',
|
838 | id: 18
|
839 | }, {
|
840 | rule: 'optional',
|
841 | type: 'string',
|
842 | name: 'uniqueId',
|
843 | id: 19
|
844 | }, {
|
845 | rule: 'optional',
|
846 | type: 'string',
|
847 | name: 'targetClientId',
|
848 | id: 20
|
849 | }, {
|
850 | rule: 'optional',
|
851 | type: 'int64',
|
852 | name: 'maxReadTimestamp',
|
853 | id: 21
|
854 | }, {
|
855 | rule: 'optional',
|
856 | type: 'int64',
|
857 | name: 'maxAckTimestamp',
|
858 | id: 22
|
859 | }, {
|
860 | rule: 'optional',
|
861 | type: 'bool',
|
862 | name: 'queryAllMembers',
|
863 | id: 23
|
864 | }, {
|
865 | rule: 'repeated',
|
866 | type: 'MaxReadTuple',
|
867 | name: 'maxReadTuples',
|
868 | id: 24
|
869 | }, {
|
870 | rule: 'repeated',
|
871 | type: 'string',
|
872 | name: 'cids',
|
873 | id: 25
|
874 | }, {
|
875 | rule: 'optional',
|
876 | type: 'ConvMemberInfo',
|
877 | name: 'info',
|
878 | id: 26
|
879 | }, {
|
880 | rule: 'optional',
|
881 | type: 'bool',
|
882 | name: 'tempConv',
|
883 | id: 27
|
884 | }, {
|
885 | rule: 'optional',
|
886 | type: 'int32',
|
887 | name: 'tempConvTTL',
|
888 | id: 28
|
889 | }, {
|
890 | rule: 'repeated',
|
891 | type: 'string',
|
892 | name: 'tempConvIds',
|
893 | id: 29
|
894 | }, {
|
895 | rule: 'repeated',
|
896 | type: 'string',
|
897 | name: 'allowedPids',
|
898 | id: 30
|
899 | }, {
|
900 | rule: 'repeated',
|
901 | type: 'ErrorCommand',
|
902 | name: 'failedPids',
|
903 | id: 31
|
904 | }, {
|
905 | rule: 'optional',
|
906 | type: 'string',
|
907 | name: 'next',
|
908 | id: 40
|
909 | }, {
|
910 | rule: 'optional',
|
911 | type: 'JsonObjectMessage',
|
912 | name: 'results',
|
913 | id: 100
|
914 | }, {
|
915 | rule: 'optional',
|
916 | type: 'JsonObjectMessage',
|
917 | name: 'where',
|
918 | id: 101
|
919 | }, {
|
920 | rule: 'optional',
|
921 | type: 'JsonObjectMessage',
|
922 | name: 'attr',
|
923 | id: 103
|
924 | }, {
|
925 | rule: 'optional',
|
926 | type: 'JsonObjectMessage',
|
927 | name: 'attrModified',
|
928 | id: 104
|
929 | }]
|
930 | }, {
|
931 | name: 'RoomCommand',
|
932 | syntax: 'proto2',
|
933 | fields: [{
|
934 | rule: 'optional',
|
935 | type: 'string',
|
936 | name: 'roomId',
|
937 | id: 1
|
938 | }, {
|
939 | rule: 'optional',
|
940 | type: 'string',
|
941 | name: 's',
|
942 | id: 2
|
943 | }, {
|
944 | rule: 'optional',
|
945 | type: 'int64',
|
946 | name: 't',
|
947 | id: 3
|
948 | }, {
|
949 | rule: 'optional',
|
950 | type: 'string',
|
951 | name: 'n',
|
952 | id: 4
|
953 | }, {
|
954 | rule: 'optional',
|
955 | type: 'bool',
|
956 | name: 'transient',
|
957 | id: 5
|
958 | }, {
|
959 | rule: 'repeated',
|
960 | type: 'string',
|
961 | name: 'roomPeerIds',
|
962 | id: 6
|
963 | }, {
|
964 | rule: 'optional',
|
965 | type: 'string',
|
966 | name: 'byPeerId',
|
967 | id: 7
|
968 | }]
|
969 | }, {
|
970 | name: 'LogsCommand',
|
971 | syntax: 'proto2',
|
972 | fields: [{
|
973 | rule: 'optional',
|
974 | type: 'string',
|
975 | name: 'cid',
|
976 | id: 1
|
977 | }, {
|
978 | rule: 'optional',
|
979 | type: 'int32',
|
980 | name: 'l',
|
981 | id: 2
|
982 | }, {
|
983 | rule: 'optional',
|
984 | type: 'int32',
|
985 | name: 'limit',
|
986 | id: 3
|
987 | }, {
|
988 | rule: 'optional',
|
989 | type: 'int64',
|
990 | name: 't',
|
991 | id: 4
|
992 | }, {
|
993 | rule: 'optional',
|
994 | type: 'int64',
|
995 | name: 'tt',
|
996 | id: 5
|
997 | }, {
|
998 | rule: 'optional',
|
999 | type: 'string',
|
1000 | name: 'tmid',
|
1001 | id: 6
|
1002 | }, {
|
1003 | rule: 'optional',
|
1004 | type: 'string',
|
1005 | name: 'mid',
|
1006 | id: 7
|
1007 | }, {
|
1008 | rule: 'optional',
|
1009 | type: 'string',
|
1010 | name: 'checksum',
|
1011 | id: 8
|
1012 | }, {
|
1013 | rule: 'optional',
|
1014 | type: 'bool',
|
1015 | name: 'stored',
|
1016 | id: 9
|
1017 | }, {
|
1018 | rule: 'optional',
|
1019 | type: 'QueryDirection',
|
1020 | name: 'direction',
|
1021 | id: 10,
|
1022 | options: {
|
1023 | default: 'OLD'
|
1024 | }
|
1025 | }, {
|
1026 | rule: 'optional',
|
1027 | type: 'bool',
|
1028 | name: 'tIncluded',
|
1029 | id: 11
|
1030 | }, {
|
1031 | rule: 'optional',
|
1032 | type: 'bool',
|
1033 | name: 'ttIncluded',
|
1034 | id: 12
|
1035 | }, {
|
1036 | rule: 'optional',
|
1037 | type: 'int32',
|
1038 | name: 'lctype',
|
1039 | id: 13
|
1040 | }, {
|
1041 | rule: 'repeated',
|
1042 | type: 'LogItem',
|
1043 | name: 'logs',
|
1044 | id: 105
|
1045 | }],
|
1046 | enums: [{
|
1047 | name: 'QueryDirection',
|
1048 | syntax: 'proto2',
|
1049 | values: [{
|
1050 | name: 'OLD',
|
1051 | id: 1
|
1052 | }, {
|
1053 | name: 'NEW',
|
1054 | id: 2
|
1055 | }]
|
1056 | }]
|
1057 | }, {
|
1058 | name: 'RcpCommand',
|
1059 | syntax: 'proto2',
|
1060 | fields: [{
|
1061 | rule: 'optional',
|
1062 | type: 'string',
|
1063 | name: 'id',
|
1064 | id: 1
|
1065 | }, {
|
1066 | rule: 'optional',
|
1067 | type: 'string',
|
1068 | name: 'cid',
|
1069 | id: 2
|
1070 | }, {
|
1071 | rule: 'optional',
|
1072 | type: 'int64',
|
1073 | name: 't',
|
1074 | id: 3
|
1075 | }, {
|
1076 | rule: 'optional',
|
1077 | type: 'bool',
|
1078 | name: 'read',
|
1079 | id: 4
|
1080 | }, {
|
1081 | rule: 'optional',
|
1082 | type: 'string',
|
1083 | name: 'from',
|
1084 | id: 5
|
1085 | }]
|
1086 | }, {
|
1087 | name: 'ReadTuple',
|
1088 | syntax: 'proto2',
|
1089 | fields: [{
|
1090 | rule: 'required',
|
1091 | type: 'string',
|
1092 | name: 'cid',
|
1093 | id: 1
|
1094 | }, {
|
1095 | rule: 'optional',
|
1096 | type: 'int64',
|
1097 | name: 'timestamp',
|
1098 | id: 2
|
1099 | }, {
|
1100 | rule: 'optional',
|
1101 | type: 'string',
|
1102 | name: 'mid',
|
1103 | id: 3
|
1104 | }]
|
1105 | }, {
|
1106 | name: 'MaxReadTuple',
|
1107 | syntax: 'proto2',
|
1108 | fields: [{
|
1109 | rule: 'optional',
|
1110 | type: 'string',
|
1111 | name: 'pid',
|
1112 | id: 1
|
1113 | }, {
|
1114 | rule: 'optional',
|
1115 | type: 'int64',
|
1116 | name: 'maxAckTimestamp',
|
1117 | id: 2
|
1118 | }, {
|
1119 | rule: 'optional',
|
1120 | type: 'int64',
|
1121 | name: 'maxReadTimestamp',
|
1122 | id: 3
|
1123 | }]
|
1124 | }, {
|
1125 | name: 'ReadCommand',
|
1126 | syntax: 'proto2',
|
1127 | fields: [{
|
1128 | rule: 'optional',
|
1129 | type: 'string',
|
1130 | name: 'cid',
|
1131 | id: 1
|
1132 | }, {
|
1133 | rule: 'repeated',
|
1134 | type: 'string',
|
1135 | name: 'cids',
|
1136 | id: 2
|
1137 | }, {
|
1138 | rule: 'repeated',
|
1139 | type: 'ReadTuple',
|
1140 | name: 'convs',
|
1141 | id: 3
|
1142 | }]
|
1143 | }, {
|
1144 | name: 'PresenceCommand',
|
1145 | syntax: 'proto2',
|
1146 | fields: [{
|
1147 | rule: 'optional',
|
1148 | type: 'StatusType',
|
1149 | name: 'status',
|
1150 | id: 1
|
1151 | }, {
|
1152 | rule: 'repeated',
|
1153 | type: 'string',
|
1154 | name: 'sessionPeerIds',
|
1155 | id: 2
|
1156 | }, {
|
1157 | rule: 'optional',
|
1158 | type: 'string',
|
1159 | name: 'cid',
|
1160 | id: 3
|
1161 | }]
|
1162 | }, {
|
1163 | name: 'ReportCommand',
|
1164 | syntax: 'proto2',
|
1165 | fields: [{
|
1166 | rule: 'optional',
|
1167 | type: 'bool',
|
1168 | name: 'initiative',
|
1169 | id: 1
|
1170 | }, {
|
1171 | rule: 'optional',
|
1172 | type: 'string',
|
1173 | name: 'type',
|
1174 | id: 2
|
1175 | }, {
|
1176 | rule: 'optional',
|
1177 | type: 'string',
|
1178 | name: 'data',
|
1179 | id: 3
|
1180 | }]
|
1181 | }, {
|
1182 | name: 'PatchItem',
|
1183 | syntax: 'proto2',
|
1184 | fields: [{
|
1185 | rule: 'optional',
|
1186 | type: 'string',
|
1187 | name: 'cid',
|
1188 | id: 1
|
1189 | }, {
|
1190 | rule: 'optional',
|
1191 | type: 'string',
|
1192 | name: 'mid',
|
1193 | id: 2
|
1194 | }, {
|
1195 | rule: 'optional',
|
1196 | type: 'int64',
|
1197 | name: 'timestamp',
|
1198 | id: 3
|
1199 | }, {
|
1200 | rule: 'optional',
|
1201 | type: 'bool',
|
1202 | name: 'recall',
|
1203 | id: 4
|
1204 | }, {
|
1205 | rule: 'optional',
|
1206 | type: 'string',
|
1207 | name: 'data',
|
1208 | id: 5
|
1209 | }, {
|
1210 | rule: 'optional',
|
1211 | type: 'int64',
|
1212 | name: 'patchTimestamp',
|
1213 | id: 6
|
1214 | }, {
|
1215 | rule: 'optional',
|
1216 | type: 'string',
|
1217 | name: 'from',
|
1218 | id: 7
|
1219 | }, {
|
1220 | rule: 'optional',
|
1221 | type: 'bytes',
|
1222 | name: 'binaryMsg',
|
1223 | id: 8
|
1224 | }, {
|
1225 | rule: 'optional',
|
1226 | type: 'bool',
|
1227 | name: 'mentionAll',
|
1228 | id: 9
|
1229 | }, {
|
1230 | rule: 'repeated',
|
1231 | type: 'string',
|
1232 | name: 'mentionPids',
|
1233 | id: 10
|
1234 | }, {
|
1235 | rule: 'optional',
|
1236 | type: 'int64',
|
1237 | name: 'patchCode',
|
1238 | id: 11
|
1239 | }, {
|
1240 | rule: 'optional',
|
1241 | type: 'string',
|
1242 | name: 'patchReason',
|
1243 | id: 12
|
1244 | }]
|
1245 | }, {
|
1246 | name: 'PatchCommand',
|
1247 | syntax: 'proto2',
|
1248 | fields: [{
|
1249 | rule: 'repeated',
|
1250 | type: 'PatchItem',
|
1251 | name: 'patches',
|
1252 | id: 1
|
1253 | }, {
|
1254 | rule: 'optional',
|
1255 | type: 'int64',
|
1256 | name: 'lastPatchTime',
|
1257 | id: 2
|
1258 | }]
|
1259 | }, {
|
1260 | name: 'PubsubCommand',
|
1261 | syntax: 'proto2',
|
1262 | fields: [{
|
1263 | rule: 'optional',
|
1264 | type: 'string',
|
1265 | name: 'cid',
|
1266 | id: 1
|
1267 | }, {
|
1268 | rule: 'repeated',
|
1269 | type: 'string',
|
1270 | name: 'cids',
|
1271 | id: 2
|
1272 | }, {
|
1273 | rule: 'optional',
|
1274 | type: 'string',
|
1275 | name: 'topic',
|
1276 | id: 3
|
1277 | }, {
|
1278 | rule: 'optional',
|
1279 | type: 'string',
|
1280 | name: 'subtopic',
|
1281 | id: 4
|
1282 | }, {
|
1283 | rule: 'repeated',
|
1284 | type: 'string',
|
1285 | name: 'topics',
|
1286 | id: 5
|
1287 | }, {
|
1288 | rule: 'repeated',
|
1289 | type: 'string',
|
1290 | name: 'subtopics',
|
1291 | id: 6
|
1292 | }, {
|
1293 | rule: 'optional',
|
1294 | type: 'JsonObjectMessage',
|
1295 | name: 'results',
|
1296 | id: 7
|
1297 | }]
|
1298 | }, {
|
1299 | name: 'BlacklistCommand',
|
1300 | syntax: 'proto2',
|
1301 | fields: [{
|
1302 | rule: 'optional',
|
1303 | type: 'string',
|
1304 | name: 'srcCid',
|
1305 | id: 1
|
1306 | }, {
|
1307 | rule: 'repeated',
|
1308 | type: 'string',
|
1309 | name: 'toPids',
|
1310 | id: 2
|
1311 | }, {
|
1312 | rule: 'optional',
|
1313 | type: 'string',
|
1314 | name: 'srcPid',
|
1315 | id: 3
|
1316 | }, {
|
1317 | rule: 'repeated',
|
1318 | type: 'string',
|
1319 | name: 'toCids',
|
1320 | id: 4
|
1321 | }, {
|
1322 | rule: 'optional',
|
1323 | type: 'int32',
|
1324 | name: 'limit',
|
1325 | id: 5
|
1326 | }, {
|
1327 | rule: 'optional',
|
1328 | type: 'string',
|
1329 | name: 'next',
|
1330 | id: 6
|
1331 | }, {
|
1332 | rule: 'repeated',
|
1333 | type: 'string',
|
1334 | name: 'blockedPids',
|
1335 | id: 8
|
1336 | }, {
|
1337 | rule: 'repeated',
|
1338 | type: 'string',
|
1339 | name: 'blockedCids',
|
1340 | id: 9
|
1341 | }, {
|
1342 | rule: 'repeated',
|
1343 | type: 'string',
|
1344 | name: 'allowedPids',
|
1345 | id: 10
|
1346 | }, {
|
1347 | rule: 'repeated',
|
1348 | type: 'ErrorCommand',
|
1349 | name: 'failedPids',
|
1350 | id: 11
|
1351 | }, {
|
1352 | rule: 'optional',
|
1353 | type: 'int64',
|
1354 | name: 't',
|
1355 | id: 12
|
1356 | }, {
|
1357 | rule: 'optional',
|
1358 | type: 'string',
|
1359 | name: 'n',
|
1360 | id: 13
|
1361 | }, {
|
1362 | rule: 'optional',
|
1363 | type: 'string',
|
1364 | name: 's',
|
1365 | id: 14
|
1366 | }]
|
1367 | }, {
|
1368 | name: 'GenericCommand',
|
1369 | syntax: 'proto2',
|
1370 | fields: [{
|
1371 | rule: 'optional',
|
1372 | type: 'CommandType',
|
1373 | name: 'cmd',
|
1374 | id: 1
|
1375 | }, {
|
1376 | rule: 'optional',
|
1377 | type: 'OpType',
|
1378 | name: 'op',
|
1379 | id: 2
|
1380 | }, {
|
1381 | rule: 'optional',
|
1382 | type: 'string',
|
1383 | name: 'appId',
|
1384 | id: 3
|
1385 | }, {
|
1386 | rule: 'optional',
|
1387 | type: 'string',
|
1388 | name: 'peerId',
|
1389 | id: 4
|
1390 | }, {
|
1391 | rule: 'optional',
|
1392 | type: 'int32',
|
1393 | name: 'i',
|
1394 | id: 5
|
1395 | }, {
|
1396 | rule: 'optional',
|
1397 | type: 'string',
|
1398 | name: 'installationId',
|
1399 | id: 6
|
1400 | }, {
|
1401 | rule: 'optional',
|
1402 | type: 'int32',
|
1403 | name: 'priority',
|
1404 | id: 7
|
1405 | }, {
|
1406 | rule: 'optional',
|
1407 | type: 'int32',
|
1408 | name: 'service',
|
1409 | id: 8
|
1410 | }, {
|
1411 | rule: 'optional',
|
1412 | type: 'int64',
|
1413 | name: 'serverTs',
|
1414 | id: 9
|
1415 | }, {
|
1416 | rule: 'optional',
|
1417 | type: 'int64',
|
1418 | name: 'clientTs',
|
1419 | id: 10
|
1420 | }, {
|
1421 | rule: 'optional',
|
1422 | type: 'int32',
|
1423 | name: 'notificationType',
|
1424 | id: 11
|
1425 | }, {
|
1426 | rule: 'optional',
|
1427 | type: 'DataCommand',
|
1428 | name: 'dataMessage',
|
1429 | id: 101
|
1430 | }, {
|
1431 | rule: 'optional',
|
1432 | type: 'SessionCommand',
|
1433 | name: 'sessionMessage',
|
1434 | id: 102
|
1435 | }, {
|
1436 | rule: 'optional',
|
1437 | type: 'ErrorCommand',
|
1438 | name: 'errorMessage',
|
1439 | id: 103
|
1440 | }, {
|
1441 | rule: 'optional',
|
1442 | type: 'DirectCommand',
|
1443 | name: 'directMessage',
|
1444 | id: 104
|
1445 | }, {
|
1446 | rule: 'optional',
|
1447 | type: 'AckCommand',
|
1448 | name: 'ackMessage',
|
1449 | id: 105
|
1450 | }, {
|
1451 | rule: 'optional',
|
1452 | type: 'UnreadCommand',
|
1453 | name: 'unreadMessage',
|
1454 | id: 106
|
1455 | }, {
|
1456 | rule: 'optional',
|
1457 | type: 'ReadCommand',
|
1458 | name: 'readMessage',
|
1459 | id: 107
|
1460 | }, {
|
1461 | rule: 'optional',
|
1462 | type: 'RcpCommand',
|
1463 | name: 'rcpMessage',
|
1464 | id: 108
|
1465 | }, {
|
1466 | rule: 'optional',
|
1467 | type: 'LogsCommand',
|
1468 | name: 'logsMessage',
|
1469 | id: 109
|
1470 | }, {
|
1471 | rule: 'optional',
|
1472 | type: 'ConvCommand',
|
1473 | name: 'convMessage',
|
1474 | id: 110
|
1475 | }, {
|
1476 | rule: 'optional',
|
1477 | type: 'RoomCommand',
|
1478 | name: 'roomMessage',
|
1479 | id: 111
|
1480 | }, {
|
1481 | rule: 'optional',
|
1482 | type: 'PresenceCommand',
|
1483 | name: 'presenceMessage',
|
1484 | id: 112
|
1485 | }, {
|
1486 | rule: 'optional',
|
1487 | type: 'ReportCommand',
|
1488 | name: 'reportMessage',
|
1489 | id: 113
|
1490 | }, {
|
1491 | rule: 'optional',
|
1492 | type: 'PatchCommand',
|
1493 | name: 'patchMessage',
|
1494 | id: 114
|
1495 | }, {
|
1496 | rule: 'optional',
|
1497 | type: 'PubsubCommand',
|
1498 | name: 'pubsubMessage',
|
1499 | id: 115
|
1500 | }, {
|
1501 | rule: 'optional',
|
1502 | type: 'BlacklistCommand',
|
1503 | name: 'blacklistMessage',
|
1504 | id: 116
|
1505 | }]
|
1506 | }],
|
1507 | enums: [{
|
1508 | name: 'CommandType',
|
1509 | syntax: 'proto2',
|
1510 | values: [{
|
1511 | name: 'session',
|
1512 | id: 0
|
1513 | }, {
|
1514 | name: 'conv',
|
1515 | id: 1
|
1516 | }, {
|
1517 | name: 'direct',
|
1518 | id: 2
|
1519 | }, {
|
1520 | name: 'ack',
|
1521 | id: 3
|
1522 | }, {
|
1523 | name: 'rcp',
|
1524 | id: 4
|
1525 | }, {
|
1526 | name: 'unread',
|
1527 | id: 5
|
1528 | }, {
|
1529 | name: 'logs',
|
1530 | id: 6
|
1531 | }, {
|
1532 | name: 'error',
|
1533 | id: 7
|
1534 | }, {
|
1535 | name: 'login',
|
1536 | id: 8
|
1537 | }, {
|
1538 | name: 'data',
|
1539 | id: 9
|
1540 | }, {
|
1541 | name: 'room',
|
1542 | id: 10
|
1543 | }, {
|
1544 | name: 'read',
|
1545 | id: 11
|
1546 | }, {
|
1547 | name: 'presence',
|
1548 | id: 12
|
1549 | }, {
|
1550 | name: 'report',
|
1551 | id: 13
|
1552 | }, {
|
1553 | name: 'echo',
|
1554 | id: 14
|
1555 | }, {
|
1556 | name: 'loggedin',
|
1557 | id: 15
|
1558 | }, {
|
1559 | name: 'logout',
|
1560 | id: 16
|
1561 | }, {
|
1562 | name: 'loggedout',
|
1563 | id: 17
|
1564 | }, {
|
1565 | name: 'patch',
|
1566 | id: 18
|
1567 | }, {
|
1568 | name: 'pubsub',
|
1569 | id: 19
|
1570 | }, {
|
1571 | name: 'blacklist',
|
1572 | id: 20
|
1573 | }, {
|
1574 | name: 'goaway',
|
1575 | id: 21
|
1576 | }]
|
1577 | }, {
|
1578 | name: 'OpType',
|
1579 | syntax: 'proto2',
|
1580 | values: [{
|
1581 | name: 'open',
|
1582 | id: 1
|
1583 | }, {
|
1584 | name: 'add',
|
1585 | id: 2
|
1586 | }, {
|
1587 | name: 'remove',
|
1588 | id: 3
|
1589 | }, {
|
1590 | name: 'close',
|
1591 | id: 4
|
1592 | }, {
|
1593 | name: 'opened',
|
1594 | id: 5
|
1595 | }, {
|
1596 | name: 'closed',
|
1597 | id: 6
|
1598 | }, {
|
1599 | name: 'query',
|
1600 | id: 7
|
1601 | }, {
|
1602 | name: 'query_result',
|
1603 | id: 8
|
1604 | }, {
|
1605 | name: 'conflict',
|
1606 | id: 9
|
1607 | }, {
|
1608 | name: 'added',
|
1609 | id: 10
|
1610 | }, {
|
1611 | name: 'removed',
|
1612 | id: 11
|
1613 | }, {
|
1614 | name: 'refresh',
|
1615 | id: 12
|
1616 | }, {
|
1617 | name: 'refreshed',
|
1618 | id: 13
|
1619 | }, {
|
1620 | name: 'start',
|
1621 | id: 30
|
1622 | }, {
|
1623 | name: 'started',
|
1624 | id: 31
|
1625 | }, {
|
1626 | name: 'joined',
|
1627 | id: 32
|
1628 | }, {
|
1629 | name: 'members_joined',
|
1630 | id: 33
|
1631 | }, {
|
1632 | name: 'left',
|
1633 | id: 39
|
1634 | }, {
|
1635 | name: 'members_left',
|
1636 | id: 40
|
1637 | }, {
|
1638 | name: 'results',
|
1639 | id: 42
|
1640 | }, {
|
1641 | name: 'count',
|
1642 | id: 43
|
1643 | }, {
|
1644 | name: 'result',
|
1645 | id: 44
|
1646 | }, {
|
1647 | name: 'update',
|
1648 | id: 45
|
1649 | }, {
|
1650 | name: 'updated',
|
1651 | id: 46
|
1652 | }, {
|
1653 | name: 'mute',
|
1654 | id: 47
|
1655 | }, {
|
1656 | name: 'unmute',
|
1657 | id: 48
|
1658 | }, {
|
1659 | name: 'status',
|
1660 | id: 49
|
1661 | }, {
|
1662 | name: 'members',
|
1663 | id: 50
|
1664 | }, {
|
1665 | name: 'max_read',
|
1666 | id: 51
|
1667 | }, {
|
1668 | name: 'is_member',
|
1669 | id: 52
|
1670 | }, {
|
1671 | name: 'member_info_update',
|
1672 | id: 53
|
1673 | }, {
|
1674 | name: 'member_info_updated',
|
1675 | id: 54
|
1676 | }, {
|
1677 | name: 'member_info_changed',
|
1678 | id: 55
|
1679 | }, {
|
1680 | name: 'join',
|
1681 | id: 80
|
1682 | }, {
|
1683 | name: 'invite',
|
1684 | id: 81
|
1685 | }, {
|
1686 | name: 'leave',
|
1687 | id: 82
|
1688 | }, {
|
1689 | name: 'kick',
|
1690 | id: 83
|
1691 | }, {
|
1692 | name: 'reject',
|
1693 | id: 84
|
1694 | }, {
|
1695 | name: 'invited',
|
1696 | id: 85
|
1697 | }, {
|
1698 | name: 'kicked',
|
1699 | id: 86
|
1700 | }, {
|
1701 | name: 'upload',
|
1702 | id: 100
|
1703 | }, {
|
1704 | name: 'uploaded',
|
1705 | id: 101
|
1706 | }, {
|
1707 | name: 'subscribe',
|
1708 | id: 120
|
1709 | }, {
|
1710 | name: 'subscribed',
|
1711 | id: 121
|
1712 | }, {
|
1713 | name: 'unsubscribe',
|
1714 | id: 122
|
1715 | }, {
|
1716 | name: 'unsubscribed',
|
1717 | id: 123
|
1718 | }, {
|
1719 | name: 'is_subscribed',
|
1720 | id: 124
|
1721 | }, {
|
1722 | name: 'modify',
|
1723 | id: 150
|
1724 | }, {
|
1725 | name: 'modified',
|
1726 | id: 151
|
1727 | }, {
|
1728 | name: 'block',
|
1729 | id: 170
|
1730 | }, {
|
1731 | name: 'unblock',
|
1732 | id: 171
|
1733 | }, {
|
1734 | name: 'blocked',
|
1735 | id: 172
|
1736 | }, {
|
1737 | name: 'unblocked',
|
1738 | id: 173
|
1739 | }, {
|
1740 | name: 'members_blocked',
|
1741 | id: 174
|
1742 | }, {
|
1743 | name: 'members_unblocked',
|
1744 | id: 175
|
1745 | }, {
|
1746 | name: 'check_block',
|
1747 | id: 176
|
1748 | }, {
|
1749 | name: 'check_result',
|
1750 | id: 177
|
1751 | }, {
|
1752 | name: 'add_shutup',
|
1753 | id: 180
|
1754 | }, {
|
1755 | name: 'remove_shutup',
|
1756 | id: 181
|
1757 | }, {
|
1758 | name: 'query_shutup',
|
1759 | id: 182
|
1760 | }, {
|
1761 | name: 'shutup_added',
|
1762 | id: 183
|
1763 | }, {
|
1764 | name: 'shutup_removed',
|
1765 | id: 184
|
1766 | }, {
|
1767 | name: 'shutup_result',
|
1768 | id: 185
|
1769 | }, {
|
1770 | name: 'shutuped',
|
1771 | id: 186
|
1772 | }, {
|
1773 | name: 'unshutuped',
|
1774 | id: 187
|
1775 | }, {
|
1776 | name: 'members_shutuped',
|
1777 | id: 188
|
1778 | }, {
|
1779 | name: 'members_unshutuped',
|
1780 | id: 189
|
1781 | }, {
|
1782 | name: 'check_shutup',
|
1783 | id: 190
|
1784 | }]
|
1785 | }, {
|
1786 | name: 'StatusType',
|
1787 | syntax: 'proto2',
|
1788 | values: [{
|
1789 | name: 'on',
|
1790 | id: 1
|
1791 | }, {
|
1792 | name: 'off',
|
1793 | id: 2
|
1794 | }]
|
1795 | }],
|
1796 | isNamespace: true
|
1797 | }).build();
|
1798 |
|
1799 | var _messages$push_server = messageCompiled.push_server.messages2,
|
1800 | JsonObjectMessage = _messages$push_server.JsonObjectMessage,
|
1801 | UnreadTuple = _messages$push_server.UnreadTuple,
|
1802 | LogItem = _messages$push_server.LogItem,
|
1803 | DataCommand = _messages$push_server.DataCommand,
|
1804 | SessionCommand = _messages$push_server.SessionCommand,
|
1805 | ErrorCommand = _messages$push_server.ErrorCommand,
|
1806 | DirectCommand = _messages$push_server.DirectCommand,
|
1807 | AckCommand = _messages$push_server.AckCommand,
|
1808 | UnreadCommand = _messages$push_server.UnreadCommand,
|
1809 | ConvCommand = _messages$push_server.ConvCommand,
|
1810 | RoomCommand = _messages$push_server.RoomCommand,
|
1811 | LogsCommand = _messages$push_server.LogsCommand,
|
1812 | RcpCommand = _messages$push_server.RcpCommand,
|
1813 | ReadTuple = _messages$push_server.ReadTuple,
|
1814 | MaxReadTuple = _messages$push_server.MaxReadTuple,
|
1815 | ReadCommand = _messages$push_server.ReadCommand,
|
1816 | PresenceCommand = _messages$push_server.PresenceCommand,
|
1817 | ReportCommand = _messages$push_server.ReportCommand,
|
1818 | GenericCommand = _messages$push_server.GenericCommand,
|
1819 | BlacklistCommand = _messages$push_server.BlacklistCommand,
|
1820 | PatchCommand = _messages$push_server.PatchCommand,
|
1821 | PatchItem = _messages$push_server.PatchItem,
|
1822 | ConvMemberInfo = _messages$push_server.ConvMemberInfo,
|
1823 | CommandType = _messages$push_server.CommandType,
|
1824 | OpType = _messages$push_server.OpType,
|
1825 | StatusType = _messages$push_server.StatusType;
|
1826 |
|
1827 | var message = Object.freeze({
|
1828 | JsonObjectMessage: JsonObjectMessage,
|
1829 | UnreadTuple: UnreadTuple,
|
1830 | LogItem: LogItem,
|
1831 | DataCommand: DataCommand,
|
1832 | SessionCommand: SessionCommand,
|
1833 | ErrorCommand: ErrorCommand,
|
1834 | DirectCommand: DirectCommand,
|
1835 | AckCommand: AckCommand,
|
1836 | UnreadCommand: UnreadCommand,
|
1837 | ConvCommand: ConvCommand,
|
1838 | RoomCommand: RoomCommand,
|
1839 | LogsCommand: LogsCommand,
|
1840 | RcpCommand: RcpCommand,
|
1841 | ReadTuple: ReadTuple,
|
1842 | MaxReadTuple: MaxReadTuple,
|
1843 | ReadCommand: ReadCommand,
|
1844 | PresenceCommand: PresenceCommand,
|
1845 | ReportCommand: ReportCommand,
|
1846 | GenericCommand: GenericCommand,
|
1847 | BlacklistCommand: BlacklistCommand,
|
1848 | PatchCommand: PatchCommand,
|
1849 | PatchItem: PatchItem,
|
1850 | ConvMemberInfo: ConvMemberInfo,
|
1851 | CommandType: CommandType,
|
1852 | OpType: OpType,
|
1853 | StatusType: StatusType
|
1854 | });
|
1855 |
|
1856 |
|
1857 | var global$1 = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : {};
|
1858 |
|
1859 | var EXPIRED = Symbol('expired');
|
1860 | var debug = d('LC:Expirable');
|
1861 |
|
1862 | var Expirable =
|
1863 |
|
1864 | function () {
|
1865 | function Expirable(value, ttl) {
|
1866 | this.originalValue = value;
|
1867 |
|
1868 | if (typeof ttl === 'number') {
|
1869 | this.expiredAt = Date.now() + ttl;
|
1870 | }
|
1871 | }
|
1872 |
|
1873 | _createClass(Expirable, [{
|
1874 | key: "value",
|
1875 | get: function get() {
|
1876 | var expired = this.expiredAt && this.expiredAt <= Date.now();
|
1877 | if (expired) debug("expired: ".concat(this.originalValue));
|
1878 | return expired ? EXPIRED : this.originalValue;
|
1879 | }
|
1880 | }]);
|
1881 |
|
1882 | return Expirable;
|
1883 | }();
|
1884 | Expirable.EXPIRED = EXPIRED;
|
1885 |
|
1886 | var debug$1 = d('LC:Cache');
|
1887 |
|
1888 | var Cache =
|
1889 |
|
1890 | function () {
|
1891 | function Cache() {
|
1892 | var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'anonymous';
|
1893 | this.name = name;
|
1894 | this._map = {};
|
1895 | }
|
1896 |
|
1897 | var _proto = Cache.prototype;
|
1898 |
|
1899 | _proto.get = function get(key) {
|
1900 | var cache = this._map[key];
|
1901 |
|
1902 | if (cache) {
|
1903 | var value = cache.value;
|
1904 |
|
1905 | if (value !== Expirable.EXPIRED) {
|
1906 | debug$1('[%s] hit: %s', this.name, key);
|
1907 | return value;
|
1908 | }
|
1909 |
|
1910 | delete this._map[key];
|
1911 | }
|
1912 |
|
1913 | debug$1("[".concat(this.name, "] missed: ").concat(key));
|
1914 | return null;
|
1915 | };
|
1916 |
|
1917 | _proto.set = function set(key, value, ttl) {
|
1918 | debug$1('[%s] set: %s %d', this.name, key, ttl);
|
1919 | this._map[key] = new Expirable(value, ttl);
|
1920 | };
|
1921 |
|
1922 | return Cache;
|
1923 | }();
|
1924 |
|
1925 | var debug$2 = {
|
1926 | enable: function enable() {
|
1927 | var namespaces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'LC*';
|
1928 | return d.enable(namespaces);
|
1929 | },
|
1930 | disable: d.disable
|
1931 | };
|
1932 | var tryAll = function tryAll(promiseConstructors) {
|
1933 | var promise = new Promise(promiseConstructors[0]);
|
1934 |
|
1935 | if (promiseConstructors.length === 1) {
|
1936 | return promise;
|
1937 | }
|
1938 |
|
1939 | return promise.catch(function () {
|
1940 | return tryAll(promiseConstructors.slice(1));
|
1941 | });
|
1942 | };
|
1943 |
|
1944 | var tap = function tap(interceptor) {
|
1945 | return function (value) {
|
1946 | return interceptor(value), value;
|
1947 | };
|
1948 | };
|
1949 | var finalize = function finalize(callback) {
|
1950 | return [
|
1951 | function (value) {
|
1952 | return callback(), value;
|
1953 | }, function (error) {
|
1954 | callback();
|
1955 | throw error;
|
1956 | }];
|
1957 | };
|
1958 |
|
1959 |
|
1960 |
|
1961 |
|
1962 |
|
1963 |
|
1964 | var decodeDate = function decodeDate(date) {
|
1965 | if (!date) return date;
|
1966 |
|
1967 | if (typeof date === 'string' || typeof date === 'number') {
|
1968 | return new Date(date);
|
1969 | }
|
1970 |
|
1971 | if (date.__type === 'Date' && date.iso) {
|
1972 | return new Date(date.iso);
|
1973 | }
|
1974 |
|
1975 |
|
1976 | if (typeof date.toNumber === 'function') {
|
1977 | return new Date(date.toNumber());
|
1978 | }
|
1979 |
|
1980 | return date;
|
1981 | };
|
1982 |
|
1983 |
|
1984 |
|
1985 |
|
1986 |
|
1987 | var getTime = function getTime(date) {
|
1988 | return date && date.getTime ? date.getTime() : undefined;
|
1989 | };
|
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 | var decode = function decode(value) {
|
1997 | if (!value) return value;
|
1998 |
|
1999 | if (value.__type === 'Date' && value.iso) {
|
2000 | return new Date(value.iso);
|
2001 | }
|
2002 |
|
2003 | if (Array.isArray(value)) {
|
2004 | return value.map(decode);
|
2005 | }
|
2006 |
|
2007 | if (isPlainObject(value)) {
|
2008 | return Object.keys(value).reduce(function (result, key) {
|
2009 | return _objectSpread({}, result, _defineProperty({}, key, decode(value[key])));
|
2010 | }, {});
|
2011 | }
|
2012 |
|
2013 | return value;
|
2014 | };
|
2015 |
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 | var encode = function encode(value) {
|
2022 | if (value instanceof Date) return {
|
2023 | __type: 'Date',
|
2024 | iso: value.toJSON()
|
2025 | };
|
2026 |
|
2027 | if (Array.isArray(value)) {
|
2028 | return value.map(encode);
|
2029 | }
|
2030 |
|
2031 | if (isPlainObject(value)) {
|
2032 | return Object.keys(value).reduce(function (result, key) {
|
2033 | return _objectSpread({}, result, _defineProperty({}, key, encode(value[key])));
|
2034 | }, {});
|
2035 | }
|
2036 |
|
2037 | return value;
|
2038 | };
|
2039 | var keyRemap = function keyRemap(keymap, obj) {
|
2040 | return Object.keys(obj).reduce(function (newObj, key) {
|
2041 | var newKey = keymap[key] || key;
|
2042 | return Object.assign(newObj, _defineProperty({}, newKey, obj[key]));
|
2043 | }, {});
|
2044 | };
|
2045 | var isIE10 = global$1.navigator && global$1.navigator.userAgent && global$1.navigator.userAgent.indexOf('MSIE 10.') !== -1;
|
2046 |
|
2047 |
|
2048 | var getStaticProperty = function getStaticProperty(klass, property) {
|
2049 | return klass[property] || (klass.__proto__ ? getStaticProperty(klass.__proto__, property) : undefined);
|
2050 | };
|
2051 |
|
2052 |
|
2053 | var union = function union(a, b) {
|
2054 | return Array.from(new Set([].concat(_toConsumableArray(a), _toConsumableArray(b))));
|
2055 | };
|
2056 | var difference = function difference(a, b) {
|
2057 | return Array.from(function (bSet) {
|
2058 | return new Set(a.filter(function (x) {
|
2059 | return !bSet.has(x);
|
2060 | }));
|
2061 | }(new Set(b)));
|
2062 | };
|
2063 | var map = new WeakMap();
|
2064 |
|
2065 | var internal = function internal(object) {
|
2066 | if (!map.has(object)) {
|
2067 | map.set(object, {});
|
2068 | }
|
2069 |
|
2070 | return map.get(object);
|
2071 | };
|
2072 | var compact = function compact(obj, filter) {
|
2073 | if (!isPlainObject(obj)) return obj;
|
2074 | var object = Object.assign({}, obj);
|
2075 |
|
2076 | for (var prop in object) {
|
2077 | if ({}.hasOwnProperty.call(object, prop)) {
|
2078 | var value = object[prop];
|
2079 |
|
2080 | if (value === filter) {
|
2081 | delete object[prop];
|
2082 | } else {
|
2083 | object[prop] = compact(value, filter);
|
2084 | }
|
2085 | }
|
2086 | }
|
2087 |
|
2088 | return object;
|
2089 | };
|
2090 |
|
2091 | var removeNull = function removeNull(obj) {
|
2092 | return compact(obj, null);
|
2093 | };
|
2094 |
|
2095 | var trim = function trim(message) {
|
2096 | return removeNull(JSON.parse(JSON.stringify(message)));
|
2097 | };
|
2098 | var ensureArray = function ensureArray(target) {
|
2099 | if (Array.isArray(target)) {
|
2100 | return target;
|
2101 | }
|
2102 |
|
2103 | if (target === undefined || target === null) {
|
2104 | return [];
|
2105 | }
|
2106 |
|
2107 | return [target];
|
2108 | };
|
2109 | var setValue = function setValue(target, key, value) {
|
2110 |
|
2111 | var segs = key.split('.');
|
2112 | var lastSeg = segs.pop();
|
2113 | var currentTarget = target;
|
2114 | segs.forEach(function (seg) {
|
2115 | if (currentTarget[seg] === undefined) currentTarget[seg] = {};
|
2116 | currentTarget = currentTarget[seg];
|
2117 | });
|
2118 | currentTarget[lastSeg] = value;
|
2119 | return target;
|
2120 | };
|
2121 | var isWeapp =
|
2122 | (typeof wx === "undefined" ? "undefined" : _typeof(wx)) === 'object' && typeof wx.connectSocket === 'function';
|
2123 |
|
2124 | var throttle = function throttle(wait) {
|
2125 | return function (target, property, descriptor) {
|
2126 | var callback = descriptor.value;
|
2127 |
|
2128 | if (callback.length) {
|
2129 | throw new Error('throttled function should not accept any arguments');
|
2130 | }
|
2131 |
|
2132 | return _objectSpread({}, descriptor, {
|
2133 | value: function value() {
|
2134 | var _this = this;
|
2135 |
|
2136 | var _internal = internal(this),
|
2137 | throttleMeta = _internal.throttleMeta;
|
2138 |
|
2139 | if (!throttleMeta) {
|
2140 | throttleMeta = {};
|
2141 | internal(this).throttleMeta = throttleMeta;
|
2142 | }
|
2143 |
|
2144 | var _throttleMeta = throttleMeta,
|
2145 | propertyMeta = _throttleMeta[property];
|
2146 |
|
2147 | if (!propertyMeta) {
|
2148 | propertyMeta = {};
|
2149 | throttleMeta[property] = propertyMeta;
|
2150 | }
|
2151 |
|
2152 | var _propertyMeta = propertyMeta,
|
2153 | _propertyMeta$previou = _propertyMeta.previouseTimestamp,
|
2154 | previouseTimestamp = _propertyMeta$previou === void 0 ? 0 : _propertyMeta$previou,
|
2155 | timeout = _propertyMeta.timeout;
|
2156 | var now = Date.now();
|
2157 | var remainingTime = wait - (now - previouseTimestamp);
|
2158 |
|
2159 | if (remainingTime <= 0) {
|
2160 | throttleMeta[property].previouseTimestamp = now;
|
2161 | callback.apply(this);
|
2162 | } else if (!timeout) {
|
2163 | propertyMeta.timeout = setTimeout(function () {
|
2164 | propertyMeta.previouseTimestamp = Date.now();
|
2165 | delete propertyMeta.timeout;
|
2166 | callback.apply(_this);
|
2167 | }, remainingTime);
|
2168 | }
|
2169 | }
|
2170 | });
|
2171 | };
|
2172 | };
|
2173 | var isCNApp = function isCNApp(appId) {
|
2174 | return appId.slice(-9) !== '-MdYXbMMI';
|
2175 | };
|
2176 |
|
2177 | var _class;
|
2178 | var debug$3 = d('LC:WebSocketPlus');
|
2179 | var OPEN = 'open';
|
2180 | var DISCONNECT = 'disconnect';
|
2181 | var RECONNECT = 'reconnect';
|
2182 | var RETRY = 'retry';
|
2183 | var SCHEDULE = 'schedule';
|
2184 | var OFFLINE = 'offline';
|
2185 | var ONLINE = 'online';
|
2186 | var ERROR = 'error';
|
2187 | var MESSAGE = 'message';
|
2188 | var HEARTBEAT_TIME = 180000;
|
2189 | var TIMEOUT_TIME = 380000;
|
2190 |
|
2191 | var DEFAULT_RETRY_STRATEGY = function DEFAULT_RETRY_STRATEGY(attempt) {
|
2192 | return Math.min(1000 * Math.pow(2, attempt), 300000);
|
2193 | };
|
2194 |
|
2195 | var requireConnected = function requireConnected(target, name, descriptor) {
|
2196 | return Object.assign({}, descriptor, {
|
2197 | value: function requireConnectedWrapper() {
|
2198 | var _descriptor$value;
|
2199 |
|
2200 | this.checkConnectionAvailability(name);
|
2201 |
|
2202 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
2203 | args[_key] = arguments[_key];
|
2204 | }
|
2205 |
|
2206 | return (_descriptor$value = descriptor.value).call.apply(_descriptor$value, [this].concat(args));
|
2207 | }
|
2208 | });
|
2209 | };
|
2210 |
|
2211 | var WebSocketPlus = (_class =
|
2212 |
|
2213 | function (_EventEmitter) {
|
2214 | _inheritsLoose(WebSocketPlus, _EventEmitter);
|
2215 |
|
2216 | _createClass(WebSocketPlus, [{
|
2217 | key: "urls",
|
2218 | get: function get() {
|
2219 | return this._urls;
|
2220 | },
|
2221 | set: function set(urls) {
|
2222 | this._urls = ensureArray(urls);
|
2223 | }
|
2224 | }]);
|
2225 |
|
2226 | function WebSocketPlus(getUrls, protocol) {
|
2227 | var _this;
|
2228 |
|
2229 | if (typeof WebSocket === 'undefined') {
|
2230 | throw new Error('WebSocket is undefined. Polyfill is required in this runtime.');
|
2231 | }
|
2232 |
|
2233 | _this = _EventEmitter.call(this) || this;
|
2234 |
|
2235 | _this.init();
|
2236 |
|
2237 | _this._protocol = protocol;
|
2238 | Promise.resolve(typeof getUrls === 'function' ? getUrls() : getUrls).then(ensureArray).then(function (urls) {
|
2239 | _this._urls = urls;
|
2240 | return _this._open();
|
2241 | }).then(function () {
|
2242 | _this.__postponeTimeoutTimer = _this._postponeTimeoutTimer.bind(_assertThisInitialized(_this));
|
2243 |
|
2244 | if (global$1.addEventListener) {
|
2245 | _this.__pause = function () {
|
2246 | if (_this.can('pause')) _this.pause();
|
2247 | };
|
2248 |
|
2249 | _this.__resume = function () {
|
2250 | if (_this.can('resume')) _this.resume();
|
2251 | };
|
2252 |
|
2253 | global$1.addEventListener('offline', _this.__pause);
|
2254 | global$1.addEventListener('online', _this.__resume);
|
2255 | }
|
2256 |
|
2257 | _this.open();
|
2258 | }).catch(_this.throw.bind(_assertThisInitialized(_this)));
|
2259 | return _this;
|
2260 | }
|
2261 |
|
2262 | var _proto = WebSocketPlus.prototype;
|
2263 |
|
2264 | _proto._open = function _open() {
|
2265 | var _this2 = this;
|
2266 |
|
2267 | return this._createWs(this._urls, this._protocol).then(function (ws) {
|
2268 | var _this2$_urls = _toArray(_this2._urls),
|
2269 | first = _this2$_urls[0],
|
2270 | reset = _this2$_urls.slice(1);
|
2271 |
|
2272 | _this2._urls = [].concat(_toConsumableArray(reset), [first]);
|
2273 | return ws;
|
2274 | });
|
2275 | };
|
2276 |
|
2277 | _proto._createWs = function _createWs(urls, protocol) {
|
2278 | var _this3 = this;
|
2279 |
|
2280 | return tryAll(urls.map(function (url) {
|
2281 | return function (resolve, reject) {
|
2282 | debug$3("connect [".concat(url, "] ").concat(protocol));
|
2283 | var ws = protocol ? new WebSocket(url, protocol) : new WebSocket(url);
|
2284 | ws.binaryType = _this3.binaryType || 'arraybuffer';
|
2285 |
|
2286 | ws.onopen = function () {
|
2287 | return resolve(ws);
|
2288 | };
|
2289 |
|
2290 | ws.onclose = function (error) {
|
2291 | if (error instanceof Error) {
|
2292 | return reject(error);
|
2293 | }
|
2294 |
|
2295 |
|
2296 | return reject(new Error("Failed to connect [".concat(url, "]")));
|
2297 | };
|
2298 |
|
2299 | ws.onerror = ws.onclose;
|
2300 | };
|
2301 | })).then(function (ws) {
|
2302 | _this3._ws = ws;
|
2303 | _this3._ws.onclose = _this3._handleClose.bind(_this3);
|
2304 | _this3._ws.onmessage = _this3._handleMessage.bind(_this3);
|
2305 | return ws;
|
2306 | });
|
2307 | };
|
2308 |
|
2309 | _proto._destroyWs = function _destroyWs() {
|
2310 | var ws = this._ws;
|
2311 | if (!ws) return;
|
2312 | ws.onopen = null;
|
2313 | ws.onclose = null;
|
2314 | ws.onerror = null;
|
2315 | ws.onmessage = null;
|
2316 | this._ws = null;
|
2317 | ws.close();
|
2318 | }
|
2319 | ;
|
2320 |
|
2321 | _proto.onbeforeevent = function onbeforeevent(event, from, to) {
|
2322 | for (var _len2 = arguments.length, payload = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
2323 | payload[_key2 - 3] = arguments[_key2];
|
2324 | }
|
2325 |
|
2326 | debug$3("".concat(event, ": ").concat(from, " -> ").concat(to, " %o"), payload);
|
2327 | };
|
2328 |
|
2329 | _proto.onopen = function onopen() {
|
2330 | this.emit(OPEN);
|
2331 | };
|
2332 |
|
2333 | _proto.onconnected = function onconnected() {
|
2334 | this._startConnectionKeeper();
|
2335 | };
|
2336 |
|
2337 | _proto.onleaveconnected = function onleaveconnected(event, from, to) {
|
2338 | this._stopConnectionKeeper();
|
2339 |
|
2340 | this._destroyWs();
|
2341 |
|
2342 | if (to === 'offline' || to === 'disconnected') {
|
2343 | this.emit(DISCONNECT);
|
2344 | }
|
2345 | };
|
2346 |
|
2347 | _proto.onpause = function onpause() {
|
2348 | this.emit(OFFLINE);
|
2349 | };
|
2350 |
|
2351 | _proto.onbeforeresume = function onbeforeresume() {
|
2352 | this.emit(ONLINE);
|
2353 | };
|
2354 |
|
2355 | _proto.onreconnect = function onreconnect() {
|
2356 | this.emit(RECONNECT);
|
2357 | };
|
2358 |
|
2359 | _proto.ondisconnected = function ondisconnected(event, from, to) {
|
2360 | var _this4 = this;
|
2361 |
|
2362 | var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
2363 | var delay = DEFAULT_RETRY_STRATEGY.call(null, attempt);
|
2364 | debug$3("schedule attempt=".concat(attempt, " delay=").concat(delay));
|
2365 | this.emit(SCHEDULE, attempt, delay);
|
2366 |
|
2367 | if (this.__scheduledRetry) {
|
2368 | clearTimeout(this.__scheduledRetry);
|
2369 | }
|
2370 |
|
2371 | this.__scheduledRetry = setTimeout(function () {
|
2372 | if (_this4.is('disconnected')) {
|
2373 | _this4.retry(attempt);
|
2374 | }
|
2375 | }, delay);
|
2376 | };
|
2377 |
|
2378 | _proto.onretry = function onretry(event, from, to) {
|
2379 | var _this5 = this;
|
2380 |
|
2381 | var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
2382 | this.emit(RETRY, attempt);
|
2383 |
|
2384 | this._open().then(function () {
|
2385 | return _this5.can('reconnect') ? _this5.reconnect() : _this5._destroyWs();
|
2386 | }, function () {
|
2387 | return _this5.can('fail') && _this5.fail(attempt + 1);
|
2388 | });
|
2389 | };
|
2390 |
|
2391 | _proto.onerror = function onerror(event, from, to, error) {
|
2392 | this.emit(ERROR, error);
|
2393 | };
|
2394 |
|
2395 | _proto.onclose = function onclose() {
|
2396 | if (global$1.removeEventListener) {
|
2397 | if (this.__pause) global$1.removeEventListener('offline', this.__pause);
|
2398 | if (this.__resume) global$1.removeEventListener('online', this.__resume);
|
2399 | }
|
2400 | };
|
2401 |
|
2402 | _proto.checkConnectionAvailability = function checkConnectionAvailability() {
|
2403 | var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'API';
|
2404 |
|
2405 | if (!this.is('connected')) {
|
2406 | var currentState = this.current;
|
2407 | console.warn("".concat(name, " should not be called when the connection is ").concat(currentState));
|
2408 |
|
2409 | if (this.is('disconnected') || this.is('reconnecting')) {
|
2410 | console.warn('disconnect and reconnect event should be handled to avoid such calls.');
|
2411 | }
|
2412 |
|
2413 | throw new Error('Connection unavailable');
|
2414 | }
|
2415 | }
|
2416 | ;
|
2417 |
|
2418 | _proto.
|
2419 | _ping = function _ping() {
|
2420 | debug$3('ping');
|
2421 |
|
2422 | try {
|
2423 | this.ping();
|
2424 | } catch (error) {
|
2425 | console.warn("websocket ping error: ".concat(error.message));
|
2426 | }
|
2427 | };
|
2428 |
|
2429 | _proto.ping = function ping() {
|
2430 | if (this._ws.ping) {
|
2431 | this._ws.ping();
|
2432 | } else {
|
2433 | console.warn("The WebSocket implement does not support sending ping frame.\n Override ping method to use application defined ping/pong mechanism.");
|
2434 | }
|
2435 | };
|
2436 |
|
2437 | _proto._postponeTimeoutTimer = function _postponeTimeoutTimer() {
|
2438 | var _this6 = this;
|
2439 |
|
2440 | debug$3('_postponeTimeoutTimer');
|
2441 |
|
2442 | this._clearTimeoutTimers();
|
2443 |
|
2444 | this._timeoutTimer = setTimeout(function () {
|
2445 | debug$3('timeout');
|
2446 |
|
2447 | _this6.disconnect();
|
2448 | }, TIMEOUT_TIME);
|
2449 | };
|
2450 |
|
2451 | _proto._clearTimeoutTimers = function _clearTimeoutTimers() {
|
2452 | if (this._timeoutTimer) {
|
2453 | clearTimeout(this._timeoutTimer);
|
2454 | }
|
2455 | };
|
2456 |
|
2457 | _proto._startConnectionKeeper = function _startConnectionKeeper() {
|
2458 | debug$3('start connection keeper');
|
2459 | this._heartbeatTimer = setInterval(this._ping.bind(this), HEARTBEAT_TIME);
|
2460 | var addListener = this._ws.addListener || this._ws.addEventListener;
|
2461 |
|
2462 | if (!addListener) {
|
2463 | debug$3('connection keeper disabled due to the lack of #addEventListener.');
|
2464 | return;
|
2465 | }
|
2466 |
|
2467 | addListener.call(this._ws, 'message', this.__postponeTimeoutTimer);
|
2468 | addListener.call(this._ws, 'pong', this.__postponeTimeoutTimer);
|
2469 |
|
2470 | this._postponeTimeoutTimer();
|
2471 | };
|
2472 |
|
2473 | _proto._stopConnectionKeeper = function _stopConnectionKeeper() {
|
2474 | debug$3('stop connection keeper');
|
2475 |
|
2476 | var removeListener = this._ws.removeListener || this._ws.removeEventListener;
|
2477 |
|
2478 | if (removeListener) {
|
2479 | removeListener.call(this._ws, 'message', this.__postponeTimeoutTimer);
|
2480 | removeListener.call(this._ws, 'pong', this.__postponeTimeoutTimer);
|
2481 |
|
2482 | this._clearTimeoutTimers();
|
2483 | }
|
2484 |
|
2485 | if (this._heartbeatTimer) {
|
2486 | clearInterval(this._heartbeatTimer);
|
2487 | }
|
2488 | };
|
2489 |
|
2490 | _proto._handleClose = function _handleClose(event) {
|
2491 | debug$3("ws closed [".concat(event.code, "] ").concat(event.reason));
|
2492 |
|
2493 | if (this.isFinished()) return;
|
2494 | this.handleClose(event);
|
2495 | };
|
2496 |
|
2497 | _proto.handleClose = function handleClose() {
|
2498 |
|
2499 | this.disconnect();
|
2500 | }
|
2501 | ;
|
2502 |
|
2503 | _proto.
|
2504 | send = function send(data) {
|
2505 | debug$3('send', data);
|
2506 |
|
2507 | this._ws.send(data);
|
2508 | };
|
2509 |
|
2510 | _proto._handleMessage = function _handleMessage(event) {
|
2511 | debug$3('message', event.data);
|
2512 | this.handleMessage(event.data);
|
2513 | };
|
2514 |
|
2515 | _proto.handleMessage = function handleMessage(message) {
|
2516 | this.emit(MESSAGE, message);
|
2517 | };
|
2518 |
|
2519 | return WebSocketPlus;
|
2520 | }(EventEmitter), (_applyDecoratedDescriptor(_class.prototype, "_ping", [requireConnected], Object.getOwnPropertyDescriptor(_class.prototype, "_ping"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "send", [requireConnected], Object.getOwnPropertyDescriptor(_class.prototype, "send"), _class.prototype)), _class);
|
2521 | StateMachine.create({
|
2522 | target: WebSocketPlus.prototype,
|
2523 | initial: {
|
2524 | state: 'initialized',
|
2525 | event: 'init',
|
2526 | defer: true
|
2527 | },
|
2528 | terminal: 'closed',
|
2529 | events: [{
|
2530 | name: 'open',
|
2531 | from: 'initialized',
|
2532 | to: 'connected'
|
2533 | }, {
|
2534 | name: 'disconnect',
|
2535 | from: 'connected',
|
2536 | to: 'disconnected'
|
2537 | }, {
|
2538 | name: 'retry',
|
2539 | from: 'disconnected',
|
2540 | to: 'reconnecting'
|
2541 | }, {
|
2542 | name: 'fail',
|
2543 | from: 'reconnecting',
|
2544 | to: 'disconnected'
|
2545 | }, {
|
2546 | name: 'reconnect',
|
2547 | from: 'reconnecting',
|
2548 | to: 'connected'
|
2549 | }, {
|
2550 | name: 'pause',
|
2551 | from: ['connected', 'disconnected', 'reconnecting'],
|
2552 | to: 'offline'
|
2553 | }, {}, {
|
2554 | name: 'resume',
|
2555 | from: 'offline',
|
2556 | to: 'disconnected'
|
2557 | }, {
|
2558 | name: 'close',
|
2559 | from: ['connected', 'disconnected', 'reconnecting', 'offline'],
|
2560 | to: 'closed'
|
2561 | }, {
|
2562 | name: 'throw',
|
2563 | from: '*',
|
2564 | to: 'error'
|
2565 | }]
|
2566 | });
|
2567 |
|
2568 | var error = Object.freeze({
|
2569 | 1000: {
|
2570 | name: 'CLOSE_NORMAL'
|
2571 | },
|
2572 | 1006: {
|
2573 | name: 'CLOSE_ABNORMAL'
|
2574 | },
|
2575 | 4100: {
|
2576 | name: 'APP_NOT_AVAILABLE',
|
2577 | message: 'App not exists or realtime message service is disabled.'
|
2578 | },
|
2579 | 4102: {
|
2580 | name: 'SIGNATURE_FAILED',
|
2581 | message: 'Login signature mismatch.'
|
2582 | },
|
2583 | 4103: {
|
2584 | name: 'INVALID_LOGIN',
|
2585 | message: 'Malformed clientId.'
|
2586 | },
|
2587 | 4105: {
|
2588 | name: 'SESSION_REQUIRED',
|
2589 | message: 'Message sent before session opened.'
|
2590 | },
|
2591 | 4107: {
|
2592 | name: 'READ_TIMEOUT'
|
2593 | },
|
2594 | 4108: {
|
2595 | name: 'LOGIN_TIMEOUT'
|
2596 | },
|
2597 | 4109: {
|
2598 | name: 'FRAME_TOO_LONG'
|
2599 | },
|
2600 | 4110: {
|
2601 | name: 'INVALID_ORIGIN',
|
2602 | message: 'Access denied by domain whitelist.'
|
2603 | },
|
2604 | 4111: {
|
2605 | name: 'SESSION_CONFLICT'
|
2606 | },
|
2607 | 4112: {
|
2608 | name: 'SESSION_TOKEN_EXPIRED'
|
2609 | },
|
2610 | 4113: {
|
2611 | name: 'APP_QUOTA_EXCEEDED',
|
2612 | message: 'The daily active users limit exceeded.'
|
2613 | },
|
2614 | 4116: {
|
2615 | name: 'MESSAGE_SENT_QUOTA_EXCEEDED',
|
2616 | message: 'Command sent too fast.'
|
2617 | },
|
2618 | 4200: {
|
2619 | name: 'INTERNAL_ERROR',
|
2620 | message: 'Internal error, please contact LeanCloud for support.'
|
2621 | },
|
2622 | 4301: {
|
2623 | name: 'CONVERSATION_API_FAILED',
|
2624 | message: 'Upstream Conversatoin API failed, see error.detail for details.'
|
2625 | },
|
2626 | 4302: {
|
2627 | name: 'CONVERSATION_SIGNATURE_FAILED',
|
2628 | message: 'Conversation action signature mismatch.'
|
2629 | },
|
2630 | 4303: {
|
2631 | name: 'CONVERSATION_NOT_FOUND'
|
2632 | },
|
2633 | 4304: {
|
2634 | name: 'CONVERSATION_FULL'
|
2635 | },
|
2636 | 4305: {
|
2637 | name: 'CONVERSATION_REJECTED_BY_APP',
|
2638 | message: 'Conversation action rejected by hook.'
|
2639 | },
|
2640 | 4306: {
|
2641 | name: 'CONVERSATION_UPDATE_FAILED'
|
2642 | },
|
2643 | 4307: {
|
2644 | name: 'CONVERSATION_READ_ONLY'
|
2645 | },
|
2646 | 4308: {
|
2647 | name: 'CONVERSATION_NOT_ALLOWED'
|
2648 | },
|
2649 | 4309: {
|
2650 | name: 'CONVERSATION_UPDATE_REJECTED',
|
2651 | message: 'Conversation update rejected because the client is not a member.'
|
2652 | },
|
2653 | 4310: {
|
2654 | name: 'CONVERSATION_QUERY_FAILED',
|
2655 | message: 'Conversation query failed because it is too expansive.'
|
2656 | },
|
2657 | 4311: {
|
2658 | name: 'CONVERSATION_LOG_FAILED'
|
2659 | },
|
2660 | 4312: {
|
2661 | name: 'CONVERSATION_LOG_REJECTED',
|
2662 | message: 'Message query rejected because the client is not a member of the conversation.'
|
2663 | },
|
2664 | 4313: {
|
2665 | name: 'SYSTEM_CONVERSATION_REQUIRED'
|
2666 | },
|
2667 | 4314: {
|
2668 | name: 'NORMAL_CONVERSATION_REQUIRED'
|
2669 | },
|
2670 | 4315: {
|
2671 | name: 'CONVERSATION_BLACKLISTED',
|
2672 | message: 'Blacklisted in the conversation.'
|
2673 | },
|
2674 | 4316: {
|
2675 | name: 'TRANSIENT_CONVERSATION_REQUIRED'
|
2676 | },
|
2677 | 4317: {
|
2678 | name: 'CONVERSATION_MEMBERSHIP_REQUIRED'
|
2679 | },
|
2680 | 4318: {
|
2681 | name: 'CONVERSATION_API_QUOTA_EXCEEDED',
|
2682 | message: 'LeanCloud API quota exceeded. You may upgrade your plan.'
|
2683 | },
|
2684 | 4323: {
|
2685 | name: 'TEMPORARY_CONVERSATION_EXPIRED',
|
2686 | message: 'Temporary conversation expired or does not exist.'
|
2687 | },
|
2688 | 4401: {
|
2689 | name: 'INVALID_MESSAGING_TARGET',
|
2690 | message: 'Conversation does not exist or client is not a member.'
|
2691 | },
|
2692 | 4402: {
|
2693 | name: 'MESSAGE_REJECTED_BY_APP',
|
2694 | message: 'Message rejected by hook.'
|
2695 | },
|
2696 | 4403: {
|
2697 | name: 'MESSAGE_OWNERSHIP_REQUIRED'
|
2698 | },
|
2699 | 4404: {
|
2700 | name: 'MESSAGE_NOT_FOUND'
|
2701 | },
|
2702 | 4405: {
|
2703 | name: 'MESSAGE_UPDATE_REJECTED_BY_APP',
|
2704 | message: 'Message update rejected by hook.'
|
2705 | },
|
2706 | 4406: {
|
2707 | name: 'MESSAGE_EDIT_DISABLED'
|
2708 | },
|
2709 | 4407: {
|
2710 | name: 'MESSAGE_RECALL_DISABLED'
|
2711 | },
|
2712 | 5130: {
|
2713 | name: 'OWNER_PROMOTION_NOT_ALLOWED',
|
2714 | message: "Updating a member's role to owner is not allowed."
|
2715 | }
|
2716 | });
|
2717 | var ErrorCode = Object.freeze(Object.keys(error).reduce(function (result, code) {
|
2718 | return Object.assign(result, _defineProperty({}, error[code].name, Number(code)));
|
2719 | }, {}));
|
2720 | var createError = function createError(_ref) {
|
2721 | var code = _ref.code,
|
2722 | reason = _ref.reason,
|
2723 | appCode = _ref.appCode,
|
2724 | detail = _ref.detail,
|
2725 | errorMessage = _ref.error;
|
2726 | var message = reason || detail || errorMessage;
|
2727 | var name = reason;
|
2728 |
|
2729 | if (!message && error[code]) {
|
2730 | name = error[code].name;
|
2731 | message = error[code].message || name;
|
2732 | }
|
2733 |
|
2734 | if (!message) {
|
2735 | message = "Unknow Error: ".concat(code);
|
2736 | }
|
2737 |
|
2738 | var err = new Error(message);
|
2739 | return Object.assign(err, {
|
2740 | code: code,
|
2741 | appCode: appCode,
|
2742 | detail: detail,
|
2743 | name: name
|
2744 | });
|
2745 | };
|
2746 |
|
2747 | var debug$4 = d('LC:Connection');
|
2748 | var COMMAND_TIMEOUT = 20000;
|
2749 | var EXPIRE = Symbol('expire');
|
2750 |
|
2751 | var Connection =
|
2752 |
|
2753 | function (_WebSocketPlus) {
|
2754 | _inheritsLoose(Connection, _WebSocketPlus);
|
2755 |
|
2756 | function Connection(getUrl, _ref) {
|
2757 | var _this;
|
2758 |
|
2759 | var format = _ref.format,
|
2760 | version = _ref.version;
|
2761 | debug$4('initializing Connection');
|
2762 | var protocolString = "lc.".concat(format, ".").concat(version);
|
2763 |
|
2764 | if (!isWeapp) {
|
2765 | _this = _WebSocketPlus.call(this, getUrl, protocolString) || this;
|
2766 | } else {
|
2767 | _this = _WebSocketPlus.call(this, getUrl().then(function (urls) {
|
2768 | return urls.map(function (url) {
|
2769 | return "".concat(url).concat(url.indexOf('?') === -1 ? '?' : '&', "subprotocol=").concat(encodeURIComponent(protocolString));
|
2770 | });
|
2771 | })) || this;
|
2772 | }
|
2773 |
|
2774 | _this._protocalFormat = format;
|
2775 | _this._commands = {};
|
2776 | _this._serialId = 0;
|
2777 | return _assertThisInitialized(_this);
|
2778 | }
|
2779 |
|
2780 | var _proto = Connection.prototype;
|
2781 |
|
2782 | _proto.send =
|
2783 |
|
2784 | function () {
|
2785 | var _send = _asyncToGenerator(
|
2786 |
|
2787 | _regeneratorRuntime.mark(function _callee(command) {
|
2788 | var _this2 = this;
|
2789 |
|
2790 | var waitingForRespond,
|
2791 | serialId,
|
2792 | message,
|
2793 | _args = arguments;
|
2794 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
2795 | while (1) {
|
2796 | switch (_context.prev = _context.next) {
|
2797 | case 0:
|
2798 | waitingForRespond = _args.length > 1 && _args[1] !== undefined ? _args[1] : true;
|
2799 |
|
2800 | if (waitingForRespond) {
|
2801 | this._serialId += 1;
|
2802 | serialId = this._serialId;
|
2803 | command.i = serialId;
|
2804 | }
|
2805 |
|
2806 | if (debug$4.enabled) debug$4('↑ %O sent', trim(command));
|
2807 |
|
2808 | if (this._protocalFormat === 'proto2base64') {
|
2809 | message = command.toBase64();
|
2810 | } else if (command.toArrayBuffer) {
|
2811 | message = command.toArrayBuffer();
|
2812 | }
|
2813 |
|
2814 | if (message) {
|
2815 | _context.next = 6;
|
2816 | break;
|
2817 | }
|
2818 |
|
2819 | throw new TypeError("".concat(command, " is not a GenericCommand"));
|
2820 |
|
2821 | case 6:
|
2822 | _WebSocketPlus.prototype.send.call(this, message);
|
2823 |
|
2824 | if (waitingForRespond) {
|
2825 | _context.next = 9;
|
2826 | break;
|
2827 | }
|
2828 |
|
2829 | return _context.abrupt("return", undefined);
|
2830 |
|
2831 | case 9:
|
2832 | return _context.abrupt("return", new Promise(function (resolve, reject) {
|
2833 | _this2._commands[serialId] = {
|
2834 | resolve: resolve,
|
2835 | reject: reject,
|
2836 | timeout: setTimeout(function () {
|
2837 | if (_this2._commands[serialId]) {
|
2838 | if (debug$4.enabled) debug$4('✗ %O timeout', trim(command));
|
2839 | reject(createError({
|
2840 | error: "Command Timeout [cmd:".concat(command.cmd, " op:").concat(command.op, "]"),
|
2841 | name: 'COMMAND_TIMEOUT'
|
2842 | }));
|
2843 | delete _this2._commands[serialId];
|
2844 | }
|
2845 | }, COMMAND_TIMEOUT)
|
2846 | };
|
2847 | }));
|
2848 |
|
2849 | case 10:
|
2850 | case "end":
|
2851 | return _context.stop();
|
2852 | }
|
2853 | }
|
2854 | }, _callee, this);
|
2855 | }));
|
2856 |
|
2857 | function send(_x) {
|
2858 | return _send.apply(this, arguments);
|
2859 | }
|
2860 |
|
2861 | return send;
|
2862 | }();
|
2863 |
|
2864 | _proto.handleMessage = function handleMessage(msg) {
|
2865 | var message;
|
2866 |
|
2867 | try {
|
2868 | message = GenericCommand.decode(msg);
|
2869 | if (debug$4.enabled) debug$4('↓ %O received', trim(message));
|
2870 | } catch (e) {
|
2871 | console.warn('Decode message failed:', e.message, msg);
|
2872 | return;
|
2873 | }
|
2874 |
|
2875 | var serialId = message.i;
|
2876 |
|
2877 | if (serialId) {
|
2878 | if (this._commands[serialId]) {
|
2879 | clearTimeout(this._commands[serialId].timeout);
|
2880 |
|
2881 | if (message.cmd === CommandType.error) {
|
2882 | this._commands[serialId].reject(createError(message.errorMessage));
|
2883 | } else {
|
2884 | this._commands[serialId].resolve(message);
|
2885 | }
|
2886 |
|
2887 | delete this._commands[serialId];
|
2888 | } else {
|
2889 | console.warn("Unexpected command received with serialId [".concat(serialId, "],\n which have timed out or never been requested."));
|
2890 | }
|
2891 | } else {
|
2892 | switch (message.cmd) {
|
2893 | case CommandType.error:
|
2894 | {
|
2895 | this.emit(ERROR, createError(message.errorMessage));
|
2896 | return;
|
2897 | }
|
2898 |
|
2899 | case CommandType.goaway:
|
2900 | {
|
2901 | this.emit(EXPIRE);
|
2902 | return;
|
2903 | }
|
2904 |
|
2905 | default:
|
2906 | {
|
2907 | this.emit(MESSAGE, message);
|
2908 | }
|
2909 | }
|
2910 | }
|
2911 | };
|
2912 |
|
2913 | _proto.ping = function ping() {
|
2914 | return this.send(new GenericCommand({
|
2915 | cmd: CommandType.echo
|
2916 | })).catch(function (error) {
|
2917 | return debug$4('ping failed:', error);
|
2918 | });
|
2919 | };
|
2920 |
|
2921 | return Connection;
|
2922 | }(WebSocketPlus);
|
2923 |
|
2924 | var checkType = function checkType(middleware) {
|
2925 | return function (param) {
|
2926 | var constructor = param.constructor;
|
2927 | return Promise.resolve(param).then(middleware).then(tap(function (result) {
|
2928 | if (result === undefined || result === null) {
|
2929 |
|
2930 | return console.warn("Middleware[".concat(middleware._pluginName || 'anonymous plugin', ":").concat(middleware.name || 'anonymous middleware', "] param/return types not match. It returns ").concat(result, " while a ").concat(param.constructor.name, " expected."));
|
2931 | }
|
2932 |
|
2933 | if (!(result instanceof constructor)) {
|
2934 |
|
2935 | return console.warn("Middleware[".concat(middleware._pluginName || 'anonymous plugin', ":").concat(middleware.name || 'anonymous middleware', "] param/return types not match. It returns a ").concat(result.constructor.name, " while a ").concat(param.constructor.name, " expected."));
|
2936 | }
|
2937 |
|
2938 | return 0;
|
2939 | }));
|
2940 | };
|
2941 | };
|
2942 |
|
2943 | var applyDecorators = function applyDecorators(decorators, target) {
|
2944 | if (decorators) {
|
2945 | decorators.forEach(function (decorator) {
|
2946 | try {
|
2947 | decorator(target);
|
2948 | } catch (error) {
|
2949 | if (decorator._pluginName) {
|
2950 | error.message += "[".concat(decorator._pluginName, "]");
|
2951 | }
|
2952 |
|
2953 | throw error;
|
2954 | }
|
2955 | });
|
2956 | }
|
2957 | };
|
2958 | var applyMiddlewares = function applyMiddlewares(middlewares) {
|
2959 | return function (target) {
|
2960 | return ensureArray(middlewares).reduce(function (previousPromise, middleware) {
|
2961 | return previousPromise.then(checkType(middleware)).catch(function (error) {
|
2962 | if (middleware._pluginName) {
|
2963 |
|
2964 | error.message += "[".concat(middleware._pluginName, "]");
|
2965 | }
|
2966 |
|
2967 | throw error;
|
2968 | });
|
2969 | }, Promise.resolve(target));
|
2970 | };
|
2971 | };
|
2972 | var applyDispatcher = function applyDispatcher(dispatchers, payload) {
|
2973 | return ensureArray(dispatchers).reduce(function (resultPromise, dispatcher) {
|
2974 | return resultPromise.then(function (shouldDispatch) {
|
2975 | return shouldDispatch === false ? false : dispatcher.apply(void 0, _toConsumableArray(payload));
|
2976 | }).catch(function (error) {
|
2977 | if (dispatcher._pluginName) {
|
2978 |
|
2979 | error.message += "[".concat(dispatcher._pluginName, "]");
|
2980 | }
|
2981 |
|
2982 | throw error;
|
2983 | });
|
2984 | }, Promise.resolve(true));
|
2985 | };
|
2986 |
|
2987 | var version = "5.0.0-beta.0";
|
2988 |
|
2989 | var debug$5 = d('LC:Realtime');
|
2990 | var debugRequest = d('LC:request');
|
2991 | var routerCache = new Cache('push-router');
|
2992 |
|
2993 | var Realtime =
|
2994 |
|
2995 | function (_EventEmitter) {
|
2996 | _inheritsLoose(Realtime, _EventEmitter);
|
2997 |
|
2998 | |
2999 |
|
3000 |
|
3001 |
|
3002 |
|
3003 |
|
3004 |
|
3005 |
|
3006 |
|
3007 |
|
3008 |
|
3009 |
|
3010 |
|
3011 | function Realtime(_ref) {
|
3012 | var _this2;
|
3013 |
|
3014 | var plugins = _ref.plugins,
|
3015 | options = _objectWithoutProperties(_ref, ["plugins"]);
|
3016 |
|
3017 | debug$5('initializing Realtime %s %O', version, options);
|
3018 | _this2 = _EventEmitter.call(this) || this;
|
3019 |
|
3020 | if (typeof options.appId !== 'string') {
|
3021 | throw new TypeError("appId [".concat(options.appId, "] is not a string"));
|
3022 | }
|
3023 |
|
3024 | if (typeof options.appKey !== 'string') {
|
3025 | throw new TypeError("appKey [".concat(options.appKey, "] is not a string"));
|
3026 | }
|
3027 |
|
3028 | if (isCNApp(options.appId)) {
|
3029 | if (!options.server) {
|
3030 | throw new TypeError("server option is required for apps from CN region");
|
3031 | }
|
3032 | }
|
3033 |
|
3034 | _this2._options = Object.assign({
|
3035 | appId: undefined,
|
3036 | appKey: undefined,
|
3037 | pushOfflineMessages: false,
|
3038 | noBinary: false,
|
3039 | ssl: true,
|
3040 | RTMServerName: process.env.RTM_SERVER_NAME
|
3041 |
|
3042 | }, options);
|
3043 | _this2._cache = new Cache('endpoints');
|
3044 |
|
3045 | var _this = internal(_assertThisInitialized(_this2));
|
3046 |
|
3047 | _this.clients = new Set();
|
3048 | _this.pendingClients = new Set();
|
3049 | var mergedPlugins = [].concat(_toConsumableArray(ensureArray(Realtime.__preRegisteredPlugins)), _toConsumableArray(ensureArray(plugins)));
|
3050 | debug$5('Using plugins %o', mergedPlugins.map(function (plugin) {
|
3051 | return plugin.name;
|
3052 | }));
|
3053 | _this2._plugins = mergedPlugins.reduce(function (result, plugin) {
|
3054 |
|
3055 | for (var hook in plugin) {
|
3056 | if ({}.hasOwnProperty.call(plugin, hook) && hook !== 'name') {
|
3057 | if (plugin.name) {
|
3058 | ensureArray(plugin[hook]).forEach(function (value) {
|
3059 |
|
3060 | value._pluginName = plugin.name;
|
3061 | });
|
3062 | }
|
3063 |
|
3064 |
|
3065 | result[hook] = ensureArray(result[hook]).concat(plugin[hook]);
|
3066 | }
|
3067 | }
|
3068 |
|
3069 | return result;
|
3070 | }, {});
|
3071 |
|
3072 | applyDecorators(_this2._plugins.onRealtimeCreate, _assertThisInitialized(_this2));
|
3073 | return _this2;
|
3074 | }
|
3075 |
|
3076 | var _proto = Realtime.prototype;
|
3077 |
|
3078 | _proto._request =
|
3079 |
|
3080 | function () {
|
3081 | var _request2 = _asyncToGenerator(
|
3082 |
|
3083 | _regeneratorRuntime.mark(function _callee(_ref2) {
|
3084 | var method, _ref2$version, version, path, query, headers, _ref2$data, data, _this$_options, appId, server, _ref3, api, url;
|
3085 |
|
3086 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
3087 | while (1) {
|
3088 | switch (_context.prev = _context.next) {
|
3089 | case 0:
|
3090 | method = _ref2.method, _ref2$version = _ref2.version, version = _ref2$version === void 0 ? '1.1' : _ref2$version, path = _ref2.path, query = _ref2.query, headers = _ref2.headers, _ref2$data = _ref2.data, data = _ref2$data === void 0 ? {} : _ref2$data;
|
3091 | _this$_options = this._options, appId = _this$_options.appId, server = _this$_options.server;
|
3092 | _context.next = 4;
|
3093 | return this.constructor._getServerUrls({
|
3094 | appId: appId,
|
3095 | server: server
|
3096 | });
|
3097 |
|
3098 | case 4:
|
3099 | _ref3 = _context.sent;
|
3100 | api = _ref3.api;
|
3101 | url = "".concat(api, "/").concat(version).concat(path);
|
3102 | debugRequest('Req: %O %O %O', method, url, {
|
3103 | query: query,
|
3104 | headers: headers,
|
3105 | data: data
|
3106 | });
|
3107 | return _context.abrupt("return", superagent(method, url).set(_objectSpread({
|
3108 | 'X-LC-Id': this._options.appId,
|
3109 | 'X-LC-Key': this._options.appKey
|
3110 | }, headers)).query(query).send(data).then(function (response) {
|
3111 | debugRequest('Res: %O %O %O', url, response.status, response.body);
|
3112 | return response.body;
|
3113 | }, function (error) {
|
3114 | debugRequest('Error: %O %O %O', url, error.response.status, error.response.body);
|
3115 |
|
3116 | if (error.response && error.response.body && error.response.body.code) {
|
3117 | throw createError(error.response.body);
|
3118 | }
|
3119 |
|
3120 | throw error;
|
3121 | }));
|
3122 |
|
3123 | case 9:
|
3124 | case "end":
|
3125 | return _context.stop();
|
3126 | }
|
3127 | }
|
3128 | }, _callee, this);
|
3129 | }));
|
3130 |
|
3131 | function _request(_x) {
|
3132 | return _request2.apply(this, arguments);
|
3133 | }
|
3134 |
|
3135 | return _request;
|
3136 | }();
|
3137 |
|
3138 | _proto._open = function _open() {
|
3139 | var _this3 = this;
|
3140 |
|
3141 | if (this._openPromise) return this._openPromise;
|
3142 | var format = 'protobuf2';
|
3143 |
|
3144 | if (this._options.noBinary) {
|
3145 |
|
3146 | format = 'proto2base64';
|
3147 | }
|
3148 |
|
3149 | var version = 3;
|
3150 |
|
3151 | if (this._options.pushOfflineMessages) {
|
3152 |
|
3153 | version = 1;
|
3154 | }
|
3155 |
|
3156 | var protocol = {
|
3157 | format: format,
|
3158 | version: version
|
3159 | };
|
3160 | this._openPromise = new Promise(function (resolve, reject) {
|
3161 | debug$5('No connection established, create a new one.');
|
3162 | var connection = new Connection(function () {
|
3163 | return _this3._getRTMServers(_this3._options);
|
3164 | }, protocol);
|
3165 | connection.on(OPEN, function () {
|
3166 | return resolve(connection);
|
3167 | }).on(ERROR, reject).on(EXPIRE,
|
3168 |
|
3169 | _asyncToGenerator(
|
3170 |
|
3171 | _regeneratorRuntime.mark(function _callee2() {
|
3172 | return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
3173 | while (1) {
|
3174 | switch (_context2.prev = _context2.next) {
|
3175 | case 0:
|
3176 | debug$5('Connection expired. Refresh endpoints.');
|
3177 |
|
3178 | _this3._cache.set('endpoints', null, 0);
|
3179 |
|
3180 | _context2.next = 4;
|
3181 | return _this3._getRTMServers(_this3._options);
|
3182 |
|
3183 | case 4:
|
3184 | connection.urls = _context2.sent;
|
3185 | connection.disconnect();
|
3186 |
|
3187 | case 6:
|
3188 | case "end":
|
3189 | return _context2.stop();
|
3190 | }
|
3191 | }
|
3192 | }, _callee2, this);
|
3193 | }))).on(MESSAGE, _this3._dispatchCommand.bind(_this3));
|
3194 | |
3195 |
|
3196 |
|
3197 |
|
3198 |
|
3199 |
|
3200 |
|
3201 | |
3202 |
|
3203 |
|
3204 |
|
3205 |
|
3206 |
|
3207 |
|
3208 | |
3209 |
|
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 | |
3215 |
|
3216 |
|
3217 |
|
3218 |
|
3219 |
|
3220 | |
3221 |
|
3222 |
|
3223 |
|
3224 |
|
3225 |
|
3226 |
|
3227 | |
3228 |
|
3229 |
|
3230 |
|
3231 |
|
3232 |
|
3233 |
|
3234 |
|
3235 | |
3236 |
|
3237 |
|
3238 |
|
3239 |
|
3240 |
|
3241 |
|
3242 | |
3243 |
|
3244 |
|
3245 |
|
3246 |
|
3247 |
|
3248 |
|
3249 | |
3250 |
|
3251 |
|
3252 |
|
3253 |
|
3254 |
|
3255 |
|
3256 | |
3257 |
|
3258 |
|
3259 |
|
3260 |
|
3261 |
|
3262 |
|
3263 | |
3264 |
|
3265 |
|
3266 |
|
3267 |
|
3268 |
|
3269 |
|
3270 |
|
3271 | [DISCONNECT, RECONNECT, RETRY, SCHEDULE, OFFLINE, ONLINE].forEach(function (event) {
|
3272 | return connection.on(event, function () {
|
3273 | for (var _len = arguments.length, payload = new Array(_len), _key = 0; _key < _len; _key++) {
|
3274 | payload[_key] = arguments[_key];
|
3275 | }
|
3276 |
|
3277 | debug$5("".concat(event, " event emitted. %o"), payload);
|
3278 |
|
3279 | _this3.emit.apply(_this3, [event].concat(payload));
|
3280 |
|
3281 | if (event !== RECONNECT) {
|
3282 | internal(_this3).clients.forEach(function (client) {
|
3283 | client.emit.apply(client, [event].concat(payload));
|
3284 | });
|
3285 | }
|
3286 | });
|
3287 | });
|
3288 |
|
3289 | connection.handleClose = function handleClose(event) {
|
3290 | var isFatal = [ErrorCode.APP_NOT_AVAILABLE, ErrorCode.INVALID_LOGIN, ErrorCode.INVALID_ORIGIN].some(function (errorCode) {
|
3291 | return errorCode === event.code;
|
3292 | });
|
3293 |
|
3294 | if (isFatal) {
|
3295 |
|
3296 | this.throw(createError(event));
|
3297 | } else {
|
3298 |
|
3299 | this.disconnect();
|
3300 | }
|
3301 | };
|
3302 |
|
3303 | internal(_this3).connection = connection;
|
3304 | });
|
3305 | return this._openPromise;
|
3306 | };
|
3307 |
|
3308 | _proto._getRTMServers =
|
3309 |
|
3310 | function () {
|
3311 | var _getRTMServers2 = _asyncToGenerator(
|
3312 |
|
3313 | _regeneratorRuntime.mark(function _callee3(options) {
|
3314 | var info, cachedEndPoints;
|
3315 | return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
3316 | while (1) {
|
3317 | switch (_context3.prev = _context3.next) {
|
3318 | case 0:
|
3319 | if (!options.RTMServers) {
|
3320 | _context3.next = 2;
|
3321 | break;
|
3322 | }
|
3323 |
|
3324 | return _context3.abrupt("return", shuffle(ensureArray(options.RTMServers)));
|
3325 |
|
3326 | case 2:
|
3327 | cachedEndPoints = this._cache.get('endpoints');
|
3328 |
|
3329 | if (!cachedEndPoints) {
|
3330 | _context3.next = 9;
|
3331 | break;
|
3332 | }
|
3333 |
|
3334 | _context3.next = 6;
|
3335 | return cachedEndPoints;
|
3336 |
|
3337 | case 6:
|
3338 | info = _context3.sent;
|
3339 | _context3.next = 13;
|
3340 | break;
|
3341 |
|
3342 | case 9:
|
3343 | _context3.next = 11;
|
3344 | return this.constructor._fetchRTMServers(options);
|
3345 |
|
3346 | case 11:
|
3347 | info = _context3.sent;
|
3348 |
|
3349 | this._cache.set('endpoints', info, info.ttl * 1000);
|
3350 |
|
3351 | case 13:
|
3352 | debug$5('endpoint info: %O', info);
|
3353 | return _context3.abrupt("return", [info.server, info.secondary]);
|
3354 |
|
3355 | case 15:
|
3356 | case "end":
|
3357 | return _context3.stop();
|
3358 | }
|
3359 | }
|
3360 | }, _callee3, this);
|
3361 | }));
|
3362 |
|
3363 | function _getRTMServers(_x2) {
|
3364 | return _getRTMServers2.apply(this, arguments);
|
3365 | }
|
3366 |
|
3367 | return _getRTMServers;
|
3368 | }();
|
3369 |
|
3370 | Realtime._getServerUrls =
|
3371 |
|
3372 | function () {
|
3373 | var _getServerUrls2 = _asyncToGenerator(
|
3374 |
|
3375 | _regeneratorRuntime.mark(function _callee4(_ref5) {
|
3376 | var appId, server, cachedRouter, defaultProtocol;
|
3377 | return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
3378 | while (1) {
|
3379 | switch (_context4.prev = _context4.next) {
|
3380 | case 0:
|
3381 | appId = _ref5.appId, server = _ref5.server;
|
3382 | debug$5('fetch server urls');
|
3383 |
|
3384 | if (!server) {
|
3385 | _context4.next = 6;
|
3386 | break;
|
3387 | }
|
3388 |
|
3389 | if (!(typeof server !== 'string')) {
|
3390 | _context4.next = 5;
|
3391 | break;
|
3392 | }
|
3393 |
|
3394 | return _context4.abrupt("return", server);
|
3395 |
|
3396 | case 5:
|
3397 | return _context4.abrupt("return", {
|
3398 | RTMRouter: server,
|
3399 | api: server
|
3400 | });
|
3401 |
|
3402 | case 6:
|
3403 | cachedRouter = routerCache.get(appId);
|
3404 |
|
3405 | if (!cachedRouter) {
|
3406 | _context4.next = 9;
|
3407 | break;
|
3408 | }
|
3409 |
|
3410 | return _context4.abrupt("return", cachedRouter);
|
3411 |
|
3412 | case 9:
|
3413 | defaultProtocol = 'https://';
|
3414 | return _context4.abrupt("return", superagent.get('https://app-router.com/2/route').query({
|
3415 | appId: appId
|
3416 | }).timeout(20000).then(function (res) {
|
3417 | return res.body;
|
3418 | }).then(tap(debug$5)).then(function (_ref6) {
|
3419 | var RTMRouterServer = _ref6.rtm_router_server,
|
3420 | APIServer = _ref6.api_server,
|
3421 | _ref6$ttl = _ref6.ttl,
|
3422 | ttl = _ref6$ttl === void 0 ? 3600 : _ref6$ttl;
|
3423 |
|
3424 | if (!RTMRouterServer) {
|
3425 | throw new Error('rtm router not exists');
|
3426 | }
|
3427 |
|
3428 | var serverUrls = {
|
3429 | RTMRouter: "".concat(defaultProtocol).concat(RTMRouterServer),
|
3430 | api: "".concat(defaultProtocol).concat(APIServer)
|
3431 | };
|
3432 | routerCache.set(appId, serverUrls, ttl * 1000);
|
3433 | return serverUrls;
|
3434 | }).catch(function () {
|
3435 | var id = appId.slice(0, 8).toLowerCase();
|
3436 | var domain = 'lncldglobal.com';
|
3437 | return {
|
3438 | RTMRouter: "".concat(defaultProtocol).concat(id, ".rtm.").concat(domain),
|
3439 | api: "".concat(defaultProtocol).concat(id, ".api.").concat(domain)
|
3440 | };
|
3441 | }));
|
3442 |
|
3443 | case 11:
|
3444 | case "end":
|
3445 | return _context4.stop();
|
3446 | }
|
3447 | }
|
3448 | }, _callee4, this);
|
3449 | }));
|
3450 |
|
3451 | function _getServerUrls(_x3) {
|
3452 | return _getServerUrls2.apply(this, arguments);
|
3453 | }
|
3454 |
|
3455 | return _getServerUrls;
|
3456 | }();
|
3457 |
|
3458 | Realtime._fetchRTMServers = function _fetchRTMServers(_ref7) {
|
3459 | var appId = _ref7.appId,
|
3460 | ssl = _ref7.ssl,
|
3461 | server = _ref7.server,
|
3462 | RTMServerName = _ref7.RTMServerName;
|
3463 | debug$5('fetch endpoint info');
|
3464 | return this._getServerUrls({
|
3465 | appId: appId,
|
3466 | server: server
|
3467 | }).then(tap(debug$5)).then(function (_ref8) {
|
3468 | var RTMRouter = _ref8.RTMRouter;
|
3469 | return superagent.get("".concat(RTMRouter, "/v1/route")).query({
|
3470 | appId: appId,
|
3471 | secure: ssl,
|
3472 | features: isWeapp ? 'wechat' : undefined,
|
3473 | server: RTMServerName,
|
3474 | _t: Date.now()
|
3475 | }).timeout(20000).then(function (res) {
|
3476 | return res.body;
|
3477 | }).then(tap(debug$5));
|
3478 | });
|
3479 | };
|
3480 |
|
3481 | _proto._close = function _close() {
|
3482 | if (this._openPromise) {
|
3483 | this._openPromise.then(function (connection) {
|
3484 | return connection.close();
|
3485 | });
|
3486 | }
|
3487 |
|
3488 | delete this._openPromise;
|
3489 | }
|
3490 | |
3491 |
|
3492 |
|
3493 |
|
3494 |
|
3495 | ;
|
3496 |
|
3497 | _proto.retry = function retry() {
|
3498 | var _internal = internal(this),
|
3499 | connection = _internal.connection;
|
3500 |
|
3501 | if (!connection) {
|
3502 | throw new Error('no connection established');
|
3503 | }
|
3504 |
|
3505 | if (connection.cannot('retry')) {
|
3506 | throw new Error("retrying not allowed when not disconnected. the connection is now ".concat(connection.current));
|
3507 | }
|
3508 |
|
3509 | return connection.retry();
|
3510 | }
|
3511 | |
3512 |
|
3513 |
|
3514 |
|
3515 |
|
3516 |
|
3517 |
|
3518 |
|
3519 | ;
|
3520 |
|
3521 | _proto.pause = function pause() {
|
3522 |
|
3523 |
|
3524 | var _internal2 = internal(this),
|
3525 | connection = _internal2.connection;
|
3526 |
|
3527 | if (!connection) return;
|
3528 | if (connection.can('pause')) connection.pause();
|
3529 | }
|
3530 | |
3531 |
|
3532 |
|
3533 |
|
3534 |
|
3535 |
|
3536 |
|
3537 | ;
|
3538 |
|
3539 | _proto.resume = function resume() {
|
3540 |
|
3541 | var _internal3 = internal(this),
|
3542 | connection = _internal3.connection;
|
3543 |
|
3544 | if (!connection) return;
|
3545 | if (connection.can('resume')) connection.resume();
|
3546 | };
|
3547 |
|
3548 | _proto._registerPending = function _registerPending(value) {
|
3549 | internal(this).pendingClients.add(value);
|
3550 | };
|
3551 |
|
3552 | _proto._deregisterPending = function _deregisterPending(client) {
|
3553 | internal(this).pendingClients.delete(client);
|
3554 | };
|
3555 |
|
3556 | _proto._register = function _register(client) {
|
3557 | internal(this).clients.add(client);
|
3558 | };
|
3559 |
|
3560 | _proto._deregister = function _deregister(client) {
|
3561 | var _this = internal(this);
|
3562 |
|
3563 | _this.clients.delete(client);
|
3564 |
|
3565 | if (_this.clients.size + _this.pendingClients.size === 0) {
|
3566 | this._close();
|
3567 | }
|
3568 | };
|
3569 |
|
3570 | _proto._dispatchCommand = function _dispatchCommand(command) {
|
3571 | return applyDispatcher(this._plugins.beforeCommandDispatch, [command, this]).then(function (shouldDispatch) {
|
3572 |
|
3573 | if (shouldDispatch) return debug$5('[WARN] Unexpected message received: %O', trim(command));
|
3574 | return false;
|
3575 | });
|
3576 | };
|
3577 |
|
3578 | return Realtime;
|
3579 | }(EventEmitter);
|
3580 |
|
3581 | var polyfilledPromise = Promise;
|
3582 |
|
3583 |
|
3584 | var UNREAD_MESSAGES_COUNT_UPDATE = 'unreadmessagescountupdate';
|
3585 | var CLOSE = 'close';
|
3586 | var CONFLICT = 'conflict';
|
3587 | var CONVERSATION_INFO_UPDATED = 'conversationinfoupdated';
|
3588 | var UNHANDLED_MESSAGE = 'unhandledmessage';
|
3589 |
|
3590 | var INVITED = 'invited';
|
3591 | var KICKED = 'kicked';
|
3592 | var MEMBERS_JOINED = 'membersjoined';
|
3593 | var MEMBERS_LEFT = 'membersleft';
|
3594 | var MEMBER_INFO_UPDATED = 'memberinfoupdated';
|
3595 | var BLOCKED = 'blocked';
|
3596 | var UNBLOCKED = 'unblocked';
|
3597 | var MEMBERS_BLOCKED = 'membersblocked';
|
3598 | var MEMBERS_UNBLOCKED = 'membersunblocked';
|
3599 | var MUTED = 'muted';
|
3600 | var UNMUTED = 'unmuted';
|
3601 | var MEMBERS_MUTED = 'membersmuted';
|
3602 | var MEMBERS_UNMUTED = 'membersunmuted';
|
3603 | var MESSAGE$1 = 'message';
|
3604 | var MESSAGE_RECALL = 'messagerecall';
|
3605 | var MESSAGE_UPDATE = 'messageupdate';
|
3606 |
|
3607 | var LAST_DELIVERED_AT_UPDATE = 'lastdeliveredatupdate';
|
3608 | var LAST_READ_AT_UPDATE = 'lastreadatupdate';
|
3609 | var INFO_UPDATED = 'infoupdated';
|
3610 |
|
3611 | var Event = Object.freeze({
|
3612 | UNREAD_MESSAGES_COUNT_UPDATE: UNREAD_MESSAGES_COUNT_UPDATE,
|
3613 | CLOSE: CLOSE,
|
3614 | CONFLICT: CONFLICT,
|
3615 | CONVERSATION_INFO_UPDATED: CONVERSATION_INFO_UPDATED,
|
3616 | UNHANDLED_MESSAGE: UNHANDLED_MESSAGE,
|
3617 | INVITED: INVITED,
|
3618 | KICKED: KICKED,
|
3619 | MEMBERS_JOINED: MEMBERS_JOINED,
|
3620 | MEMBERS_LEFT: MEMBERS_LEFT,
|
3621 | MEMBER_INFO_UPDATED: MEMBER_INFO_UPDATED,
|
3622 | BLOCKED: BLOCKED,
|
3623 | UNBLOCKED: UNBLOCKED,
|
3624 | MEMBERS_BLOCKED: MEMBERS_BLOCKED,
|
3625 | MEMBERS_UNBLOCKED: MEMBERS_UNBLOCKED,
|
3626 | MUTED: MUTED,
|
3627 | UNMUTED: UNMUTED,
|
3628 | MEMBERS_MUTED: MEMBERS_MUTED,
|
3629 | MEMBERS_UNMUTED: MEMBERS_UNMUTED,
|
3630 | MESSAGE: MESSAGE$1,
|
3631 | MESSAGE_RECALL: MESSAGE_RECALL,
|
3632 | MESSAGE_UPDATE: MESSAGE_UPDATE,
|
3633 | LAST_DELIVERED_AT_UPDATE: LAST_DELIVERED_AT_UPDATE,
|
3634 | LAST_READ_AT_UPDATE: LAST_READ_AT_UPDATE,
|
3635 | INFO_UPDATED: INFO_UPDATED
|
3636 | });
|
3637 |
|
3638 | var _rMessageStatus;
|
3639 |
|
3640 |
|
3641 |
|
3642 |
|
3643 |
|
3644 |
|
3645 |
|
3646 | var MessageStatus = {
|
3647 |
|
3648 | NONE: Symbol('none'),
|
3649 |
|
3650 |
|
3651 | SENDING: Symbol('sending'),
|
3652 |
|
3653 |
|
3654 | SENT: Symbol('sent'),
|
3655 |
|
3656 |
|
3657 | DELIVERED: Symbol('delivered'),
|
3658 |
|
3659 |
|
3660 | FAILED: Symbol('failed')
|
3661 | };
|
3662 | Object.freeze(MessageStatus);
|
3663 | var rMessageStatus = (_rMessageStatus = {}, _defineProperty(_rMessageStatus, MessageStatus.NONE, true), _defineProperty(_rMessageStatus, MessageStatus.SENDING, true), _defineProperty(_rMessageStatus, MessageStatus.SENT, true), _defineProperty(_rMessageStatus, MessageStatus.DELIVERED, true), _defineProperty(_rMessageStatus, MessageStatus.READ, true), _defineProperty(_rMessageStatus, MessageStatus.FAILED, true), _rMessageStatus);
|
3664 |
|
3665 | var Message =
|
3666 |
|
3667 | function () {
|
3668 | |
3669 |
|
3670 |
|
3671 |
|
3672 | function Message(content) {
|
3673 | Object.assign(this, {
|
3674 | content: content
|
3675 | }, {
|
3676 | |
3677 |
|
3678 |
|
3679 |
|
3680 | id: uuid(),
|
3681 |
|
3682 | |
3683 |
|
3684 |
|
3685 |
|
3686 |
|
3687 | cid: null,
|
3688 |
|
3689 | |
3690 |
|
3691 |
|
3692 |
|
3693 |
|
3694 | timestamp: new Date(),
|
3695 |
|
3696 | |
3697 |
|
3698 |
|
3699 |
|
3700 |
|
3701 | from: undefined,
|
3702 |
|
3703 | |
3704 |
|
3705 |
|
3706 |
|
3707 |
|
3708 |
|
3709 | mentionList: [],
|
3710 |
|
3711 | |
3712 |
|
3713 |
|
3714 |
|
3715 |
|
3716 |
|
3717 | mentionedAll: false,
|
3718 | _mentioned: false
|
3719 | });
|
3720 |
|
3721 | this._setStatus(MessageStatus.NONE);
|
3722 | }
|
3723 | |
3724 |
|
3725 |
|
3726 |
|
3727 |
|
3728 |
|
3729 |
|
3730 | var _proto = Message.prototype;
|
3731 |
|
3732 | _proto.getPayload = function getPayload() {
|
3733 | return this.content;
|
3734 | };
|
3735 |
|
3736 | _proto._toJSON = function _toJSON() {
|
3737 | var id = this.id,
|
3738 | cid = this.cid,
|
3739 | from = this.from,
|
3740 | timestamp = this.timestamp,
|
3741 | deliveredAt = this.deliveredAt,
|
3742 | updatedAt = this.updatedAt,
|
3743 | mentionList = this.mentionList,
|
3744 | mentionedAll = this.mentionedAll,
|
3745 | mentioned = this.mentioned;
|
3746 | return {
|
3747 | id: id,
|
3748 | cid: cid,
|
3749 | from: from,
|
3750 | timestamp: timestamp,
|
3751 | deliveredAt: deliveredAt,
|
3752 | updatedAt: updatedAt,
|
3753 | mentionList: mentionList,
|
3754 | mentionedAll: mentionedAll,
|
3755 | mentioned: mentioned
|
3756 | };
|
3757 | }
|
3758 | |
3759 |
|
3760 |
|
3761 |
|
3762 | ;
|
3763 |
|
3764 | _proto.toJSON = function toJSON() {
|
3765 | return _objectSpread({}, this._toJSON(), {
|
3766 | data: this.content
|
3767 | });
|
3768 | }
|
3769 | |
3770 |
|
3771 |
|
3772 |
|
3773 |
|
3774 | ;
|
3775 |
|
3776 | _proto.toFullJSON = function toFullJSON() {
|
3777 | var content = this.content,
|
3778 | id = this.id,
|
3779 | cid = this.cid,
|
3780 | from = this.from,
|
3781 | timestamp = this.timestamp,
|
3782 | deliveredAt = this.deliveredAt,
|
3783 | _updatedAt = this._updatedAt,
|
3784 | mentionList = this.mentionList,
|
3785 | mentionedAll = this.mentionedAll;
|
3786 | return {
|
3787 | data: content,
|
3788 | id: id,
|
3789 | cid: cid,
|
3790 | from: from,
|
3791 | timestamp: getTime(timestamp),
|
3792 | deliveredAt: getTime(deliveredAt),
|
3793 | updatedAt: getTime(_updatedAt),
|
3794 | mentionList: mentionList,
|
3795 | mentionedAll: mentionedAll
|
3796 | };
|
3797 | }
|
3798 | |
3799 |
|
3800 |
|
3801 |
|
3802 |
|
3803 |
|
3804 | ;
|
3805 |
|
3806 | _proto._setStatus = function _setStatus(status) {
|
3807 | if (!rMessageStatus[status]) {
|
3808 | throw new Error('Invalid message status');
|
3809 | }
|
3810 |
|
3811 | this._status = status;
|
3812 | };
|
3813 |
|
3814 | _proto._updateMentioned = function _updateMentioned(client) {
|
3815 | this._mentioned = this.from !== client && (this.mentionedAll || this.mentionList.indexOf(client) > -1);
|
3816 | }
|
3817 | |
3818 |
|
3819 |
|
3820 |
|
3821 |
|
3822 | ;
|
3823 |
|
3824 | _proto.getMentionList = function getMentionList() {
|
3825 | return this.mentionList;
|
3826 | }
|
3827 | |
3828 |
|
3829 |
|
3830 |
|
3831 |
|
3832 |
|
3833 | ;
|
3834 |
|
3835 | _proto.setMentionList = function setMentionList(clients) {
|
3836 | this.mentionList = ensureArray(clients);
|
3837 | return this;
|
3838 | }
|
3839 | |
3840 |
|
3841 |
|
3842 |
|
3843 |
|
3844 |
|
3845 | ;
|
3846 |
|
3847 | _proto.mentionAll = function mentionAll() {
|
3848 | var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
3849 | this.mentionedAll = Boolean(value);
|
3850 | return this;
|
3851 | }
|
3852 | |
3853 |
|
3854 |
|
3855 |
|
3856 |
|
3857 |
|
3858 |
|
3859 | ;
|
3860 |
|
3861 | Message.validate = function validate() {
|
3862 | return true;
|
3863 | }
|
3864 | |
3865 |
|
3866 |
|
3867 |
|
3868 |
|
3869 |
|
3870 |
|
3871 |
|
3872 |
|
3873 |
|
3874 |
|
3875 | ;
|
3876 |
|
3877 | Message.parse = function parse(json, message) {
|
3878 | return message || new this(json);
|
3879 | };
|
3880 |
|
3881 | _createClass(Message, [{
|
3882 | key: "status",
|
3883 | get: function get() {
|
3884 | return this._status;
|
3885 | }
|
3886 | }, {
|
3887 | key: "timestamp",
|
3888 | get: function get() {
|
3889 | return this._timestamp;
|
3890 | },
|
3891 | set: function set(value) {
|
3892 | this._timestamp = decodeDate(value);
|
3893 | }
|
3894 | |
3895 |
|
3896 |
|
3897 |
|
3898 |
|
3899 | }, {
|
3900 | key: "deliveredAt",
|
3901 | get: function get() {
|
3902 | return this._deliveredAt;
|
3903 | },
|
3904 | set: function set(value) {
|
3905 | this._deliveredAt = decodeDate(value);
|
3906 | }
|
3907 | |
3908 |
|
3909 |
|
3910 |
|
3911 |
|
3912 |
|
3913 | }, {
|
3914 | key: "updatedAt",
|
3915 | get: function get() {
|
3916 | return this._updatedAt || this.timestamp;
|
3917 | },
|
3918 | set: function set(value) {
|
3919 | this._updatedAt = decodeDate(value);
|
3920 | }
|
3921 | |
3922 |
|
3923 |
|
3924 |
|
3925 |
|
3926 |
|
3927 |
|
3928 | }, {
|
3929 | key: "mentioned",
|
3930 | get: function get() {
|
3931 | return this._mentioned;
|
3932 | }
|
3933 | }]);
|
3934 |
|
3935 | return Message;
|
3936 | }();
|
3937 |
|
3938 |
|
3939 |
|
3940 | var messageType = function messageType(type) {
|
3941 | if (typeof type !== 'number') {
|
3942 | throw new TypeError("".concat(type, " is not a Number"));
|
3943 | }
|
3944 |
|
3945 | return function (target) {
|
3946 | target.TYPE = type;
|
3947 |
|
3948 | target.validate = function (json) {
|
3949 | return json._lctype === type;
|
3950 | };
|
3951 |
|
3952 | target.prototype._getType = function () {
|
3953 | return {
|
3954 | _lctype: type
|
3955 | };
|
3956 | };
|
3957 | };
|
3958 | };
|
3959 |
|
3960 | var messageField = function messageField(fields) {
|
3961 | if (typeof fields !== 'string') {
|
3962 | if (!Array.isArray(fields)) {
|
3963 | throw new TypeError("".concat(fields, " is not an Array"));
|
3964 | } else if (fields.some(function (value) {
|
3965 | return typeof value !== 'string';
|
3966 | })) {
|
3967 | throw new TypeError('fields contains non-string typed member');
|
3968 | }
|
3969 | }
|
3970 |
|
3971 | return function (target) {
|
3972 |
|
3973 |
|
3974 |
|
3975 | var originalCustomFields = isIE10 ? getStaticProperty(target, '_customFields') : target._customFields;
|
3976 | originalCustomFields = Array.isArray(originalCustomFields) ? originalCustomFields : [];
|
3977 | target._customFields = originalCustomFields.concat(fields);
|
3978 | };
|
3979 | };
|
3980 |
|
3981 |
|
3982 |
|
3983 | var IE10Compatible = function IE10Compatible(target) {
|
3984 | if (isIE10) {
|
3985 | target.parse = getStaticProperty(target, 'parse');
|
3986 | }
|
3987 | };
|
3988 |
|
3989 | var _dec, _class$1;
|
3990 |
|
3991 | var
|
3992 |
|
3993 |
|
3994 |
|
3995 |
|
3996 |
|
3997 | TypedMessage = (_dec = messageField(['_lctext', '_lcattrs']), _dec(_class$1 =
|
3998 |
|
3999 | function (_Message) {
|
4000 | _inheritsLoose(TypedMessage, _Message);
|
4001 |
|
4002 | function TypedMessage() {
|
4003 | return _Message.apply(this, arguments) || this;
|
4004 | }
|
4005 |
|
4006 | var _proto = TypedMessage.prototype;
|
4007 |
|
4008 | |
4009 |
|
4010 |
|
4011 |
|
4012 | _proto.setText = function setText(text) {
|
4013 | this._lctext = text;
|
4014 | return this;
|
4015 | }
|
4016 | |
4017 |
|
4018 |
|
4019 | ;
|
4020 |
|
4021 | _proto.getText = function getText() {
|
4022 | return this._lctext;
|
4023 | }
|
4024 | |
4025 |
|
4026 |
|
4027 |
|
4028 | ;
|
4029 |
|
4030 | _proto.setAttributes = function setAttributes(attributes) {
|
4031 | this._lcattrs = attributes;
|
4032 | return this;
|
4033 | }
|
4034 | |
4035 |
|
4036 |
|
4037 | ;
|
4038 |
|
4039 | _proto.getAttributes = function getAttributes() {
|
4040 | return this._lcattrs;
|
4041 | };
|
4042 |
|
4043 | _proto._getCustomFields = function _getCustomFields() {
|
4044 | var _this = this;
|
4045 |
|
4046 | var fields = Array.isArray(this.constructor._customFields) ? this.constructor._customFields : [];
|
4047 | return fields.reduce(function (result, field) {
|
4048 | if (typeof field !== 'string') return result;
|
4049 | result[field] = _this[field];
|
4050 |
|
4051 | return result;
|
4052 | }, {});
|
4053 | }
|
4054 |
|
4055 | ;
|
4056 |
|
4057 | _proto._getType = function _getType() {
|
4058 | throw new Error('not implemented');
|
4059 | }
|
4060 |
|
4061 | ;
|
4062 |
|
4063 | _proto.getPayload = function getPayload() {
|
4064 | return compact(Object.assign({
|
4065 | _lctext: this.getText(),
|
4066 | _lcattrs: this.getAttributes()
|
4067 | }, this._getCustomFields(), this._getType()));
|
4068 | };
|
4069 |
|
4070 | _proto.toJSON = function toJSON() {
|
4071 | var type = this.type,
|
4072 | text = this.text,
|
4073 | attributes = this.attributes,
|
4074 | summary = this.summary;
|
4075 | return _objectSpread({}, _Message.prototype._toJSON.call(this), {
|
4076 | type: type,
|
4077 | text: text,
|
4078 | attributes: attributes,
|
4079 | summary: summary
|
4080 | });
|
4081 | };
|
4082 |
|
4083 | _proto.toFullJSON = function toFullJSON() {
|
4084 | return _objectSpread({}, _Message.prototype.toFullJSON.call(this), {
|
4085 | data: this.getPayload()
|
4086 | });
|
4087 | }
|
4088 | |
4089 |
|
4090 |
|
4091 |
|
4092 |
|
4093 |
|
4094 |
|
4095 |
|
4096 |
|
4097 |
|
4098 |
|
4099 | ;
|
4100 |
|
4101 | TypedMessage.parse = function parse(json) {
|
4102 | var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new this();
|
4103 | message.content = json;
|
4104 |
|
4105 | var customFields = isIE10 ? getStaticProperty(message.constructor, '_customFields') : message.constructor._customFields;
|
4106 | var fields = Array.isArray(customFields) ? customFields : [];
|
4107 | fields = fields.reduce(function (result, field) {
|
4108 | if (typeof field !== 'string') return result;
|
4109 | result[field] = json[field];
|
4110 |
|
4111 | return result;
|
4112 | }, {});
|
4113 | Object.assign(message, fields);
|
4114 | return _Message.parse.call(this, json, message);
|
4115 | };
|
4116 |
|
4117 | _createClass(TypedMessage, [{
|
4118 | key: "type",
|
4119 |
|
4120 | |
4121 |
|
4122 |
|
4123 |
|
4124 | get: function get() {
|
4125 | return this.constructor.TYPE;
|
4126 | }
|
4127 |
|
4128 |
|
4129 | }, {
|
4130 | key: "text",
|
4131 | set: function set(text) {
|
4132 | return this.setText(text);
|
4133 | },
|
4134 | get: function get() {
|
4135 | return this.getText();
|
4136 | }
|
4137 |
|
4138 |
|
4139 | }, {
|
4140 | key: "attributes",
|
4141 | set: function set(attributes) {
|
4142 | return this.setAttributes(attributes);
|
4143 | },
|
4144 | get: function get() {
|
4145 | return this.getAttributes();
|
4146 | }
|
4147 | |
4148 |
|
4149 |
|
4150 |
|
4151 |
|
4152 |
|
4153 |
|
4154 |
|
4155 | }, {
|
4156 | key: "summary",
|
4157 | get: function get() {
|
4158 | return this.text;
|
4159 | }
|
4160 | }]);
|
4161 |
|
4162 | return TypedMessage;
|
4163 | }(Message)) || _class$1);
|
4164 |
|
4165 | var _dec$1, _class$2;
|
4166 |
|
4167 | var
|
4168 |
|
4169 |
|
4170 |
|
4171 |
|
4172 |
|
4173 | RecalledMessage = (_dec$1 = messageType(-127), _dec$1(_class$2 = IE10Compatible(_class$2 =
|
4174 |
|
4175 | function (_TypedMessage) {
|
4176 | _inheritsLoose(RecalledMessage, _TypedMessage);
|
4177 |
|
4178 | function RecalledMessage() {
|
4179 | return _TypedMessage.apply(this, arguments) || this;
|
4180 | }
|
4181 |
|
4182 | _createClass(RecalledMessage, [{
|
4183 | key: "summary",
|
4184 |
|
4185 | |
4186 |
|
4187 |
|
4188 |
|
4189 |
|
4190 |
|
4191 | get: function get() {
|
4192 | return '[该消息已撤回]';
|
4193 | }
|
4194 | }]);
|
4195 |
|
4196 | return RecalledMessage;
|
4197 | }(TypedMessage)) || _class$2) || _class$2);
|
4198 |
|
4199 | var debug$6 = d('LC:Conversation');
|
4200 |
|
4201 | var serializeMessage = function serializeMessage(message) {
|
4202 | var content = message.getPayload();
|
4203 | var msg;
|
4204 | var binaryMsg;
|
4205 |
|
4206 | if (content instanceof ArrayBuffer) {
|
4207 | binaryMsg = content;
|
4208 | } else if (typeof content !== 'string') {
|
4209 | msg = JSON.stringify(content);
|
4210 | } else {
|
4211 | msg = content;
|
4212 | }
|
4213 |
|
4214 | return {
|
4215 | msg: msg,
|
4216 | binaryMsg: binaryMsg
|
4217 | };
|
4218 | };
|
4219 |
|
4220 | var _LogsCommand$QueryDir = LogsCommand.QueryDirection,
|
4221 | NEW = _LogsCommand$QueryDir.NEW,
|
4222 | OLD = _LogsCommand$QueryDir.OLD;
|
4223 |
|
4224 |
|
4225 |
|
4226 |
|
4227 |
|
4228 |
|
4229 |
|
4230 | var MessageQueryDirection = {
|
4231 |
|
4232 | NEW_TO_OLD: OLD,
|
4233 |
|
4234 |
|
4235 | OLD_TO_NEW: NEW
|
4236 | };
|
4237 | Object.freeze(MessageQueryDirection);
|
4238 |
|
4239 | var ConversationBase =
|
4240 |
|
4241 | function (_EventEmitter) {
|
4242 | _inheritsLoose(ConversationBase, _EventEmitter);
|
4243 |
|
4244 | |
4245 |
|
4246 |
|
4247 |
|
4248 |
|
4249 | function ConversationBase(_ref, client) {
|
4250 | var _this;
|
4251 |
|
4252 | var id = _ref.id,
|
4253 | lastMessageAt = _ref.lastMessageAt,
|
4254 | lastMessage = _ref.lastMessage,
|
4255 | lastDeliveredAt = _ref.lastDeliveredAt,
|
4256 | lastReadAt = _ref.lastReadAt,
|
4257 | _ref$unreadMessagesCo = _ref.unreadMessagesCount,
|
4258 | unreadMessagesCount = _ref$unreadMessagesCo === void 0 ? 0 : _ref$unreadMessagesCo,
|
4259 | _ref$members = _ref.members,
|
4260 | members = _ref$members === void 0 ? [] : _ref$members,
|
4261 | _ref$mentioned = _ref.mentioned,
|
4262 | mentioned = _ref$mentioned === void 0 ? false : _ref$mentioned,
|
4263 | properties = _objectWithoutProperties(_ref, ["id", "lastMessageAt", "lastMessage", "lastDeliveredAt", "lastReadAt", "unreadMessagesCount", "members", "mentioned"]);
|
4264 |
|
4265 | _this = _EventEmitter.call(this) || this;
|
4266 | Object.assign(_assertThisInitialized(_this), _objectSpread({
|
4267 | |
4268 |
|
4269 |
|
4270 |
|
4271 |
|
4272 | id: id,
|
4273 |
|
4274 | |
4275 |
|
4276 |
|
4277 |
|
4278 |
|
4279 | lastMessageAt: lastMessageAt,
|
4280 |
|
4281 | |
4282 |
|
4283 |
|
4284 |
|
4285 |
|
4286 | lastMessage: lastMessage,
|
4287 |
|
4288 | |
4289 |
|
4290 |
|
4291 |
|
4292 |
|
4293 | members: members
|
4294 | }, properties));
|
4295 | _this.members = Array.from(new Set(_this.members));
|
4296 | Object.assign(internal(_assertThisInitialized(_this)), {
|
4297 | messagesWaitingForReceipt: {},
|
4298 | lastDeliveredAt: lastDeliveredAt,
|
4299 | lastReadAt: lastReadAt,
|
4300 | unreadMessagesCount: unreadMessagesCount,
|
4301 | mentioned: mentioned
|
4302 | });
|
4303 | _this._client = client;
|
4304 |
|
4305 | if (debug$6.enabled) {
|
4306 | values(Event).forEach(function (event) {
|
4307 | return _this.on(event, function () {
|
4308 | for (var _len = arguments.length, payload = new Array(_len), _key = 0; _key < _len; _key++) {
|
4309 | payload[_key] = arguments[_key];
|
4310 | }
|
4311 |
|
4312 | return _this._debug("".concat(event, " event emitted. %o"), payload);
|
4313 | });
|
4314 | });
|
4315 | }
|
4316 |
|
4317 |
|
4318 | applyDecorators(_this._client._plugins.onConversationCreate, _assertThisInitialized(_this));
|
4319 | return _this;
|
4320 | }
|
4321 | |
4322 |
|
4323 |
|
4324 |
|
4325 |
|
4326 |
|
4327 |
|
4328 | var _proto = ConversationBase.prototype;
|
4329 |
|
4330 | _proto._setUnreadMessagesMentioned = function _setUnreadMessagesMentioned(value) {
|
4331 | internal(this).unreadMessagesMentioned = Boolean(value);
|
4332 | };
|
4333 |
|
4334 | _proto._setLastDeliveredAt = function _setLastDeliveredAt(value) {
|
4335 | var date = decodeDate(value);
|
4336 |
|
4337 | if (!(date < internal(this).lastDeliveredAt)) {
|
4338 | internal(this).lastDeliveredAt = date;
|
4339 | |
4340 |
|
4341 |
|
4342 |
|
4343 |
|
4344 |
|
4345 | this.emit(LAST_DELIVERED_AT_UPDATE);
|
4346 | }
|
4347 | }
|
4348 | |
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 | ;
|
4354 |
|
4355 | _proto._setLastReadAt = function _setLastReadAt(value) {
|
4356 | var date = decodeDate(value);
|
4357 |
|
4358 | if (!(date < internal(this).lastReadAt)) {
|
4359 | internal(this).lastReadAt = date;
|
4360 | |
4361 |
|
4362 |
|
4363 |
|
4364 |
|
4365 |
|
4366 | this.emit(LAST_READ_AT_UPDATE);
|
4367 | }
|
4368 | }
|
4369 | |
4370 |
|
4371 |
|
4372 |
|
4373 |
|
4374 | ;
|
4375 |
|
4376 | _proto.toFullJSON = function toFullJSON() {
|
4377 | var id = this.id,
|
4378 | members = this.members,
|
4379 | lastMessageAt = this.lastMessageAt,
|
4380 | lastDeliveredAt = this.lastDeliveredAt,
|
4381 | lastReadAt = this.lastReadAt,
|
4382 | lastMessage = this.lastMessage,
|
4383 | unreadMessagesCount = this.unreadMessagesCount;
|
4384 | return {
|
4385 | id: id,
|
4386 | members: members,
|
4387 | lastMessageAt: getTime(lastMessageAt),
|
4388 | lastDeliveredAt: getTime(lastDeliveredAt),
|
4389 | lastReadAt: getTime(lastReadAt),
|
4390 | lastMessage: lastMessage ? lastMessage.toFullJSON() : undefined,
|
4391 | unreadMessagesCount: unreadMessagesCount
|
4392 | };
|
4393 | }
|
4394 | |
4395 |
|
4396 |
|
4397 |
|
4398 |
|
4399 | ;
|
4400 |
|
4401 | _proto.toJSON = function toJSON() {
|
4402 | var id = this.id,
|
4403 | members = this.members,
|
4404 | lastMessageAt = this.lastMessageAt,
|
4405 | lastDeliveredAt = this.lastDeliveredAt,
|
4406 | lastReadAt = this.lastReadAt,
|
4407 | lastMessage = this.lastMessage,
|
4408 | unreadMessagesCount = this.unreadMessagesCount,
|
4409 | unreadMessagesMentioned = this.unreadMessagesMentioned;
|
4410 | return {
|
4411 | id: id,
|
4412 | members: members,
|
4413 | lastMessageAt: lastMessageAt,
|
4414 | lastDeliveredAt: lastDeliveredAt,
|
4415 | lastReadAt: lastReadAt,
|
4416 | lastMessage: lastMessage ? lastMessage.toJSON() : undefined,
|
4417 | unreadMessagesCount: unreadMessagesCount,
|
4418 | unreadMessagesMentioned: unreadMessagesMentioned
|
4419 | };
|
4420 | };
|
4421 |
|
4422 | _proto._debug = function _debug() {
|
4423 | for (var _len2 = arguments.length, params = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
4424 | params[_key2] = arguments[_key2];
|
4425 | }
|
4426 |
|
4427 | debug$6.apply(void 0, params.concat(["[".concat(this.id, "]")]));
|
4428 | };
|
4429 |
|
4430 | _proto._send = function _send(command) {
|
4431 | var _this$_client;
|
4432 |
|
4433 |
|
4434 | if (command.cmd === null) {
|
4435 | command.cmd = 'conv';
|
4436 | }
|
4437 |
|
4438 | if (command.cmd === 'conv' && command.convMessage === null) {
|
4439 | command.convMessage = new ConvCommand();
|
4440 | }
|
4441 |
|
4442 | if (command.convMessage && command.convMessage.cid === null) {
|
4443 | command.convMessage.cid = this.id;
|
4444 | }
|
4445 |
|
4446 |
|
4447 |
|
4448 | for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
4449 | args[_key3 - 1] = arguments[_key3];
|
4450 | }
|
4451 |
|
4452 | return (_this$_client = this._client)._send.apply(_this$_client, [command].concat(args));
|
4453 | }
|
4454 | |
4455 |
|
4456 |
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 |
|
4463 |
|
4464 |
|
4465 |
|
4466 |
|
4467 | ;
|
4468 |
|
4469 | _proto.send =
|
4470 |
|
4471 | function () {
|
4472 | var _send2 = _asyncToGenerator(
|
4473 |
|
4474 | _regeneratorRuntime.mark(function _callee(message, options) {
|
4475 | var _Object$assign, transient, receipt, priority, pushData, will, _serializeMessage, msg, binaryMsg, command, resCommand, _resCommand$ackMessag, uid, t, code, reason, appCode;
|
4476 |
|
4477 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
4478 | while (1) {
|
4479 | switch (_context.prev = _context.next) {
|
4480 | case 0:
|
4481 | this._debug(message, 'send');
|
4482 |
|
4483 | if (message instanceof Message) {
|
4484 | _context.next = 3;
|
4485 | break;
|
4486 | }
|
4487 |
|
4488 | throw new TypeError("".concat(message, " is not a Message"));
|
4489 |
|
4490 | case 3:
|
4491 | _Object$assign = Object.assign({},
|
4492 | message.constructor.sendOptions,
|
4493 | typeof message.constructor.getSendOptions === 'function' ? message.constructor.getSendOptions(message) : {}, options), transient = _Object$assign.transient, receipt = _Object$assign.receipt, priority = _Object$assign.priority, pushData = _Object$assign.pushData, will = _Object$assign.will;
|
4494 |
|
4495 | if (receipt) {
|
4496 | if (this.transient) {
|
4497 | console.warn('receipt option is ignored as the conversation is transient.');
|
4498 | } else if (transient) {
|
4499 | console.warn('receipt option is ignored as the message is sent transiently.');
|
4500 | } else if (this.members.length > 2) {
|
4501 | console.warn('receipt option is recommended to be used in one-on-one conversation.');
|
4502 | }
|
4503 | }
|
4504 |
|
4505 | if (priority && !this.transient) {
|
4506 | console.warn('priority option is ignored as the conversation is not transient.');
|
4507 | }
|
4508 |
|
4509 | Object.assign(message, {
|
4510 | cid: this.id,
|
4511 | from: this._client.id
|
4512 | });
|
4513 |
|
4514 | message._setStatus(MessageStatus.SENDING);
|
4515 |
|
4516 | _serializeMessage = serializeMessage(message), msg = _serializeMessage.msg, binaryMsg = _serializeMessage.binaryMsg;
|
4517 | command = new GenericCommand({
|
4518 | cmd: 'direct',
|
4519 | directMessage: new DirectCommand({
|
4520 | msg: msg,
|
4521 | binaryMsg: binaryMsg,
|
4522 | cid: this.id,
|
4523 | r: receipt,
|
4524 | transient: transient,
|
4525 | dt: message.id,
|
4526 | pushData: JSON.stringify(pushData),
|
4527 | will: will,
|
4528 | mentionPids: message.mentionList,
|
4529 | mentionAll: message.mentionedAll
|
4530 | }),
|
4531 | priority: priority
|
4532 | });
|
4533 | _context.prev = 10;
|
4534 | _context.next = 13;
|
4535 | return this._send(command);
|
4536 |
|
4537 | case 13:
|
4538 | resCommand = _context.sent;
|
4539 | _resCommand$ackMessag = resCommand.ackMessage, uid = _resCommand$ackMessag.uid, t = _resCommand$ackMessag.t, code = _resCommand$ackMessag.code, reason = _resCommand$ackMessag.reason, appCode = _resCommand$ackMessag.appCode;
|
4540 |
|
4541 | if (!(code !== null)) {
|
4542 | _context.next = 17;
|
4543 | break;
|
4544 | }
|
4545 |
|
4546 | throw createError({
|
4547 | code: code,
|
4548 | reason: reason,
|
4549 | appCode: appCode
|
4550 | });
|
4551 |
|
4552 | case 17:
|
4553 | Object.assign(message, {
|
4554 | id: uid,
|
4555 | timestamp: t
|
4556 | });
|
4557 |
|
4558 | if (!transient) {
|
4559 | this.lastMessage = message;
|
4560 | this.lastMessageAt = message.timestamp;
|
4561 | }
|
4562 |
|
4563 | message._setStatus(MessageStatus.SENT);
|
4564 |
|
4565 | if (receipt) {
|
4566 | internal(this).messagesWaitingForReceipt[message.id] = message;
|
4567 | }
|
4568 |
|
4569 | return _context.abrupt("return", message);
|
4570 |
|
4571 | case 24:
|
4572 | _context.prev = 24;
|
4573 | _context.t0 = _context["catch"](10);
|
4574 |
|
4575 | message._setStatus(MessageStatus.FAILED);
|
4576 |
|
4577 | throw _context.t0;
|
4578 |
|
4579 | case 28:
|
4580 | case "end":
|
4581 | return _context.stop();
|
4582 | }
|
4583 | }
|
4584 | }, _callee, this, [[10, 24]]);
|
4585 | }));
|
4586 |
|
4587 | function send(_x, _x2) {
|
4588 | return _send2.apply(this, arguments);
|
4589 | }
|
4590 |
|
4591 | return send;
|
4592 | }();
|
4593 |
|
4594 | _proto._update =
|
4595 |
|
4596 | function () {
|
4597 | var _update2 = _asyncToGenerator(
|
4598 |
|
4599 | _regeneratorRuntime.mark(function _callee2(message, newMessage, recall) {
|
4600 | var msg, binaryMsg, content, id, cid, timestamp, from, _status;
|
4601 |
|
4602 | return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
4603 | while (1) {
|
4604 | switch (_context2.prev = _context2.next) {
|
4605 | case 0:
|
4606 | this._debug('patch %O %O %O', message, newMessage, recall);
|
4607 |
|
4608 | if (!(message instanceof Message)) {
|
4609 | _context2.next = 8;
|
4610 | break;
|
4611 | }
|
4612 |
|
4613 | if (!(message.from !== this._client.id)) {
|
4614 | _context2.next = 4;
|
4615 | break;
|
4616 | }
|
4617 |
|
4618 | throw new Error('Updating message from others is not allowed');
|
4619 |
|
4620 | case 4:
|
4621 | if (!(message.status !== MessageStatus.SENT && message.status !== MessageStatus.DELIVERED)) {
|
4622 | _context2.next = 6;
|
4623 | break;
|
4624 | }
|
4625 |
|
4626 | throw new Error('Message is not sent');
|
4627 |
|
4628 | case 6:
|
4629 | _context2.next = 10;
|
4630 | break;
|
4631 |
|
4632 | case 8:
|
4633 | if (message.id && message.timestamp) {
|
4634 | _context2.next = 10;
|
4635 | break;
|
4636 | }
|
4637 |
|
4638 | throw new TypeError("".concat(message, " is not a Message"));
|
4639 |
|
4640 | case 10:
|
4641 | if (!recall) {
|
4642 | content = serializeMessage(newMessage);
|
4643 | msg = content.msg;
|
4644 | binaryMsg = content.binaryMsg;
|
4645 | }
|
4646 |
|
4647 | _context2.next = 13;
|
4648 | return this._send(new GenericCommand({
|
4649 | cmd: CommandType.patch,
|
4650 | op: OpType.modify,
|
4651 | patchMessage: new PatchCommand({
|
4652 | patches: [new PatchItem({
|
4653 | cid: this.id,
|
4654 | mid: message.id,
|
4655 | timestamp: Number(message.timestamp),
|
4656 | recall: recall,
|
4657 | data: msg,
|
4658 | binaryMsg: binaryMsg,
|
4659 | mentionPids: newMessage.mentionList,
|
4660 | mentionAll: newMessage.mentionedAll
|
4661 | })],
|
4662 | lastPatchTime: this._client._lastPatchTime
|
4663 | })
|
4664 | }));
|
4665 |
|
4666 | case 13:
|
4667 | id = message.id, cid = message.cid, timestamp = message.timestamp, from = message.from, _status = message._status;
|
4668 | Object.assign(newMessage, {
|
4669 | id: id,
|
4670 | cid: cid,
|
4671 | timestamp: timestamp,
|
4672 | from: from,
|
4673 | _status: _status
|
4674 | });
|
4675 |
|
4676 | if (this.lastMessage.id === newMessage.id) {
|
4677 | this.lastMessage = newMessage;
|
4678 | }
|
4679 |
|
4680 | return _context2.abrupt("return", newMessage);
|
4681 |
|
4682 | case 17:
|
4683 | case "end":
|
4684 | return _context2.stop();
|
4685 | }
|
4686 | }
|
4687 | }, _callee2, this);
|
4688 | }));
|
4689 |
|
4690 | function _update(_x3, _x4, _x5) {
|
4691 | return _update2.apply(this, arguments);
|
4692 | }
|
4693 |
|
4694 | return _update;
|
4695 | }()
|
4696 | |
4697 |
|
4698 |
|
4699 |
|
4700 | ;
|
4701 |
|
4702 | _proto.count =
|
4703 |
|
4704 | function () {
|
4705 | var _count = _asyncToGenerator(
|
4706 |
|
4707 | _regeneratorRuntime.mark(function _callee3() {
|
4708 | var resCommand;
|
4709 | return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
4710 | while (1) {
|
4711 | switch (_context3.prev = _context3.next) {
|
4712 | case 0:
|
4713 | this._debug('count');
|
4714 |
|
4715 | _context3.next = 3;
|
4716 | return this._send(new GenericCommand({
|
4717 | op: 'count'
|
4718 | }));
|
4719 |
|
4720 | case 3:
|
4721 | resCommand = _context3.sent;
|
4722 | return _context3.abrupt("return", resCommand.convMessage.count);
|
4723 |
|
4724 | case 5:
|
4725 | case "end":
|
4726 | return _context3.stop();
|
4727 | }
|
4728 | }
|
4729 | }, _callee3, this);
|
4730 | }));
|
4731 |
|
4732 | function count() {
|
4733 | return _count.apply(this, arguments);
|
4734 | }
|
4735 |
|
4736 | return count;
|
4737 | }()
|
4738 | |
4739 |
|
4740 |
|
4741 |
|
4742 |
|
4743 |
|
4744 | ;
|
4745 |
|
4746 | _proto._addMembers = function _addMembers() {}
|
4747 | |
4748 |
|
4749 |
|
4750 |
|
4751 |
|
4752 |
|
4753 | ;
|
4754 |
|
4755 | _proto._removeMembers = function _removeMembers() {}
|
4756 | |
4757 |
|
4758 |
|
4759 |
|
4760 |
|
4761 |
|
4762 | ;
|
4763 |
|
4764 | _proto.update =
|
4765 |
|
4766 | function () {
|
4767 | var _update3 = _asyncToGenerator(
|
4768 |
|
4769 | _regeneratorRuntime.mark(function _callee4(message, newMessage) {
|
4770 | return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
4771 | while (1) {
|
4772 | switch (_context4.prev = _context4.next) {
|
4773 | case 0:
|
4774 | if (newMessage instanceof Message) {
|
4775 | _context4.next = 2;
|
4776 | break;
|
4777 | }
|
4778 |
|
4779 | throw new TypeError("".concat(newMessage, " is not a Message"));
|
4780 |
|
4781 | case 2:
|
4782 | return _context4.abrupt("return", this._update(message, newMessage, false));
|
4783 |
|
4784 | case 3:
|
4785 | case "end":
|
4786 | return _context4.stop();
|
4787 | }
|
4788 | }
|
4789 | }, _callee4, this);
|
4790 | }));
|
4791 |
|
4792 | function update(_x6, _x7) {
|
4793 | return _update3.apply(this, arguments);
|
4794 | }
|
4795 |
|
4796 | return update;
|
4797 | }()
|
4798 | |
4799 |
|
4800 |
|
4801 |
|
4802 |
|
4803 | ;
|
4804 |
|
4805 | _proto.recall =
|
4806 |
|
4807 | function () {
|
4808 | var _recall = _asyncToGenerator(
|
4809 |
|
4810 | _regeneratorRuntime.mark(function _callee5(message) {
|
4811 | return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
4812 | while (1) {
|
4813 | switch (_context5.prev = _context5.next) {
|
4814 | case 0:
|
4815 | return _context5.abrupt("return", this._update(message, new RecalledMessage(), true));
|
4816 |
|
4817 | case 1:
|
4818 | case "end":
|
4819 | return _context5.stop();
|
4820 | }
|
4821 | }
|
4822 | }, _callee5, this);
|
4823 | }));
|
4824 |
|
4825 | function recall(_x8) {
|
4826 | return _recall.apply(this, arguments);
|
4827 | }
|
4828 |
|
4829 | return recall;
|
4830 | }()
|
4831 | |
4832 |
|
4833 |
|
4834 |
|
4835 |
|
4836 |
|
4837 |
|
4838 |
|
4839 |
|
4840 |
|
4841 |
|
4842 |
|
4843 |
|
4844 |
|
4845 |
|
4846 |
|
4847 |
|
4848 |
|
4849 |
|
4850 |
|
4851 |
|
4852 |
|
4853 |
|
4854 |
|
4855 |
|
4856 |
|
4857 |
|
4858 | ;
|
4859 |
|
4860 | _proto.queryMessages =
|
4861 |
|
4862 | function () {
|
4863 | var _queryMessages = _asyncToGenerator(
|
4864 |
|
4865 | _regeneratorRuntime.mark(function _callee7() {
|
4866 | var _this2 = this;
|
4867 |
|
4868 | var options,
|
4869 | beforeTime,
|
4870 | beforeMessageId,
|
4871 | afterTime,
|
4872 | afterMessageId,
|
4873 | limit,
|
4874 | direction,
|
4875 | type,
|
4876 | startTime,
|
4877 | startMessageId,
|
4878 | startClosed,
|
4879 | endTime,
|
4880 | endMessageId,
|
4881 | endClosed,
|
4882 | conditions,
|
4883 | resCommand,
|
4884 | _args7 = arguments;
|
4885 | return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
4886 | while (1) {
|
4887 | switch (_context7.prev = _context7.next) {
|
4888 | case 0:
|
4889 | options = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
|
4890 |
|
4891 | this._debug('query messages %O', options);
|
4892 |
|
4893 | beforeTime = options.beforeTime, beforeMessageId = options.beforeMessageId, afterTime = options.afterTime, afterMessageId = options.afterMessageId, limit = options.limit, direction = options.direction, type = options.type, startTime = options.startTime, startMessageId = options.startMessageId, startClosed = options.startClosed, endTime = options.endTime, endMessageId = options.endMessageId, endClosed = options.endClosed;
|
4894 |
|
4895 | if (!(beforeMessageId || beforeTime || afterMessageId || afterTime)) {
|
4896 | _context7.next = 6;
|
4897 | break;
|
4898 | }
|
4899 |
|
4900 | console.warn('DEPRECATION: queryMessages options beforeTime, beforeMessageId, afterTime and afterMessageId are deprecated in favor of startTime, startMessageId, endTime and endMessageId.');
|
4901 | return _context7.abrupt("return", this.queryMessages({
|
4902 | startTime: beforeTime,
|
4903 | startMessageId: beforeMessageId,
|
4904 | endTime: afterTime,
|
4905 | endMessageId: afterMessageId,
|
4906 | limit: limit
|
4907 | }));
|
4908 |
|
4909 | case 6:
|
4910 | if (!(startMessageId && !startTime)) {
|
4911 | _context7.next = 8;
|
4912 | break;
|
4913 | }
|
4914 |
|
4915 | throw new Error('query option startMessageId must be used with option startTime');
|
4916 |
|
4917 | case 8:
|
4918 | if (!(endMessageId && !endTime)) {
|
4919 | _context7.next = 10;
|
4920 | break;
|
4921 | }
|
4922 |
|
4923 | throw new Error('query option endMessageId must be used with option endTime');
|
4924 |
|
4925 | case 10:
|
4926 | conditions = {
|
4927 | t: startTime,
|
4928 | mid: startMessageId,
|
4929 | tIncluded: startClosed,
|
4930 | tt: endTime,
|
4931 | tmid: endMessageId,
|
4932 | ttIncluded: endClosed,
|
4933 | l: limit,
|
4934 | lctype: type
|
4935 | };
|
4936 |
|
4937 | if (conditions.t instanceof Date) {
|
4938 | conditions.t = conditions.t.getTime();
|
4939 | }
|
4940 |
|
4941 | if (conditions.tt instanceof Date) {
|
4942 | conditions.tt = conditions.tt.getTime();
|
4943 | }
|
4944 |
|
4945 | if (direction !== undefined) {
|
4946 | conditions.direction = direction;
|
4947 | } else if (conditions.tt > conditions.t) {
|
4948 | conditions.direction = MessageQueryDirection.OLD_TO_NEW;
|
4949 | }
|
4950 |
|
4951 | _context7.next = 16;
|
4952 | return this._send(new GenericCommand({
|
4953 | cmd: 'logs',
|
4954 | logsMessage: new LogsCommand(Object.assign(conditions, {
|
4955 | cid: this.id
|
4956 | }))
|
4957 | }));
|
4958 |
|
4959 | case 16:
|
4960 | resCommand = _context7.sent;
|
4961 | return _context7.abrupt("return", Promise.all(resCommand.logsMessage.logs.map(
|
4962 |
|
4963 | function () {
|
4964 | var _ref3 = _asyncToGenerator(
|
4965 |
|
4966 | _regeneratorRuntime.mark(function _callee6(_ref2) {
|
4967 | var msgId, timestamp, patchTimestamp, from, ackAt, readAt, data, mentionAll, mentionPids, bin, messageData, message, status;
|
4968 | return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
4969 | while (1) {
|
4970 | switch (_context6.prev = _context6.next) {
|
4971 | case 0:
|
4972 | msgId = _ref2.msgId, timestamp = _ref2.timestamp, patchTimestamp = _ref2.patchTimestamp, from = _ref2.from, ackAt = _ref2.ackAt, readAt = _ref2.readAt, data = _ref2.data, mentionAll = _ref2.mentionAll, mentionPids = _ref2.mentionPids, bin = _ref2.bin;
|
4973 | messageData = {
|
4974 | data: data,
|
4975 | bin: bin,
|
4976 | id: msgId,
|
4977 | cid: _this2.id,
|
4978 | timestamp: timestamp,
|
4979 | from: from,
|
4980 | deliveredAt: ackAt,
|
4981 | updatedAt: patchTimestamp,
|
4982 | mentionList: mentionPids,
|
4983 | mentionedAll: mentionAll
|
4984 | };
|
4985 | _context6.next = 4;
|
4986 | return _this2._client.parseMessage(messageData);
|
4987 |
|
4988 | case 4:
|
4989 | message = _context6.sent;
|
4990 | status = MessageStatus.SENT;
|
4991 |
|
4992 | if (_this2.members.length === 2) {
|
4993 | if (ackAt) status = MessageStatus.DELIVERED;
|
4994 | if (ackAt) _this2._setLastDeliveredAt(ackAt);
|
4995 | if (readAt) _this2._setLastReadAt(readAt);
|
4996 | }
|
4997 |
|
4998 | message._setStatus(status);
|
4999 |
|
5000 | return _context6.abrupt("return", message);
|
5001 |
|
5002 | case 9:
|
5003 | case "end":
|
5004 | return _context6.stop();
|
5005 | }
|
5006 | }
|
5007 | }, _callee6, this);
|
5008 | }));
|
5009 |
|
5010 | return function (_x9) {
|
5011 | return _ref3.apply(this, arguments);
|
5012 | };
|
5013 | }())));
|
5014 |
|
5015 | case 18:
|
5016 | case "end":
|
5017 | return _context7.stop();
|
5018 | }
|
5019 | }
|
5020 | }, _callee7, this);
|
5021 | }));
|
5022 |
|
5023 | function queryMessages() {
|
5024 | return _queryMessages.apply(this, arguments);
|
5025 | }
|
5026 |
|
5027 | return queryMessages;
|
5028 | }()
|
5029 | |
5030 |
|
5031 |
|
5032 |
|
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 |
|
5038 |
|
5039 |
|
5040 |
|
5041 |
|
5042 |
|
5043 |
|
5044 |
|
5045 |
|
5046 |
|
5047 |
|
5048 |
|
5049 |
|
5050 |
|
5051 |
|
5052 |
|
5053 |
|
5054 |
|
5055 | ;
|
5056 |
|
5057 | _proto.createMessagesIterator = function createMessagesIterator() {
|
5058 | var _this3 = this;
|
5059 |
|
5060 | var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
5061 | beforeTime = _ref4.beforeTime,
|
5062 | beforeMessageId = _ref4.beforeMessageId,
|
5063 | limit = _ref4.limit;
|
5064 |
|
5065 | var promise;
|
5066 | return {
|
5067 | next: function next() {
|
5068 | if (promise === undefined) {
|
5069 |
|
5070 | promise = _this3.queryMessages({
|
5071 | limit: limit,
|
5072 | startTime: beforeTime,
|
5073 | startMessageId: beforeMessageId
|
5074 | });
|
5075 | } else {
|
5076 | promise = promise.then(function (prevMessages) {
|
5077 | if (prevMessages.length === 0 || prevMessages.length < limit) {
|
5078 |
|
5079 | return [];
|
5080 | }
|
5081 |
|
5082 | return _this3.queryMessages({
|
5083 | startTime: prevMessages[0].timestamp,
|
5084 | startMessageId: prevMessages[0].id,
|
5085 | limit: limit
|
5086 | });
|
5087 | });
|
5088 | }
|
5089 |
|
5090 | return promise.then(function (value) {
|
5091 | return {
|
5092 | value: Array.from(value),
|
5093 | done: value.length === 0 || value.length < limit
|
5094 | };
|
5095 | });
|
5096 | }
|
5097 | };
|
5098 | }
|
5099 | |
5100 |
|
5101 |
|
5102 |
|
5103 | ;
|
5104 |
|
5105 | _proto.read =
|
5106 |
|
5107 | function () {
|
5108 | var _read = _asyncToGenerator(
|
5109 |
|
5110 | _regeneratorRuntime.mark(function _callee8() {
|
5111 | var client;
|
5112 | return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
5113 | while (1) {
|
5114 | switch (_context8.prev = _context8.next) {
|
5115 | case 0:
|
5116 | this.unreadMessagesCount = 0;
|
5117 |
|
5118 | this._setUnreadMessagesMentioned(false);
|
5119 |
|
5120 |
|
5121 | if (!this.transient) {
|
5122 | _context8.next = 4;
|
5123 | break;
|
5124 | }
|
5125 |
|
5126 | return _context8.abrupt("return", this);
|
5127 |
|
5128 | case 4:
|
5129 | client = this._client;
|
5130 |
|
5131 | if (!internal(client).readConversationsBuffer) {
|
5132 | internal(client).readConversationsBuffer = new Set();
|
5133 | }
|
5134 |
|
5135 | internal(client).readConversationsBuffer.add(this);
|
5136 |
|
5137 | client._doSendRead();
|
5138 |
|
5139 | return _context8.abrupt("return", this);
|
5140 |
|
5141 | case 9:
|
5142 | case "end":
|
5143 | return _context8.stop();
|
5144 | }
|
5145 | }
|
5146 | }, _callee8, this);
|
5147 | }));
|
5148 |
|
5149 | function read() {
|
5150 | return _read.apply(this, arguments);
|
5151 | }
|
5152 |
|
5153 | return read;
|
5154 | }();
|
5155 |
|
5156 | _proto._handleReceipt = function _handleReceipt(_ref5) {
|
5157 | var messageId = _ref5.messageId,
|
5158 | timestamp = _ref5.timestamp,
|
5159 | read = _ref5.read;
|
5160 |
|
5161 | if (read) {
|
5162 | this._setLastReadAt(timestamp);
|
5163 | } else {
|
5164 | this._setLastDeliveredAt(timestamp);
|
5165 | }
|
5166 |
|
5167 | var _internal = internal(this),
|
5168 | messagesWaitingForReceipt = _internal.messagesWaitingForReceipt;
|
5169 |
|
5170 | var message = messagesWaitingForReceipt[messageId];
|
5171 | if (!message) return;
|
5172 |
|
5173 | message._setStatus(MessageStatus.DELIVERED);
|
5174 |
|
5175 | message.deliveredAt = timestamp;
|
5176 | delete messagesWaitingForReceipt[messageId];
|
5177 | }
|
5178 | |
5179 |
|
5180 |
|
5181 |
|
5182 |
|
5183 | ;
|
5184 |
|
5185 | _proto.fetchReceiptTimestamps =
|
5186 |
|
5187 | function () {
|
5188 | var _fetchReceiptTimestamps = _asyncToGenerator(
|
5189 |
|
5190 | _regeneratorRuntime.mark(function _callee9() {
|
5191 | var _ref6, _ref6$convMessage, maxReadTimestamp, maxAckTimestamp;
|
5192 |
|
5193 | return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
5194 | while (1) {
|
5195 | switch (_context9.prev = _context9.next) {
|
5196 | case 0:
|
5197 | _context9.next = 2;
|
5198 | return this._send(new GenericCommand({
|
5199 | op: 'max_read'
|
5200 | }));
|
5201 |
|
5202 | case 2:
|
5203 | _ref6 = _context9.sent;
|
5204 | _ref6$convMessage = _ref6.convMessage;
|
5205 | maxReadTimestamp = _ref6$convMessage.maxReadTimestamp;
|
5206 | maxAckTimestamp = _ref6$convMessage.maxAckTimestamp;
|
5207 |
|
5208 | this._setLastDeliveredAt(maxAckTimestamp);
|
5209 |
|
5210 | this._setLastReadAt(maxReadTimestamp);
|
5211 |
|
5212 | return _context9.abrupt("return", this);
|
5213 |
|
5214 | case 9:
|
5215 | case "end":
|
5216 | return _context9.stop();
|
5217 | }
|
5218 | }
|
5219 | }, _callee9, this);
|
5220 | }));
|
5221 |
|
5222 | function fetchReceiptTimestamps() {
|
5223 | return _fetchReceiptTimestamps.apply(this, arguments);
|
5224 | }
|
5225 |
|
5226 | return fetchReceiptTimestamps;
|
5227 | }();
|
5228 |
|
5229 | _proto._fetchAllReceiptTimestamps = function _fetchAllReceiptTimestamps() {
|
5230 | var convMessage = new ConvCommand({
|
5231 | queryAllMembers: true
|
5232 | });
|
5233 | return this._send(new GenericCommand({
|
5234 | op: 'max_read',
|
5235 | convMessage: convMessage
|
5236 | })).then(function (_ref7) {
|
5237 | var maxReadTuples = _ref7.convMessage.maxReadTuples;
|
5238 | return maxReadTuples.filter(function (maxReadTuple) {
|
5239 | return maxReadTuple.maxAckTimestamp || maxReadTuple.maxReadTimestamp;
|
5240 | }).map(function (_ref8) {
|
5241 | var pid = _ref8.pid,
|
5242 | maxAckTimestamp = _ref8.maxAckTimestamp,
|
5243 | maxReadTimestamp = _ref8.maxReadTimestamp;
|
5244 | return {
|
5245 | pid: pid,
|
5246 | lastDeliveredAt: decodeDate(maxAckTimestamp),
|
5247 | lastReadAt: decodeDate(maxReadTimestamp)
|
5248 | };
|
5249 | });
|
5250 | });
|
5251 | };
|
5252 |
|
5253 | _createClass(ConversationBase, [{
|
5254 | key: "unreadMessagesMentioned",
|
5255 | get: function get() {
|
5256 | return internal(this).unreadMessagesMentioned;
|
5257 | }
|
5258 | }, {
|
5259 | key: "unreadMessagesCount",
|
5260 | set: function set(value) {
|
5261 | if (value !== this.unreadMessagesCount) {
|
5262 | internal(this).unreadMessagesCount = value;
|
5263 |
|
5264 | this._client.emit(UNREAD_MESSAGES_COUNT_UPDATE, [this]);
|
5265 | }
|
5266 | }
|
5267 | |
5268 |
|
5269 |
|
5270 |
|
5271 | ,
|
5272 | get: function get() {
|
5273 | return internal(this).unreadMessagesCount;
|
5274 | }
|
5275 | }, {
|
5276 | key: "lastMessageAt",
|
5277 | set: function set(value) {
|
5278 | var time = decodeDate(value);
|
5279 | if (time <= this._lastMessageAt) return;
|
5280 | this._lastMessageAt = time;
|
5281 | },
|
5282 | get: function get() {
|
5283 | return this._lastMessageAt;
|
5284 | }
|
5285 | |
5286 |
|
5287 |
|
5288 |
|
5289 |
|
5290 |
|
5291 | }, {
|
5292 | key: "lastDeliveredAt",
|
5293 | get: function get() {
|
5294 | if (this.members.length !== 2) return null;
|
5295 | return internal(this).lastDeliveredAt;
|
5296 | }
|
5297 | }, {
|
5298 | key: "lastReadAt",
|
5299 | get: function get() {
|
5300 | if (this.members.length !== 2) return null;
|
5301 | return internal(this).lastReadAt;
|
5302 | }
|
5303 | }]);
|
5304 |
|
5305 | return ConversationBase;
|
5306 | }(EventEmitter);
|
5307 |
|
5308 | var debug$7 = d('LC:SignatureFactoryRunner');
|
5309 |
|
5310 | function _validateSignature() {
|
5311 | var signatureResult = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
5312 | var signature = signatureResult.signature,
|
5313 | timestamp = signatureResult.timestamp,
|
5314 | nonce = signatureResult.nonce;
|
5315 |
|
5316 | if (typeof signature !== 'string' || typeof timestamp !== 'number' || typeof nonce !== 'string') {
|
5317 | throw new Error('malformed signature');
|
5318 | }
|
5319 |
|
5320 | return {
|
5321 | signature: signature,
|
5322 | timestamp: timestamp,
|
5323 | nonce: nonce
|
5324 | };
|
5325 | }
|
5326 |
|
5327 | var runSignatureFactory = (function (signatureFactory, params) {
|
5328 | return Promise.resolve().then(function () {
|
5329 | debug$7('call signatureFactory with %O', params);
|
5330 | return signatureFactory.apply(void 0, _toConsumableArray(params));
|
5331 | }).then(tap(function (signatureResult) {
|
5332 | return debug$7('sign result %O', signatureResult);
|
5333 | }), function (error) {
|
5334 |
|
5335 | error.message = "sign error: ".concat(error.message);
|
5336 | debug$7(error);
|
5337 | throw error;
|
5338 | }).then(_validateSignature);
|
5339 | });
|
5340 |
|
5341 |
|
5342 |
|
5343 |
|
5344 |
|
5345 |
|
5346 |
|
5347 |
|
5348 |
|
5349 |
|
5350 |
|
5351 |
|
5352 |
|
5353 |
|
5354 |
|
5355 |
|
5356 |
|
5357 |
|
5358 |
|
5359 |
|
5360 |
|
5361 |
|
5362 |
|
5363 |
|
5364 |
|
5365 |
|
5366 |
|
5367 | var createPartiallySuccess = function createPartiallySuccess(_ref) {
|
5368 | var allowedPids = _ref.allowedPids,
|
5369 | failedPids = _ref.failedPids;
|
5370 | return {
|
5371 | successfulClientIds: allowedPids,
|
5372 | failures: failedPids.map(function (_ref2) {
|
5373 | var pids = _ref2.pids,
|
5374 | error = _objectWithoutProperties(_ref2, ["pids"]);
|
5375 |
|
5376 | return Object.assign(createError(error), {
|
5377 | clientIds: pids
|
5378 | });
|
5379 | })
|
5380 | };
|
5381 | };
|
5382 |
|
5383 |
|
5384 |
|
5385 |
|
5386 |
|
5387 |
|
5388 |
|
5389 | var PersistentConversation =
|
5390 |
|
5391 | function (_ConversationBase) {
|
5392 | _inheritsLoose(PersistentConversation, _ConversationBase);
|
5393 |
|
5394 | function PersistentConversation(data, _ref3, client) {
|
5395 | var _this;
|
5396 |
|
5397 | var creator = _ref3.creator,
|
5398 | createdAt = _ref3.createdAt,
|
5399 | updatedAt = _ref3.updatedAt,
|
5400 | _ref3$transient = _ref3.transient,
|
5401 | transient = _ref3$transient === void 0 ? false : _ref3$transient,
|
5402 | _ref3$system = _ref3.system,
|
5403 | system = _ref3$system === void 0 ? false : _ref3$system,
|
5404 | _ref3$muted = _ref3.muted,
|
5405 | muted = _ref3$muted === void 0 ? false : _ref3$muted,
|
5406 | _ref3$mutedMembers = _ref3.mutedMembers,
|
5407 | mutedMembers = _ref3$mutedMembers === void 0 ? [] : _ref3$mutedMembers,
|
5408 | attributes = _objectWithoutProperties(_ref3, ["creator", "createdAt", "updatedAt", "transient", "system", "muted", "mutedMembers"]);
|
5409 |
|
5410 | _this = _ConversationBase.call(this, _objectSpread({}, data, {
|
5411 | |
5412 |
|
5413 |
|
5414 |
|
5415 |
|
5416 | creator: creator,
|
5417 |
|
5418 | |
5419 |
|
5420 |
|
5421 |
|
5422 |
|
5423 | createdAt: createdAt,
|
5424 |
|
5425 | |
5426 |
|
5427 |
|
5428 |
|
5429 |
|
5430 | updatedAt: updatedAt,
|
5431 |
|
5432 | |
5433 |
|
5434 |
|
5435 |
|
5436 |
|
5437 | mutedMembers: mutedMembers,
|
5438 |
|
5439 | |
5440 |
|
5441 |
|
5442 |
|
5443 |
|
5444 | transient: transient,
|
5445 |
|
5446 | |
5447 |
|
5448 |
|
5449 |
|
5450 |
|
5451 |
|
5452 | system: system,
|
5453 |
|
5454 | |
5455 |
|
5456 |
|
5457 |
|
5458 |
|
5459 | muted: muted,
|
5460 | _attributes: attributes
|
5461 | }), client) || this;
|
5462 |
|
5463 | _this._reset();
|
5464 |
|
5465 | return _this;
|
5466 | }
|
5467 |
|
5468 | var _proto = PersistentConversation.prototype;
|
5469 |
|
5470 | |
5471 |
|
5472 |
|
5473 |
|
5474 |
|
5475 |
|
5476 | _proto.get = function get(key) {
|
5477 | return internal(this).currentAttributes[key];
|
5478 | }
|
5479 | |
5480 |
|
5481 |
|
5482 |
|
5483 |
|
5484 |
|
5485 |
|
5486 |
|
5487 |
|
5488 |
|
5489 |
|
5490 |
|
5491 |
|
5492 |
|
5493 |
|
5494 |
|
5495 | ;
|
5496 |
|
5497 | _proto.set = function set(key, value) {
|
5498 | this._debug("set [".concat(key, "]: ").concat(value));
|
5499 |
|
5500 | var _internal = internal(this),
|
5501 | pendingAttributes = _internal.pendingAttributes;
|
5502 |
|
5503 | var pendingKeys = Object.keys(pendingAttributes);
|
5504 |
|
5505 |
|
5506 | var re = new RegExp("^".concat(key));
|
5507 | var childKeys = pendingKeys.filter(re.test.bind(re));
|
5508 | childKeys.forEach(function (k) {
|
5509 | delete pendingAttributes[k];
|
5510 | });
|
5511 |
|
5512 | if (childKeys.length) {
|
5513 | pendingAttributes[key] = value;
|
5514 | } else {
|
5515 |
|
5516 |
|
5517 | var parentKey = find(pendingKeys, function (k) {
|
5518 | return key.indexOf(k) === 0;
|
5519 | });
|
5520 |
|
5521 | if (parentKey) {
|
5522 | setValue(pendingAttributes[parentKey], key.slice(parentKey.length + 1), value);
|
5523 | } else {
|
5524 | pendingAttributes[key] = value;
|
5525 | }
|
5526 | }
|
5527 |
|
5528 | this._buildCurrentAttributes();
|
5529 |
|
5530 | return this;
|
5531 | };
|
5532 |
|
5533 | _proto._buildCurrentAttributes = function _buildCurrentAttributes() {
|
5534 | var _internal2 = internal(this),
|
5535 | pendingAttributes = _internal2.pendingAttributes;
|
5536 |
|
5537 | internal(this).currentAttributes = Object.keys(pendingAttributes).reduce(function (target, k) {
|
5538 | return setValue(target, k, pendingAttributes[k]);
|
5539 | }, cloneDeep(this._attributes));
|
5540 | };
|
5541 |
|
5542 | _proto._updateServerAttributes = function _updateServerAttributes(attributes) {
|
5543 | var _this2 = this;
|
5544 |
|
5545 | Object.keys(attributes).forEach(function (key) {
|
5546 | return setValue(_this2._attributes, key, attributes[key]);
|
5547 | });
|
5548 |
|
5549 | this._buildCurrentAttributes();
|
5550 | };
|
5551 |
|
5552 | _proto._reset = function _reset() {
|
5553 | Object.assign(internal(this), {
|
5554 | pendingAttributes: {},
|
5555 | currentAttributes: this._attributes
|
5556 | });
|
5557 | }
|
5558 | |
5559 |
|
5560 |
|
5561 |
|
5562 | ;
|
5563 |
|
5564 | _proto.save =
|
5565 |
|
5566 | function () {
|
5567 | var _save = _asyncToGenerator(
|
5568 |
|
5569 | _regeneratorRuntime.mark(function _callee() {
|
5570 | var attr, convMessage, resCommand;
|
5571 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
5572 | while (1) {
|
5573 | switch (_context.prev = _context.next) {
|
5574 | case 0:
|
5575 | this._debug('save');
|
5576 |
|
5577 | attr = internal(this).pendingAttributes;
|
5578 |
|
5579 | if (!isEmpty(attr)) {
|
5580 | _context.next = 5;
|
5581 | break;
|
5582 | }
|
5583 |
|
5584 | this._debug('nothing touched, resolve with self');
|
5585 |
|
5586 | return _context.abrupt("return", this);
|
5587 |
|
5588 | case 5:
|
5589 | this._debug('attr: %O', attr);
|
5590 |
|
5591 | convMessage = new ConvCommand({
|
5592 | attr: new JsonObjectMessage({
|
5593 | data: JSON.stringify(encode(attr))
|
5594 | })
|
5595 | });
|
5596 | _context.next = 9;
|
5597 | return this._send(new GenericCommand({
|
5598 | op: 'update',
|
5599 | convMessage: convMessage
|
5600 | }));
|
5601 |
|
5602 | case 9:
|
5603 | resCommand = _context.sent;
|
5604 | this.updatedAt = resCommand.convMessage.udate;
|
5605 | this._attributes = internal(this).currentAttributes;
|
5606 | internal(this).pendingAttributes = {};
|
5607 | return _context.abrupt("return", this);
|
5608 |
|
5609 | case 14:
|
5610 | case "end":
|
5611 | return _context.stop();
|
5612 | }
|
5613 | }
|
5614 | }, _callee, this);
|
5615 | }));
|
5616 |
|
5617 | function save() {
|
5618 | return _save.apply(this, arguments);
|
5619 | }
|
5620 |
|
5621 | return save;
|
5622 | }()
|
5623 | |
5624 |
|
5625 |
|
5626 |
|
5627 | ;
|
5628 |
|
5629 | _proto.fetch =
|
5630 |
|
5631 | function () {
|
5632 | var _fetch = _asyncToGenerator(
|
5633 |
|
5634 | _regeneratorRuntime.mark(function _callee2() {
|
5635 | var query;
|
5636 | return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
5637 | while (1) {
|
5638 | switch (_context2.prev = _context2.next) {
|
5639 | case 0:
|
5640 | query = this._client.getQuery().equalTo('objectId', this.id);
|
5641 | _context2.next = 3;
|
5642 | return query.find();
|
5643 |
|
5644 | case 3:
|
5645 | return _context2.abrupt("return", this);
|
5646 |
|
5647 | case 4:
|
5648 | case "end":
|
5649 | return _context2.stop();
|
5650 | }
|
5651 | }
|
5652 | }, _callee2, this);
|
5653 | }));
|
5654 |
|
5655 | function fetch() {
|
5656 | return _fetch.apply(this, arguments);
|
5657 | }
|
5658 |
|
5659 | return fetch;
|
5660 | }()
|
5661 | |
5662 |
|
5663 |
|
5664 |
|
5665 | ;
|
5666 |
|
5667 | _proto.mute =
|
5668 |
|
5669 | function () {
|
5670 | var _mute = _asyncToGenerator(
|
5671 |
|
5672 | _regeneratorRuntime.mark(function _callee3() {
|
5673 | return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
5674 | while (1) {
|
5675 | switch (_context3.prev = _context3.next) {
|
5676 | case 0:
|
5677 | this._debug('mute');
|
5678 |
|
5679 | _context3.next = 3;
|
5680 | return this._send(new GenericCommand({
|
5681 | op: 'mute'
|
5682 | }));
|
5683 |
|
5684 | case 3:
|
5685 | if (!this.transient) {
|
5686 | this.muted = true;
|
5687 | this.mutedMembers = union(this.mutedMembers, [this._client.id]);
|
5688 | }
|
5689 |
|
5690 | return _context3.abrupt("return", this);
|
5691 |
|
5692 | case 5:
|
5693 | case "end":
|
5694 | return _context3.stop();
|
5695 | }
|
5696 | }
|
5697 | }, _callee3, this);
|
5698 | }));
|
5699 |
|
5700 | function mute() {
|
5701 | return _mute.apply(this, arguments);
|
5702 | }
|
5703 |
|
5704 | return mute;
|
5705 | }()
|
5706 | |
5707 |
|
5708 |
|
5709 |
|
5710 | ;
|
5711 |
|
5712 | _proto.unmute =
|
5713 |
|
5714 | function () {
|
5715 | var _unmute = _asyncToGenerator(
|
5716 |
|
5717 | _regeneratorRuntime.mark(function _callee4() {
|
5718 | return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
5719 | while (1) {
|
5720 | switch (_context4.prev = _context4.next) {
|
5721 | case 0:
|
5722 | this._debug('unmute');
|
5723 |
|
5724 | _context4.next = 3;
|
5725 | return this._send(new GenericCommand({
|
5726 | op: 'unmute'
|
5727 | }));
|
5728 |
|
5729 | case 3:
|
5730 | if (!this.transient) {
|
5731 | this.muted = false;
|
5732 | this.mutedMembers = difference(this.mutedMembers, [this._client.id]);
|
5733 | }
|
5734 |
|
5735 | return _context4.abrupt("return", this);
|
5736 |
|
5737 | case 5:
|
5738 | case "end":
|
5739 | return _context4.stop();
|
5740 | }
|
5741 | }
|
5742 | }, _callee4, this);
|
5743 | }));
|
5744 |
|
5745 | function unmute() {
|
5746 | return _unmute.apply(this, arguments);
|
5747 | }
|
5748 |
|
5749 | return unmute;
|
5750 | }();
|
5751 |
|
5752 | _proto._appendConversationSignature =
|
5753 |
|
5754 | function () {
|
5755 | var _appendConversationSignature2 = _asyncToGenerator(
|
5756 |
|
5757 | _regeneratorRuntime.mark(function _callee5(command, action, clientIds) {
|
5758 | var params, signatureResult;
|
5759 | return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
5760 | while (1) {
|
5761 | switch (_context5.prev = _context5.next) {
|
5762 | case 0:
|
5763 | if (!this._client.options.conversationSignatureFactory) {
|
5764 | _context5.next = 6;
|
5765 | break;
|
5766 | }
|
5767 |
|
5768 | params = [this.id, this._client.id, clientIds.sort(), action];
|
5769 | _context5.next = 4;
|
5770 | return runSignatureFactory(this._client.options.conversationSignatureFactory, params);
|
5771 |
|
5772 | case 4:
|
5773 | signatureResult = _context5.sent;
|
5774 | Object.assign(command.convMessage, keyRemap({
|
5775 | signature: 's',
|
5776 | timestamp: 't',
|
5777 | nonce: 'n'
|
5778 | }, signatureResult));
|
5779 |
|
5780 | case 6:
|
5781 | case "end":
|
5782 | return _context5.stop();
|
5783 | }
|
5784 | }
|
5785 | }, _callee5, this);
|
5786 | }));
|
5787 |
|
5788 | function _appendConversationSignature(_x, _x2, _x3) {
|
5789 | return _appendConversationSignature2.apply(this, arguments);
|
5790 | }
|
5791 |
|
5792 | return _appendConversationSignature;
|
5793 | }();
|
5794 |
|
5795 | _proto._appendBlacklistSignature =
|
5796 |
|
5797 | function () {
|
5798 | var _appendBlacklistSignature2 = _asyncToGenerator(
|
5799 |
|
5800 | _regeneratorRuntime.mark(function _callee6(command, action, clientIds) {
|
5801 | var params, signatureResult;
|
5802 | return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
5803 | while (1) {
|
5804 | switch (_context6.prev = _context6.next) {
|
5805 | case 0:
|
5806 | if (!this._client.options.blacklistSignatureFactory) {
|
5807 | _context6.next = 6;
|
5808 | break;
|
5809 | }
|
5810 |
|
5811 | params = [this._client.id, this.id, clientIds.sort(), action];
|
5812 | _context6.next = 4;
|
5813 | return runSignatureFactory(this._client.options.blacklistSignatureFactory, params);
|
5814 |
|
5815 | case 4:
|
5816 | signatureResult = _context6.sent;
|
5817 | Object.assign(command.blacklistMessage, keyRemap({
|
5818 | signature: 's',
|
5819 | timestamp: 't',
|
5820 | nonce: 'n'
|
5821 | }, signatureResult));
|
5822 |
|
5823 | case 6:
|
5824 | case "end":
|
5825 | return _context6.stop();
|
5826 | }
|
5827 | }
|
5828 | }, _callee6, this);
|
5829 | }));
|
5830 |
|
5831 | function _appendBlacklistSignature(_x4, _x5, _x6) {
|
5832 | return _appendBlacklistSignature2.apply(this, arguments);
|
5833 | }
|
5834 |
|
5835 | return _appendBlacklistSignature;
|
5836 | }()
|
5837 | |
5838 |
|
5839 |
|
5840 |
|
5841 |
|
5842 | ;
|
5843 |
|
5844 | _proto.add =
|
5845 |
|
5846 | function () {
|
5847 | var _add = _asyncToGenerator(
|
5848 |
|
5849 | _regeneratorRuntime.mark(function _callee7(clientIds) {
|
5850 | var command, _ref4, convMessage, allowedPids;
|
5851 |
|
5852 | return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
5853 | while (1) {
|
5854 | switch (_context7.prev = _context7.next) {
|
5855 | case 0:
|
5856 | this._debug('add', clientIds);
|
5857 |
|
5858 | if (typeof clientIds === 'string') {
|
5859 | clientIds = [clientIds];
|
5860 | }
|
5861 |
|
5862 | command = new GenericCommand({
|
5863 | op: 'add',
|
5864 | convMessage: new ConvCommand({
|
5865 | m: clientIds
|
5866 | })
|
5867 | });
|
5868 | _context7.next = 5;
|
5869 | return this._appendConversationSignature(command, 'add', clientIds);
|
5870 |
|
5871 | case 5:
|
5872 | _context7.next = 7;
|
5873 | return this._send(command);
|
5874 |
|
5875 | case 7:
|
5876 | _ref4 = _context7.sent;
|
5877 | convMessage = _ref4.convMessage;
|
5878 | allowedPids = _ref4.convMessage.allowedPids;
|
5879 |
|
5880 | this._addMembers(allowedPids);
|
5881 |
|
5882 | return _context7.abrupt("return", createPartiallySuccess(convMessage));
|
5883 |
|
5884 | case 12:
|
5885 | case "end":
|
5886 | return _context7.stop();
|
5887 | }
|
5888 | }
|
5889 | }, _callee7, this);
|
5890 | }));
|
5891 |
|
5892 | function add(_x7) {
|
5893 | return _add.apply(this, arguments);
|
5894 | }
|
5895 |
|
5896 | return add;
|
5897 | }()
|
5898 | |
5899 |
|
5900 |
|
5901 |
|
5902 |
|
5903 | ;
|
5904 |
|
5905 | _proto.remove =
|
5906 |
|
5907 | function () {
|
5908 | var _remove = _asyncToGenerator(
|
5909 |
|
5910 | _regeneratorRuntime.mark(function _callee8(clientIds) {
|
5911 | var command, _ref5, convMessage, allowedPids;
|
5912 |
|
5913 | return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
5914 | while (1) {
|
5915 | switch (_context8.prev = _context8.next) {
|
5916 | case 0:
|
5917 | this._debug('remove', clientIds);
|
5918 |
|
5919 | if (typeof clientIds === 'string') {
|
5920 | clientIds = [clientIds];
|
5921 | }
|
5922 |
|
5923 | command = new GenericCommand({
|
5924 | op: 'remove',
|
5925 | convMessage: new ConvCommand({
|
5926 | m: clientIds
|
5927 | })
|
5928 | });
|
5929 | _context8.next = 5;
|
5930 | return this._appendConversationSignature(command, 'remove', clientIds);
|
5931 |
|
5932 | case 5:
|
5933 | _context8.next = 7;
|
5934 | return this._send(command);
|
5935 |
|
5936 | case 7:
|
5937 | _ref5 = _context8.sent;
|
5938 | convMessage = _ref5.convMessage;
|
5939 | allowedPids = _ref5.convMessage.allowedPids;
|
5940 |
|
5941 | this._removeMembers(allowedPids);
|
5942 |
|
5943 | return _context8.abrupt("return", createPartiallySuccess(convMessage));
|
5944 |
|
5945 | case 12:
|
5946 | case "end":
|
5947 | return _context8.stop();
|
5948 | }
|
5949 | }
|
5950 | }, _callee8, this);
|
5951 | }));
|
5952 |
|
5953 | function remove(_x8) {
|
5954 | return _remove.apply(this, arguments);
|
5955 | }
|
5956 |
|
5957 | return remove;
|
5958 | }()
|
5959 | |
5960 |
|
5961 |
|
5962 |
|
5963 | ;
|
5964 |
|
5965 | _proto.join =
|
5966 |
|
5967 | function () {
|
5968 | var _join = _asyncToGenerator(
|
5969 |
|
5970 | _regeneratorRuntime.mark(function _callee9() {
|
5971 | var _this3 = this;
|
5972 |
|
5973 | return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
5974 | while (1) {
|
5975 | switch (_context9.prev = _context9.next) {
|
5976 | case 0:
|
5977 | this._debug('join');
|
5978 |
|
5979 | return _context9.abrupt("return", this.add(this._client.id).then(function (_ref6) {
|
5980 | var failures = _ref6.failures;
|
5981 | if (failures[0]) throw failures[0];
|
5982 | return _this3;
|
5983 | }));
|
5984 |
|
5985 | case 2:
|
5986 | case "end":
|
5987 | return _context9.stop();
|
5988 | }
|
5989 | }
|
5990 | }, _callee9, this);
|
5991 | }));
|
5992 |
|
5993 | function join() {
|
5994 | return _join.apply(this, arguments);
|
5995 | }
|
5996 |
|
5997 | return join;
|
5998 | }()
|
5999 | |
6000 |
|
6001 |
|
6002 |
|
6003 | ;
|
6004 |
|
6005 | _proto.quit =
|
6006 |
|
6007 | function () {
|
6008 | var _quit = _asyncToGenerator(
|
6009 |
|
6010 | _regeneratorRuntime.mark(function _callee10() {
|
6011 | var _this4 = this;
|
6012 |
|
6013 | return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
6014 | while (1) {
|
6015 | switch (_context10.prev = _context10.next) {
|
6016 | case 0:
|
6017 | this._debug('quit');
|
6018 |
|
6019 | return _context10.abrupt("return", this.remove(this._client.id).then(function (_ref7) {
|
6020 | var failures = _ref7.failures;
|
6021 | if (failures[0]) throw failures[0];
|
6022 | return _this4;
|
6023 | }));
|
6024 |
|
6025 | case 2:
|
6026 | case "end":
|
6027 | return _context10.stop();
|
6028 | }
|
6029 | }
|
6030 | }, _callee10, this);
|
6031 | }));
|
6032 |
|
6033 | function quit() {
|
6034 | return _quit.apply(this, arguments);
|
6035 | }
|
6036 |
|
6037 | return quit;
|
6038 | }()
|
6039 | |
6040 |
|
6041 |
|
6042 |
|
6043 |
|
6044 | ;
|
6045 |
|
6046 | _proto.muteMembers =
|
6047 |
|
6048 | function () {
|
6049 | var _muteMembers = _asyncToGenerator(
|
6050 |
|
6051 | _regeneratorRuntime.mark(function _callee11(clientIds) {
|
6052 | var command, _ref8, convMessage;
|
6053 |
|
6054 | return _regeneratorRuntime.wrap(function _callee11$(_context11) {
|
6055 | while (1) {
|
6056 | switch (_context11.prev = _context11.next) {
|
6057 | case 0:
|
6058 | this._debug('mute', clientIds);
|
6059 |
|
6060 | clientIds = ensureArray(clientIds);
|
6061 |
|
6062 | command = new GenericCommand({
|
6063 | op: OpType.add_shutup,
|
6064 | convMessage: new ConvCommand({
|
6065 | m: clientIds
|
6066 | })
|
6067 | });
|
6068 | _context11.next = 5;
|
6069 | return this._send(command);
|
6070 |
|
6071 | case 5:
|
6072 | _ref8 = _context11.sent;
|
6073 | convMessage = _ref8.convMessage;
|
6074 | return _context11.abrupt("return", createPartiallySuccess(convMessage));
|
6075 |
|
6076 | case 8:
|
6077 | case "end":
|
6078 | return _context11.stop();
|
6079 | }
|
6080 | }
|
6081 | }, _callee11, this);
|
6082 | }));
|
6083 |
|
6084 | function muteMembers(_x9) {
|
6085 | return _muteMembers.apply(this, arguments);
|
6086 | }
|
6087 |
|
6088 | return muteMembers;
|
6089 | }()
|
6090 | |
6091 |
|
6092 |
|
6093 |
|
6094 |
|
6095 | ;
|
6096 |
|
6097 | _proto.unmuteMembers =
|
6098 |
|
6099 | function () {
|
6100 | var _unmuteMembers = _asyncToGenerator(
|
6101 |
|
6102 | _regeneratorRuntime.mark(function _callee12(clientIds) {
|
6103 | var command, _ref9, convMessage;
|
6104 |
|
6105 | return _regeneratorRuntime.wrap(function _callee12$(_context12) {
|
6106 | while (1) {
|
6107 | switch (_context12.prev = _context12.next) {
|
6108 | case 0:
|
6109 | this._debug('unmute', clientIds);
|
6110 |
|
6111 | clientIds = ensureArray(clientIds);
|
6112 |
|
6113 | command = new GenericCommand({
|
6114 | op: OpType.remove_shutup,
|
6115 | convMessage: new ConvCommand({
|
6116 | m: clientIds
|
6117 | })
|
6118 | });
|
6119 | _context12.next = 5;
|
6120 | return this._send(command);
|
6121 |
|
6122 | case 5:
|
6123 | _ref9 = _context12.sent;
|
6124 | convMessage = _ref9.convMessage;
|
6125 | return _context12.abrupt("return", createPartiallySuccess(convMessage));
|
6126 |
|
6127 | case 8:
|
6128 | case "end":
|
6129 | return _context12.stop();
|
6130 | }
|
6131 | }
|
6132 | }, _callee12, this);
|
6133 | }));
|
6134 |
|
6135 | function unmuteMembers(_x10) {
|
6136 | return _unmuteMembers.apply(this, arguments);
|
6137 | }
|
6138 |
|
6139 | return unmuteMembers;
|
6140 | }()
|
6141 | |
6142 |
|
6143 |
|
6144 |
|
6145 |
|
6146 |
|
6147 |
|
6148 | ;
|
6149 |
|
6150 | _proto.queryMutedMembers =
|
6151 |
|
6152 | function () {
|
6153 | var _queryMutedMembers = _asyncToGenerator(
|
6154 |
|
6155 | _regeneratorRuntime.mark(function _callee13() {
|
6156 | var _ref10,
|
6157 | limit,
|
6158 | next,
|
6159 | command,
|
6160 | _ref11,
|
6161 | _ref11$convMessage,
|
6162 | m,
|
6163 | newNext,
|
6164 | _args13 = arguments;
|
6165 |
|
6166 | return _regeneratorRuntime.wrap(function _callee13$(_context13) {
|
6167 | while (1) {
|
6168 | switch (_context13.prev = _context13.next) {
|
6169 | case 0:
|
6170 | _ref10 = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {}, limit = _ref10.limit, next = _ref10.next;
|
6171 |
|
6172 | this._debug('query muted: limit %O, next: %O', limit, next);
|
6173 |
|
6174 | command = new GenericCommand({
|
6175 | op: OpType.query_shutup,
|
6176 | convMessage: new ConvCommand({
|
6177 | limit: limit,
|
6178 | next: next
|
6179 | })
|
6180 | });
|
6181 | _context13.next = 5;
|
6182 | return this._send(command);
|
6183 |
|
6184 | case 5:
|
6185 | _ref11 = _context13.sent;
|
6186 | _ref11$convMessage = _ref11.convMessage;
|
6187 | m = _ref11$convMessage.m;
|
6188 | newNext = _ref11$convMessage.next;
|
6189 | return _context13.abrupt("return", {
|
6190 | results: m,
|
6191 | next: newNext
|
6192 | });
|
6193 |
|
6194 | case 10:
|
6195 | case "end":
|
6196 | return _context13.stop();
|
6197 | }
|
6198 | }
|
6199 | }, _callee13, this);
|
6200 | }));
|
6201 |
|
6202 | function queryMutedMembers() {
|
6203 | return _queryMutedMembers.apply(this, arguments);
|
6204 | }
|
6205 |
|
6206 | return queryMutedMembers;
|
6207 | }()
|
6208 | |
6209 |
|
6210 |
|
6211 |
|
6212 |
|
6213 | ;
|
6214 |
|
6215 | _proto.blockMembers =
|
6216 |
|
6217 | function () {
|
6218 | var _blockMembers = _asyncToGenerator(
|
6219 |
|
6220 | _regeneratorRuntime.mark(function _callee14(clientIds) {
|
6221 | var command, _ref12, blacklistMessage;
|
6222 |
|
6223 | return _regeneratorRuntime.wrap(function _callee14$(_context14) {
|
6224 | while (1) {
|
6225 | switch (_context14.prev = _context14.next) {
|
6226 | case 0:
|
6227 | this._debug('block', clientIds);
|
6228 |
|
6229 | clientIds = ensureArray(clientIds);
|
6230 |
|
6231 | command = new GenericCommand({
|
6232 | cmd: 'blacklist',
|
6233 | op: OpType.block,
|
6234 | blacklistMessage: new BlacklistCommand({
|
6235 | srcCid: this.id,
|
6236 | toPids: clientIds
|
6237 | })
|
6238 | });
|
6239 | _context14.next = 5;
|
6240 | return this._appendBlacklistSignature(command, 'conversation-block-clients', clientIds);
|
6241 |
|
6242 | case 5:
|
6243 | _context14.next = 7;
|
6244 | return this._send(command);
|
6245 |
|
6246 | case 7:
|
6247 | _ref12 = _context14.sent;
|
6248 | blacklistMessage = _ref12.blacklistMessage;
|
6249 | return _context14.abrupt("return", createPartiallySuccess(blacklistMessage));
|
6250 |
|
6251 | case 10:
|
6252 | case "end":
|
6253 | return _context14.stop();
|
6254 | }
|
6255 | }
|
6256 | }, _callee14, this);
|
6257 | }));
|
6258 |
|
6259 | function blockMembers(_x11) {
|
6260 | return _blockMembers.apply(this, arguments);
|
6261 | }
|
6262 |
|
6263 | return blockMembers;
|
6264 | }()
|
6265 | |
6266 |
|
6267 |
|
6268 |
|
6269 |
|
6270 | ;
|
6271 |
|
6272 | _proto.unblockMembers =
|
6273 |
|
6274 | function () {
|
6275 | var _unblockMembers = _asyncToGenerator(
|
6276 |
|
6277 | _regeneratorRuntime.mark(function _callee15(clientIds) {
|
6278 | var command, _ref13, blacklistMessage;
|
6279 |
|
6280 | return _regeneratorRuntime.wrap(function _callee15$(_context15) {
|
6281 | while (1) {
|
6282 | switch (_context15.prev = _context15.next) {
|
6283 | case 0:
|
6284 | this._debug('unblock', clientIds);
|
6285 |
|
6286 | clientIds = ensureArray(clientIds);
|
6287 |
|
6288 | command = new GenericCommand({
|
6289 | cmd: 'blacklist',
|
6290 | op: OpType.unblock,
|
6291 | blacklistMessage: new BlacklistCommand({
|
6292 | srcCid: this.id,
|
6293 | toPids: clientIds
|
6294 | })
|
6295 | });
|
6296 | _context15.next = 5;
|
6297 | return this._appendBlacklistSignature(command, 'conversation-unblock-clients', clientIds);
|
6298 |
|
6299 | case 5:
|
6300 | _context15.next = 7;
|
6301 | return this._send(command);
|
6302 |
|
6303 | case 7:
|
6304 | _ref13 = _context15.sent;
|
6305 | blacklistMessage = _ref13.blacklistMessage;
|
6306 | return _context15.abrupt("return", createPartiallySuccess(blacklistMessage));
|
6307 |
|
6308 | case 10:
|
6309 | case "end":
|
6310 | return _context15.stop();
|
6311 | }
|
6312 | }
|
6313 | }, _callee15, this);
|
6314 | }));
|
6315 |
|
6316 | function unblockMembers(_x12) {
|
6317 | return _unblockMembers.apply(this, arguments);
|
6318 | }
|
6319 |
|
6320 | return unblockMembers;
|
6321 | }()
|
6322 | |
6323 |
|
6324 |
|
6325 |
|
6326 |
|
6327 |
|
6328 |
|
6329 | ;
|
6330 |
|
6331 | _proto.queryBlockedMembers =
|
6332 |
|
6333 | function () {
|
6334 | var _queryBlockedMembers = _asyncToGenerator(
|
6335 |
|
6336 | _regeneratorRuntime.mark(function _callee16() {
|
6337 | var _ref14,
|
6338 | limit,
|
6339 | next,
|
6340 | command,
|
6341 | _ref15,
|
6342 | _ref15$blacklistMessa,
|
6343 | blockedPids,
|
6344 | newNext,
|
6345 | _args16 = arguments;
|
6346 |
|
6347 | return _regeneratorRuntime.wrap(function _callee16$(_context16) {
|
6348 | while (1) {
|
6349 | switch (_context16.prev = _context16.next) {
|
6350 | case 0:
|
6351 | _ref14 = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {}, limit = _ref14.limit, next = _ref14.next;
|
6352 |
|
6353 | this._debug('query blocked: limit %O, next: %O', limit, next);
|
6354 |
|
6355 | command = new GenericCommand({
|
6356 | cmd: 'blacklist',
|
6357 | op: OpType.query,
|
6358 | blacklistMessage: new BlacklistCommand({
|
6359 | srcCid: this.id,
|
6360 | limit: limit,
|
6361 | next: next
|
6362 | })
|
6363 | });
|
6364 | _context16.next = 5;
|
6365 | return this._send(command);
|
6366 |
|
6367 | case 5:
|
6368 | _ref15 = _context16.sent;
|
6369 | _ref15$blacklistMessa = _ref15.blacklistMessage;
|
6370 | blockedPids = _ref15$blacklistMessa.blockedPids;
|
6371 | newNext = _ref15$blacklistMessa.next;
|
6372 | return _context16.abrupt("return", {
|
6373 | results: blockedPids,
|
6374 | next: newNext
|
6375 | });
|
6376 |
|
6377 | case 10:
|
6378 | case "end":
|
6379 | return _context16.stop();
|
6380 | }
|
6381 | }
|
6382 | }, _callee16, this);
|
6383 | }));
|
6384 |
|
6385 | function queryBlockedMembers() {
|
6386 | return _queryBlockedMembers.apply(this, arguments);
|
6387 | }
|
6388 |
|
6389 | return queryBlockedMembers;
|
6390 | }();
|
6391 |
|
6392 | _proto.toFullJSON = function toFullJSON() {
|
6393 | var creator = this.creator,
|
6394 | system = this.system,
|
6395 | transient = this.transient,
|
6396 | createdAt = this.createdAt,
|
6397 | updatedAt = this.updatedAt,
|
6398 | _attributes = this._attributes;
|
6399 | return _objectSpread({}, _ConversationBase.prototype.toFullJSON.call(this), {
|
6400 | creator: creator,
|
6401 | system: system,
|
6402 | transient: transient,
|
6403 | createdAt: getTime(createdAt),
|
6404 | updatedAt: getTime(updatedAt)
|
6405 | }, _attributes);
|
6406 | };
|
6407 |
|
6408 | _proto.toJSON = function toJSON() {
|
6409 | var creator = this.creator,
|
6410 | system = this.system,
|
6411 | transient = this.transient,
|
6412 | muted = this.muted,
|
6413 | mutedMembers = this.mutedMembers,
|
6414 | createdAt = this.createdAt,
|
6415 | updatedAt = this.updatedAt,
|
6416 | _attributes = this._attributes;
|
6417 | return _objectSpread({}, _ConversationBase.prototype.toJSON.call(this), {
|
6418 | creator: creator,
|
6419 | system: system,
|
6420 | transient: transient,
|
6421 | muted: muted,
|
6422 | mutedMembers: mutedMembers,
|
6423 | createdAt: createdAt,
|
6424 | updatedAt: updatedAt
|
6425 | }, _attributes);
|
6426 | };
|
6427 |
|
6428 | _createClass(PersistentConversation, [{
|
6429 | key: "createdAt",
|
6430 | set: function set(value) {
|
6431 | this._createdAt = decodeDate(value);
|
6432 | },
|
6433 | get: function get() {
|
6434 | return this._createdAt;
|
6435 | }
|
6436 | }, {
|
6437 | key: "updatedAt",
|
6438 | set: function set(value) {
|
6439 | this._updatedAt = decodeDate(value);
|
6440 | },
|
6441 | get: function get() {
|
6442 | return this._updatedAt;
|
6443 | }
|
6444 | |
6445 |
|
6446 |
|
6447 |
|
6448 |
|
6449 | }, {
|
6450 | key: "name",
|
6451 | get: function get() {
|
6452 | return this.get('name');
|
6453 | },
|
6454 | set: function set(value) {
|
6455 | this.set('name', value);
|
6456 | }
|
6457 | }]);
|
6458 |
|
6459 | return PersistentConversation;
|
6460 | }(ConversationBase);
|
6461 |
|
6462 |
|
6463 |
|
6464 |
|
6465 |
|
6466 |
|
6467 |
|
6468 |
|
6469 | var ConversationMemberRole = {
|
6470 |
|
6471 | OWNER: 'Owner',
|
6472 |
|
6473 |
|
6474 | MANAGER: 'Manager',
|
6475 |
|
6476 |
|
6477 | MEMBER: 'Member'
|
6478 | };
|
6479 | Object.freeze(ConversationMemberRole);
|
6480 |
|
6481 | var ConversationMemberInfo =
|
6482 |
|
6483 | function () {
|
6484 | |
6485 |
|
6486 |
|
6487 |
|
6488 | function ConversationMemberInfo(_ref) {
|
6489 | var conversation = _ref.conversation,
|
6490 | memberId = _ref.memberId,
|
6491 | role = _ref.role;
|
6492 | if (!conversation) throw new Error('conversation requried');
|
6493 | if (!memberId) throw new Error('memberId requried');
|
6494 | Object.assign(internal(this), {
|
6495 | conversation: conversation,
|
6496 | memberId: memberId,
|
6497 | role: role
|
6498 | });
|
6499 | }
|
6500 | |
6501 |
|
6502 |
|
6503 |
|
6504 |
|
6505 |
|
6506 |
|
6507 | var _proto = ConversationMemberInfo.prototype;
|
6508 |
|
6509 | _proto.toJSON = function toJSON() {
|
6510 | var conversationId = this.conversationId,
|
6511 | memberId = this.memberId,
|
6512 | role = this.role,
|
6513 | isOwner = this.isOwner;
|
6514 | return {
|
6515 | conversationId: conversationId,
|
6516 | memberId: memberId,
|
6517 | role: role,
|
6518 | isOwner: isOwner
|
6519 | };
|
6520 | };
|
6521 |
|
6522 | _createClass(ConversationMemberInfo, [{
|
6523 | key: "conversationId",
|
6524 | get: function get() {
|
6525 | return internal(this).conversation.id;
|
6526 | }
|
6527 | |
6528 |
|
6529 |
|
6530 |
|
6531 |
|
6532 |
|
6533 | }, {
|
6534 | key: "memberId",
|
6535 | get: function get() {
|
6536 | return internal(this).memberId;
|
6537 | }
|
6538 | |
6539 |
|
6540 |
|
6541 |
|
6542 |
|
6543 |
|
6544 | }, {
|
6545 | key: "role",
|
6546 | get: function get() {
|
6547 | if (this.isOwner) return ConversationMemberRole.OWNER;
|
6548 | return internal(this).role;
|
6549 | }
|
6550 | |
6551 |
|
6552 |
|
6553 |
|
6554 |
|
6555 |
|
6556 | }, {
|
6557 | key: "isOwner",
|
6558 | get: function get() {
|
6559 | return this.memberId === internal(this).conversation.creator;
|
6560 | }
|
6561 | }]);
|
6562 |
|
6563 | return ConversationMemberInfo;
|
6564 | }();
|
6565 |
|
6566 |
|
6567 |
|
6568 |
|
6569 |
|
6570 |
|
6571 |
|
6572 |
|
6573 |
|
6574 | var Conversation =
|
6575 |
|
6576 | function (_PersistentConversati) {
|
6577 | _inheritsLoose(Conversation, _PersistentConversati);
|
6578 |
|
6579 | function Conversation() {
|
6580 | return _PersistentConversati.apply(this, arguments) || this;
|
6581 | }
|
6582 |
|
6583 | var _proto = Conversation.prototype;
|
6584 |
|
6585 | _proto._addMembers = function _addMembers(members) {
|
6586 | var _this = this;
|
6587 |
|
6588 | _PersistentConversati.prototype._addMembers.call(this, members);
|
6589 |
|
6590 | this.members = union(this.members, members);
|
6591 |
|
6592 | var _internal = internal(this),
|
6593 | memberInfoMap = _internal.memberInfoMap;
|
6594 |
|
6595 | if (!memberInfoMap) return;
|
6596 | members.forEach(function (memberId) {
|
6597 | memberInfoMap[memberId] = memberInfoMap[memberId] || new ConversationMemberInfo({
|
6598 | conversation: _this,
|
6599 | memberId: memberId,
|
6600 | role: ConversationMemberRole.MEMBER
|
6601 | });
|
6602 | });
|
6603 | };
|
6604 |
|
6605 | _proto._removeMembers = function _removeMembers(members) {
|
6606 | _PersistentConversati.prototype._removeMembers.call(this, members);
|
6607 |
|
6608 | this.members = difference(this.members, members);
|
6609 |
|
6610 | var _internal2 = internal(this),
|
6611 | memberInfoMap = _internal2.memberInfoMap;
|
6612 |
|
6613 | if (!memberInfoMap) return;
|
6614 | members.forEach(function (memberId) {
|
6615 | delete memberInfoMap[memberId];
|
6616 | });
|
6617 | };
|
6618 |
|
6619 | _proto._fetchAllMemberInfo =
|
6620 |
|
6621 | function () {
|
6622 | var _fetchAllMemberInfo2 = _asyncToGenerator(
|
6623 |
|
6624 | _regeneratorRuntime.mark(function _callee() {
|
6625 | var _this2 = this;
|
6626 |
|
6627 | var response, memberInfos, memberInfoMap;
|
6628 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
6629 | while (1) {
|
6630 | switch (_context.prev = _context.next) {
|
6631 | case 0:
|
6632 | _context.next = 2;
|
6633 | return this._client._requestWithSessionToken({
|
6634 | method: 'GET',
|
6635 | path: '/classes/_ConversationMemberInfo',
|
6636 | query: {
|
6637 | where: {
|
6638 | cid: this.id
|
6639 | }
|
6640 | }
|
6641 | });
|
6642 |
|
6643 | case 2:
|
6644 | response = _context.sent;
|
6645 | memberInfos = response.results.map(function (info) {
|
6646 | return new ConversationMemberInfo({
|
6647 | conversation: _this2,
|
6648 | memberId: info.clientId,
|
6649 | role: info.role
|
6650 | });
|
6651 | });
|
6652 | memberInfoMap = {};
|
6653 | memberInfos.forEach(function (memberInfo) {
|
6654 | memberInfoMap[memberInfo.memberId] = memberInfo;
|
6655 | });
|
6656 | this.members.forEach(function (memberId) {
|
6657 | memberInfoMap[memberId] = memberInfoMap[memberId] || new ConversationMemberInfo({
|
6658 | conversation: _this2,
|
6659 | memberId: memberId,
|
6660 | role: ConversationMemberRole.MEMBER
|
6661 | });
|
6662 | });
|
6663 | internal(this).memberInfoMap = memberInfoMap;
|
6664 | return _context.abrupt("return", memberInfoMap);
|
6665 |
|
6666 | case 9:
|
6667 | case "end":
|
6668 | return _context.stop();
|
6669 | }
|
6670 | }
|
6671 | }, _callee, this);
|
6672 | }));
|
6673 |
|
6674 | function _fetchAllMemberInfo() {
|
6675 | return _fetchAllMemberInfo2.apply(this, arguments);
|
6676 | }
|
6677 |
|
6678 | return _fetchAllMemberInfo;
|
6679 | }()
|
6680 | |
6681 |
|
6682 |
|
6683 |
|
6684 |
|
6685 | ;
|
6686 |
|
6687 | _proto.getAllMemberInfo =
|
6688 |
|
6689 | function () {
|
6690 | var _getAllMemberInfo = _asyncToGenerator(
|
6691 |
|
6692 | _regeneratorRuntime.mark(function _callee2() {
|
6693 | var _ref,
|
6694 | _ref$noCache,
|
6695 | noCache,
|
6696 | _internal3,
|
6697 | memberInfoMap,
|
6698 | _args2 = arguments;
|
6699 |
|
6700 | return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
6701 | while (1) {
|
6702 | switch (_context2.prev = _context2.next) {
|
6703 | case 0:
|
6704 | _ref = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref$noCache = _ref.noCache, noCache = _ref$noCache === void 0 ? false : _ref$noCache;
|
6705 | _internal3 = internal(this), memberInfoMap = _internal3.memberInfoMap;
|
6706 |
|
6707 | if (!(!memberInfoMap || noCache)) {
|
6708 | _context2.next = 6;
|
6709 | break;
|
6710 | }
|
6711 |
|
6712 | _context2.next = 5;
|
6713 | return this._fetchAllMemberInfo();
|
6714 |
|
6715 | case 5:
|
6716 | memberInfoMap = _context2.sent;
|
6717 |
|
6718 | case 6:
|
6719 | return _context2.abrupt("return", this.members.map(function (memberId) {
|
6720 | return memberInfoMap[memberId];
|
6721 | }));
|
6722 |
|
6723 | case 7:
|
6724 | case "end":
|
6725 | return _context2.stop();
|
6726 | }
|
6727 | }
|
6728 | }, _callee2, this);
|
6729 | }));
|
6730 |
|
6731 | function getAllMemberInfo() {
|
6732 | return _getAllMemberInfo.apply(this, arguments);
|
6733 | }
|
6734 |
|
6735 | return getAllMemberInfo;
|
6736 | }()
|
6737 | |
6738 |
|
6739 |
|
6740 |
|
6741 |
|
6742 |
|
6743 | ;
|
6744 |
|
6745 | _proto.getMemberInfo =
|
6746 |
|
6747 | function () {
|
6748 | var _getMemberInfo = _asyncToGenerator(
|
6749 |
|
6750 | _regeneratorRuntime.mark(function _callee3(memberId) {
|
6751 | var _internal4, memberInfoMap;
|
6752 |
|
6753 | return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
6754 | while (1) {
|
6755 | switch (_context3.prev = _context3.next) {
|
6756 | case 0:
|
6757 | if (!(this.members.indexOf(memberId) === -1)) {
|
6758 | _context3.next = 2;
|
6759 | break;
|
6760 | }
|
6761 |
|
6762 | throw new Error("".concat(memberId, " is not the mumber of conversation[").concat(this.id, "]"));
|
6763 |
|
6764 | case 2:
|
6765 | _internal4 = internal(this), memberInfoMap = _internal4.memberInfoMap;
|
6766 |
|
6767 | if (memberInfoMap && memberInfoMap[memberId]) {
|
6768 | _context3.next = 6;
|
6769 | break;
|
6770 | }
|
6771 |
|
6772 | _context3.next = 6;
|
6773 | return this.getAllMemberInfo();
|
6774 |
|
6775 | case 6:
|
6776 | return _context3.abrupt("return", internal(this).memberInfoMap[memberId]);
|
6777 |
|
6778 | case 7:
|
6779 | case "end":
|
6780 | return _context3.stop();
|
6781 | }
|
6782 | }
|
6783 | }, _callee3, this);
|
6784 | }));
|
6785 |
|
6786 | function getMemberInfo(_x) {
|
6787 | return _getMemberInfo.apply(this, arguments);
|
6788 | }
|
6789 |
|
6790 | return getMemberInfo;
|
6791 | }()
|
6792 | |
6793 |
|
6794 |
|
6795 |
|
6796 |
|
6797 |
|
6798 |
|
6799 | ;
|
6800 |
|
6801 | _proto.updateMemberRole =
|
6802 |
|
6803 | function () {
|
6804 | var _updateMemberRole = _asyncToGenerator(
|
6805 |
|
6806 | _regeneratorRuntime.mark(function _callee4(memberId, role) {
|
6807 | var _internal5, memberInfos;
|
6808 |
|
6809 | return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
6810 | while (1) {
|
6811 | switch (_context4.prev = _context4.next) {
|
6812 | case 0:
|
6813 | this._debug('update member role');
|
6814 |
|
6815 | if (!(role === ConversationMemberRole.OWNER)) {
|
6816 | _context4.next = 3;
|
6817 | break;
|
6818 | }
|
6819 |
|
6820 | throw createError({
|
6821 | code: ErrorCode.OWNER_PROMOTION_NOT_ALLOWED
|
6822 | });
|
6823 |
|
6824 | case 3:
|
6825 | _context4.next = 5;
|
6826 | return this._send(new GenericCommand({
|
6827 | op: OpType.member_info_update,
|
6828 | convMessage: new ConvCommand({
|
6829 | targetClientId: memberId,
|
6830 | info: new ConvMemberInfo({
|
6831 | pid: memberId,
|
6832 | role: role
|
6833 | })
|
6834 | })
|
6835 | }));
|
6836 |
|
6837 | case 5:
|
6838 | _internal5 = internal(this), memberInfos = _internal5.memberInfos;
|
6839 |
|
6840 | if (memberInfos && memberInfos[memberId]) {
|
6841 | internal(memberInfos[memberId]).role = role;
|
6842 | }
|
6843 |
|
6844 | return _context4.abrupt("return", this);
|
6845 |
|
6846 | case 8:
|
6847 | case "end":
|
6848 | return _context4.stop();
|
6849 | }
|
6850 | }
|
6851 | }, _callee4, this);
|
6852 | }));
|
6853 |
|
6854 | function updateMemberRole(_x2, _x3) {
|
6855 | return _updateMemberRole.apply(this, arguments);
|
6856 | }
|
6857 |
|
6858 | return updateMemberRole;
|
6859 | }();
|
6860 |
|
6861 | return Conversation;
|
6862 | }(PersistentConversation);
|
6863 |
|
6864 |
|
6865 |
|
6866 |
|
6867 |
|
6868 |
|
6869 |
|
6870 |
|
6871 |
|
6872 |
|
6873 | var ChatRoom =
|
6874 |
|
6875 | function (_PersistentConversati) {
|
6876 | _inheritsLoose(ChatRoom, _PersistentConversati);
|
6877 |
|
6878 | function ChatRoom() {
|
6879 | return _PersistentConversati.apply(this, arguments) || this;
|
6880 | }
|
6881 |
|
6882 | return ChatRoom;
|
6883 | }(PersistentConversation);
|
6884 |
|
6885 |
|
6886 |
|
6887 |
|
6888 |
|
6889 |
|
6890 |
|
6891 |
|
6892 |
|
6893 |
|
6894 | var ServiceConversation =
|
6895 |
|
6896 | function (_PersistentConversati) {
|
6897 | _inheritsLoose(ServiceConversation, _PersistentConversati);
|
6898 |
|
6899 | function ServiceConversation() {
|
6900 | return _PersistentConversati.apply(this, arguments) || this;
|
6901 | }
|
6902 |
|
6903 | var _proto = ServiceConversation.prototype;
|
6904 |
|
6905 | |
6906 |
|
6907 |
|
6908 |
|
6909 | _proto.subscribe =
|
6910 |
|
6911 | function () {
|
6912 | var _subscribe = _asyncToGenerator(
|
6913 |
|
6914 | _regeneratorRuntime.mark(function _callee() {
|
6915 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
6916 | while (1) {
|
6917 | switch (_context.prev = _context.next) {
|
6918 | case 0:
|
6919 | return _context.abrupt("return", this.join());
|
6920 |
|
6921 | case 1:
|
6922 | case "end":
|
6923 | return _context.stop();
|
6924 | }
|
6925 | }
|
6926 | }, _callee, this);
|
6927 | }));
|
6928 |
|
6929 | function subscribe() {
|
6930 | return _subscribe.apply(this, arguments);
|
6931 | }
|
6932 |
|
6933 | return subscribe;
|
6934 | }()
|
6935 | |
6936 |
|
6937 |
|
6938 |
|
6939 | ;
|
6940 |
|
6941 | _proto.unsubscribe =
|
6942 |
|
6943 | function () {
|
6944 | var _unsubscribe = _asyncToGenerator(
|
6945 |
|
6946 | _regeneratorRuntime.mark(function _callee2() {
|
6947 | return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
6948 | while (1) {
|
6949 | switch (_context2.prev = _context2.next) {
|
6950 | case 0:
|
6951 | return _context2.abrupt("return", this.quit());
|
6952 |
|
6953 | case 1:
|
6954 | case "end":
|
6955 | return _context2.stop();
|
6956 | }
|
6957 | }
|
6958 | }, _callee2, this);
|
6959 | }));
|
6960 |
|
6961 | function unsubscribe() {
|
6962 | return _unsubscribe.apply(this, arguments);
|
6963 | }
|
6964 |
|
6965 | return unsubscribe;
|
6966 | }();
|
6967 |
|
6968 | return ServiceConversation;
|
6969 | }(PersistentConversation);
|
6970 |
|
6971 | var transformNotFoundError = function transformNotFoundError(error) {
|
6972 | return error.code === ErrorCode.CONVERSATION_NOT_FOUND ? createError({
|
6973 | code: ErrorCode.TEMPORARY_CONVERSATION_EXPIRED
|
6974 | }) : error;
|
6975 | };
|
6976 |
|
6977 |
|
6978 |
|
6979 |
|
6980 |
|
6981 |
|
6982 |
|
6983 |
|
6984 | var TemporaryConversation =
|
6985 |
|
6986 | function (_ConversationBase) {
|
6987 | _inheritsLoose(TemporaryConversation, _ConversationBase);
|
6988 |
|
6989 | |
6990 |
|
6991 |
|
6992 | function TemporaryConversation(data, _ref, client) {
|
6993 | var expiredAt = _ref.expiredAt;
|
6994 | return _ConversationBase.call(this, _objectSpread({}, data, {
|
6995 | expiredAt: expiredAt
|
6996 | }), client) || this;
|
6997 | }
|
6998 | |
6999 |
|
7000 |
|
7001 |
|
7002 |
|
7003 |
|
7004 | var _proto = TemporaryConversation.prototype;
|
7005 |
|
7006 | _proto._send =
|
7007 |
|
7008 | function () {
|
7009 | var _send2 = _asyncToGenerator(
|
7010 |
|
7011 | _regeneratorRuntime.mark(function _callee() {
|
7012 | var _ConversationBase$pro,
|
7013 | _len,
|
7014 | args,
|
7015 | _key,
|
7016 | _args = arguments;
|
7017 |
|
7018 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
7019 | while (1) {
|
7020 | switch (_context.prev = _context.next) {
|
7021 | case 0:
|
7022 | if (!this.expired) {
|
7023 | _context.next = 2;
|
7024 | break;
|
7025 | }
|
7026 |
|
7027 | throw createError({
|
7028 | code: ErrorCode.TEMPORARY_CONVERSATION_EXPIRED
|
7029 | });
|
7030 |
|
7031 | case 2:
|
7032 | _context.prev = 2;
|
7033 |
|
7034 | for (_len = _args.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
7035 | args[_key] = _args[_key];
|
7036 | }
|
7037 |
|
7038 | _context.next = 6;
|
7039 | return (_ConversationBase$pro = _ConversationBase.prototype._send).call.apply(_ConversationBase$pro, [this].concat(args));
|
7040 |
|
7041 | case 6:
|
7042 | return _context.abrupt("return", _context.sent);
|
7043 |
|
7044 | case 9:
|
7045 | _context.prev = 9;
|
7046 | _context.t0 = _context["catch"](2);
|
7047 | throw transformNotFoundError(_context.t0);
|
7048 |
|
7049 | case 12:
|
7050 | case "end":
|
7051 | return _context.stop();
|
7052 | }
|
7053 | }
|
7054 | }, _callee, this, [[2, 9]]);
|
7055 | }));
|
7056 |
|
7057 | function _send() {
|
7058 | return _send2.apply(this, arguments);
|
7059 | }
|
7060 |
|
7061 | return _send;
|
7062 | }();
|
7063 |
|
7064 | _proto.send =
|
7065 |
|
7066 | function () {
|
7067 | var _send3 = _asyncToGenerator(
|
7068 |
|
7069 | _regeneratorRuntime.mark(function _callee2() {
|
7070 | var _ConversationBase$pro2,
|
7071 | _len2,
|
7072 | args,
|
7073 | _key2,
|
7074 | _args2 = arguments;
|
7075 |
|
7076 | return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
7077 | while (1) {
|
7078 | switch (_context2.prev = _context2.next) {
|
7079 | case 0:
|
7080 | _context2.prev = 0;
|
7081 |
|
7082 | for (_len2 = _args2.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
7083 | args[_key2] = _args2[_key2];
|
7084 | }
|
7085 |
|
7086 | _context2.next = 4;
|
7087 | return (_ConversationBase$pro2 = _ConversationBase.prototype.send).call.apply(_ConversationBase$pro2, [this].concat(args));
|
7088 |
|
7089 | case 4:
|
7090 | return _context2.abrupt("return", _context2.sent);
|
7091 |
|
7092 | case 7:
|
7093 | _context2.prev = 7;
|
7094 | _context2.t0 = _context2["catch"](0);
|
7095 | throw transformNotFoundError(_context2.t0);
|
7096 |
|
7097 | case 10:
|
7098 | case "end":
|
7099 | return _context2.stop();
|
7100 | }
|
7101 | }
|
7102 | }, _callee2, this, [[0, 7]]);
|
7103 | }));
|
7104 |
|
7105 | function send() {
|
7106 | return _send3.apply(this, arguments);
|
7107 | }
|
7108 |
|
7109 | return send;
|
7110 | }();
|
7111 |
|
7112 | _proto.toFullJSON = function toFullJSON() {
|
7113 | var expiredAt = this.expiredAt;
|
7114 | return _objectSpread({}, _ConversationBase.prototype.toFullJSON.call(this), {
|
7115 | expiredAt: getTime(expiredAt)
|
7116 | });
|
7117 | };
|
7118 |
|
7119 | _proto.toJSON = function toJSON() {
|
7120 | var expiredAt = this.expiredAt,
|
7121 | expired = this.expired;
|
7122 | return _objectSpread({}, _ConversationBase.prototype.toJSON.call(this), {
|
7123 | expiredAt: expiredAt,
|
7124 | expired: expired
|
7125 | });
|
7126 | };
|
7127 |
|
7128 | _createClass(TemporaryConversation, [{
|
7129 | key: "expiredAt",
|
7130 | set: function set(value) {
|
7131 | this._expiredAt = decodeDate(value);
|
7132 | },
|
7133 | get: function get() {
|
7134 | return this._expiredAt;
|
7135 | }
|
7136 | |
7137 |
|
7138 |
|
7139 |
|
7140 |
|
7141 | }, {
|
7142 | key: "expired",
|
7143 | get: function get() {
|
7144 | return this.expiredAt < new Date();
|
7145 | }
|
7146 | }]);
|
7147 |
|
7148 | return TemporaryConversation;
|
7149 | }(ConversationBase);
|
7150 |
|
7151 | var debug$8 = d('LC:ConversationQuery');
|
7152 |
|
7153 | var ConversationQuery =
|
7154 |
|
7155 | function () {
|
7156 | ConversationQuery._encode = function _encode(value) {
|
7157 | if (value instanceof Date) {
|
7158 | return {
|
7159 | __type: 'Date',
|
7160 | iso: value.toJSON()
|
7161 | };
|
7162 | }
|
7163 |
|
7164 | if (value instanceof RegExp) {
|
7165 | return value.source;
|
7166 | }
|
7167 |
|
7168 | return value;
|
7169 | };
|
7170 |
|
7171 | ConversationQuery._quote = function _quote(s) {
|
7172 | return "\\Q".concat(s.replace('\\E', '\\E\\\\E\\Q'), "\\E");
|
7173 | };
|
7174 |
|
7175 | ConversationQuery._calculateFlag = function _calculateFlag(options) {
|
7176 | return ['withLastMessagesRefreshed', 'compact'].reduce(
|
7177 | function (prev, key) {
|
7178 | return (prev << 1) + Boolean(options[key]);
|
7179 | }, 0);
|
7180 | }
|
7181 | |
7182 |
|
7183 |
|
7184 |
|
7185 | ;
|
7186 |
|
7187 | function ConversationQuery(client) {
|
7188 | this._client = client;
|
7189 | this._where = {};
|
7190 | this._extraOptions = {};
|
7191 | }
|
7192 |
|
7193 | var _proto = ConversationQuery.prototype;
|
7194 |
|
7195 | _proto._addCondition = function _addCondition(key, condition, value) {
|
7196 |
|
7197 | if (!this._where[key]) {
|
7198 | this._where[key] = {};
|
7199 | }
|
7200 |
|
7201 | this._where[key][condition] = this.constructor._encode(value);
|
7202 | return this;
|
7203 | };
|
7204 |
|
7205 | _proto.toJSON = function toJSON() {
|
7206 | var json = {
|
7207 | where: this._where,
|
7208 | flag: this.constructor._calculateFlag(this._extraOptions)
|
7209 | };
|
7210 | if (typeof this._skip !== 'undefined') json.skip = this._skip;
|
7211 | if (typeof this._limit !== 'undefined') json.limit = this._limit;
|
7212 | if (typeof this._order !== 'undefined') json.sort = this._order;
|
7213 | debug$8(json);
|
7214 | return json;
|
7215 | }
|
7216 | |
7217 |
|
7218 |
|
7219 |
|
7220 |
|
7221 | ;
|
7222 |
|
7223 | _proto.containsMembers = function containsMembers(peerIds) {
|
7224 | return this.containsAll('m', peerIds);
|
7225 | }
|
7226 | |
7227 |
|
7228 |
|
7229 |
|
7230 |
|
7231 |
|
7232 |
|
7233 | ;
|
7234 |
|
7235 | _proto.withMembers = function withMembers(peerIds, includeSelf) {
|
7236 | var peerIdsSet = new Set(peerIds);
|
7237 |
|
7238 | if (includeSelf) {
|
7239 | peerIdsSet.add(this._client.id);
|
7240 | }
|
7241 |
|
7242 | this.sizeEqualTo('m', peerIdsSet.size);
|
7243 | return this.containsMembers(Array.from(peerIdsSet));
|
7244 | }
|
7245 | |
7246 |
|
7247 |
|
7248 |
|
7249 |
|
7250 |
|
7251 |
|
7252 | ;
|
7253 |
|
7254 | _proto.equalTo = function equalTo(key, value) {
|
7255 | this._where[key] = this.constructor._encode(value);
|
7256 | return this;
|
7257 | }
|
7258 | |
7259 |
|
7260 |
|
7261 |
|
7262 |
|
7263 |
|
7264 | ;
|
7265 |
|
7266 | _proto.lessThan = function lessThan(key, value) {
|
7267 | return this._addCondition(key, '$lt', value);
|
7268 | }
|
7269 | |
7270 |
|
7271 |
|
7272 |
|
7273 |
|
7274 |
|
7275 | ;
|
7276 |
|
7277 | _proto.lessThanOrEqualTo = function lessThanOrEqualTo(key, value) {
|
7278 | return this._addCondition(key, '$lte', value);
|
7279 | }
|
7280 | |
7281 |
|
7282 |
|
7283 |
|
7284 |
|
7285 |
|
7286 |
|
7287 | ;
|
7288 |
|
7289 | _proto.greaterThan = function greaterThan(key, value) {
|
7290 | return this._addCondition(key, '$gt', value);
|
7291 | }
|
7292 | |
7293 |
|
7294 |
|
7295 |
|
7296 |
|
7297 |
|
7298 |
|
7299 | ;
|
7300 |
|
7301 | _proto.greaterThanOrEqualTo = function greaterThanOrEqualTo(key, value) {
|
7302 | return this._addCondition(key, '$gte', value);
|
7303 | }
|
7304 | |
7305 |
|
7306 |
|
7307 |
|
7308 |
|
7309 |
|
7310 |
|
7311 | ;
|
7312 |
|
7313 | _proto.notEqualTo = function notEqualTo(key, value) {
|
7314 | return this._addCondition(key, '$ne', value);
|
7315 | }
|
7316 | |
7317 |
|
7318 |
|
7319 |
|
7320 |
|
7321 |
|
7322 |
|
7323 | ;
|
7324 |
|
7325 | _proto.exists = function exists(key) {
|
7326 | return this._addCondition(key, '$exists', true);
|
7327 | }
|
7328 | |
7329 |
|
7330 |
|
7331 |
|
7332 |
|
7333 |
|
7334 |
|
7335 | ;
|
7336 |
|
7337 | _proto.doesNotExist = function doesNotExist(key) {
|
7338 | return this._addCondition(key, '$exists', false);
|
7339 | }
|
7340 | |
7341 |
|
7342 |
|
7343 |
|
7344 |
|
7345 |
|
7346 |
|
7347 | ;
|
7348 |
|
7349 | _proto.containedIn = function containedIn(key, values) {
|
7350 | return this._addCondition(key, '$in', values);
|
7351 | }
|
7352 | |
7353 |
|
7354 |
|
7355 |
|
7356 |
|
7357 |
|
7358 |
|
7359 | ;
|
7360 |
|
7361 | _proto.notContainsIn = function notContainsIn(key, values) {
|
7362 | return this._addCondition(key, '$nin', values);
|
7363 | }
|
7364 | |
7365 |
|
7366 |
|
7367 |
|
7368 |
|
7369 |
|
7370 |
|
7371 | ;
|
7372 |
|
7373 | _proto.containsAll = function containsAll(key, values) {
|
7374 | return this._addCondition(key, '$all', values);
|
7375 | }
|
7376 | |
7377 |
|
7378 |
|
7379 |
|
7380 |
|
7381 |
|
7382 |
|
7383 | ;
|
7384 |
|
7385 | _proto.contains = function contains(key, subString) {
|
7386 | return this._addCondition(key, '$regex', ConversationQuery._quote(subString));
|
7387 | }
|
7388 | |
7389 |
|
7390 |
|
7391 |
|
7392 |
|
7393 |
|
7394 |
|
7395 | ;
|
7396 |
|
7397 | _proto.startsWith = function startsWith(key, prefix) {
|
7398 | return this._addCondition(key, '$regex', "^".concat(ConversationQuery._quote(prefix)));
|
7399 | }
|
7400 | |
7401 |
|
7402 |
|
7403 |
|
7404 |
|
7405 |
|
7406 |
|
7407 | ;
|
7408 |
|
7409 | _proto.endsWith = function endsWith(key, suffix) {
|
7410 | return this._addCondition(key, '$regex', "".concat(ConversationQuery._quote(suffix), "$"));
|
7411 | }
|
7412 | |
7413 |
|
7414 |
|
7415 |
|
7416 |
|
7417 |
|
7418 |
|
7419 | ;
|
7420 |
|
7421 | _proto.matches = function matches(key, regex) {
|
7422 | this._addCondition(key, '$regex', regex);
|
7423 |
|
7424 |
|
7425 |
|
7426 |
|
7427 | var _modifiers = '';
|
7428 |
|
7429 | if (regex.ignoreCase) {
|
7430 | _modifiers += 'i';
|
7431 | }
|
7432 |
|
7433 | if (regex.multiline) {
|
7434 | _modifiers += 'm';
|
7435 | }
|
7436 |
|
7437 | if (_modifiers && _modifiers.length) {
|
7438 | this._addCondition(key, '$options', _modifiers);
|
7439 | }
|
7440 |
|
7441 | return this;
|
7442 | }
|
7443 | |
7444 |
|
7445 |
|
7446 |
|
7447 |
|
7448 |
|
7449 |
|
7450 | ;
|
7451 |
|
7452 | _proto.sizeEqualTo = function sizeEqualTo(key, length) {
|
7453 | return this._addCondition(key, '$size', length);
|
7454 | }
|
7455 | |
7456 |
|
7457 |
|
7458 |
|
7459 |
|
7460 |
|
7461 | ;
|
7462 |
|
7463 | _proto.limit = function limit(_limit) {
|
7464 | this._limit = _limit;
|
7465 | return this;
|
7466 | }
|
7467 | |
7468 |
|
7469 |
|
7470 |
|
7471 |
|
7472 |
|
7473 | ;
|
7474 |
|
7475 | _proto.skip = function skip(_skip) {
|
7476 | this._skip = _skip;
|
7477 | return this;
|
7478 | }
|
7479 | |
7480 |
|
7481 |
|
7482 |
|
7483 |
|
7484 |
|
7485 | ;
|
7486 |
|
7487 | _proto.ascending = function ascending(key) {
|
7488 | this._order = key;
|
7489 | return this;
|
7490 | }
|
7491 | |
7492 |
|
7493 |
|
7494 |
|
7495 |
|
7496 |
|
7497 | ;
|
7498 |
|
7499 | _proto.addAscending = function addAscending(key) {
|
7500 | if (this._order) {
|
7501 | this._order += ",".concat(key);
|
7502 | } else {
|
7503 | this._order = key;
|
7504 | }
|
7505 |
|
7506 | return this;
|
7507 | }
|
7508 | |
7509 |
|
7510 |
|
7511 |
|
7512 |
|
7513 |
|
7514 | ;
|
7515 |
|
7516 | _proto.descending = function descending(key) {
|
7517 | this._order = "-".concat(key);
|
7518 | return this;
|
7519 | }
|
7520 | |
7521 |
|
7522 |
|
7523 |
|
7524 |
|
7525 |
|
7526 | ;
|
7527 |
|
7528 | _proto.addDescending = function addDescending(key) {
|
7529 | if (this._order) {
|
7530 | this._order += ",-".concat(key);
|
7531 | } else {
|
7532 | this._order = "-".concat(key);
|
7533 | }
|
7534 |
|
7535 | return this;
|
7536 | }
|
7537 | |
7538 |
|
7539 |
|
7540 |
|
7541 |
|
7542 | ;
|
7543 |
|
7544 | _proto.withLastMessagesRefreshed = function withLastMessagesRefreshed() {
|
7545 | var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
7546 | this._extraOptions.withLastMessagesRefreshed = enabled;
|
7547 | return this;
|
7548 | }
|
7549 | |
7550 |
|
7551 |
|
7552 |
|
7553 |
|
7554 | ;
|
7555 |
|
7556 | _proto.compact = function compact() {
|
7557 | var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
7558 | this._extraOptions.compact = enabled;
|
7559 | return this;
|
7560 | }
|
7561 | |
7562 |
|
7563 |
|
7564 |
|
7565 | ;
|
7566 |
|
7567 | _proto.find =
|
7568 |
|
7569 | function () {
|
7570 | var _find = _asyncToGenerator(
|
7571 |
|
7572 | _regeneratorRuntime.mark(function _callee() {
|
7573 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
7574 | while (1) {
|
7575 | switch (_context.prev = _context.next) {
|
7576 | case 0:
|
7577 | return _context.abrupt("return", this._client._executeQuery(this));
|
7578 |
|
7579 | case 1:
|
7580 | case "end":
|
7581 | return _context.stop();
|
7582 | }
|
7583 | }
|
7584 | }, _callee, this);
|
7585 | }));
|
7586 |
|
7587 | function find() {
|
7588 | return _find.apply(this, arguments);
|
7589 | }
|
7590 |
|
7591 | return find;
|
7592 | }();
|
7593 |
|
7594 | return ConversationQuery;
|
7595 | }();
|
7596 |
|
7597 | var debug$9 = d('LC:SessionManager');
|
7598 |
|
7599 | var SessionManager =
|
7600 |
|
7601 | function () {
|
7602 | function SessionManager() {
|
7603 | var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
7604 | refresh = _ref.refresh,
|
7605 | onBeforeGetSessionToken = _ref.onBeforeGetSessionToken;
|
7606 |
|
7607 | this.refresh = refresh;
|
7608 | this._onBeforeGetSessionToken = onBeforeGetSessionToken;
|
7609 | this.setSessionToken(null, 0);
|
7610 | }
|
7611 |
|
7612 | var _proto = SessionManager.prototype;
|
7613 |
|
7614 | _proto.setSessionToken = function setSessionToken(token, ttl) {
|
7615 | debug$9('set session token', token, ttl);
|
7616 | var sessionToken = new Expirable(token, ttl * 1000);
|
7617 | this._sessionToken = sessionToken;
|
7618 | delete this._pendingSessionTokenPromise;
|
7619 | return sessionToken;
|
7620 | };
|
7621 |
|
7622 | _proto.setSessionTokenAsync =
|
7623 |
|
7624 | function () {
|
7625 | var _setSessionTokenAsync = _asyncToGenerator(
|
7626 |
|
7627 | _regeneratorRuntime.mark(function _callee(promise) {
|
7628 | var _this = this;
|
7629 |
|
7630 | var currentSessionToken;
|
7631 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
7632 | while (1) {
|
7633 | switch (_context.prev = _context.next) {
|
7634 | case 0:
|
7635 | currentSessionToken = this._sessionToken;
|
7636 | this._pendingSessionTokenPromise = promise.catch(function (error) {
|
7637 |
|
7638 |
|
7639 | _this._sessionToken = currentSessionToken;
|
7640 | throw error;
|
7641 | });
|
7642 | _context.t0 = this.setSessionToken;
|
7643 | _context.t1 = this;
|
7644 | _context.t2 = _toConsumableArray;
|
7645 | _context.next = 7;
|
7646 | return this._pendingSessionTokenPromise;
|
7647 |
|
7648 | case 7:
|
7649 | _context.t3 = _context.sent;
|
7650 | _context.t4 = (0, _context.t2)(_context.t3);
|
7651 | return _context.abrupt("return", _context.t0.apply.call(_context.t0, _context.t1, _context.t4));
|
7652 |
|
7653 | case 10:
|
7654 | case "end":
|
7655 | return _context.stop();
|
7656 | }
|
7657 | }
|
7658 | }, _callee, this);
|
7659 | }));
|
7660 |
|
7661 | function setSessionTokenAsync(_x) {
|
7662 | return _setSessionTokenAsync.apply(this, arguments);
|
7663 | }
|
7664 |
|
7665 | return setSessionTokenAsync;
|
7666 | }();
|
7667 |
|
7668 | _proto.getSessionToken =
|
7669 |
|
7670 | function () {
|
7671 | var _getSessionToken = _asyncToGenerator(
|
7672 |
|
7673 | _regeneratorRuntime.mark(function _callee2() {
|
7674 | var _ref2,
|
7675 | _ref2$autoRefresh,
|
7676 | autoRefresh,
|
7677 | _ref3,
|
7678 | value,
|
7679 | originalValue,
|
7680 | _ref4,
|
7681 | newValue,
|
7682 | _args2 = arguments;
|
7683 |
|
7684 | return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
7685 | while (1) {
|
7686 | switch (_context2.prev = _context2.next) {
|
7687 | case 0:
|
7688 | _ref2 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref2$autoRefresh = _ref2.autoRefresh, autoRefresh = _ref2$autoRefresh === void 0 ? true : _ref2$autoRefresh;
|
7689 | debug$9('get session token');
|
7690 |
|
7691 | if (this._onBeforeGetSessionToken) {
|
7692 | this._onBeforeGetSessionToken(this);
|
7693 | }
|
7694 |
|
7695 | _context2.t0 = this._sessionToken;
|
7696 |
|
7697 | if (_context2.t0) {
|
7698 | _context2.next = 8;
|
7699 | break;
|
7700 | }
|
7701 |
|
7702 | _context2.next = 7;
|
7703 | return this._pendingSessionTokenPromise;
|
7704 |
|
7705 | case 7:
|
7706 | _context2.t0 = _context2.sent;
|
7707 |
|
7708 | case 8:
|
7709 | _ref3 = _context2.t0;
|
7710 | value = _ref3.value;
|
7711 | originalValue = _ref3.originalValue;
|
7712 |
|
7713 | if (!(value === Expirable.EXPIRED && autoRefresh && this.refresh)) {
|
7714 | _context2.next = 19;
|
7715 | break;
|
7716 | }
|
7717 |
|
7718 | debug$9('refresh expired session token');
|
7719 | _context2.next = 15;
|
7720 | return this.setSessionTokenAsync(this.refresh(this, originalValue));
|
7721 |
|
7722 | case 15:
|
7723 | _ref4 = _context2.sent;
|
7724 | newValue = _ref4.value;
|
7725 | debug$9('session token', newValue);
|
7726 | return _context2.abrupt("return", newValue);
|
7727 |
|
7728 | case 19:
|
7729 | debug$9('session token', value);
|
7730 | return _context2.abrupt("return", value);
|
7731 |
|
7732 | case 21:
|
7733 | case "end":
|
7734 | return _context2.stop();
|
7735 | }
|
7736 | }
|
7737 | }, _callee2, this);
|
7738 | }));
|
7739 |
|
7740 | function getSessionToken() {
|
7741 | return _getSessionToken.apply(this, arguments);
|
7742 | }
|
7743 |
|
7744 | return getSessionToken;
|
7745 | }();
|
7746 |
|
7747 | _proto.revoke = function revoke() {
|
7748 | if (this._sessionToken) this._sessionToken.expiredAt = -1;
|
7749 | };
|
7750 |
|
7751 | return SessionManager;
|
7752 | }();
|
7753 |
|
7754 | var _dec$2, _dec2, _class$3;
|
7755 | var debug$a = d('LC:IMClient');
|
7756 | var INVITED$1 = INVITED,
|
7757 | KICKED$1 = KICKED,
|
7758 | MEMBERS_JOINED$1 = MEMBERS_JOINED,
|
7759 | MEMBERS_LEFT$1 = MEMBERS_LEFT,
|
7760 | MEMBER_INFO_UPDATED$1 = MEMBER_INFO_UPDATED,
|
7761 | BLOCKED$1 = BLOCKED,
|
7762 | UNBLOCKED$1 = UNBLOCKED,
|
7763 | MEMBERS_BLOCKED$1 = MEMBERS_BLOCKED,
|
7764 | MEMBERS_UNBLOCKED$1 = MEMBERS_UNBLOCKED,
|
7765 | MUTED$1 = MUTED,
|
7766 | UNMUTED$1 = UNMUTED,
|
7767 | MEMBERS_MUTED$1 = MEMBERS_MUTED,
|
7768 | MEMBERS_UNMUTED$1 = MEMBERS_UNMUTED,
|
7769 | MESSAGE$2 = MESSAGE$1,
|
7770 | UNREAD_MESSAGES_COUNT_UPDATE$1 = UNREAD_MESSAGES_COUNT_UPDATE,
|
7771 | CLOSE$1 = CLOSE,
|
7772 | CONFLICT$1 = CONFLICT,
|
7773 | UNHANDLED_MESSAGE$1 = UNHANDLED_MESSAGE,
|
7774 | CONVERSATION_INFO_UPDATED$1 = CONVERSATION_INFO_UPDATED,
|
7775 | MESSAGE_RECALL$1 = MESSAGE_RECALL,
|
7776 | MESSAGE_UPDATE$1 = MESSAGE_UPDATE,
|
7777 | INFO_UPDATED$1 = INFO_UPDATED;
|
7778 |
|
7779 | var isTemporaryConversatrionId = function isTemporaryConversatrionId(id) {
|
7780 | return /^_tmp:/.test(id);
|
7781 | };
|
7782 |
|
7783 |
|
7784 |
|
7785 |
|
7786 |
|
7787 |
|
7788 |
|
7789 |
|
7790 |
|
7791 |
|
7792 |
|
7793 | var configBitmap = 59;
|
7794 | var IMClient = (_dec$2 = throttle(1000), _dec2 = throttle(1000), (_class$3 =
|
7795 |
|
7796 | function (_EventEmitter) {
|
7797 | _inheritsLoose(IMClient, _EventEmitter);
|
7798 |
|
7799 | |
7800 |
|
7801 |
|
7802 |
|
7803 |
|
7804 | function IMClient(id) {
|
7805 | var _this;
|
7806 |
|
7807 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
7808 | var props = arguments.length > 2 ? arguments[2] : undefined;
|
7809 |
|
7810 | if (!(id === undefined || typeof id === 'string')) {
|
7811 | throw new TypeError("Client id [".concat(id, "] is not a String"));
|
7812 | }
|
7813 |
|
7814 | _this = _EventEmitter.call(this) || this;
|
7815 | Object.assign(_assertThisInitialized(_this), {
|
7816 | |
7817 |
|
7818 |
|
7819 |
|
7820 | id: id,
|
7821 | options: options
|
7822 | }, props);
|
7823 |
|
7824 | if (!_this._messageParser) {
|
7825 | throw new Error('IMClient must be initialized with a MessageParser');
|
7826 | }
|
7827 |
|
7828 | _this._conversationCache = new Cache("client:".concat(_this.id));
|
7829 | _this._ackMessageBuffer = {};
|
7830 | internal(_assertThisInitialized(_this)).lastPatchTime = Date.now();
|
7831 | internal(_assertThisInitialized(_this)).lastNotificationTime = undefined;
|
7832 | internal(_assertThisInitialized(_this))._eventemitter = new EventEmitter();
|
7833 |
|
7834 | if (debug$a.enabled) {
|
7835 | values(Event).forEach(function (event) {
|
7836 | return _this.on(event, function () {
|
7837 | for (var _len = arguments.length, payload = new Array(_len), _key = 0; _key < _len; _key++) {
|
7838 | payload[_key] = arguments[_key];
|
7839 | }
|
7840 |
|
7841 | return _this._debug("".concat(event, " event emitted. %o"), payload);
|
7842 | });
|
7843 | });
|
7844 | }
|
7845 |
|
7846 |
|
7847 | applyDecorators(_this._plugins.onIMClientCreate, _assertThisInitialized(_this));
|
7848 | return _this;
|
7849 | }
|
7850 |
|
7851 | var _proto = IMClient.prototype;
|
7852 |
|
7853 | _proto._debug = function _debug() {
|
7854 | for (var _len2 = arguments.length, params = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
7855 | params[_key2] = arguments[_key2];
|
7856 | }
|
7857 |
|
7858 | debug$a.apply(void 0, params.concat(["[".concat(this.id, "]")]));
|
7859 | }
|
7860 | |
7861 |
|
7862 |
|
7863 |
|
7864 | ;
|
7865 |
|
7866 | _proto._dispatchCommand =
|
7867 |
|
7868 | function () {
|
7869 | var _dispatchCommand2 = _asyncToGenerator(
|
7870 |
|
7871 | _regeneratorRuntime.mark(function _callee(command) {
|
7872 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
7873 | while (1) {
|
7874 | switch (_context.prev = _context.next) {
|
7875 | case 0:
|
7876 | this._debug(trim(command), 'received');
|
7877 |
|
7878 | if (command.serverTs && command.notificationType === 1) {
|
7879 | internal(this).lastNotificationTime = getTime(decodeDate(command.serverTs));
|
7880 | }
|
7881 |
|
7882 | _context.t0 = command.cmd;
|
7883 | _context.next = _context.t0 === CommandType.conv ? 5 : _context.t0 === CommandType.direct ? 6 : _context.t0 === CommandType.session ? 7 : _context.t0 === CommandType.unread ? 8 : _context.t0 === CommandType.rcp ? 9 : _context.t0 === CommandType.patch ? 10 : 11;
|
7884 | break;
|
7885 |
|
7886 | case 5:
|
7887 | return _context.abrupt("return", this._dispatchConvMessage(command));
|
7888 |
|
7889 | case 6:
|
7890 | return _context.abrupt("return", this._dispatchDirectMessage(command));
|
7891 |
|
7892 | case 7:
|
7893 | return _context.abrupt("return", this._dispatchSessionMessage(command));
|
7894 |
|
7895 | case 8:
|
7896 | return _context.abrupt("return", this._dispatchUnreadMessage(command));
|
7897 |
|
7898 | case 9:
|
7899 | return _context.abrupt("return", this._dispatchRcpMessage(command));
|
7900 |
|
7901 | case 10:
|
7902 | return _context.abrupt("return", this._dispatchPatchMessage(command));
|
7903 |
|
7904 | case 11:
|
7905 | return _context.abrupt("return", this.emit(UNHANDLED_MESSAGE$1, command));
|
7906 |
|
7907 | case 12:
|
7908 | case "end":
|
7909 | return _context.stop();
|
7910 | }
|
7911 | }
|
7912 | }, _callee, this);
|
7913 | }));
|
7914 |
|
7915 | function _dispatchCommand(_x) {
|
7916 | return _dispatchCommand2.apply(this, arguments);
|
7917 | }
|
7918 |
|
7919 | return _dispatchCommand;
|
7920 | }();
|
7921 |
|
7922 | _proto._dispatchSessionMessage =
|
7923 |
|
7924 | function () {
|
7925 | var _dispatchSessionMessage2 = _asyncToGenerator(
|
7926 |
|
7927 | _regeneratorRuntime.mark(function _callee2(message) {
|
7928 | var _message$sessionMessa, code, reason;
|
7929 |
|
7930 | return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
7931 | while (1) {
|
7932 | switch (_context2.prev = _context2.next) {
|
7933 | case 0:
|
7934 | _message$sessionMessa = message.sessionMessage, code = _message$sessionMessa.code, reason = _message$sessionMessa.reason;
|
7935 | _context2.t0 = message.op;
|
7936 | _context2.next = _context2.t0 === OpType.closed ? 4 : 8;
|
7937 | break;
|
7938 |
|
7939 | case 4:
|
7940 | internal(this)._eventemitter.emit('close');
|
7941 |
|
7942 | if (!(code === ErrorCode.SESSION_CONFLICT)) {
|
7943 | _context2.next = 7;
|
7944 | break;
|
7945 | }
|
7946 |
|
7947 | return _context2.abrupt("return", this.emit(CONFLICT$1, {
|
7948 | reason: reason
|
7949 | }));
|
7950 |
|
7951 | case 7:
|
7952 | return _context2.abrupt("return", this.emit(CLOSE$1, {
|
7953 | code: code,
|
7954 | reason: reason
|
7955 | }));
|
7956 |
|
7957 | case 8:
|
7958 | this.emit(UNHANDLED_MESSAGE$1, message);
|
7959 | throw new Error('Unrecognized session command');
|
7960 |
|
7961 | case 10:
|
7962 | case "end":
|
7963 | return _context2.stop();
|
7964 | }
|
7965 | }
|
7966 | }, _callee2, this);
|
7967 | }));
|
7968 |
|
7969 | function _dispatchSessionMessage(_x2) {
|
7970 | return _dispatchSessionMessage2.apply(this, arguments);
|
7971 | }
|
7972 |
|
7973 | return _dispatchSessionMessage;
|
7974 | }();
|
7975 |
|
7976 | _proto._dispatchUnreadMessage = function _dispatchUnreadMessage(_ref) {
|
7977 | var _this2 = this;
|
7978 |
|
7979 | var _ref$unreadMessage = _ref.unreadMessage,
|
7980 | convs = _ref$unreadMessage.convs,
|
7981 | notifTime = _ref$unreadMessage.notifTime;
|
7982 | internal(this).lastUnreadNotifTime = notifTime;
|
7983 |
|
7984 | return this.getConversations(convs.map(function (conv) {
|
7985 | return conv.cid;
|
7986 | })).then(function () {
|
7987 | return (
|
7988 | Promise.all(convs.map(function (_ref2) {
|
7989 | var cid = _ref2.cid,
|
7990 | unread = _ref2.unread,
|
7991 | mid = _ref2.mid,
|
7992 | ts = _ref2.timestamp,
|
7993 | from = _ref2.from,
|
7994 | data = _ref2.data,
|
7995 | binaryMsg = _ref2.binaryMsg,
|
7996 | patchTimestamp = _ref2.patchTimestamp,
|
7997 | mentioned = _ref2.mentioned;
|
7998 |
|
7999 | var conversation = _this2._conversationCache.get(cid);
|
8000 |
|
8001 |
|
8002 | if (!conversation) return null;
|
8003 | var timestamp;
|
8004 |
|
8005 | if (ts) {
|
8006 | timestamp = decodeDate(ts);
|
8007 | conversation.lastMessageAt = timestamp;
|
8008 | }
|
8009 |
|
8010 | return (mid ? _this2._messageParser.parse(binaryMsg || data).then(function (message) {
|
8011 | var messageProps = {
|
8012 | id: mid,
|
8013 | cid: cid,
|
8014 | timestamp: timestamp,
|
8015 | updatedAt: patchTimestamp,
|
8016 | from: from
|
8017 | };
|
8018 | Object.assign(message, messageProps);
|
8019 | conversation.lastMessage = message;
|
8020 | }) : Promise.resolve()).then(function () {
|
8021 | conversation._setUnreadMessagesMentioned(mentioned);
|
8022 |
|
8023 | var countNotUpdated = unread === internal(conversation).unreadMessagesCount;
|
8024 | if (countNotUpdated) return null;
|
8025 |
|
8026 |
|
8027 | internal(conversation).unreadMessagesCount = unread;
|
8028 | return conversation;
|
8029 | });
|
8030 | })).then(function (conversations) {
|
8031 | return conversations.filter(function (conversation) {
|
8032 | return conversation;
|
8033 | });
|
8034 | })
|
8035 | );
|
8036 | }).then(function (conversations) {
|
8037 | if (conversations.length) {
|
8038 | |
8039 |
|
8040 |
|
8041 |
|
8042 |
|
8043 |
|
8044 | _this2.emit(UNREAD_MESSAGES_COUNT_UPDATE$1, conversations);
|
8045 | }
|
8046 | });
|
8047 | };
|
8048 |
|
8049 | _proto._dispatchRcpMessage =
|
8050 |
|
8051 | function () {
|
8052 | var _dispatchRcpMessage2 = _asyncToGenerator(
|
8053 |
|
8054 | _regeneratorRuntime.mark(function _callee3(message) {
|
8055 | var rcpMessage, read, conversationId, messageId, timestamp, conversation;
|
8056 | return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
8057 | while (1) {
|
8058 | switch (_context3.prev = _context3.next) {
|
8059 | case 0:
|
8060 | rcpMessage = message.rcpMessage, read = message.rcpMessage.read;
|
8061 | conversationId = rcpMessage.cid;
|
8062 | messageId = rcpMessage.id;
|
8063 | timestamp = decodeDate(rcpMessage.t);
|
8064 | conversation = this._conversationCache.get(conversationId);
|
8065 |
|
8066 |
|
8067 | if (conversation) {
|
8068 | _context3.next = 7;
|
8069 | break;
|
8070 | }
|
8071 |
|
8072 | return _context3.abrupt("return");
|
8073 |
|
8074 | case 7:
|
8075 | conversation._handleReceipt({
|
8076 | messageId: messageId,
|
8077 | timestamp: timestamp,
|
8078 | read: read
|
8079 | });
|
8080 |
|
8081 | case 8:
|
8082 | case "end":
|
8083 | return _context3.stop();
|
8084 | }
|
8085 | }
|
8086 | }, _callee3, this);
|
8087 | }));
|
8088 |
|
8089 | function _dispatchRcpMessage(_x3) {
|
8090 | return _dispatchRcpMessage2.apply(this, arguments);
|
8091 | }
|
8092 |
|
8093 | return _dispatchRcpMessage;
|
8094 | }();
|
8095 |
|
8096 | _proto._dispatchPatchMessage = function _dispatchPatchMessage(_ref3) {
|
8097 | var _this3 = this;
|
8098 |
|
8099 | var patches = _ref3.patchMessage.patches;
|
8100 |
|
8101 | return this.getConversations(patches.map(function (patch) {
|
8102 | return patch.cid;
|
8103 | })).then(function () {
|
8104 | return Promise.all(patches.map(function (_ref4) {
|
8105 | var cid = _ref4.cid,
|
8106 | mid = _ref4.mid,
|
8107 | timestamp = _ref4.timestamp,
|
8108 | recall = _ref4.recall,
|
8109 | data = _ref4.data,
|
8110 | patchTimestamp = _ref4.patchTimestamp,
|
8111 | from = _ref4.from,
|
8112 | binaryMsg = _ref4.binaryMsg,
|
8113 | mentionAll = _ref4.mentionAll,
|
8114 | mentionPids = _ref4.mentionPids,
|
8115 | patchCode = _ref4.patchCode,
|
8116 | patchReason = _ref4.patchReason;
|
8117 |
|
8118 | var conversation = _this3._conversationCache.get(cid);
|
8119 |
|
8120 |
|
8121 | if (!conversation) return null;
|
8122 | return _this3._messageParser.parse(binaryMsg || data).then(function (message) {
|
8123 | var patchTime = getTime(decodeDate(patchTimestamp));
|
8124 | var messageProps = {
|
8125 | id: mid,
|
8126 | cid: cid,
|
8127 | timestamp: timestamp,
|
8128 | updatedAt: patchTime,
|
8129 | from: from,
|
8130 | mentionList: mentionPids,
|
8131 | mentionedAll: mentionAll
|
8132 | };
|
8133 | Object.assign(message, messageProps);
|
8134 |
|
8135 | message._setStatus(MessageStatus.SENT);
|
8136 |
|
8137 | message._updateMentioned(_this3.id);
|
8138 |
|
8139 | if (internal(_this3).lastPatchTime < patchTime) {
|
8140 | internal(_this3).lastPatchTime = patchTime;
|
8141 | }
|
8142 |
|
8143 |
|
8144 | if (conversation.lastMessage && conversation.lastMessage.id === mid) {
|
8145 | conversation.lastMessage = message;
|
8146 | }
|
8147 |
|
8148 | var reason;
|
8149 |
|
8150 | if (patchCode) {
|
8151 | reason = {
|
8152 | code: patchCode.toNumber(),
|
8153 | detail: patchReason
|
8154 | };
|
8155 | }
|
8156 |
|
8157 | if (recall) {
|
8158 | |
8159 |
|
8160 |
|
8161 |
|
8162 |
|
8163 |
|
8164 |
|
8165 | _this3.emit(MESSAGE_RECALL$1, message, conversation, reason);
|
8166 | |
8167 |
|
8168 |
|
8169 |
|
8170 |
|
8171 |
|
8172 |
|
8173 |
|
8174 | conversation.emit(MESSAGE_RECALL$1, message, reason);
|
8175 | } else {
|
8176 | |
8177 |
|
8178 |
|
8179 |
|
8180 |
|
8181 |
|
8182 |
|
8183 | _this3.emit(MESSAGE_UPDATE$1, message, conversation, reason);
|
8184 | |
8185 |
|
8186 |
|
8187 |
|
8188 |
|
8189 |
|
8190 |
|
8191 |
|
8192 | conversation.emit(MESSAGE_UPDATE$1, message, reason);
|
8193 | }
|
8194 | });
|
8195 | }));
|
8196 | });
|
8197 | };
|
8198 |
|
8199 | _proto._dispatchConvMessage =
|
8200 |
|
8201 | function () {
|
8202 | var _dispatchConvMessage2 = _asyncToGenerator(
|
8203 |
|
8204 | _regeneratorRuntime.mark(function _callee4(message) {
|
8205 | var convMessage, _message$convMessage, initBy, m, info, attr, conversation, payload, _payload, _payload2, _payload3, _payload4, _payload5, _payload6, _payload7, _payload8, _payload9, _payload10, _payload11, pid, role, _internal, memberInfoMap, memberInfo, _payload12, attributes, _payload13;
|
8206 |
|
8207 | return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
8208 | while (1) {
|
8209 | switch (_context4.prev = _context4.next) {
|
8210 | case 0:
|
8211 | convMessage = message.convMessage, _message$convMessage = message.convMessage, initBy = _message$convMessage.initBy, m = _message$convMessage.m, info = _message$convMessage.info, attr = _message$convMessage.attr;
|
8212 | _context4.next = 3;
|
8213 | return this.getConversation(convMessage.cid);
|
8214 |
|
8215 | case 3:
|
8216 | conversation = _context4.sent;
|
8217 | _context4.t0 = message.op;
|
8218 | _context4.next = _context4.t0 === OpType.joined ? 7 : _context4.t0 === OpType.left ? 12 : _context4.t0 === OpType.members_joined ? 17 : _context4.t0 === OpType.members_left ? 22 : _context4.t0 === OpType.members_blocked ? 27 : _context4.t0 === OpType.members_unblocked ? 31 : _context4.t0 === OpType.blocked ? 35 : _context4.t0 === OpType.unblocked ? 39 : _context4.t0 === OpType.members_shutuped ? 43 : _context4.t0 === OpType.members_unshutuped ? 47 : _context4.t0 === OpType.shutuped ? 51 : _context4.t0 === OpType.unshutuped ? 55 : _context4.t0 === OpType.member_info_changed ? 59 : _context4.t0 === OpType.updated ? 71 : 77;
|
8219 | break;
|
8220 |
|
8221 | case 7:
|
8222 | conversation._addMembers([this.id]);
|
8223 |
|
8224 | payload = {
|
8225 | invitedBy: initBy
|
8226 | };
|
8227 | |
8228 |
|
8229 |
|
8230 |
|
8231 |
|
8232 |
|
8233 |
|
8234 |
|
8235 | this.emit(INVITED$1, payload, conversation);
|
8236 | |
8237 |
|
8238 |
|
8239 |
|
8240 |
|
8241 |
|
8242 |
|
8243 | conversation.emit(INVITED$1, payload);
|
8244 | return _context4.abrupt("return");
|
8245 |
|
8246 | case 12:
|
8247 | conversation._removeMembers([this.id]);
|
8248 |
|
8249 | _payload = {
|
8250 | kickedBy: initBy
|
8251 | };
|
8252 | |
8253 |
|
8254 |
|
8255 |
|
8256 |
|
8257 |
|
8258 |
|
8259 |
|
8260 | this.emit(KICKED$1, _payload, conversation);
|
8261 | |
8262 |
|
8263 |
|
8264 |
|
8265 |
|
8266 |
|
8267 |
|
8268 | conversation.emit(KICKED$1, _payload);
|
8269 | return _context4.abrupt("return");
|
8270 |
|
8271 | case 17:
|
8272 | conversation._addMembers(m);
|
8273 |
|
8274 | _payload2 = {
|
8275 | invitedBy: initBy,
|
8276 | members: m
|
8277 | };
|
8278 | |
8279 |
|
8280 |
|
8281 |
|
8282 |
|
8283 |
|
8284 |
|
8285 |
|
8286 |
|
8287 | this.emit(MEMBERS_JOINED$1, _payload2, conversation);
|
8288 | |
8289 |
|
8290 |
|
8291 |
|
8292 |
|
8293 |
|
8294 |
|
8295 |
|
8296 | conversation.emit(MEMBERS_JOINED$1, _payload2);
|
8297 | return _context4.abrupt("return");
|
8298 |
|
8299 | case 22:
|
8300 | conversation._removeMembers(m);
|
8301 |
|
8302 | _payload3 = {
|
8303 | kickedBy: initBy,
|
8304 | members: m
|
8305 | };
|
8306 | |
8307 |
|
8308 |
|
8309 |
|
8310 |
|
8311 |
|
8312 |
|
8313 |
|
8314 |
|
8315 | this.emit(MEMBERS_LEFT$1, _payload3, conversation);
|
8316 | |
8317 |
|
8318 |
|
8319 |
|
8320 |
|
8321 |
|
8322 |
|
8323 |
|
8324 | conversation.emit(MEMBERS_LEFT$1, _payload3);
|
8325 | return _context4.abrupt("return");
|
8326 |
|
8327 | case 27:
|
8328 | _payload4 = {
|
8329 | blockedBy: initBy,
|
8330 | members: m
|
8331 | };
|
8332 | |
8333 |
|
8334 |
|
8335 |
|
8336 |
|
8337 |
|
8338 |
|
8339 |
|
8340 |
|
8341 | this.emit(MEMBERS_BLOCKED$1, _payload4, conversation);
|
8342 | |
8343 |
|
8344 |
|
8345 |
|
8346 |
|
8347 |
|
8348 |
|
8349 |
|
8350 | conversation.emit(MEMBERS_BLOCKED$1, _payload4);
|
8351 | return _context4.abrupt("return");
|
8352 |
|
8353 | case 31:
|
8354 | _payload5 = {
|
8355 | unblockedBy: initBy,
|
8356 | members: m
|
8357 | };
|
8358 | |
8359 |
|
8360 |
|
8361 |
|
8362 |
|
8363 |
|
8364 |
|
8365 |
|
8366 |
|
8367 | this.emit(MEMBERS_UNBLOCKED$1, _payload5, conversation);
|
8368 | |
8369 |
|
8370 |
|
8371 |
|
8372 |
|
8373 |
|
8374 |
|
8375 |
|
8376 | conversation.emit(MEMBERS_UNBLOCKED$1, _payload5);
|
8377 | return _context4.abrupt("return");
|
8378 |
|
8379 | case 35:
|
8380 | _payload6 = {
|
8381 | blockedBy: initBy
|
8382 | };
|
8383 | |
8384 |
|
8385 |
|
8386 |
|
8387 |
|
8388 |
|
8389 |
|
8390 |
|
8391 | this.emit(BLOCKED$1, _payload6, conversation);
|
8392 | |
8393 |
|
8394 |
|
8395 |
|
8396 |
|
8397 |
|
8398 |
|
8399 | conversation.emit(BLOCKED$1, _payload6);
|
8400 | return _context4.abrupt("return");
|
8401 |
|
8402 | case 39:
|
8403 | _payload7 = {
|
8404 | unblockedBy: initBy
|
8405 | };
|
8406 | |
8407 |
|
8408 |
|
8409 |
|
8410 |
|
8411 |
|
8412 |
|
8413 |
|
8414 | this.emit(UNBLOCKED$1, _payload7, conversation);
|
8415 | |
8416 |
|
8417 |
|
8418 |
|
8419 |
|
8420 |
|
8421 |
|
8422 | conversation.emit(UNBLOCKED$1, _payload7);
|
8423 | return _context4.abrupt("return");
|
8424 |
|
8425 | case 43:
|
8426 | _payload8 = {
|
8427 | mutedBy: initBy,
|
8428 | members: m
|
8429 | };
|
8430 | |
8431 |
|
8432 |
|
8433 |
|
8434 |
|
8435 |
|
8436 |
|
8437 |
|
8438 |
|
8439 | this.emit(MEMBERS_MUTED$1, _payload8, conversation);
|
8440 | |
8441 |
|
8442 |
|
8443 |
|
8444 |
|
8445 |
|
8446 |
|
8447 |
|
8448 | conversation.emit(MEMBERS_MUTED$1, _payload8);
|
8449 | return _context4.abrupt("return");
|
8450 |
|
8451 | case 47:
|
8452 | _payload9 = {
|
8453 | unmutedBy: initBy,
|
8454 | members: m
|
8455 | };
|
8456 | |
8457 |
|
8458 |
|
8459 |
|
8460 |
|
8461 |
|
8462 |
|
8463 |
|
8464 |
|
8465 | this.emit(MEMBERS_UNMUTED$1, _payload9, conversation);
|
8466 | |
8467 |
|
8468 |
|
8469 |
|
8470 |
|
8471 |
|
8472 |
|
8473 |
|
8474 | conversation.emit(MEMBERS_UNMUTED$1, _payload9);
|
8475 | return _context4.abrupt("return");
|
8476 |
|
8477 | case 51:
|
8478 | _payload10 = {
|
8479 | mutedBy: initBy
|
8480 | };
|
8481 | |
8482 |
|
8483 |
|
8484 |
|
8485 |
|
8486 |
|
8487 |
|
8488 |
|
8489 | this.emit(MUTED$1, _payload10, conversation);
|
8490 | |
8491 |
|
8492 |
|
8493 |
|
8494 |
|
8495 |
|
8496 |
|
8497 | conversation.emit(MUTED$1, _payload10);
|
8498 | return _context4.abrupt("return");
|
8499 |
|
8500 | case 55:
|
8501 | _payload11 = {
|
8502 | unmutedBy: initBy
|
8503 | };
|
8504 | |
8505 |
|
8506 |
|
8507 |
|
8508 |
|
8509 |
|
8510 |
|
8511 |
|
8512 | this.emit(UNMUTED$1, _payload11, conversation);
|
8513 | |
8514 |
|
8515 |
|
8516 |
|
8517 |
|
8518 |
|
8519 |
|
8520 | conversation.emit(UNMUTED$1, _payload11);
|
8521 | return _context4.abrupt("return");
|
8522 |
|
8523 | case 59:
|
8524 | pid = info.pid, role = info.role;
|
8525 | _internal = internal(conversation), memberInfoMap = _internal.memberInfoMap;
|
8526 |
|
8527 | if (!(!memberInfoMap && !role)) {
|
8528 | _context4.next = 63;
|
8529 | break;
|
8530 | }
|
8531 |
|
8532 | return _context4.abrupt("return");
|
8533 |
|
8534 | case 63:
|
8535 | _context4.next = 65;
|
8536 | return conversation.getMemberInfo(pid);
|
8537 |
|
8538 | case 65:
|
8539 | memberInfo = _context4.sent;
|
8540 | internal(memberInfo).role = role;
|
8541 | _payload12 = {
|
8542 | member: pid,
|
8543 | memberInfo: memberInfo,
|
8544 | updatedBy: initBy
|
8545 | };
|
8546 | |
8547 |
|
8548 |
|
8549 |
|
8550 |
|
8551 |
|
8552 |
|
8553 |
|
8554 |
|
8555 |
|
8556 | this.emit(MEMBER_INFO_UPDATED$1, _payload12, conversation);
|
8557 | |
8558 |
|
8559 |
|
8560 |
|
8561 |
|
8562 |
|
8563 |
|
8564 |
|
8565 |
|
8566 | conversation.emit(MEMBER_INFO_UPDATED$1, _payload12);
|
8567 | return _context4.abrupt("return");
|
8568 |
|
8569 | case 71:
|
8570 | attributes = decode(JSON.parse(attr.data));
|
8571 |
|
8572 | conversation._updateServerAttributes(attributes);
|
8573 |
|
8574 | _payload13 = {
|
8575 | attributes: attributes,
|
8576 | updatedBy: initBy
|
8577 | };
|
8578 | |
8579 |
|
8580 |
|
8581 |
|
8582 |
|
8583 |
|
8584 |
|
8585 |
|
8586 |
|
8587 | this.emit(CONVERSATION_INFO_UPDATED$1, _payload13, conversation);
|
8588 | |
8589 |
|
8590 |
|
8591 |
|
8592 |
|
8593 |
|
8594 |
|
8595 |
|
8596 | conversation.emit(INFO_UPDATED$1, _payload13);
|
8597 | return _context4.abrupt("return");
|
8598 |
|
8599 | case 77:
|
8600 | this.emit(UNHANDLED_MESSAGE$1, message);
|
8601 | throw new Error('Unrecognized conversation command');
|
8602 |
|
8603 | case 79:
|
8604 | case "end":
|
8605 | return _context4.stop();
|
8606 | }
|
8607 | }
|
8608 | }, _callee4, this);
|
8609 | }));
|
8610 |
|
8611 | function _dispatchConvMessage(_x4) {
|
8612 | return _dispatchConvMessage2.apply(this, arguments);
|
8613 | }
|
8614 |
|
8615 | return _dispatchConvMessage;
|
8616 | }();
|
8617 |
|
8618 | _proto._dispatchDirectMessage = function _dispatchDirectMessage(originalMessage) {
|
8619 | var _this4 = this;
|
8620 |
|
8621 | var directMessage = originalMessage.directMessage,
|
8622 | _originalMessage$dire = originalMessage.directMessage,
|
8623 | id = _originalMessage$dire.id,
|
8624 | cid = _originalMessage$dire.cid,
|
8625 | fromPeerId = _originalMessage$dire.fromPeerId,
|
8626 | timestamp = _originalMessage$dire.timestamp,
|
8627 | transient = _originalMessage$dire.transient,
|
8628 | patchTimestamp = _originalMessage$dire.patchTimestamp,
|
8629 | mentionPids = _originalMessage$dire.mentionPids,
|
8630 | mentionAll = _originalMessage$dire.mentionAll,
|
8631 | binaryMsg = _originalMessage$dire.binaryMsg,
|
8632 | msg = _originalMessage$dire.msg;
|
8633 | var content = binaryMsg ? binaryMsg.toArrayBuffer() : msg;
|
8634 | return Promise.all([this.getConversation(directMessage.cid), this._messageParser.parse(content)]).then(function (_ref5) {
|
8635 | var _ref6 = _slicedToArray(_ref5, 2),
|
8636 | conversation = _ref6[0],
|
8637 | message = _ref6[1];
|
8638 |
|
8639 |
|
8640 | if (!conversation) return undefined;
|
8641 | var messageProps = {
|
8642 | id: id,
|
8643 | cid: cid,
|
8644 | timestamp: timestamp,
|
8645 | updatedAt: patchTimestamp,
|
8646 | from: fromPeerId,
|
8647 | mentionList: mentionPids,
|
8648 | mentionedAll: mentionAll
|
8649 | };
|
8650 | Object.assign(message, messageProps);
|
8651 |
|
8652 | message._updateMentioned(_this4.id);
|
8653 |
|
8654 | message._setStatus(MessageStatus.SENT);
|
8655 |
|
8656 |
|
8657 | if (message.from !== _this4.id) {
|
8658 | if (!(transient || conversation.transient)) {
|
8659 | _this4._sendAck(message);
|
8660 | }
|
8661 | }
|
8662 |
|
8663 | return _this4._dispatchParsedMessage(message, conversation);
|
8664 | });
|
8665 | };
|
8666 |
|
8667 | _proto._dispatchParsedMessage = function _dispatchParsedMessage(message, conversation) {
|
8668 | var _this5 = this;
|
8669 |
|
8670 |
|
8671 | return applyDispatcher(this._plugins.beforeMessageDispatch, [message, conversation]).then(function (shouldDispatch) {
|
8672 | if (shouldDispatch === false) return;
|
8673 | conversation.lastMessage = message;
|
8674 |
|
8675 | conversation.lastMessageAt = message.timestamp;
|
8676 |
|
8677 |
|
8678 | if (message.from !== _this5.id) {
|
8679 | conversation.unreadMessagesCount += 1;
|
8680 |
|
8681 | if (message.mentioned) conversation._setUnreadMessagesMentioned(true);
|
8682 | }
|
8683 | |
8684 |
|
8685 |
|
8686 |
|
8687 |
|
8688 |
|
8689 |
|
8690 |
|
8691 | _this5.emit(MESSAGE$2, message, conversation);
|
8692 | |
8693 |
|
8694 |
|
8695 |
|
8696 |
|
8697 |
|
8698 |
|
8699 | conversation.emit(MESSAGE$2, message);
|
8700 | });
|
8701 | };
|
8702 |
|
8703 | _proto._sendAck = function _sendAck(message) {
|
8704 | this._debug('send ack for %O', message);
|
8705 |
|
8706 | var cid = message.cid;
|
8707 |
|
8708 | if (!cid) {
|
8709 | throw new Error('missing cid');
|
8710 | }
|
8711 |
|
8712 | if (!this._ackMessageBuffer[cid]) {
|
8713 | this._ackMessageBuffer[cid] = [];
|
8714 | }
|
8715 |
|
8716 | this._ackMessageBuffer[cid].push(message);
|
8717 |
|
8718 | return this._doSendAck();
|
8719 | }
|
8720 | ;
|
8721 |
|
8722 | _proto.
|
8723 | _doSendAck = function _doSendAck() {
|
8724 | var _this6 = this;
|
8725 |
|
8726 |
|
8727 | if (!this._connection.is('connected')) return;
|
8728 |
|
8729 | this._debug('do send ack %O', this._ackMessageBuffer);
|
8730 |
|
8731 | Promise.all(Object.keys(this._ackMessageBuffer).map(function (cid) {
|
8732 | var convAckMessages = _this6._ackMessageBuffer[cid];
|
8733 | var timestamps = convAckMessages.map(function (message) {
|
8734 | return message.timestamp;
|
8735 | });
|
8736 | var command = new GenericCommand({
|
8737 | cmd: 'ack',
|
8738 | peerId: _this6.id,
|
8739 | ackMessage: new AckCommand({
|
8740 | cid: cid,
|
8741 | fromts: Math.min.apply(null, timestamps),
|
8742 | tots: Math.max.apply(null, timestamps)
|
8743 | })
|
8744 | });
|
8745 | delete _this6._ackMessageBuffer[cid];
|
8746 | return _this6._send(command, false).catch(function (error) {
|
8747 | _this6._debug('send ack failed: %O', error);
|
8748 |
|
8749 | _this6._ackMessageBuffer[cid] = convAckMessages;
|
8750 | });
|
8751 | }));
|
8752 | };
|
8753 |
|
8754 | _proto._omitPeerId = function _omitPeerId(value) {
|
8755 | internal(this).peerIdOmittable = value;
|
8756 | };
|
8757 |
|
8758 | _proto._send = function _send(cmd) {
|
8759 | var _this$_connection;
|
8760 |
|
8761 | var command = cmd;
|
8762 |
|
8763 | if (!internal(this).peerIdOmittable && this.id) {
|
8764 | command.peerId = this.id;
|
8765 | }
|
8766 |
|
8767 | for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
8768 | args[_key3 - 1] = arguments[_key3];
|
8769 | }
|
8770 |
|
8771 | return (_this$_connection = this._connection).send.apply(_this$_connection, [command].concat(args));
|
8772 | };
|
8773 |
|
8774 | _proto._open =
|
8775 |
|
8776 | function () {
|
8777 | var _open2 = _asyncToGenerator(
|
8778 |
|
8779 | _regeneratorRuntime.mark(function _callee5(appId, tag, deviceId) {
|
8780 | var isReconnect,
|
8781 | _internal2,
|
8782 | lastUnreadNotifTime,
|
8783 | lastPatchTime,
|
8784 | lastNotificationTime,
|
8785 | command,
|
8786 | signatureResult,
|
8787 | sessionToken,
|
8788 | resCommand,
|
8789 | _resCommand,
|
8790 | peerId,
|
8791 | sessionMessage,
|
8792 | _resCommand$sessionMe,
|
8793 | token,
|
8794 | tokenTTL,
|
8795 | code,
|
8796 | serverTs,
|
8797 | serverTime,
|
8798 | _args5 = arguments;
|
8799 |
|
8800 | return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
8801 | while (1) {
|
8802 | switch (_context5.prev = _context5.next) {
|
8803 | case 0:
|
8804 | isReconnect = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : false;
|
8805 |
|
8806 | this._debug('open session');
|
8807 |
|
8808 | _internal2 = internal(this), lastUnreadNotifTime = _internal2.lastUnreadNotifTime, lastPatchTime = _internal2.lastPatchTime, lastNotificationTime = _internal2.lastNotificationTime;
|
8809 | command = new GenericCommand({
|
8810 | cmd: 'session',
|
8811 | op: 'open',
|
8812 | appId: appId,
|
8813 | peerId: this.id,
|
8814 | sessionMessage: new SessionCommand({
|
8815 | ua: "js/".concat(version),
|
8816 | r: isReconnect,
|
8817 | lastUnreadNotifTime: lastUnreadNotifTime,
|
8818 | lastPatchTime: lastPatchTime,
|
8819 | configBitmap: configBitmap
|
8820 | })
|
8821 | });
|
8822 |
|
8823 | if (isReconnect) {
|
8824 | _context5.next = 13;
|
8825 | break;
|
8826 | }
|
8827 |
|
8828 | Object.assign(command.sessionMessage, trim({
|
8829 | tag: tag,
|
8830 | deviceId: deviceId
|
8831 | }));
|
8832 |
|
8833 | if (!this.options.signatureFactory) {
|
8834 | _context5.next = 11;
|
8835 | break;
|
8836 | }
|
8837 |
|
8838 | _context5.next = 9;
|
8839 | return runSignatureFactory(this.options.signatureFactory, [this._identity]);
|
8840 |
|
8841 | case 9:
|
8842 | signatureResult = _context5.sent;
|
8843 | Object.assign(command.sessionMessage, keyRemap({
|
8844 | signature: 's',
|
8845 | timestamp: 't',
|
8846 | nonce: 'n'
|
8847 | }, signatureResult));
|
8848 |
|
8849 | case 11:
|
8850 | _context5.next = 17;
|
8851 | break;
|
8852 |
|
8853 | case 13:
|
8854 | _context5.next = 15;
|
8855 | return this._sessionManager.getSessionToken({
|
8856 | autoRefresh: false
|
8857 | });
|
8858 |
|
8859 | case 15:
|
8860 | sessionToken = _context5.sent;
|
8861 |
|
8862 | if (sessionToken && sessionToken !== Expirable.EXPIRED) {
|
8863 | Object.assign(command.sessionMessage, {
|
8864 | st: sessionToken
|
8865 | });
|
8866 | }
|
8867 |
|
8868 | case 17:
|
8869 | _context5.prev = 17;
|
8870 | _context5.next = 20;
|
8871 | return this._send(command);
|
8872 |
|
8873 | case 20:
|
8874 | resCommand = _context5.sent;
|
8875 | _context5.next = 32;
|
8876 | break;
|
8877 |
|
8878 | case 23:
|
8879 | _context5.prev = 23;
|
8880 | _context5.t0 = _context5["catch"](17);
|
8881 |
|
8882 | if (!(_context5.t0.code === ErrorCode.SESSION_TOKEN_EXPIRED)) {
|
8883 | _context5.next = 31;
|
8884 | break;
|
8885 | }
|
8886 |
|
8887 | if (this._sessionManager) {
|
8888 | _context5.next = 28;
|
8889 | break;
|
8890 | }
|
8891 |
|
8892 | throw new Error('Unexpected session expiration');
|
8893 |
|
8894 | case 28:
|
8895 | debug$a('Session token expired, reopening');
|
8896 |
|
8897 | this._sessionManager.revoke();
|
8898 |
|
8899 | return _context5.abrupt("return", this._open(appId, tag, deviceId, isReconnect));
|
8900 |
|
8901 | case 31:
|
8902 | throw _context5.t0;
|
8903 |
|
8904 | case 32:
|
8905 | _resCommand = resCommand, peerId = _resCommand.peerId, sessionMessage = _resCommand.sessionMessage, _resCommand$sessionMe = _resCommand.sessionMessage, token = _resCommand$sessionMe.st, tokenTTL = _resCommand$sessionMe.stTtl, code = _resCommand$sessionMe.code, serverTs = _resCommand.serverTs;
|
8906 |
|
8907 | if (!code) {
|
8908 | _context5.next = 35;
|
8909 | break;
|
8910 | }
|
8911 |
|
8912 | throw createError(sessionMessage);
|
8913 |
|
8914 | case 35:
|
8915 | if (peerId) {
|
8916 | this.id = peerId;
|
8917 | if (!this._identity) this._identity = peerId;
|
8918 |
|
8919 | if (token) {
|
8920 | this._sessionManager = this._sessionManager || this._createSessionManager();
|
8921 |
|
8922 | this._sessionManager.setSessionToken(token, tokenTTL);
|
8923 | }
|
8924 |
|
8925 | serverTime = getTime(decodeDate(serverTs));
|
8926 |
|
8927 | if (serverTs) {
|
8928 | internal(this).lastPatchTime = serverTime;
|
8929 | }
|
8930 |
|
8931 | if (lastNotificationTime) {
|
8932 |
|
8933 | this._syncNotifications(lastNotificationTime).catch(function (error) {
|
8934 | return console.warn('Syncing notifications failed:', error);
|
8935 | });
|
8936 | } else {
|
8937 |
|
8938 | internal(this).lastNotificationTime = serverTime;
|
8939 | }
|
8940 | } else {
|
8941 | console.warn('Unexpected session opened without peerId.');
|
8942 | }
|
8943 |
|
8944 | return _context5.abrupt("return", undefined);
|
8945 |
|
8946 | case 37:
|
8947 | case "end":
|
8948 | return _context5.stop();
|
8949 | }
|
8950 | }
|
8951 | }, _callee5, this, [[17, 23]]);
|
8952 | }));
|
8953 |
|
8954 | function _open(_x5, _x6, _x7) {
|
8955 | return _open2.apply(this, arguments);
|
8956 | }
|
8957 |
|
8958 | return _open;
|
8959 | }();
|
8960 |
|
8961 | _proto._syncNotifications =
|
8962 |
|
8963 | function () {
|
8964 | var _syncNotifications2 = _asyncToGenerator(
|
8965 |
|
8966 | _regeneratorRuntime.mark(function _callee6(timestamp) {
|
8967 | var _this7 = this;
|
8968 |
|
8969 | var _ref7, hasMore, notifications;
|
8970 |
|
8971 | return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
8972 | while (1) {
|
8973 | switch (_context6.prev = _context6.next) {
|
8974 | case 0:
|
8975 | _context6.next = 2;
|
8976 | return this._fetchNotifications(timestamp);
|
8977 |
|
8978 | case 2:
|
8979 | _ref7 = _context6.sent;
|
8980 | hasMore = _ref7.hasMore;
|
8981 | notifications = _ref7.notifications;
|
8982 | notifications.forEach(function (notification) {
|
8983 | var cmd = notification.cmd,
|
8984 | op = notification.op,
|
8985 | serverTs = notification.serverTs,
|
8986 | notificationType = notification.notificationType,
|
8987 | payload = _objectWithoutProperties(notification, ["cmd", "op", "serverTs", "notificationType"]);
|
8988 |
|
8989 | _this7._dispatchCommand(_defineProperty({
|
8990 | cmd: CommandType[cmd],
|
8991 | op: OpType[op],
|
8992 | serverTs: serverTs,
|
8993 | notificationType: notificationType
|
8994 | }, "".concat(cmd, "Message"), payload));
|
8995 | });
|
8996 |
|
8997 | if (!hasMore) {
|
8998 | _context6.next = 8;
|
8999 | break;
|
9000 | }
|
9001 |
|
9002 | return _context6.abrupt("return", this._syncNotifications(internal(this).lastNotificationTime));
|
9003 |
|
9004 | case 8:
|
9005 | return _context6.abrupt("return", undefined);
|
9006 |
|
9007 | case 9:
|
9008 | case "end":
|
9009 | return _context6.stop();
|
9010 | }
|
9011 | }
|
9012 | }, _callee6, this);
|
9013 | }));
|
9014 |
|
9015 | function _syncNotifications(_x8) {
|
9016 | return _syncNotifications2.apply(this, arguments);
|
9017 | }
|
9018 |
|
9019 | return _syncNotifications;
|
9020 | }();
|
9021 |
|
9022 | _proto._fetchNotifications =
|
9023 |
|
9024 | function () {
|
9025 | var _fetchNotifications2 = _asyncToGenerator(
|
9026 |
|
9027 | _regeneratorRuntime.mark(function _callee7(timestamp) {
|
9028 | return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
9029 | while (1) {
|
9030 | switch (_context7.prev = _context7.next) {
|
9031 | case 0:
|
9032 | return _context7.abrupt("return", this._requestWithSessionToken({
|
9033 | method: 'GET',
|
9034 | path: '/rtm/notifications',
|
9035 | query: {
|
9036 | start_ts: timestamp,
|
9037 | notification_type: 'permanent'
|
9038 | }
|
9039 | }));
|
9040 |
|
9041 | case 1:
|
9042 | case "end":
|
9043 | return _context7.stop();
|
9044 | }
|
9045 | }
|
9046 | }, _callee7, this);
|
9047 | }));
|
9048 |
|
9049 | function _fetchNotifications(_x9) {
|
9050 | return _fetchNotifications2.apply(this, arguments);
|
9051 | }
|
9052 |
|
9053 | return _fetchNotifications;
|
9054 | }();
|
9055 |
|
9056 | _proto._createSessionManager = function _createSessionManager() {
|
9057 | var _this8 = this;
|
9058 |
|
9059 | debug$a('create SessionManager');
|
9060 | return new SessionManager({
|
9061 | onBeforeGetSessionToken: this._connection.checkConnectionAvailability.bind(this._connection),
|
9062 | refresh: function refresh(manager, expiredSessionToken) {
|
9063 | return manager.setSessionTokenAsync(Promise.resolve(new GenericCommand({
|
9064 | cmd: 'session',
|
9065 | op: 'refresh',
|
9066 | sessionMessage: new SessionCommand({
|
9067 | ua: "js/".concat(version),
|
9068 | st: expiredSessionToken
|
9069 | })
|
9070 | })).then(
|
9071 |
|
9072 | function () {
|
9073 | var _ref8 = _asyncToGenerator(
|
9074 |
|
9075 | _regeneratorRuntime.mark(function _callee8(command) {
|
9076 | var signatureResult;
|
9077 | return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
9078 | while (1) {
|
9079 | switch (_context8.prev = _context8.next) {
|
9080 | case 0:
|
9081 | if (!_this8.options.signatureFactory) {
|
9082 | _context8.next = 5;
|
9083 | break;
|
9084 | }
|
9085 |
|
9086 | _context8.next = 3;
|
9087 | return runSignatureFactory(_this8.options.signatureFactory, [_this8._identity]);
|
9088 |
|
9089 | case 3:
|
9090 | signatureResult = _context8.sent;
|
9091 | Object.assign(command.sessionMessage, keyRemap({
|
9092 | signature: 's',
|
9093 | timestamp: 't',
|
9094 | nonce: 'n'
|
9095 | }, signatureResult));
|
9096 |
|
9097 | case 5:
|
9098 | return _context8.abrupt("return", command);
|
9099 |
|
9100 | case 6:
|
9101 | case "end":
|
9102 | return _context8.stop();
|
9103 | }
|
9104 | }
|
9105 | }, _callee8, this);
|
9106 | }));
|
9107 |
|
9108 | return function (_x10) {
|
9109 | return _ref8.apply(this, arguments);
|
9110 | };
|
9111 | }()).then(_this8._send.bind(_this8)).then(function (_ref9) {
|
9112 | var _ref9$sessionMessage = _ref9.sessionMessage,
|
9113 | token = _ref9$sessionMessage.st,
|
9114 | ttl = _ref9$sessionMessage.stTtl;
|
9115 | return [token, ttl];
|
9116 | }));
|
9117 | }
|
9118 | });
|
9119 | };
|
9120 |
|
9121 | _proto._requestWithSessionToken =
|
9122 |
|
9123 | function () {
|
9124 | var _requestWithSessionToken2 = _asyncToGenerator(
|
9125 |
|
9126 | _regeneratorRuntime.mark(function _callee9(_ref10) {
|
9127 | var headers, query, params, sessionToken;
|
9128 | return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
9129 | while (1) {
|
9130 | switch (_context9.prev = _context9.next) {
|
9131 | case 0:
|
9132 | headers = _ref10.headers, query = _ref10.query, params = _objectWithoutProperties(_ref10, ["headers", "query"]);
|
9133 | _context9.next = 3;
|
9134 | return this._sessionManager.getSessionToken();
|
9135 |
|
9136 | case 3:
|
9137 | sessionToken = _context9.sent;
|
9138 | return _context9.abrupt("return", this._request(_objectSpread({
|
9139 | headers: _objectSpread({
|
9140 | 'X-LC-IM-Session-Token': sessionToken
|
9141 | }, headers),
|
9142 | query: _objectSpread({
|
9143 | client_id: this.id
|
9144 | }, query)
|
9145 | }, params)));
|
9146 |
|
9147 | case 5:
|
9148 | case "end":
|
9149 | return _context9.stop();
|
9150 | }
|
9151 | }
|
9152 | }, _callee9, this);
|
9153 | }));
|
9154 |
|
9155 | function _requestWithSessionToken(_x11) {
|
9156 | return _requestWithSessionToken2.apply(this, arguments);
|
9157 | }
|
9158 |
|
9159 | return _requestWithSessionToken;
|
9160 | }()
|
9161 | |
9162 |
|
9163 |
|
9164 |
|
9165 | ;
|
9166 |
|
9167 | _proto.close =
|
9168 |
|
9169 | function () {
|
9170 | var _close = _asyncToGenerator(
|
9171 |
|
9172 | _regeneratorRuntime.mark(function _callee10() {
|
9173 | var _ee, command;
|
9174 |
|
9175 | return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
9176 | while (1) {
|
9177 | switch (_context10.prev = _context10.next) {
|
9178 | case 0:
|
9179 | this._debug('close session');
|
9180 |
|
9181 | _ee = internal(this)._eventemitter;
|
9182 |
|
9183 | _ee.emit('beforeclose');
|
9184 |
|
9185 | if (!this._connection.is('connected')) {
|
9186 | _context10.next = 7;
|
9187 | break;
|
9188 | }
|
9189 |
|
9190 | command = new GenericCommand({
|
9191 | cmd: 'session',
|
9192 | op: 'close'
|
9193 | });
|
9194 | _context10.next = 7;
|
9195 | return this._send(command);
|
9196 |
|
9197 | case 7:
|
9198 | _ee.emit('close');
|
9199 |
|
9200 | this.emit(CLOSE$1, {
|
9201 | code: 0
|
9202 | });
|
9203 |
|
9204 | case 9:
|
9205 | case "end":
|
9206 | return _context10.stop();
|
9207 | }
|
9208 | }
|
9209 | }, _callee10, this);
|
9210 | }));
|
9211 |
|
9212 | function close() {
|
9213 | return _close.apply(this, arguments);
|
9214 | }
|
9215 |
|
9216 | return close;
|
9217 | }()
|
9218 | |
9219 |
|
9220 |
|
9221 |
|
9222 |
|
9223 | ;
|
9224 |
|
9225 | _proto.ping =
|
9226 |
|
9227 | function () {
|
9228 | var _ping = _asyncToGenerator(
|
9229 |
|
9230 | _regeneratorRuntime.mark(function _callee11(clientIds) {
|
9231 | var command, resCommand;
|
9232 | return _regeneratorRuntime.wrap(function _callee11$(_context11) {
|
9233 | while (1) {
|
9234 | switch (_context11.prev = _context11.next) {
|
9235 | case 0:
|
9236 | this._debug('ping');
|
9237 |
|
9238 | if (clientIds instanceof Array) {
|
9239 | _context11.next = 3;
|
9240 | break;
|
9241 | }
|
9242 |
|
9243 | throw new TypeError("clientIds ".concat(clientIds, " is not an Array"));
|
9244 |
|
9245 | case 3:
|
9246 | if (clientIds.length) {
|
9247 | _context11.next = 5;
|
9248 | break;
|
9249 | }
|
9250 |
|
9251 | return _context11.abrupt("return", Promise.resolve([]));
|
9252 |
|
9253 | case 5:
|
9254 | command = new GenericCommand({
|
9255 | cmd: 'session',
|
9256 | op: 'query',
|
9257 | sessionMessage: new SessionCommand({
|
9258 | sessionPeerIds: clientIds
|
9259 | })
|
9260 | });
|
9261 | _context11.next = 8;
|
9262 | return this._send(command);
|
9263 |
|
9264 | case 8:
|
9265 | resCommand = _context11.sent;
|
9266 | return _context11.abrupt("return", resCommand.sessionMessage.onlineSessionPeerIds);
|
9267 |
|
9268 | case 10:
|
9269 | case "end":
|
9270 | return _context11.stop();
|
9271 | }
|
9272 | }
|
9273 | }, _callee11, this);
|
9274 | }));
|
9275 |
|
9276 | function ping(_x12) {
|
9277 | return _ping.apply(this, arguments);
|
9278 | }
|
9279 |
|
9280 | return ping;
|
9281 | }()
|
9282 | |
9283 |
|
9284 |
|
9285 |
|
9286 |
|
9287 |
|
9288 | ;
|
9289 |
|
9290 | _proto.getConversation =
|
9291 |
|
9292 | function () {
|
9293 | var _getConversation = _asyncToGenerator(
|
9294 |
|
9295 | _regeneratorRuntime.mark(function _callee12(id) {
|
9296 | var noCache,
|
9297 | cachedConversation,
|
9298 | _args12 = arguments;
|
9299 | return _regeneratorRuntime.wrap(function _callee12$(_context12) {
|
9300 | while (1) {
|
9301 | switch (_context12.prev = _context12.next) {
|
9302 | case 0:
|
9303 | noCache = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : false;
|
9304 |
|
9305 | if (!(typeof id !== 'string')) {
|
9306 | _context12.next = 3;
|
9307 | break;
|
9308 | }
|
9309 |
|
9310 | throw new TypeError("".concat(id, " is not a String"));
|
9311 |
|
9312 | case 3:
|
9313 | if (noCache) {
|
9314 | _context12.next = 7;
|
9315 | break;
|
9316 | }
|
9317 |
|
9318 | cachedConversation = this._conversationCache.get(id);
|
9319 |
|
9320 | if (!cachedConversation) {
|
9321 | _context12.next = 7;
|
9322 | break;
|
9323 | }
|
9324 |
|
9325 | return _context12.abrupt("return", cachedConversation);
|
9326 |
|
9327 | case 7:
|
9328 | if (!isTemporaryConversatrionId(id)) {
|
9329 | _context12.next = 14;
|
9330 | break;
|
9331 | }
|
9332 |
|
9333 | _context12.next = 10;
|
9334 | return this._getTemporaryConversations([id]);
|
9335 |
|
9336 | case 10:
|
9337 | _context12.t0 = _context12.sent[0];
|
9338 |
|
9339 | if (_context12.t0) {
|
9340 | _context12.next = 13;
|
9341 | break;
|
9342 | }
|
9343 |
|
9344 | _context12.t0 = null;
|
9345 |
|
9346 | case 13:
|
9347 | return _context12.abrupt("return", _context12.t0);
|
9348 |
|
9349 | case 14:
|
9350 | return _context12.abrupt("return", this.getQuery().equalTo('objectId', id).find().then(function (conversations) {
|
9351 | return conversations[0] || null;
|
9352 | }));
|
9353 |
|
9354 | case 15:
|
9355 | case "end":
|
9356 | return _context12.stop();
|
9357 | }
|
9358 | }
|
9359 | }, _callee12, this);
|
9360 | }));
|
9361 |
|
9362 | function getConversation(_x13) {
|
9363 | return _getConversation.apply(this, arguments);
|
9364 | }
|
9365 |
|
9366 | return getConversation;
|
9367 | }()
|
9368 | |
9369 |
|
9370 |
|
9371 |
|
9372 |
|
9373 |
|
9374 |
|
9375 | ;
|
9376 |
|
9377 | _proto.getConversations =
|
9378 |
|
9379 | function () {
|
9380 | var _getConversations = _asyncToGenerator(
|
9381 |
|
9382 | _regeneratorRuntime.mark(function _callee13(ids) {
|
9383 | var _this9 = this;
|
9384 |
|
9385 | var noCache,
|
9386 | remoteConversationIds,
|
9387 | remoteTemporaryConversationIds,
|
9388 | query,
|
9389 | remoteTemporaryConversationsPromise,
|
9390 | _args13 = arguments;
|
9391 | return _regeneratorRuntime.wrap(function _callee13$(_context13) {
|
9392 | while (1) {
|
9393 | switch (_context13.prev = _context13.next) {
|
9394 | case 0:
|
9395 | noCache = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : false;
|
9396 | remoteConversationIds = noCache ? ids : ids.filter(function (id) {
|
9397 | return _this9._conversationCache.get(id) === null;
|
9398 | });
|
9399 |
|
9400 | if (!remoteConversationIds.length) {
|
9401 | _context13.next = 9;
|
9402 | break;
|
9403 | }
|
9404 |
|
9405 | remoteTemporaryConversationIds = remove(remoteConversationIds, isTemporaryConversatrionId);
|
9406 | query = [];
|
9407 |
|
9408 | if (remoteConversationIds.length) {
|
9409 | query.push(this.getQuery().containedIn('objectId', remoteConversationIds).limit(999).find());
|
9410 | }
|
9411 |
|
9412 | if (remoteTemporaryConversationIds.length) {
|
9413 | remoteTemporaryConversationsPromise = remoteTemporaryConversationIds.map(this._getTemporaryConversations.bind(this));
|
9414 | query.push.apply(query, _toConsumableArray(remoteTemporaryConversationsPromise));
|
9415 | }
|
9416 |
|
9417 | _context13.next = 9;
|
9418 | return Promise.all(query);
|
9419 |
|
9420 | case 9:
|
9421 | return _context13.abrupt("return", ids.map(function (id) {
|
9422 | return _this9._conversationCache.get(id);
|
9423 | }));
|
9424 |
|
9425 | case 10:
|
9426 | case "end":
|
9427 | return _context13.stop();
|
9428 | }
|
9429 | }
|
9430 | }, _callee13, this);
|
9431 | }));
|
9432 |
|
9433 | function getConversations(_x14) {
|
9434 | return _getConversations.apply(this, arguments);
|
9435 | }
|
9436 |
|
9437 | return getConversations;
|
9438 | }();
|
9439 |
|
9440 | _proto._getTemporaryConversations =
|
9441 |
|
9442 | function () {
|
9443 | var _getTemporaryConversations2 = _asyncToGenerator(
|
9444 |
|
9445 | _regeneratorRuntime.mark(function _callee14(ids) {
|
9446 | var command, resCommand;
|
9447 | return _regeneratorRuntime.wrap(function _callee14$(_context14) {
|
9448 | while (1) {
|
9449 | switch (_context14.prev = _context14.next) {
|
9450 | case 0:
|
9451 | command = new GenericCommand({
|
9452 | cmd: 'conv',
|
9453 | op: 'query',
|
9454 | convMessage: new ConvCommand({
|
9455 | tempConvIds: ids
|
9456 | })
|
9457 | });
|
9458 | _context14.next = 3;
|
9459 | return this._send(command);
|
9460 |
|
9461 | case 3:
|
9462 | resCommand = _context14.sent;
|
9463 | return _context14.abrupt("return", this._handleQueryResults(resCommand));
|
9464 |
|
9465 | case 5:
|
9466 | case "end":
|
9467 | return _context14.stop();
|
9468 | }
|
9469 | }
|
9470 | }, _callee14, this);
|
9471 | }));
|
9472 |
|
9473 | function _getTemporaryConversations(_x15) {
|
9474 | return _getTemporaryConversations2.apply(this, arguments);
|
9475 | }
|
9476 |
|
9477 | return _getTemporaryConversations;
|
9478 | }()
|
9479 | |
9480 |
|
9481 |
|
9482 |
|
9483 | ;
|
9484 |
|
9485 | _proto.getQuery = function getQuery() {
|
9486 | return new ConversationQuery(this);
|
9487 | }
|
9488 | |
9489 |
|
9490 |
|
9491 |
|
9492 | ;
|
9493 |
|
9494 | _proto.getChatRoomQuery = function getChatRoomQuery() {
|
9495 | return this.getQuery().equalTo('tr', true);
|
9496 | }
|
9497 | |
9498 |
|
9499 |
|
9500 |
|
9501 | ;
|
9502 |
|
9503 | _proto.getServiceConversationQuery = function getServiceConversationQuery() {
|
9504 | return this.getQuery().equalTo('sys', true);
|
9505 | };
|
9506 |
|
9507 | _proto._executeQuery =
|
9508 |
|
9509 | function () {
|
9510 | var _executeQuery2 = _asyncToGenerator(
|
9511 |
|
9512 | _regeneratorRuntime.mark(function _callee15(query) {
|
9513 | var queryJSON, command, resCommand;
|
9514 | return _regeneratorRuntime.wrap(function _callee15$(_context15) {
|
9515 | while (1) {
|
9516 | switch (_context15.prev = _context15.next) {
|
9517 | case 0:
|
9518 | queryJSON = query.toJSON();
|
9519 | queryJSON.where = new JsonObjectMessage({
|
9520 | data: JSON.stringify(encode(queryJSON.where))
|
9521 | });
|
9522 | command = new GenericCommand({
|
9523 | cmd: 'conv',
|
9524 | op: 'query',
|
9525 | convMessage: new ConvCommand(queryJSON)
|
9526 | });
|
9527 | _context15.next = 5;
|
9528 | return this._send(command);
|
9529 |
|
9530 | case 5:
|
9531 | resCommand = _context15.sent;
|
9532 | return _context15.abrupt("return", this._handleQueryResults(resCommand));
|
9533 |
|
9534 | case 7:
|
9535 | case "end":
|
9536 | return _context15.stop();
|
9537 | }
|
9538 | }
|
9539 | }, _callee15, this);
|
9540 | }));
|
9541 |
|
9542 | function _executeQuery(_x16) {
|
9543 | return _executeQuery2.apply(this, arguments);
|
9544 | }
|
9545 |
|
9546 | return _executeQuery;
|
9547 | }();
|
9548 |
|
9549 | _proto._handleQueryResults =
|
9550 |
|
9551 | function () {
|
9552 | var _handleQueryResults2 = _asyncToGenerator(
|
9553 |
|
9554 | _regeneratorRuntime.mark(function _callee16(resCommand) {
|
9555 | var conversations, commandString;
|
9556 | return _regeneratorRuntime.wrap(function _callee16$(_context16) {
|
9557 | while (1) {
|
9558 | switch (_context16.prev = _context16.next) {
|
9559 | case 0:
|
9560 | _context16.prev = 0;
|
9561 | conversations = decode(JSON.parse(resCommand.convMessage.results.data));
|
9562 | _context16.next = 8;
|
9563 | break;
|
9564 |
|
9565 | case 4:
|
9566 | _context16.prev = 4;
|
9567 | _context16.t0 = _context16["catch"](0);
|
9568 | commandString = JSON.stringify(trim(resCommand));
|
9569 | throw new Error("Parse query result failed: ".concat(_context16.t0.message, ". Command: ").concat(commandString));
|
9570 |
|
9571 | case 8:
|
9572 | _context16.next = 10;
|
9573 | return Promise.all(conversations.map(this._parseConversationFromRawData.bind(this)));
|
9574 |
|
9575 | case 10:
|
9576 | conversations = _context16.sent;
|
9577 | return _context16.abrupt("return", conversations.map(this._upsertConversationToCache.bind(this)));
|
9578 |
|
9579 | case 12:
|
9580 | case "end":
|
9581 | return _context16.stop();
|
9582 | }
|
9583 | }
|
9584 | }, _callee16, this, [[0, 4]]);
|
9585 | }));
|
9586 |
|
9587 | function _handleQueryResults(_x17) {
|
9588 | return _handleQueryResults2.apply(this, arguments);
|
9589 | }
|
9590 |
|
9591 | return _handleQueryResults;
|
9592 | }();
|
9593 |
|
9594 | _proto._upsertConversationToCache = function _upsertConversationToCache(fetchedConversation) {
|
9595 | var conversation = this._conversationCache.get(fetchedConversation.id);
|
9596 |
|
9597 | if (!conversation) {
|
9598 | conversation = fetchedConversation;
|
9599 |
|
9600 | this._debug('no match, set cache');
|
9601 |
|
9602 | this._conversationCache.set(fetchedConversation.id, fetchedConversation);
|
9603 | } else {
|
9604 | this._debug('update cached conversation');
|
9605 |
|
9606 | ['creator', 'createdAt', 'updatedAt', 'lastMessageAt', 'lastMessage', 'mutedMembers', 'members', '_attributes', 'transient', 'muted'].forEach(function (key) {
|
9607 | var value = fetchedConversation[key];
|
9608 | if (value !== undefined) conversation[key] = value;
|
9609 | });
|
9610 | if (conversation._reset) conversation._reset();
|
9611 | }
|
9612 |
|
9613 | return conversation;
|
9614 | }
|
9615 | |
9616 |
|
9617 |
|
9618 |
|
9619 |
|
9620 |
|
9621 | ;
|
9622 |
|
9623 | _proto.parseMessage =
|
9624 |
|
9625 | function () {
|
9626 | var _parseMessage = _asyncToGenerator(
|
9627 |
|
9628 | _regeneratorRuntime.mark(function _callee17(_ref11) {
|
9629 | var data, _ref11$bin, bin, properties, content, message;
|
9630 |
|
9631 | return _regeneratorRuntime.wrap(function _callee17$(_context17) {
|
9632 | while (1) {
|
9633 | switch (_context17.prev = _context17.next) {
|
9634 | case 0:
|
9635 | data = _ref11.data, _ref11$bin = _ref11.bin, bin = _ref11$bin === void 0 ? false : _ref11$bin, properties = _objectWithoutProperties(_ref11, ["data", "bin"]);
|
9636 | content = bin ? base64Arraybuffer.decode(data) : data;
|
9637 | _context17.next = 4;
|
9638 | return this._messageParser.parse(content);
|
9639 |
|
9640 | case 4:
|
9641 | message = _context17.sent;
|
9642 | Object.assign(message, properties);
|
9643 |
|
9644 | message._updateMentioned(this.id);
|
9645 |
|
9646 | return _context17.abrupt("return", message);
|
9647 |
|
9648 | case 8:
|
9649 | case "end":
|
9650 | return _context17.stop();
|
9651 | }
|
9652 | }
|
9653 | }, _callee17, this);
|
9654 | }));
|
9655 |
|
9656 | function parseMessage(_x18) {
|
9657 | return _parseMessage.apply(this, arguments);
|
9658 | }
|
9659 |
|
9660 | return parseMessage;
|
9661 | }()
|
9662 | |
9663 |
|
9664 |
|
9665 |
|
9666 |
|
9667 |
|
9668 | ;
|
9669 |
|
9670 | _proto.parseConversation =
|
9671 |
|
9672 | function () {
|
9673 | var _parseConversation = _asyncToGenerator(
|
9674 |
|
9675 | _regeneratorRuntime.mark(function _callee18(_ref12) {
|
9676 | var id, lastMessageAt, lastMessage, lastDeliveredAt, lastReadAt, unreadMessagesCount, members, mentioned, properties, conversationData, transient, system, expiredAt;
|
9677 | return _regeneratorRuntime.wrap(function _callee18$(_context18) {
|
9678 | while (1) {
|
9679 | switch (_context18.prev = _context18.next) {
|
9680 | case 0:
|
9681 | id = _ref12.id, lastMessageAt = _ref12.lastMessageAt, lastMessage = _ref12.lastMessage, lastDeliveredAt = _ref12.lastDeliveredAt, lastReadAt = _ref12.lastReadAt, unreadMessagesCount = _ref12.unreadMessagesCount, members = _ref12.members, mentioned = _ref12.mentioned, properties = _objectWithoutProperties(_ref12, ["id", "lastMessageAt", "lastMessage", "lastDeliveredAt", "lastReadAt", "unreadMessagesCount", "members", "mentioned"]);
|
9682 | conversationData = {
|
9683 | id: id,
|
9684 | lastMessageAt: lastMessageAt,
|
9685 | lastMessage: lastMessage,
|
9686 | lastDeliveredAt: lastDeliveredAt,
|
9687 | lastReadAt: lastReadAt,
|
9688 | unreadMessagesCount: unreadMessagesCount,
|
9689 | members: members,
|
9690 | mentioned: mentioned
|
9691 | };
|
9692 |
|
9693 | if (!lastMessage) {
|
9694 | _context18.next = 7;
|
9695 | break;
|
9696 | }
|
9697 |
|
9698 | _context18.next = 5;
|
9699 | return this.parseMessage(lastMessage);
|
9700 |
|
9701 | case 5:
|
9702 | conversationData.lastMessage = _context18.sent;
|
9703 |
|
9704 | conversationData.lastMessage._setStatus(MessageStatus.SENT);
|
9705 |
|
9706 | case 7:
|
9707 | transient = properties.transient, system = properties.system, expiredAt = properties.expiredAt;
|
9708 |
|
9709 | if (!transient) {
|
9710 | _context18.next = 10;
|
9711 | break;
|
9712 | }
|
9713 |
|
9714 | return _context18.abrupt("return", new ChatRoom(conversationData, properties, this));
|
9715 |
|
9716 | case 10:
|
9717 | if (!system) {
|
9718 | _context18.next = 12;
|
9719 | break;
|
9720 | }
|
9721 |
|
9722 | return _context18.abrupt("return", new ServiceConversation(conversationData, properties, this));
|
9723 |
|
9724 | case 12:
|
9725 | if (!(expiredAt || isTemporaryConversatrionId(id))) {
|
9726 | _context18.next = 14;
|
9727 | break;
|
9728 | }
|
9729 |
|
9730 | return _context18.abrupt("return", new TemporaryConversation(conversationData, {
|
9731 | expiredAt: expiredAt
|
9732 | }, this));
|
9733 |
|
9734 | case 14:
|
9735 | return _context18.abrupt("return", new Conversation(conversationData, properties, this));
|
9736 |
|
9737 | case 15:
|
9738 | case "end":
|
9739 | return _context18.stop();
|
9740 | }
|
9741 | }
|
9742 | }, _callee18, this);
|
9743 | }));
|
9744 |
|
9745 | function parseConversation(_x19) {
|
9746 | return _parseConversation.apply(this, arguments);
|
9747 | }
|
9748 |
|
9749 | return parseConversation;
|
9750 | }();
|
9751 |
|
9752 | _proto._parseConversationFromRawData =
|
9753 |
|
9754 | function () {
|
9755 | var _parseConversationFromRawData2 = _asyncToGenerator(
|
9756 |
|
9757 | _regeneratorRuntime.mark(function _callee19(rawData) {
|
9758 | var data, ttl;
|
9759 | return _regeneratorRuntime.wrap(function _callee19$(_context19) {
|
9760 | while (1) {
|
9761 | switch (_context19.prev = _context19.next) {
|
9762 | case 0:
|
9763 | data = keyRemap({
|
9764 | objectId: 'id',
|
9765 | lm: 'lastMessageAt',
|
9766 | m: 'members',
|
9767 | tr: 'transient',
|
9768 | sys: 'system',
|
9769 | c: 'creator',
|
9770 | mu: 'mutedMembers'
|
9771 | }, rawData);
|
9772 |
|
9773 | if (data.msg) {
|
9774 | data.lastMessage = {
|
9775 | data: data.msg,
|
9776 | bin: data.bin,
|
9777 | from: data.msg_from,
|
9778 | id: data.msg_mid,
|
9779 | timestamp: data.msg_timestamp,
|
9780 | updatedAt: data.patch_timestamp
|
9781 | };
|
9782 | delete data.lastMessageFrom;
|
9783 | delete data.lastMessageId;
|
9784 | delete data.lastMessageTimestamp;
|
9785 | delete data.lastMessagePatchTimestamp;
|
9786 | }
|
9787 |
|
9788 | ttl = data.ttl;
|
9789 | if (ttl) data.expiredAt = Date.now() + ttl * 1000;
|
9790 | return _context19.abrupt("return", this.parseConversation(data));
|
9791 |
|
9792 | case 5:
|
9793 | case "end":
|
9794 | return _context19.stop();
|
9795 | }
|
9796 | }
|
9797 | }, _callee19, this);
|
9798 | }));
|
9799 |
|
9800 | function _parseConversationFromRawData(_x20) {
|
9801 | return _parseConversationFromRawData2.apply(this, arguments);
|
9802 | }
|
9803 |
|
9804 | return _parseConversationFromRawData;
|
9805 | }()
|
9806 | |
9807 |
|
9808 |
|
9809 |
|
9810 |
|
9811 |
|
9812 |
|
9813 |
|
9814 | ;
|
9815 |
|
9816 | _proto.createConversation =
|
9817 |
|
9818 | function () {
|
9819 | var _createConversation = _asyncToGenerator(
|
9820 |
|
9821 | _regeneratorRuntime.mark(function _callee20() {
|
9822 | var _ref13,
|
9823 | m,
|
9824 | name,
|
9825 | transient,
|
9826 | _ref13$unique,
|
9827 | unique,
|
9828 | tempConv,
|
9829 | tempConvTTL,
|
9830 | properties,
|
9831 | members,
|
9832 | attr,
|
9833 | startCommandJson,
|
9834 | command,
|
9835 | params,
|
9836 | signatureResult,
|
9837 | _ref14,
|
9838 | _ref14$convMessage,
|
9839 | cid,
|
9840 | cdate,
|
9841 | ttl,
|
9842 | data,
|
9843 | conversation,
|
9844 | _args20 = arguments;
|
9845 |
|
9846 | return _regeneratorRuntime.wrap(function _callee20$(_context20) {
|
9847 | while (1) {
|
9848 | switch (_context20.prev = _context20.next) {
|
9849 | case 0:
|
9850 | _ref13 = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : {}, m = _ref13.members, name = _ref13.name, transient = _ref13.transient, _ref13$unique = _ref13.unique, unique = _ref13$unique === void 0 ? true : _ref13$unique, tempConv = _ref13._tempConv, tempConvTTL = _ref13._tempConvTTL, properties = _objectWithoutProperties(_ref13, ["members", "name", "transient", "unique", "_tempConv", "_tempConvTTL"]);
|
9851 |
|
9852 | if (transient || Array.isArray(m)) {
|
9853 | _context20.next = 3;
|
9854 | break;
|
9855 | }
|
9856 |
|
9857 | throw new TypeError("conversation members ".concat(m, " is not an array"));
|
9858 |
|
9859 | case 3:
|
9860 | members = new Set(m);
|
9861 | members.add(this.id);
|
9862 | members = Array.from(members).sort();
|
9863 | attr = properties || {};
|
9864 |
|
9865 | if (!name) {
|
9866 | _context20.next = 11;
|
9867 | break;
|
9868 | }
|
9869 |
|
9870 | if (!(typeof name !== 'string')) {
|
9871 | _context20.next = 10;
|
9872 | break;
|
9873 | }
|
9874 |
|
9875 | throw new TypeError("conversation name ".concat(name, " is not a string"));
|
9876 |
|
9877 | case 10:
|
9878 | attr.name = name;
|
9879 |
|
9880 | case 11:
|
9881 | attr = new JsonObjectMessage({
|
9882 | data: JSON.stringify(encode(attr))
|
9883 | });
|
9884 | startCommandJson = {
|
9885 | m: members,
|
9886 | attr: attr,
|
9887 | transient: transient,
|
9888 | unique: unique,
|
9889 | tempConv: tempConv,
|
9890 | tempConvTTL: tempConvTTL
|
9891 | };
|
9892 | command = new GenericCommand({
|
9893 | cmd: 'conv',
|
9894 | op: 'start',
|
9895 | convMessage: new ConvCommand(startCommandJson)
|
9896 | });
|
9897 |
|
9898 | if (!this.options.conversationSignatureFactory) {
|
9899 | _context20.next = 20;
|
9900 | break;
|
9901 | }
|
9902 |
|
9903 | params = [null, this._identity, members, 'create'];
|
9904 | _context20.next = 18;
|
9905 | return runSignatureFactory(this.options.conversationSignatureFactory, params);
|
9906 |
|
9907 | case 18:
|
9908 | signatureResult = _context20.sent;
|
9909 | Object.assign(command.convMessage, keyRemap({
|
9910 | signature: 's',
|
9911 | timestamp: 't',
|
9912 | nonce: 'n'
|
9913 | }, signatureResult));
|
9914 |
|
9915 | case 20:
|
9916 | _context20.next = 22;
|
9917 | return this._send(command);
|
9918 |
|
9919 | case 22:
|
9920 | _ref14 = _context20.sent;
|
9921 | _ref14$convMessage = _ref14.convMessage;
|
9922 | cid = _ref14$convMessage.cid;
|
9923 | cdate = _ref14$convMessage.cdate;
|
9924 | ttl = _ref14$convMessage.tempConvTTL;
|
9925 | data = _objectSpread({
|
9926 | name: name,
|
9927 | transient: transient,
|
9928 | unique: unique,
|
9929 | id: cid,
|
9930 | createdAt: cdate,
|
9931 | updatedAt: cdate,
|
9932 | lastMessageAt: null,
|
9933 | creator: this.id,
|
9934 | members: transient ? [] : members
|
9935 | }, properties);
|
9936 | if (ttl) data.expiredAt = Date.now() + ttl * 1000;
|
9937 | _context20.next = 31;
|
9938 | return this.parseConversation(data);
|
9939 |
|
9940 | case 31:
|
9941 | conversation = _context20.sent;
|
9942 | return _context20.abrupt("return", this._upsertConversationToCache(conversation));
|
9943 |
|
9944 | case 33:
|
9945 | case "end":
|
9946 | return _context20.stop();
|
9947 | }
|
9948 | }
|
9949 | }, _callee20, this);
|
9950 | }));
|
9951 |
|
9952 | function createConversation() {
|
9953 | return _createConversation.apply(this, arguments);
|
9954 | }
|
9955 |
|
9956 | return createConversation;
|
9957 | }()
|
9958 | |
9959 |
|
9960 |
|
9961 |
|
9962 |
|
9963 |
|
9964 |
|
9965 | ;
|
9966 |
|
9967 | _proto.createChatRoom =
|
9968 |
|
9969 | function () {
|
9970 | var _createChatRoom = _asyncToGenerator(
|
9971 |
|
9972 | _regeneratorRuntime.mark(function _callee21(param) {
|
9973 | return _regeneratorRuntime.wrap(function _callee21$(_context21) {
|
9974 | while (1) {
|
9975 | switch (_context21.prev = _context21.next) {
|
9976 | case 0:
|
9977 | return _context21.abrupt("return", this.createConversation(_objectSpread({}, param, {
|
9978 | transient: true,
|
9979 | members: null,
|
9980 | unique: false,
|
9981 | _tempConv: false
|
9982 | })));
|
9983 |
|
9984 | case 1:
|
9985 | case "end":
|
9986 | return _context21.stop();
|
9987 | }
|
9988 | }
|
9989 | }, _callee21, this);
|
9990 | }));
|
9991 |
|
9992 | function createChatRoom(_x21) {
|
9993 | return _createChatRoom.apply(this, arguments);
|
9994 | }
|
9995 |
|
9996 | return createChatRoom;
|
9997 | }()
|
9998 | |
9999 |
|
10000 |
|
10001 |
|
10002 |
|
10003 |
|
10004 |
|
10005 |
|
10006 | ;
|
10007 |
|
10008 | _proto.createTemporaryConversation =
|
10009 |
|
10010 | function () {
|
10011 | var _createTemporaryConversation = _asyncToGenerator(
|
10012 |
|
10013 | _regeneratorRuntime.mark(function _callee22(_ref15) {
|
10014 | var _tempConvTTL, param;
|
10015 |
|
10016 | return _regeneratorRuntime.wrap(function _callee22$(_context22) {
|
10017 | while (1) {
|
10018 | switch (_context22.prev = _context22.next) {
|
10019 | case 0:
|
10020 | _tempConvTTL = _ref15.ttl, param = _objectWithoutProperties(_ref15, ["ttl"]);
|
10021 | return _context22.abrupt("return", this.createConversation(_objectSpread({}, param, {
|
10022 | transient: false,
|
10023 | unique: false,
|
10024 | _tempConv: true,
|
10025 | _tempConvTTL: _tempConvTTL
|
10026 | })));
|
10027 |
|
10028 | case 2:
|
10029 | case "end":
|
10030 | return _context22.stop();
|
10031 | }
|
10032 | }
|
10033 | }, _callee22, this);
|
10034 | }));
|
10035 |
|
10036 | function createTemporaryConversation(_x22) {
|
10037 | return _createTemporaryConversation.apply(this, arguments);
|
10038 | }
|
10039 |
|
10040 | return createTemporaryConversation;
|
10041 | }()
|
10042 | ;
|
10043 |
|
10044 | _proto.
|
10045 | _doSendRead = function _doSendRead() {
|
10046 | var _this10 = this;
|
10047 |
|
10048 |
|
10049 | if (!this._connection.is('connected')) return;
|
10050 | var buffer = internal(this).readConversationsBuffer;
|
10051 | var conversations = Array.from(buffer);
|
10052 | if (!conversations.length) return;
|
10053 | var ids = conversations.map(function (conversation) {
|
10054 | if (!(conversation instanceof ConversationBase)) {
|
10055 | throw new TypeError("".concat(conversation, " is not a Conversation"));
|
10056 | }
|
10057 |
|
10058 | return conversation.id;
|
10059 | });
|
10060 |
|
10061 | this._debug("mark [".concat(ids, "] as read"));
|
10062 |
|
10063 | buffer.clear();
|
10064 |
|
10065 | this._sendReadCommand(conversations).catch(function (error) {
|
10066 | _this10._debug('send read failed: %O', error);
|
10067 |
|
10068 | conversations.forEach(buffer.add.bind(buffer));
|
10069 | });
|
10070 | };
|
10071 |
|
10072 | _proto._sendReadCommand = function _sendReadCommand(conversations) {
|
10073 | var _this11 = this;
|
10074 |
|
10075 | return this._send(new GenericCommand({
|
10076 | cmd: 'read',
|
10077 | readMessage: new ReadCommand({
|
10078 | convs: conversations.map(function (conversation) {
|
10079 | return new ReadTuple({
|
10080 | cid: conversation.id,
|
10081 | mid: conversation.lastMessage && conversation.lastMessage.from !== _this11.id ? conversation.lastMessage.id : undefined,
|
10082 | timestamp: (conversation.lastMessageAt || new Date()).getTime()
|
10083 | });
|
10084 | })
|
10085 | })
|
10086 | }), false);
|
10087 | };
|
10088 |
|
10089 | return IMClient;
|
10090 | }(EventEmitter), (_applyDecoratedDescriptor(_class$3.prototype, "_doSendAck", [_dec$2], Object.getOwnPropertyDescriptor(_class$3.prototype, "_doSendAck"), _class$3.prototype), _applyDecoratedDescriptor(_class$3.prototype, "_doSendRead", [_dec2], Object.getOwnPropertyDescriptor(_class$3.prototype, "_doSendRead"), _class$3.prototype)), _class$3));
|
10091 |
|
10092 |
|
10093 |
|
10094 |
|
10095 |
|
10096 |
|
10097 |
|
10098 |
|
10099 | var RECONNECT_ERROR = 'reconnecterror';
|
10100 |
|
10101 | var CoreEvent = Object.freeze({
|
10102 | RECONNECT_ERROR: RECONNECT_ERROR,
|
10103 | DISCONNECT: DISCONNECT,
|
10104 | RECONNECT: RECONNECT,
|
10105 | RETRY: RETRY,
|
10106 | SCHEDULE: SCHEDULE,
|
10107 | OFFLINE: OFFLINE,
|
10108 | ONLINE: ONLINE
|
10109 | });
|
10110 |
|
10111 | var _class$4;
|
10112 |
|
10113 | var
|
10114 | BinaryMessage = IE10Compatible(_class$4 =
|
10115 |
|
10116 | function (_Message) {
|
10117 | _inheritsLoose(BinaryMessage, _Message);
|
10118 |
|
10119 | |
10120 |
|
10121 |
|
10122 |
|
10123 |
|
10124 |
|
10125 | function BinaryMessage(buffer) {
|
10126 | if (!(buffer instanceof ArrayBuffer)) {
|
10127 | throw new TypeError("".concat(buffer, " is not an ArrayBuffer"));
|
10128 | }
|
10129 |
|
10130 | return _Message.call(this, buffer) || this;
|
10131 | }
|
10132 | |
10133 |
|
10134 |
|
10135 |
|
10136 |
|
10137 | BinaryMessage.validate = function validate(target) {
|
10138 | return target instanceof ArrayBuffer;
|
10139 | };
|
10140 |
|
10141 | var _proto = BinaryMessage.prototype;
|
10142 |
|
10143 | _proto.toJSON = function toJSON() {
|
10144 | return _objectSpread({}, _Message.prototype._toJSON.call(this), {
|
10145 | data: base64Arraybuffer.encode(this.content)
|
10146 | });
|
10147 | };
|
10148 |
|
10149 | _proto.toFullJSON = function toFullJSON() {
|
10150 | return _objectSpread({}, _Message.prototype.toFullJSON.call(this), {
|
10151 | bin: true,
|
10152 | data: base64Arraybuffer.encode(this.content)
|
10153 | });
|
10154 | };
|
10155 |
|
10156 | _createClass(BinaryMessage, [{
|
10157 | key: "buffer",
|
10158 | get: function get() {
|
10159 | return this.content;
|
10160 | },
|
10161 | set: function set(buffer) {
|
10162 | this.content = buffer;
|
10163 | }
|
10164 | }]);
|
10165 |
|
10166 | return BinaryMessage;
|
10167 | }(Message)) || _class$4;
|
10168 |
|
10169 | var _dec$3, _class$5;
|
10170 |
|
10171 | var
|
10172 | TextMessage = (_dec$3 = messageType(-1), _dec$3(_class$5 = IE10Compatible(_class$5 =
|
10173 |
|
10174 | function (_TypedMessage) {
|
10175 | _inheritsLoose(TextMessage, _TypedMessage);
|
10176 |
|
10177 | |
10178 |
|
10179 |
|
10180 |
|
10181 |
|
10182 |
|
10183 | function TextMessage() {
|
10184 | var _this;
|
10185 |
|
10186 | var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
10187 |
|
10188 | if (typeof text !== 'string') {
|
10189 | throw new TypeError("".concat(text, " is not a string"));
|
10190 | }
|
10191 |
|
10192 | _this = _TypedMessage.call(this) || this;
|
10193 |
|
10194 | _this.setText(text);
|
10195 |
|
10196 | return _this;
|
10197 | }
|
10198 |
|
10199 | return TextMessage;
|
10200 | }(TypedMessage)) || _class$5) || _class$5);
|
10201 |
|
10202 |
|
10203 |
|
10204 |
|
10205 |
|
10206 |
|
10207 |
|
10208 |
|
10209 | var _class$6;
|
10210 | var debug$b = d('LC:MessageParser');
|
10211 |
|
10212 | var tryParseJson = function tryParseJson(target, key, descriptor) {
|
10213 | var fn = descriptor.value;
|
10214 |
|
10215 | descriptor.value = function wrapper(param) {
|
10216 | var content;
|
10217 |
|
10218 | if (typeof param !== 'string') {
|
10219 | content = param;
|
10220 | } else {
|
10221 | try {
|
10222 | content = JSON.parse(param);
|
10223 | } catch (error) {
|
10224 | content = param;
|
10225 | }
|
10226 | }
|
10227 |
|
10228 | return fn.call(this, content);
|
10229 | };
|
10230 | };
|
10231 |
|
10232 | var applyPlugins = function applyPlugins(target, key, descriptor) {
|
10233 | var fn = descriptor.value;
|
10234 |
|
10235 | descriptor.value = function wrapper(json) {
|
10236 | var _this = this;
|
10237 |
|
10238 | return Promise.resolve(json).then(applyMiddlewares(this._plugins.beforeMessageParse)).then(function (decoratedJson) {
|
10239 | return fn.call(_this, decoratedJson);
|
10240 | }).then(applyMiddlewares(this._plugins.afterMessageParse));
|
10241 | };
|
10242 | };
|
10243 |
|
10244 | var MessageParser = (_class$6 =
|
10245 |
|
10246 | function () {
|
10247 | function MessageParser() {
|
10248 | var plugins = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
10249 | this._plugins = plugins;
|
10250 | this._messageClasses = [];
|
10251 | }
|
10252 |
|
10253 | var _proto = MessageParser.prototype;
|
10254 |
|
10255 | _proto.register = function register(messageClass) {
|
10256 | if (messageClass && messageClass.parse && messageClass.prototype && messageClass.prototype.getPayload) {
|
10257 | this._messageClasses.unshift(messageClass);
|
10258 | } else {
|
10259 | throw new TypeError('Invalid messageClass');
|
10260 | }
|
10261 | }
|
10262 | ;
|
10263 |
|
10264 | _proto.
|
10265 | parse = function parse(content) {
|
10266 | debug$b('parsing message: %O', content);
|
10267 |
|
10268 | var _iteratorNormalCompletion = true;
|
10269 | var _didIteratorError = false;
|
10270 | var _iteratorError = undefined;
|
10271 |
|
10272 | try {
|
10273 | for (var _iterator = this._messageClasses[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
10274 | var Klass = _step.value;
|
10275 | var contentCopy = isPlainObject(content) ? Object.assign({}, content) : content;
|
10276 | var valid = void 0;
|
10277 | var result = void 0;
|
10278 |
|
10279 | try {
|
10280 | valid = Klass.validate(contentCopy);
|
10281 | } catch (error) {
|
10282 | }
|
10283 |
|
10284 | if (valid) {
|
10285 | try {
|
10286 | result = Klass.parse(contentCopy);
|
10287 | } catch (error) {
|
10288 | console.warn('parsing a valid message content error', {
|
10289 | error: error,
|
10290 | Klass: Klass,
|
10291 | content: contentCopy
|
10292 | });
|
10293 | }
|
10294 |
|
10295 | if (result !== undefined) {
|
10296 | debug$b('parse result: %O', result);
|
10297 | return result;
|
10298 | }
|
10299 | }
|
10300 | }
|
10301 | } catch (err) {
|
10302 | _didIteratorError = true;
|
10303 | _iteratorError = err;
|
10304 | } finally {
|
10305 | try {
|
10306 | if (!_iteratorNormalCompletion && _iterator.return != null) {
|
10307 | _iterator.return();
|
10308 | }
|
10309 | } finally {
|
10310 | if (_didIteratorError) {
|
10311 | throw _iteratorError;
|
10312 | }
|
10313 | }
|
10314 | }
|
10315 |
|
10316 | throw new Error('No Message Class matched');
|
10317 | };
|
10318 |
|
10319 | return MessageParser;
|
10320 | }(), (_applyDecoratedDescriptor(_class$6.prototype, "parse", [tryParseJson, applyPlugins], Object.getOwnPropertyDescriptor(_class$6.prototype, "parse"), _class$6.prototype)), _class$6);
|
10321 |
|
10322 | var debug$c = d('LC:IMPlugin');
|
10323 |
|
10324 |
|
10325 |
|
10326 |
|
10327 |
|
10328 |
|
10329 | var MessagePriority = {
|
10330 |
|
10331 | HIGH: 1,
|
10332 |
|
10333 |
|
10334 | NORMAL: 2,
|
10335 |
|
10336 |
|
10337 | LOW: 3
|
10338 | };
|
10339 | Object.freeze(MessagePriority);
|
10340 |
|
10341 |
|
10342 |
|
10343 |
|
10344 |
|
10345 |
|
10346 |
|
10347 |
|
10348 |
|
10349 |
|
10350 |
|
10351 |
|
10352 |
|
10353 |
|
10354 |
|
10355 |
|
10356 | var defineConversationProperty = function defineConversationProperty(prop) {
|
10357 | var descriptor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
10358 | get: function get() {
|
10359 | return this.get(prop);
|
10360 | },
|
10361 | set: function set(value) {
|
10362 | this.set(prop, value);
|
10363 | }
|
10364 | };
|
10365 | Object.defineProperty(Conversation.prototype, prop, descriptor);
|
10366 | };
|
10367 |
|
10368 | var onRealtimeCreate = function onRealtimeCreate(realtime) {
|
10369 |
|
10370 | var deviceId = uuid();
|
10371 | realtime._IMClients = {};
|
10372 | realtime._IMClientsCreationCount = 0;
|
10373 | var messageParser = new MessageParser(realtime._plugins);
|
10374 | realtime._messageParser = messageParser;
|
10375 |
|
10376 | var signAVUser =
|
10377 |
|
10378 | function () {
|
10379 | var _ref = _asyncToGenerator(
|
10380 |
|
10381 | _regeneratorRuntime.mark(function _callee(user) {
|
10382 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
10383 | while (1) {
|
10384 | switch (_context.prev = _context.next) {
|
10385 | case 0:
|
10386 | return _context.abrupt("return", realtime._request({
|
10387 | method: 'POST',
|
10388 | path: '/rtm/sign',
|
10389 | data: {
|
10390 | session_token: user.getSessionToken()
|
10391 | }
|
10392 | }));
|
10393 |
|
10394 | case 1:
|
10395 | case "end":
|
10396 | return _context.stop();
|
10397 | }
|
10398 | }
|
10399 | }, _callee, this);
|
10400 | }));
|
10401 |
|
10402 | return function signAVUser(_x) {
|
10403 | return _ref.apply(this, arguments);
|
10404 | };
|
10405 | }();
|
10406 | |
10407 |
|
10408 |
|
10409 |
|
10410 |
|
10411 |
|
10412 |
|
10413 |
|
10414 |
|
10415 |
|
10416 |
|
10417 |
|
10418 |
|
10419 | var register = function register(messageClass) {
|
10420 | return ensureArray(messageClass).map(messageParser.register.bind(messageParser));
|
10421 | };
|
10422 |
|
10423 | register(ensureArray(realtime._plugins.messageClasses));
|
10424 | |
10425 |
|
10426 |
|
10427 |
|
10428 |
|
10429 |
|
10430 |
|
10431 |
|
10432 |
|
10433 |
|
10434 |
|
10435 |
|
10436 |
|
10437 |
|
10438 |
|
10439 | var createIMClient =
|
10440 |
|
10441 | function () {
|
10442 | var _ref2 = _asyncToGenerator(
|
10443 |
|
10444 | _regeneratorRuntime.mark(function _callee2(identity) {
|
10445 | var _realtime$_open$then;
|
10446 |
|
10447 | var _ref3,
|
10448 | tag,
|
10449 | isReconnect,
|
10450 | clientOptions,
|
10451 | lagecyTag,
|
10452 | id,
|
10453 | buildinOptions,
|
10454 | sessionToken,
|
10455 | _tag,
|
10456 | promise,
|
10457 | _args2 = arguments;
|
10458 |
|
10459 | return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
10460 | while (1) {
|
10461 | switch (_context2.prev = _context2.next) {
|
10462 | case 0:
|
10463 | _ref3 = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}, tag = _ref3.tag, isReconnect = _ref3.isReconnect, clientOptions = _objectWithoutProperties(_ref3, ["tag", "isReconnect"]);
|
10464 | lagecyTag = _args2.length > 2 ? _args2[2] : undefined;
|
10465 | buildinOptions = {};
|
10466 |
|
10467 | if (!identity) {
|
10468 | _context2.next = 19;
|
10469 | break;
|
10470 | }
|
10471 |
|
10472 | if (!(typeof identity === 'string')) {
|
10473 | _context2.next = 8;
|
10474 | break;
|
10475 | }
|
10476 |
|
10477 | id = identity;
|
10478 | _context2.next = 17;
|
10479 | break;
|
10480 |
|
10481 | case 8:
|
10482 | if (!(identity.id && identity.getSessionToken)) {
|
10483 | _context2.next = 16;
|
10484 | break;
|
10485 | }
|
10486 |
|
10487 | id = identity.id;
|
10488 | sessionToken = identity.getSessionToken();
|
10489 |
|
10490 | if (sessionToken) {
|
10491 | _context2.next = 13;
|
10492 | break;
|
10493 | }
|
10494 |
|
10495 | throw new Error('User must be authenticated');
|
10496 |
|
10497 | case 13:
|
10498 | buildinOptions.signatureFactory = signAVUser;
|
10499 | _context2.next = 17;
|
10500 | break;
|
10501 |
|
10502 | case 16:
|
10503 | throw new TypeError('Identity must be a String or an AV.User');
|
10504 |
|
10505 | case 17:
|
10506 | if (!(realtime._IMClients[id] !== undefined)) {
|
10507 | _context2.next = 19;
|
10508 | break;
|
10509 | }
|
10510 |
|
10511 | return _context2.abrupt("return", realtime._IMClients[id]);
|
10512 |
|
10513 | case 19:
|
10514 | if (lagecyTag) {
|
10515 | console.warn('DEPRECATION createIMClient tag param: Use options.tag instead.');
|
10516 | }
|
10517 |
|
10518 | _tag = tag || lagecyTag;
|
10519 | promise = (_realtime$_open$then = realtime._open().then(function (connection) {
|
10520 | var client = new IMClient(id, _objectSpread({}, buildinOptions, clientOptions), {
|
10521 | _connection: connection,
|
10522 | _request: realtime._request.bind(realtime),
|
10523 | _messageParser: messageParser,
|
10524 | _plugins: realtime._plugins,
|
10525 | _identity: identity
|
10526 | });
|
10527 | connection.on(RECONNECT, function () {
|
10528 | return client._open(realtime._options.appId, _tag, deviceId, true)
|
10529 | |
10530 |
|
10531 |
|
10532 |
|
10533 |
|
10534 |
|
10535 |
|
10536 | |
10537 |
|
10538 |
|
10539 |
|
10540 |
|
10541 | .then(function () {
|
10542 | return client.emit(RECONNECT);
|
10543 | }, function (error) {
|
10544 | return client.emit(RECONNECT_ERROR, error);
|
10545 | });
|
10546 | });
|
10547 |
|
10548 | internal(client)._eventemitter.on('beforeclose', function () {
|
10549 | delete realtime._IMClients[client.id];
|
10550 |
|
10551 | if (realtime._firstIMClient === client) {
|
10552 | delete realtime._firstIMClient;
|
10553 | }
|
10554 | }, realtime);
|
10555 |
|
10556 | internal(client)._eventemitter.on('close', function () {
|
10557 | realtime._deregister(client);
|
10558 | }, realtime);
|
10559 |
|
10560 | return client._open(realtime._options.appId, _tag, deviceId, isReconnect).then(function () {
|
10561 | realtime._IMClients[client.id] = client;
|
10562 | realtime._IMClientsCreationCount += 1;
|
10563 |
|
10564 | if (realtime._IMClientsCreationCount === 1) {
|
10565 | client._omitPeerId(true);
|
10566 |
|
10567 | realtime._firstIMClient = client;
|
10568 | } else if (realtime._IMClientsCreationCount > 1 && realtime._firstIMClient) {
|
10569 | realtime._firstIMClient._omitPeerId(false);
|
10570 | }
|
10571 |
|
10572 | realtime._register(client);
|
10573 |
|
10574 | return client;
|
10575 | }).catch(function (error) {
|
10576 | delete realtime._IMClients[client.id];
|
10577 | throw error;
|
10578 | });
|
10579 | })).then.apply(_realtime$_open$then, _toConsumableArray(finalize(function () {
|
10580 | realtime._deregisterPending(promise);
|
10581 | })));
|
10582 |
|
10583 | if (identity) {
|
10584 | realtime._IMClients[id] = promise;
|
10585 | }
|
10586 |
|
10587 | realtime._registerPending(promise);
|
10588 |
|
10589 | return _context2.abrupt("return", promise);
|
10590 |
|
10591 | case 25:
|
10592 | case "end":
|
10593 | return _context2.stop();
|
10594 | }
|
10595 | }
|
10596 | }, _callee2, this);
|
10597 | }));
|
10598 |
|
10599 | return function createIMClient(_x2) {
|
10600 | return _ref2.apply(this, arguments);
|
10601 | };
|
10602 | }();
|
10603 |
|
10604 | Object.assign(realtime, {
|
10605 | register: register,
|
10606 | createIMClient: createIMClient
|
10607 | });
|
10608 |
|
10609 | };
|
10610 |
|
10611 | var beforeCommandDispatch = function beforeCommandDispatch(command, realtime) {
|
10612 | var isIMCommand = command.service === null || command.service === 2;
|
10613 | if (!isIMCommand) return true;
|
10614 | var targetClient = command.peerId ? realtime._IMClients[command.peerId] : realtime._firstIMClient;
|
10615 |
|
10616 | if (targetClient) {
|
10617 | Promise.resolve(targetClient).then(function (client) {
|
10618 | return client._dispatchCommand(command);
|
10619 | }).catch(debug$c);
|
10620 | } else {
|
10621 | debug$c('[WARN] Unexpected message received without any live client match: %O', trim(command));
|
10622 | }
|
10623 |
|
10624 | return false;
|
10625 | };
|
10626 |
|
10627 | var IMPlugin = {
|
10628 | name: 'leancloud-realtime-plugin-im',
|
10629 | onRealtimeCreate: onRealtimeCreate,
|
10630 | beforeCommandDispatch: beforeCommandDispatch,
|
10631 | messageClasses: [Message, BinaryMessage, RecalledMessage, TextMessage]
|
10632 | };
|
10633 |
|
10634 | Realtime.defineConversationProperty = defineConversationProperty;
|
10635 | Realtime.__preRegisteredPlugins = [IMPlugin];
|
10636 |
|
10637 | var Event$1 = _objectSpread({}, CoreEvent, Event);
|
10638 |
|
10639 | exports.EventEmitter = EventEmitter;
|
10640 | exports.Event = Event$1;
|
10641 | exports.ErrorCode = ErrorCode;
|
10642 | exports.Protocals = message;
|
10643 | exports.Promise = polyfilledPromise;
|
10644 | exports.Realtime = Realtime;
|
10645 | exports.debug = debug$2;
|
10646 | exports.Message = Message;
|
10647 | exports.BinaryMessage = BinaryMessage;
|
10648 | exports.TypedMessage = TypedMessage;
|
10649 | exports.TextMessage = TextMessage;
|
10650 | exports.RecalledMessage = RecalledMessage;
|
10651 | exports.MessagePriority = MessagePriority;
|
10652 | exports.MessageStatus = MessageStatus;
|
10653 | exports.MessageQueryDirection = MessageQueryDirection;
|
10654 | exports.defineConversationProperty = defineConversationProperty;
|
10655 | exports.IMPlugin = IMPlugin;
|
10656 | exports.messageType = messageType;
|
10657 | exports.messageField = messageField;
|
10658 | exports.IE10Compatible = IE10Compatible;
|
10659 | exports.ConversationMemberRole = ConversationMemberRole;
|
10660 | exports.Conversation = Conversation;
|
10661 | exports.ChatRoom = ChatRoom;
|
10662 | exports.ServiceConversation = ServiceConversation;
|
10663 | exports.TemporaryConversation = TemporaryConversation;
|
10664 |
|