@webex/internal-plugin-conversation 3.7.0 → 3.8.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.
@@ -391,7 +391,7 @@ var ShareActivity = _webexCore.WebexPlugin.extend({
391
391
  return res.body.spaceUrl;
392
392
  });
393
393
  },
394
- version: "3.7.0"
394
+ version: "3.8.0"
395
395
  });
396
396
 
397
397
  /**
package/package.json CHANGED
@@ -19,12 +19,12 @@
19
19
  ]
20
20
  },
21
21
  "dependencies": {
22
- "@webex/common": "3.7.0",
23
- "@webex/helper-html": "3.7.0",
24
- "@webex/helper-image": "3.7.0",
25
- "@webex/internal-plugin-encryption": "3.7.0",
26
- "@webex/internal-plugin-user": "3.7.0",
27
- "@webex/webex-core": "3.7.0",
22
+ "@webex/common": "3.8.0",
23
+ "@webex/helper-html": "3.8.0",
24
+ "@webex/helper-image": "3.8.0",
25
+ "@webex/internal-plugin-encryption": "3.8.0",
26
+ "@webex/internal-plugin-user": "3.8.0",
27
+ "@webex/webex-core": "3.8.0",
28
28
  "crypto-js": "^4.1.1",
29
29
  "lodash": "^4.17.21",
30
30
  "node-scr": "^0.3.0",
@@ -36,13 +36,13 @@
36
36
  "@webex/eslint-config-legacy": "0.0.0",
37
37
  "@webex/jest-config-legacy": "0.0.0",
38
38
  "@webex/legacy-tools": "0.0.0",
39
- "@webex/test-helper-chai": "3.7.0",
40
- "@webex/test-helper-file": "3.7.0",
41
- "@webex/test-helper-make-local-url": "3.7.0",
42
- "@webex/test-helper-mocha": "3.7.0",
43
- "@webex/test-helper-mock-webex": "3.7.0",
44
- "@webex/test-helper-retry": "3.7.0",
45
- "@webex/test-helper-test-users": "3.7.0",
39
+ "@webex/test-helper-chai": "3.8.0",
40
+ "@webex/test-helper-file": "3.8.0",
41
+ "@webex/test-helper-make-local-url": "3.8.0",
42
+ "@webex/test-helper-mocha": "3.8.0",
43
+ "@webex/test-helper-mock-webex": "3.8.0",
44
+ "@webex/test-helper-retry": "3.8.0",
45
+ "@webex/test-helper-test-users": "3.8.0",
46
46
  "eslint": "^8.24.0",
47
47
  "prettier": "^2.7.1",
48
48
  "sinon": "^9.2.4"
@@ -56,5 +56,5 @@
56
56
  "test:style": "eslint ./src/**/*.*",
57
57
  "test:unit": "webex-legacy-tools test --unit --runner jest"
58
58
  },
59
- "version": "3.7.0"
59
+ "version": "3.8.0"
60
60
  }
@@ -303,15 +303,16 @@ const Conversation = WebexPlugin.extend({
303
303
  },
304
304
 
305
305
  /**
306
- * delete a reaction
307
- * @param {Object} conversation
308
- * @param {Object} reactionId,
309
- * @param {String} recipientId,
306
+ * create a reaction
307
+ * @param {Object} conversation the conversation in which the reaction will be added
308
+ * @param {Object} reactionId reaction activity to be deleted
309
+ * @param {Object} actorId id of person object who is reacting
310
+ * @param {String} recipientId used when reacting to direct IMC messages
310
311
  * @returns {Promise<Activity>}
311
312
  */
312
- deleteReaction(conversation, reactionId, recipientId) {
313
+ deleteReaction(conversation, reactionId, actorId, recipientId) {
313
314
  const deleteReactionPayload = {
314
- actor: {objectType: 'person', id: this.webex.internal.device.userId},
315
+ actor: {objectType: 'person', id: actorId ?? this.webex.internal.device.userId},
315
316
  object: {
316
317
  id: reactionId,
317
318
  objectType: 'activity',
@@ -334,39 +335,43 @@ const Conversation = WebexPlugin.extend({
334
335
 
335
336
  /**
336
337
  * create a reaction
337
- * @param {Object} conversation
338
+ * @param {Object} conversation the conversation in which the reaction will be added
338
339
  * @param {Object} displayName must be 'celebrate', 'heart', 'thumbsup', 'smiley', 'haha', 'confused', 'sad'
339
- * @param {Object} activity activity object from convo we are reacting to
340
- * @param {String} recipientId,
340
+ * @param {Object} parentActivity activity object from that we are reacting to
341
+ * @param {Object} actorId id of person object who is reacting
342
+ * @param {String} recipientId used when reacting to direct IMC messages
341
343
  * @returns {Promise<Activity>}
342
344
  */
343
- addReaction(conversation, displayName, activity, recipientId) {
344
- return this.createReactionHmac(displayName, activity).then((hmac) => {
345
- const addReactionPayload = {
346
- actor: {objectType: 'person', id: this.webex.internal.device.userId},
347
- target: {
348
- id: conversation.id,
349
- objectType: 'conversation',
350
- },
351
- verb: 'add',
352
- objectType: 'activity',
353
- parent: {
354
- type: 'reaction',
355
- id: activity.id,
356
- },
357
- object: {
358
- objectType: 'reaction2',
359
- displayName,
360
- hmac,
361
- },
362
- };
345
+ async addReaction(conversation, displayName, parentActivity, actorId, recipientId) {
346
+ let hmac;
347
+ if (this.config.includeEncryptionTransforms) {
348
+ hmac = await this.createReactionHmac(displayName, parentActivity);
349
+ }
363
350
 
364
- if (recipientId) {
365
- addReactionPayload.recipients = {items: [{id: recipientId, objectType: 'person'}]};
366
- }
351
+ const addReactionPayload = {
352
+ actor: {objectType: 'person', id: actorId ?? this.webex.internal.device.userId},
353
+ target: {
354
+ id: conversation.id,
355
+ objectType: 'conversation',
356
+ },
357
+ verb: 'add',
358
+ objectType: 'activity',
359
+ parent: {
360
+ type: 'reaction',
361
+ id: parentActivity.id,
362
+ },
363
+ object: {
364
+ objectType: 'reaction2',
365
+ displayName,
366
+ hmac,
367
+ },
368
+ };
367
369
 
368
- return this.sendReaction(conversation, addReactionPayload);
369
- });
370
+ if (recipientId) {
371
+ addReactionPayload.recipients = {items: [{id: recipientId, objectType: 'person'}]};
372
+ }
373
+
374
+ return this.sendReaction(conversation, addReactionPayload);
370
375
  },
371
376
 
372
377
  /**
@@ -37,67 +37,78 @@ describe('plugin-conversation', () => {
37
37
  });
38
38
 
39
39
  describe('addReaction()', () => {
40
- it('should add recipients to the payload if provided', () => {
41
- const {conversation} = webex.internal;
42
- const recipientId = 'example-recipient-id';
43
- const expected = {items: [{id: recipientId, objectType: 'person'}]};
40
+ let conversation;
41
+ let recipientId;
42
+ let expectedRecipients;
43
+ let actorId;
44
+
45
+ beforeEach(() => {
46
+ conversation = webex.internal.conversation;
47
+ recipientId = 'example-recipient-id';
48
+ actorId = 'actorId-123';
49
+ expectedRecipients = {items: [{id: recipientId, objectType: 'person'}]};
44
50
  conversation.sendReaction = sinon.stub().returns(Promise.resolve());
45
51
  conversation.createReactionHmac = sinon.stub().returns(Promise.resolve('hmac'));
52
+ });
53
+ it('should add recipients to the payload if provided', async () => {
54
+ conversation.config.includeEncryptionTransforms = true;
46
55
 
47
- return conversation.addReaction({}, 'example-display-name', {}, recipientId).then(() => {
48
- assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expected);
49
- });
56
+ await conversation.addReaction({}, 'example-display-name', {}, actorId, recipientId);
57
+ assert.called(conversation.createReactionHmac);
58
+ assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expectedRecipients);
50
59
  });
51
- });
52
60
 
53
- describe('deleteReaction()', () => {
54
- it('should add recipients to the payload if provided', () => {
55
- const {conversation} = webex.internal;
56
- const recipientId = 'example-recipient-id';
57
- const expected = {items: [{id: recipientId, objectType: 'person'}]};
58
- conversation.sendReaction = sinon.stub().returns(Promise.resolve());
61
+ it('will not call createReactionHmac if config prohibits', async () => {
62
+ conversation.config.includeEncryptionTransforms = false;
59
63
 
60
- return conversation.deleteReaction({}, 'example-reaction-id', recipientId).then(() => {
61
- assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expected);
62
- });
64
+ await conversation.addReaction({}, 'example-display-name', {}, actorId, recipientId);
65
+ assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expectedRecipients);
66
+ assert.notCalled(conversation.createReactionHmac);
63
67
  });
64
- });
65
68
 
66
- describe('prepare()', () => {
67
- it('should ammend activity recipients to the returned object', () => {
68
- const {conversation} = webex.internal;
69
- const activity = {recipients: 'example-recipients'};
69
+ it('should use actorId if provided', async () => {
70
+ await conversation.addReaction({}, 'example-display-name', {}, actorId, recipientId);
71
+ assert.equal(conversation.sendReaction.args[0][1].actor.id, actorId);
72
+ });
70
73
 
71
- return conversation.prepare(activity).then((results) => {
72
- assert.deepEqual(results.recipients, activity.recipients);
73
- });
74
+ it('should use fallback device.userId if no actorId provided', async () => {
75
+ const defaultUserId = 'fallback-id';
76
+ webex.internal.device.userId = defaultUserId;
77
+ await conversation.addReaction({}, 'example-display-name', {}, undefined, recipientId);
78
+ assert.equal(conversation.sendReaction.args[0][1].actor.id, defaultUserId);
74
79
  });
75
80
  });
76
81
 
77
- describe('addReaction()', () => {
78
- it('should add recipients to the payload if provided', () => {
79
- const {conversation} = webex.internal;
80
- const recipientId = 'example-recipient-id';
81
- const expected = {items: [{id: recipientId, objectType: 'person'}]};
82
+ describe('deleteReaction()', () => {
83
+ let conversation;
84
+ let recipientId;
85
+ let expectedRecipients;
86
+ let actorId;
87
+
88
+ beforeEach(() => {
89
+ conversation = webex.internal.conversation;
90
+ recipientId = 'example-recipient-id';
91
+ actorId = 'actorId-123';
92
+ expectedRecipients = {items: [{id: recipientId, objectType: 'person'}]};
82
93
  conversation.sendReaction = sinon.stub().returns(Promise.resolve());
83
94
  conversation.createReactionHmac = sinon.stub().returns(Promise.resolve('hmac'));
95
+ });
84
96
 
85
- return conversation.addReaction({}, 'example-display-name', {}, recipientId).then(() => {
86
- assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expected);
87
- });
97
+ it('should add recipients to the payload if provided', async () => {
98
+ await conversation.deleteReaction({}, 'example-reaction-id', actorId, recipientId);
99
+ assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expectedRecipients);
88
100
  });
89
- });
90
101
 
91
- describe('deleteReaction()', () => {
92
- it('should add recipients to the payload if provided', () => {
93
- const {conversation} = webex.internal;
94
- const recipientId = 'example-recipient-id';
95
- const expected = {items: [{id: recipientId, objectType: 'person'}]};
96
- conversation.sendReaction = sinon.stub().returns(Promise.resolve());
102
+ it('should use actorId if provided', async () => {
103
+ await conversation.deleteReaction({}, 'example-reaction-id', actorId, recipientId);
104
+ assert.equal(conversation.sendReaction.args[0][1].actor.id, actorId);
105
+ });
97
106
 
98
- return conversation.deleteReaction({}, 'example-reaction-id', recipientId).then(() => {
99
- assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expected);
100
- });
107
+ it('should use fallback device.userId if no actorId provided', async () => {
108
+ const defaultUserId = 'fallback-id';
109
+ webex.internal.device.userId = defaultUserId;
110
+ await conversation.deleteReaction({}, 'example-reaction-id', undefined, recipientId);
111
+ assert.equal(conversation.sendReaction.args[0][1].actor.id, defaultUserId);
101
112
  });
102
113
  });
103
114