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