Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(conversation): pass actorId to addReaction and deleteReaction #4037

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions packages/@webex/internal-plugin-conversation/src/conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,16 @@ const Conversation = WebexPlugin.extend({
},

/**
* delete a reaction
* @param {Object} conversation
* @param {Object} reactionId,
* @param {String} recipientId,
* create a reaction
* @param {Object} conversation the conversation in which the reaction will be added
* @param {Object} reactionId reaction activity to be deleted
* @param {Object} actorId id of person object who is reacting
* @param {String} recipientId used when reacting to direct IMC messages
* @returns {Promise<Activity>}
*/
deleteReaction(conversation, reactionId, recipientId) {
deleteReaction(conversation, reactionId, actorId, recipientId) {
const deleteReactionPayload = {
actor: {objectType: 'person', id: this.webex.internal.device.userId},
actor: {objectType: 'person', id: actorId ?? this.webex.internal.device.userId},
object: {
id: reactionId,
objectType: 'activity',
Expand All @@ -334,20 +335,21 @@ const Conversation = WebexPlugin.extend({

/**
* create a reaction
* @param {Object} conversation
* @param {Object} conversation the conversation in which the reaction will be added
* @param {Object} displayName must be 'celebrate', 'heart', 'thumbsup', 'smiley', 'haha', 'confused', 'sad'
* @param {Object} activity activity object from convo we are reacting to
* @param {String} recipientId,
* @param {Object} parentActivity activity object from that we are reacting to
* @param {Object} actorId id of person object who is reacting
* @param {String} recipientId used when reacting to direct IMC messages
* @returns {Promise<Activity>}
*/
async addReaction(conversation, displayName, activity, recipientId) {
async addReaction(conversation, displayName, parentActivity, actorId, recipientId) {
let hmac;
if (this.config.includeEncryptionTransforms) {
hmac = await this.createReactionHmac(displayName, activity);
hmac = await this.createReactionHmac(displayName, parentActivity);
}

const addReactionPayload = {
actor: {objectType: 'person', id: this.webex.internal.device.userId},
actor: {objectType: 'person', id: actorId ?? this.webex.internal.device.userId},
target: {
id: conversation.id,
objectType: 'conversation',
Expand All @@ -356,7 +358,7 @@ const Conversation = WebexPlugin.extend({
objectType: 'activity',
parent: {
type: 'reaction',
id: activity.id,
id: parentActivity.id,
},
object: {
objectType: 'reaction2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,78 @@ describe('plugin-conversation', () => {
});

describe('addReaction()', () => {
it('should add recipients to the payload if provided', () => {
const {conversation} = webex.internal;
const recipientId = 'example-recipient-id';
const expected = {items: [{id: recipientId, objectType: 'person'}]};
conversation.config.includeEncryptionTransforms = true;
let conversation;
let recipientId;
let expectedRecipients;
let actorId;

beforeEach(() => {
conversation = webex.internal.conversation;
recipientId = 'example-recipient-id';
actorId = 'actorId-123';
expectedRecipients = {items: [{id: recipientId, objectType: 'person'}]};
conversation.sendReaction = sinon.stub().returns(Promise.resolve());
conversation.createReactionHmac = sinon.stub().returns(Promise.resolve('hmac'));
});
it('should add recipients to the payload if provided', async () => {
conversation.config.includeEncryptionTransforms = true;

return conversation.addReaction({}, 'example-display-name', {}, recipientId).then(() => {
assert.called(conversation.createReactionHmac);
assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expected);
});
await conversation.addReaction({}, 'example-display-name', {}, actorId, recipientId);
assert.called(conversation.createReactionHmac);
assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expectedRecipients);
});

it('will not call createReactionHmac if config prohibits', () => {
const {conversation} = webex.internal;
const recipientId = 'example-recipient-id';
const expected = {items: [{id: recipientId, objectType: 'person'}]};
it('will not call createReactionHmac if config prohibits', async () => {
conversation.config.includeEncryptionTransforms = false;
conversation.sendReaction = sinon.stub().returns(Promise.resolve());
conversation.createReactionHmac = sinon.stub();

return conversation.addReaction({}, 'example-display-name', {}, recipientId).then(() => {
assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expected);
assert.notCalled(conversation.createReactionHmac);
});
await conversation.addReaction({}, 'example-display-name', {}, actorId, recipientId);
assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expectedRecipients);
assert.notCalled(conversation.createReactionHmac);
});

it('should use actorId if provided', async () => {
await conversation.addReaction({}, 'example-display-name', {}, actorId, recipientId);
assert.equal(conversation.sendReaction.args[0][1].actor.id, actorId);
});

it('should use fallback device.userId if no actorId provided', async () => {
const defaultUserId = 'fallback-id';
webex.internal.device.userId = defaultUserId;
await conversation.addReaction({}, 'example-display-name', {}, undefined, recipientId);
assert.equal(conversation.sendReaction.args[0][1].actor.id, defaultUserId);
});
});

describe('deleteReaction()', () => {
it('should add recipients to the payload if provided', () => {
const {conversation} = webex.internal;
const recipientId = 'example-recipient-id';
const expected = {items: [{id: recipientId, objectType: 'person'}]};
let conversation;
let recipientId;
let expectedRecipients;
let actorId;

beforeEach(() => {
conversation = webex.internal.conversation;
recipientId = 'example-recipient-id';
actorId = 'actorId-123';
expectedRecipients = {items: [{id: recipientId, objectType: 'person'}]};
conversation.sendReaction = sinon.stub().returns(Promise.resolve());
conversation.createReactionHmac = sinon.stub().returns(Promise.resolve('hmac'));
});

return conversation.deleteReaction({}, 'example-reaction-id', recipientId).then(() => {
assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expected);
});
it('should add recipients to the payload if provided', async () => {
await conversation.deleteReaction({}, 'example-reaction-id', actorId, recipientId);
assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expectedRecipients);
});

it('should use actorId if provided', async () => {
await conversation.deleteReaction({}, 'example-reaction-id', actorId, recipientId);
assert.equal(conversation.sendReaction.args[0][1].actor.id, actorId);
});

it('should use fallback device.userId if no actorId provided', async () => {
const defaultUserId = 'fallback-id';
webex.internal.device.userId = defaultUserId;
await conversation.deleteReaction({}, 'example-reaction-id', undefined, recipientId);
assert.equal(conversation.sendReaction.args[0][1].actor.id, defaultUserId);
});
});

Expand Down
Loading