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: handle reactions added/removed separately #3796

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions libraries/botbuilder-core/src/activityHandlerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ export class ActivityHandlerBase {
* call [onReactionsRemovedActivity](xref:botbuilder-core.ActivityHandlerBase.onReactionsRemovedActivity).
*/
protected async onMessageReactionActivity(context: TurnContext): Promise<void> {
if (context.activity.reactionsAdded && context.activity.reactionsAdded.length > 0) {
if (context.activity.reactionsAdded?.length) {
await this.onReactionsAddedActivity(context.activity.reactionsAdded, context);
} else if (context.activity.reactionsRemoved && context.activity.reactionsRemoved.length > 0) {
}

if (context.activity.reactionsRemoved?.length) {
await this.onReactionsRemovedActivity(context.activity.reactionsRemoved, context);
}
}
Expand Down
15 changes: 15 additions & 0 deletions libraries/botbuilder-core/tests/activityHandlerBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,5 +317,20 @@ describe('ActivityHandlerBase', function () {
assert(onMessageReactionActivityCalled, 'onMessageReactionActivity was not called');
assert(onReactionsRemovedActivityCalled, 'onReactionsRemovedActivity was not called');
});

it(`should call onReactionsAddedActivity if reactionsAdded and onReactionsRemovedActivity if reactionsRemoved if they both exist and have items`, async function () {
const bot = new MessageReactionActivityHandler();
const activity = createMsgReactActivity('bot', {
reactionsAdded: [{ type: 'laugh' }],
reactionsRemoved: [{ type: 'like' }],
});

await processActivity(activity, bot);

assert(onTurnActivityCalled, 'onTurnActivity was not called');
assert(onMessageReactionActivityCalled, 'onMessageReactionActivity was not called');
assert(onReactionsAddedActivityCalled, 'onReactionsAddedActivity was not called');
assert(onReactionsRemovedActivityCalled, 'onReactionsRemovedActivity was not called');
});
});
});