reactions.js: Refactor reaction_popover_reaction_on_click.

This commit is contained in:
Joshua Pan
2017-03-19 01:38:01 +00:00
committed by Tim Abbott
parent 356f57c831
commit c8f2da3f3e

View File

@@ -46,23 +46,16 @@ exports.message_reaction_on_click = function (message_id, emoji_name) {
send_reaction_ajax(message_id, emoji_name, operation); send_reaction_ajax(message_id, emoji_name, operation);
}; };
function reaction_popover_reaction_on_click() { exports.toggle_reaction = function (message_id, emoji_name) {
// When an emoji is clicked in the popover,
// if the user has reacted to this message with this emoji
// the reaction is removed
// otherwise, the reaction is added
var emoji_name = this.title;
var message_id = $(this).parent().attr('data-message-id');
var user_list = get_user_list_for_message_reaction(message_id, emoji_name); var user_list = get_user_list_for_message_reaction(message_id, emoji_name);
var operation = 'add'; var operation = 'add';
if (user_list.indexOf(page_params.user_id) !== -1) { if (user_list.indexOf(page_params.user_id) !== -1) {
// User has reacted with this emoji to this message // User has reacted with this emoji to this message
$(this).removeClass('reacted');
operation = 'remove'; operation = 'remove';
} }
send_reaction_ajax(message_id, emoji_name, operation); send_reaction_ajax(message_id, emoji_name, operation);
popovers.hide_reactions_popover(); popovers.hide_reactions_popover();
} };
function filter_emojis() { function filter_emojis() {
var elt = $(".reaction-popover-filter").expectOne(); var elt = $(".reaction-popover-filter").expectOne();
@@ -80,7 +73,20 @@ function filter_emojis() {
} }
} }
$(document).on('click', '.reaction-popover-reaction', reaction_popover_reaction_on_click); $(document).on('click', '.reaction-popover-reaction', function() {
// When an emoji is clicked in the popover,
// if the user has reacted to this message with this emoji
// the reaction is removed
// otherwise, the reaction is added
var emoji_name = this.title;
var message_id = $(this).parent().attr('data-message-id');
var user_list = get_user_list_for_message_reaction(message_id, emoji_name);
if (user_list.indexOf(page_params.user_id) !== -1) {
$(this).removeClass('reacted');
}
exports.toggle_reaction(message_id, emoji_name);
});
$(document).on('input', '.reaction-popover-filter', filter_emojis); $(document).on('input', '.reaction-popover-filter', filter_emojis);
function full_name(user_id) { function full_name(user_id) {