@webex/plugin-messages 3.0.0-beta.9 → 3.0.0-bnr.0

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.
package/src/messages.js CHANGED
@@ -8,27 +8,21 @@ import {
8
8
  buildHydraPersonId,
9
9
  buildHydraRoomId,
10
10
  createEventEnvelope,
11
- getHydraClusterString
11
+ getHydraClusterString,
12
12
  } from '@webex/common';
13
- import {
14
- Page,
15
- WebexPlugin
16
- } from '@webex/webex-core';
13
+ import {Page, WebexPlugin} from '@webex/webex-core';
17
14
  import {cloneDeep, isArray} from 'lodash';
18
15
 
19
16
  const verbToType = {
20
- [SDK_EVENT.INTERNAL.ACTIVITY_VERB.SHARE]:
21
- SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED,
22
- [SDK_EVENT.INTERNAL.ACTIVITY_VERB.POST]:
23
- SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED,
24
- [SDK_EVENT.INTERNAL.ACTIVITY_VERB.DELETE]:
25
- SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED
17
+ [SDK_EVENT.INTERNAL.ACTIVITY_VERB.SHARE]: SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED,
18
+ [SDK_EVENT.INTERNAL.ACTIVITY_VERB.POST]: SDK_EVENT.EXTERNAL.EVENT_TYPE.CREATED,
19
+ [SDK_EVENT.INTERNAL.ACTIVITY_VERB.DELETE]: SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED,
26
20
  };
27
21
 
28
22
  const getRoomType = (roomTags) =>
29
- (roomTags.includes(SDK_EVENT.INTERNAL.ACTIVITY_TAG.ONE_ON_ONE) ?
30
- SDK_EVENT.EXTERNAL.SPACE_TYPE.DIRECT :
31
- SDK_EVENT.EXTERNAL.SPACE_TYPE.GROUP);
23
+ roomTags.includes(SDK_EVENT.INTERNAL.ACTIVITY_TAG.ONE_ON_ONE)
24
+ ? SDK_EVENT.EXTERNAL.SPACE_TYPE.DIRECT
25
+ : SDK_EVENT.EXTERNAL.SPACE_TYPE.GROUP;
32
26
 
33
27
  /**
34
28
  * @typedef {Object} MessageObject
@@ -100,18 +94,18 @@ const Messages = WebexPlugin.extend({
100
94
  */
101
95
  listen() {
102
96
  // Create a common envelope that we will wrap all events in
103
- return createEventEnvelope(this.webex,
104
- SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES)
105
- .then((envelope) => {
97
+ return createEventEnvelope(this.webex, SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES).then(
98
+ (envelope) => {
106
99
  this.eventEnvelope = envelope;
107
100
 
108
101
  // Register to listen to events
109
102
  return this.webex.internal.mercury.connect().then(() => {
110
- this.listenTo(this.webex.internal.mercury,
111
- SDK_EVENT.INTERNAL.WEBEX_ACTIVITY,
112
- (event) => this.onWebexApiEvent(event));
103
+ this.listenTo(this.webex.internal.mercury, SDK_EVENT.INTERNAL.WEBEX_ACTIVITY, (event) =>
104
+ this.onWebexApiEvent(event)
105
+ );
113
106
  });
114
- });
107
+ }
108
+ );
115
109
  },
116
110
 
117
111
  /**
@@ -143,12 +137,17 @@ const Messages = WebexPlugin.extend({
143
137
  let key = 'body';
144
138
 
145
139
  if (message.file) {
146
- this.logger.warn('Supplying a single `file` property is deprecated; please supply a `files` array');
140
+ this.logger.warn(
141
+ 'Supplying a single `file` property is deprecated; please supply a `files` array'
142
+ );
147
143
  message.files = [message.file];
148
144
  Reflect.deleteProperty(message, 'file');
149
145
  }
150
146
 
151
- if (isArray(message.files) && message.files.reduce((type, file) => type || typeof file !== 'string', false)) {
147
+ if (
148
+ isArray(message.files) &&
149
+ message.files.reduce((type, file) => type || typeof file !== 'string', false)
150
+ ) {
152
151
  key = 'formData';
153
152
  }
154
153
 
@@ -156,11 +155,10 @@ const Messages = WebexPlugin.extend({
156
155
  method: 'POST',
157
156
  service: 'hydra',
158
157
  resource: 'messages',
159
- [key]: message
158
+ [key]: message,
160
159
  };
161
160
 
162
- return this.request(options)
163
- .then((res) => res.body);
161
+ return this.request(options).then((res) => res.body);
164
162
  },
165
163
 
166
164
  /**
@@ -194,9 +192,8 @@ const Messages = WebexPlugin.extend({
194
192
 
195
193
  return this.request({
196
194
  service: 'hydra',
197
- resource: `messages/${id}`
198
- })
199
- .then((res) => res.body.items || res.body);
195
+ resource: `messages/${id}`,
196
+ }).then((res) => res.body.items || res.body);
200
197
  },
201
198
 
202
199
  /**
@@ -242,9 +239,8 @@ const Messages = WebexPlugin.extend({
242
239
  return this.request({
243
240
  service: 'hydra',
244
241
  resource: 'messages',
245
- qs: options
246
- })
247
- .then((res) => new Page(res, this.webex));
242
+ qs: options,
243
+ }).then((res) => new Page(res, this.webex));
248
244
  },
249
245
 
250
246
  /**
@@ -293,17 +289,16 @@ const Messages = WebexPlugin.extend({
293
289
  return this.request({
294
290
  method: 'DELETE',
295
291
  service: 'hydra',
296
- resource: `messages/${id}`
297
- })
298
- .then((res) => {
299
- // Firefox has some issues with 204s and/or DELETE. This should move to
300
- // http-core
301
- if (res.statusCode === 204) {
302
- return undefined;
303
- }
292
+ resource: `messages/${id}`,
293
+ }).then((res) => {
294
+ // Firefox has some issues with 204s and/or DELETE. This should move to
295
+ // http-core
296
+ if (res.statusCode === 204) {
297
+ return undefined;
298
+ }
304
299
 
305
- return res.body;
306
- });
300
+ return res.body;
301
+ });
307
302
  },
308
303
 
309
304
  /**
@@ -335,8 +330,7 @@ const Messages = WebexPlugin.extend({
335
330
  return;
336
331
  }
337
332
 
338
- this.getMessageEvent(activity, type)
339
- .then(this.fire(type));
333
+ this.getMessageEvent(activity, type).then(this.fire(type));
340
334
  },
341
335
 
342
336
  /**
@@ -354,7 +348,7 @@ const Messages = WebexPlugin.extend({
354
348
  id,
355
349
  actor: {entryUUID: actorId, emailAddress},
356
350
  object: {id: objectId},
357
- target: {id: roomId, url: roomUrl, tags: roomTags}
351
+ target: {id: roomId, url: roomUrl, tags: roomTags},
358
352
  } = activity;
359
353
 
360
354
  const cluster = getHydraClusterString(this.webex, roomUrl);
@@ -374,18 +368,17 @@ const Messages = WebexPlugin.extend({
374
368
  personEmail: emailAddress || actorId,
375
369
  personId,
376
370
  roomId: buildHydraRoomId(roomId, cluster),
377
- roomType: getRoomType(roomTags)
378
- }
371
+ roomType: getRoomType(roomTags),
372
+ },
379
373
  });
380
374
  }
381
375
 
382
- return this.get(buildHydraMessageId(id, cluster))
383
- .then((data) => ({
384
- ...combinedEvent,
385
- actorId: data.personId,
386
- data
387
- }));
388
- }
376
+ return this.get(buildHydraMessageId(id, cluster)).then((data) => ({
377
+ ...combinedEvent,
378
+ actorId: data.personId,
379
+ data,
380
+ }));
381
+ },
389
382
  });
390
383
 
391
384
  export default Messages;