@webex/plugin-memberships 3.0.0-beta.7 → 3.0.0-beta.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ import {
13
13
  buildHydraRoomId,
14
14
  getHydraClusterString,
15
15
  getHydraRoomType,
16
- deconstructHydraId
16
+ deconstructHydraId,
17
17
  } from '@webex/common';
18
18
  import {WebexPlugin, Page} from '@webex/webex-core';
19
19
  import {cloneDeep} from 'lodash';
@@ -86,18 +86,18 @@ const Memberships = WebexPlugin.extend({
86
86
  */
87
87
  listen() {
88
88
  // Create a common envelope that we will wrap all events in
89
- return createEventEnvelope(this.webex,
90
- SDK_EVENT.EXTERNAL.RESOURCE.MEMBERSHIPS)
91
- .then((envelope) => {
89
+ return createEventEnvelope(this.webex, SDK_EVENT.EXTERNAL.RESOURCE.MEMBERSHIPS).then(
90
+ (envelope) => {
92
91
  this.eventEnvelope = envelope;
93
92
 
94
93
  // Register to listen to events
95
94
  return this.webex.internal.mercury.connect().then(() => {
96
- this.listenTo(this.webex.internal.mercury,
97
- SDK_EVENT.INTERNAL.WEBEX_ACTIVITY,
98
- (event) => this.onWebexApiEvent(event));
95
+ this.listenTo(this.webex.internal.mercury, SDK_EVENT.INTERNAL.WEBEX_ACTIVITY, (event) =>
96
+ this.onWebexApiEvent(event)
97
+ );
99
98
  });
100
- });
99
+ }
100
+ );
101
101
  },
102
102
 
103
103
  /**
@@ -134,9 +134,8 @@ const Memberships = WebexPlugin.extend({
134
134
  method: 'POST',
135
135
  service: 'hydra',
136
136
  resource: 'memberships',
137
- body: membership
138
- })
139
- .then((res) => res.body);
137
+ body: membership,
138
+ }).then((res) => res.body);
140
139
  },
141
140
 
142
141
  /**
@@ -170,9 +169,8 @@ const Memberships = WebexPlugin.extend({
170
169
 
171
170
  return this.request({
172
171
  service: 'hydra',
173
- resource: `memberships/${id}`
174
- })
175
- .then((res) => res.body.items || res.body);
172
+ resource: `memberships/${id}`,
173
+ }).then((res) => res.body.items || res.body);
176
174
  },
177
175
 
178
176
  /**
@@ -215,9 +213,8 @@ const Memberships = WebexPlugin.extend({
215
213
  return this.request({
216
214
  service: 'hydra',
217
215
  resource: 'memberships',
218
- qs: options
219
- })
220
- .then((res) => new Page(res, this.webex));
216
+ qs: options,
217
+ }).then((res) => new Page(res, this.webex));
221
218
  },
222
219
 
223
220
  /**
@@ -251,15 +248,15 @@ const Memberships = WebexPlugin.extend({
251
248
  const deconstructedId = deconstructHydraId(options.roomId);
252
249
  const conversation = {
253
250
  id: deconstructedId.id,
254
- cluster: deconstructedId.cluster
251
+ cluster: deconstructedId.cluster,
255
252
  };
256
253
 
257
- return ensureMyIdIsAvailable(this.webex)
258
- .then(() => this.webex.internal.services.waitForCatalog('postauth')
259
- .then(() => this.webex.internal.conversation.get(conversation,
260
- {
254
+ return ensureMyIdIsAvailable(this.webex).then(() =>
255
+ this.webex.internal.services.waitForCatalog('postauth').then(() =>
256
+ this.webex.internal.conversation
257
+ .get(conversation, {
261
258
  participantAckFilter: 'all', // show lastAck info for each participant
262
- activitiesLimit: 0 // don't send the whole history of activity
259
+ activitiesLimit: 0, // don't send the whole history of activity
263
260
  })
264
261
  .then((resp) => {
265
262
  try {
@@ -275,31 +272,28 @@ const Memberships = WebexPlugin.extend({
275
272
  for (let i = 0; i < participants.length; i += 1) {
276
273
  const participant = participants[i];
277
274
  const participantInfo = {
278
- id: buildHydraMembershipId(participant.entryUUID, roomUUID,
279
- conversation.cluster),
275
+ id: buildHydraMembershipId(participant.entryUUID, roomUUID, conversation.cluster),
280
276
  roomId,
281
277
  personId: buildHydraPersonId(participant.entryUUID),
282
- personEmail: participant.entryEmailAddress ||
283
- participant.entryEmail,
278
+ personEmail: participant.entryEmailAddress || participant.entryEmail,
284
279
  personDisplayName: participant.displayName,
285
- personOrgId: buildHydraOrgId(participant.orgId,
286
- conversation.cluster),
280
+ personOrgId: buildHydraOrgId(participant.orgId, conversation.cluster),
287
281
  isMonitor: false, // deprecated, but included for completeness
288
- roomType
282
+ roomType,
289
283
  // created is not available in the conversations payload
290
284
  };
291
285
 
292
- if ((isRoomHidden) && (participantInfo.personId === myId)) {
286
+ if (isRoomHidden && participantInfo.personId === myId) {
293
287
  participantInfo.isRoomHidden = isRoomHidden;
294
288
  }
295
289
 
296
290
  if ('roomProperties' in participant) {
297
291
  if ('lastSeenActivityDate' in participant.roomProperties) {
298
- participantInfo.lastSeenId =
299
- buildHydraMessageId(participant.roomProperties.lastSeenActivityUUID,
300
- conversation.cluster);
301
- participantInfo.lastSeenDate =
302
- participant.roomProperties.lastSeenActivityDate;
292
+ participantInfo.lastSeenId = buildHydraMessageId(
293
+ participant.roomProperties.lastSeenActivityUUID,
294
+ conversation.cluster
295
+ );
296
+ participantInfo.lastSeenDate = participant.roomProperties.lastSeenActivityDate;
303
297
  }
304
298
  if ('isModerator' in participant.roomProperties) {
305
299
  participantInfo.isModerator = participant.roomProperties.isModerator;
@@ -310,11 +304,12 @@ const Memberships = WebexPlugin.extend({
310
304
  }
311
305
 
312
306
  return Promise.resolve(lastReadInfo);
313
- }
314
- catch (e) {
307
+ } catch (e) {
315
308
  return Promise.reject(e);
316
309
  }
317
- })));
310
+ })
311
+ )
312
+ );
318
313
  },
319
314
 
320
315
  /**
@@ -358,17 +353,16 @@ const Memberships = WebexPlugin.extend({
358
353
  return this.request({
359
354
  method: 'DELETE',
360
355
  service: 'hydra',
361
- resource: `memberships/${id}`
362
- })
363
- .then((res) => {
364
- // Firefox has some issues with 204s and/or DELETE. This should move to
365
- // http-core
366
- if (res.statusCode === 204) {
367
- return undefined;
368
- }
356
+ resource: `memberships/${id}`,
357
+ }).then((res) => {
358
+ // Firefox has some issues with 204s and/or DELETE. This should move to
359
+ // http-core
360
+ if (res.statusCode === 204) {
361
+ return undefined;
362
+ }
369
363
 
370
- return res.body;
371
- });
364
+ return res.body;
365
+ });
372
366
  },
373
367
 
374
368
  /**
@@ -440,9 +434,8 @@ const Memberships = WebexPlugin.extend({
440
434
  method: 'PUT',
441
435
  service: 'hydra',
442
436
  resource: `memberships/${id}`,
443
- body: membership
444
- })
445
- .then((res) => res.body);
437
+ body: membership,
438
+ }).then((res) => res.body);
446
439
  },
447
440
 
448
441
  /**
@@ -457,30 +450,29 @@ const Memberships = WebexPlugin.extend({
457
450
  */
458
451
  updateLastSeen(message) {
459
452
  const activity = {
460
- id: deconstructHydraId(message.id).id
453
+ id: deconstructHydraId(message.id).id,
461
454
  };
462
455
  const deconstructedId = deconstructHydraId(message.roomId);
463
456
  const conversation = {
464
457
  id: deconstructedId.id,
465
- cluster: deconstructedId.cluster
458
+ cluster: deconstructedId.cluster,
466
459
  };
467
460
 
468
- return this.webex.internal.services.waitForCatalog('postauth')
469
- .then(() => this.webex.internal.conversation.acknowledge(conversation, activity)
470
- .then((ack) => ({
471
- lastSeenId: buildHydraMessageId(ack.object.id, conversation.cluster),
472
- id: buildHydraMembershipId(ack.actor.entryUUID,
473
- ack.target.id, conversation.cluster),
474
- personId: buildHydraPersonId(ack.actor.entryUUID, conversation.cluster),
475
- personEmail: ack.actor.emailAddress || ack.actor.entryEmail,
476
- personDisplayName: ack.actor.displayName,
477
- personOrgId: buildHydraOrgId(ack.actor.orgId, conversation.cluster),
478
- roomId: buildHydraRoomId(ack.target.id, conversation.cluster),
479
- roomType: getHydraRoomType(ack.target.tags),
480
- isRoomHidden: false, // any activity unhides a space.
481
- isMonitor: false, // deprecated, returned for back compat
482
- created: ack.published
483
- })));
461
+ return this.webex.internal.services.waitForCatalog('postauth').then(() =>
462
+ this.webex.internal.conversation.acknowledge(conversation, activity).then((ack) => ({
463
+ lastSeenId: buildHydraMessageId(ack.object.id, conversation.cluster),
464
+ id: buildHydraMembershipId(ack.actor.entryUUID, ack.target.id, conversation.cluster),
465
+ personId: buildHydraPersonId(ack.actor.entryUUID, conversation.cluster),
466
+ personEmail: ack.actor.emailAddress || ack.actor.entryEmail,
467
+ personDisplayName: ack.actor.displayName,
468
+ personOrgId: buildHydraOrgId(ack.actor.orgId, conversation.cluster),
469
+ roomId: buildHydraRoomId(ack.target.id, conversation.cluster),
470
+ roomType: getHydraRoomType(ack.target.tags),
471
+ isRoomHidden: false, // any activity unhides a space.
472
+ isMonitor: false, // deprecated, returned for back compat
473
+ created: ack.published,
474
+ }))
475
+ );
484
476
  },
485
477
 
486
478
  /**
@@ -498,16 +490,16 @@ const Memberships = WebexPlugin.extend({
498
490
  /* eslint-disable no-case-declarations */
499
491
  switch (activity.verb) {
500
492
  case SDK_EVENT.INTERNAL.ACTIVITY_VERB.CREATE:
501
- const membershipCreatedEventDataArray =
502
- activity.object.participants.items.map((participant) => {
493
+ const membershipCreatedEventDataArray = activity.object.participants.items.map(
494
+ (participant) => {
503
495
  const output = cloneDeep(activity);
504
496
 
505
497
  output.target = cloneDeep(activity.object);
506
498
  output.object = cloneDeep(participant);
507
499
 
508
- return this.getMembershipEvent(output,
509
- SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED);
510
- });
500
+ return this.getMembershipEvent(output, SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED);
501
+ }
502
+ );
511
503
 
512
504
  membershipCreatedEventDataArray.forEach((data) => {
513
505
  if (data) {
@@ -518,8 +510,10 @@ const Memberships = WebexPlugin.extend({
518
510
  break;
519
511
 
520
512
  case SDK_EVENT.INTERNAL.ACTIVITY_VERB.ADD:
521
- const membershipCreatedEventData =
522
- this.getMembershipEvent(activity, SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED);
513
+ const membershipCreatedEventData = this.getMembershipEvent(
514
+ activity,
515
+ SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED
516
+ );
523
517
 
524
518
  if (membershipCreatedEventData) {
525
519
  debug(`membership "created" payload: \
@@ -529,8 +523,10 @@ const Memberships = WebexPlugin.extend({
529
523
  break;
530
524
 
531
525
  case SDK_EVENT.INTERNAL.ACTIVITY_VERB.LEAVE:
532
- const membershipDeletedEventData =
533
- this.getMembershipEvent(activity, SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED);
526
+ const membershipDeletedEventData = this.getMembershipEvent(
527
+ activity,
528
+ SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED
529
+ );
534
530
 
535
531
  if (membershipDeletedEventData) {
536
532
  debug(`membership "deleted" payload: \
@@ -542,8 +538,10 @@ const Memberships = WebexPlugin.extend({
542
538
  case SDK_EVENT.INTERNAL.ACTIVITY_VERB.ADD_MODERATOR:
543
539
  case SDK_EVENT.INTERNAL.ACTIVITY_VERB.REMOVE_MODERATOR:
544
540
  case SDK_EVENT.INTERNAL.ACTIVITY_VERB.HIDE:
545
- const membershipUpdatedEventData =
546
- this.getMembershipEvent(activity, SDK_EVENT.EXTERNAL.EVENT_TYPE.UPDATED);
541
+ const membershipUpdatedEventData = this.getMembershipEvent(
542
+ activity,
543
+ SDK_EVENT.EXTERNAL.EVENT_TYPE.UPDATED
544
+ );
547
545
 
548
546
  if (membershipUpdatedEventData) {
549
547
  debug(`membership "updated" payload: \
@@ -553,8 +551,10 @@ const Memberships = WebexPlugin.extend({
553
551
  break;
554
552
 
555
553
  case SDK_EVENT.INTERNAL.ACTIVITY_VERB.ACKNOWLEDGE:
556
- const membershipSeenEventData =
557
- this.getMembershipEvent(activity, SDK_EVENT.EXTERNAL.EVENT_TYPE.SEEN);
554
+ const membershipSeenEventData = this.getMembershipEvent(
555
+ activity,
556
+ SDK_EVENT.EXTERNAL.EVENT_TYPE.SEEN
557
+ );
558
558
 
559
559
  if (membershipSeenEventData) {
560
560
  debug(`membership "updated" payload: \
@@ -581,9 +581,10 @@ const Memberships = WebexPlugin.extend({
581
581
  getMembershipEvent(activity, event) {
582
582
  try {
583
583
  const sdkEvent = cloneDeep(this.eventEnvelope);
584
- const cluster = (activity.verb !== SDK_EVENT.INTERNAL.ACTIVITY_VERB.HIDE) ?
585
- getHydraClusterString(this.webex, activity.target.url) :
586
- getHydraClusterString(this.webex, activity.url);
584
+ const cluster =
585
+ activity.verb !== SDK_EVENT.INTERNAL.ACTIVITY_VERB.HIDE
586
+ ? getHydraClusterString(this.webex, activity.target.url)
587
+ : getHydraClusterString(this.webex, activity.url);
587
588
  let member;
588
589
  let space;
589
590
 
@@ -594,18 +595,16 @@ const Memberships = WebexPlugin.extend({
594
595
  sdkEvent.data.roomId = buildHydraRoomId(activity.target.id, cluster);
595
596
  sdkEvent.data.roomType = getHydraRoomType(activity.target.tags);
596
597
  sdkEvent.data.isRoomHidden = false; // any activity unhides a space.
597
- }
598
- else {
598
+ } else {
599
599
  sdkEvent.data.roomId = buildHydraRoomId(activity.object.id, cluster);
600
600
  sdkEvent.data.roomType = SDK_EVENT.EXTERNAL.SPACE_TYPE.DIRECT;
601
601
  // currently hidden attribute is only set on 1-1
602
602
  sdkEvent.data.isRoomHidden = true;
603
603
  }
604
604
  if (activity.verb !== SDK_EVENT.INTERNAL.ACTIVITY_VERB.ACKNOWLEDGE) {
605
- if ((activity.object.roomProperties) && (activity.object.roomProperties.isModerator)) {
605
+ if (activity.object.roomProperties && activity.object.roomProperties.isModerator) {
606
606
  sdkEvent.data.isModerator = true;
607
- }
608
- else {
607
+ } else {
609
608
  sdkEvent.data.isModerator = false;
610
609
  }
611
610
  }
@@ -620,38 +619,36 @@ const Memberships = WebexPlugin.extend({
620
619
  space = SDK_EVENT.INTERNAL.ACTIVITY_FIELD.TARGET;
621
620
  // And the "object" is the message that was last seen
622
621
  sdkEvent.data.lastSeenId = buildHydraMessageId(activity.object.id, cluster);
623
- }
624
- else if (activity.verb === SDK_EVENT.INTERNAL.ACTIVITY_VERB.HIDE) {
622
+ } else if (activity.verb === SDK_EVENT.INTERNAL.ACTIVITY_VERB.HIDE) {
625
623
  // For a hide activity the person is also the "actor"
626
624
  member = SDK_EVENT.INTERNAL.ACTIVITY_FIELD.ACTOR;
627
625
  // But the space is now the "object"
628
626
  space = SDK_EVENT.INTERNAL.ACTIVITY_FIELD.OBJECT;
629
- }
630
- else {
627
+ } else {
631
628
  // For most memberships events the person is the 'object"
632
629
  member = SDK_EVENT.INTERNAL.ACTIVITY_FIELD.OBJECT;
633
630
  // and the space is the "target"
634
631
  space = SDK_EVENT.INTERNAL.ACTIVITY_FIELD.TARGET;
635
632
  }
636
633
 
637
- sdkEvent.data.id = buildHydraMembershipId(activity[member].entryUUID,
638
- activity[space].id, cluster);
634
+ sdkEvent.data.id = buildHydraMembershipId(
635
+ activity[member].entryUUID,
636
+ activity[space].id,
637
+ cluster
638
+ );
639
639
  sdkEvent.data.personId = buildHydraPersonId(activity[member].entryUUID, cluster);
640
- sdkEvent.data.personEmail =
641
- activity[member].emailAddress || activity[member].entryEmail;
640
+ sdkEvent.data.personEmail = activity[member].emailAddress || activity[member].entryEmail;
642
641
  sdkEvent.data.personDisplayName = activity[member].displayName;
643
642
  sdkEvent.data.personOrgId = buildHydraOrgId(activity[member].orgId, cluster);
644
643
 
645
644
  return sdkEvent;
646
- }
647
- catch (e) {
645
+ } catch (e) {
648
646
  this.webex.logger.error(`Unable to generate SDK event from mercury \
649
647
  'socket activity for memberships:${event} event: ${e.message}`);
650
648
 
651
649
  return null;
652
650
  }
653
- }
654
-
651
+ },
655
652
  });
656
653
 
657
654
  export default Memberships;