Skip to content

Commit

Permalink
Use a proper context in insert_new_reaction().
Browse files Browse the repository at this point in the history
Before this change, we were piggybacking fields on to the event
object, which coupled us to any other function that relies on
the event.
  • Loading branch information
showell committed Jun 29, 2017
1 parent e1ce3da commit 791e489
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
1 change: 0 additions & 1 deletion frontend_tests/node_tests/reactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ set_global('message_store', {
assert.equal(data.class, 'message_reaction reacted');
assert(!data.is_realm_emoji);
assert.equal(data.message_id, 1001);
assert.equal(data.user.user_id, alice.user_id);
assert.equal(data.title, 'You (click to remove) reacted with :8ball:');
return 'new-reaction-html-stub';
};
Expand Down
23 changes: 14 additions & 9 deletions static/js/reactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ exports.add_reaction = function (event) {
return;
}

event.emoji_name_css_class = emoji.emojis_name_to_css_class[emoji_name];
event.user.id = event.user.user_id;

message.reactions.push(event);
Expand Down Expand Up @@ -171,24 +170,30 @@ exports.insert_new_reaction = function (event, user_list) {
var message_id = event.message_id;
var emoji_name = event.emoji_name;

var context = {
message_id: message_id,
emoji_name: emoji_name,
};

var new_title = generate_title(emoji_name, user_list);

if (emoji.realm_emojis[emoji_name]) {
event.is_realm_emoji = true;
event.url = emoji.realm_emojis[emoji_name].emoji_url;
context.is_realm_emoji = true;
context.url = emoji.realm_emojis[emoji_name].emoji_url;
}

event.count = 1;
event.title = new_title;
event.emoji_alt_code = page_params.emoji_alt_code;
context.count = 1;
context.title = new_title;
context.emoji_alt_code = page_params.emoji_alt_code;
context.emoji_name_css_class = emoji.emojis_name_to_css_class[emoji_name];

if (event.user.id === page_params.user_id) {
event.class = "message_reaction reacted";
context.class = "message_reaction reacted";
} else {
event.class = "message_reaction";
context.class = "message_reaction";
}

var new_reaction = $(templates.render('message_reaction', event));
var new_reaction = $(templates.render('message_reaction', context));

// Now insert it before the add button.
var reaction_button_element = exports.get_add_reaction_button(message_id);
Expand Down

0 comments on commit 791e489

Please sign in to comment.