2016-12-02 13:23:23 +01:00
|
|
|
var reactions = (function () {
|
|
|
|
var exports = {};
|
|
|
|
|
2017-06-28 21:29:45 +02:00
|
|
|
exports.view = {}; // function namespace
|
|
|
|
|
2017-10-31 22:33:28 +01:00
|
|
|
exports.get_local_reaction_id = function (reaction_info) {
|
|
|
|
return [reaction_info.reaction_type,
|
|
|
|
reaction_info.emoji_name,
|
|
|
|
reaction_info.emoji_code].join(',');
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.get_reaction_info = function (reaction_id) {
|
|
|
|
var reaction_info = reaction_id.split(',');
|
|
|
|
return {
|
|
|
|
reaction_type: reaction_info[0],
|
|
|
|
emoji_name: reaction_info[1],
|
|
|
|
emoji_code: reaction_info[2],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-09-18 22:06:39 +02:00
|
|
|
exports.open_reactions_popover = function () {
|
|
|
|
var message = current_msg_list.selected_message();
|
|
|
|
var target = $(current_msg_list.selected_row()).find(".actions_hover")[0];
|
|
|
|
if (!message.sent_by_me) {
|
|
|
|
target = $(current_msg_list.selected_row()).find(".reaction_button")[0];
|
|
|
|
}
|
|
|
|
emoji_picker.toggle_emoji_popover(target, current_msg_list.selected_id());
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2017-10-31 22:33:28 +01:00
|
|
|
exports.current_user_has_reacted_to_emoji = function (message, emoji_code, type) {
|
|
|
|
var user_id = page_params.user_id;
|
|
|
|
return _.any(message.reactions, function (r) {
|
|
|
|
return (r.user.id === user_id) &&
|
|
|
|
(r.reaction_type === type) &&
|
|
|
|
(r.emoji_code === emoji_code);
|
|
|
|
});
|
|
|
|
};
|
2017-10-08 17:02:14 +02:00
|
|
|
|
2017-10-31 22:33:28 +01:00
|
|
|
function get_message(message_id) {
|
|
|
|
var message = message_store.get(message_id);
|
|
|
|
if (!message) {
|
|
|
|
blueslip.error('reactions: Bad message id: ' + message_id);
|
2016-12-02 13:23:23 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-10-31 22:33:28 +01:00
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2017-12-19 00:55:40 +01:00
|
|
|
function create_reaction(message_id, reaction_info) {
|
|
|
|
return {
|
|
|
|
message_id: message_id,
|
|
|
|
user: {
|
|
|
|
user_id: page_params.user_id,
|
|
|
|
id: page_params.user_id,
|
|
|
|
},
|
|
|
|
local_id: exports.get_local_reaction_id(reaction_info),
|
|
|
|
reaction_type: reaction_info.reaction_type,
|
|
|
|
emoji_name: reaction_info.emoji_name,
|
|
|
|
emoji_code: reaction_info.emoji_code,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_ui_and_send_reaction_ajax(message_id, reaction_info) {
|
2017-10-31 22:33:28 +01:00
|
|
|
var message = get_message(message_id);
|
|
|
|
var has_reacted = exports.current_user_has_reacted_to_emoji(
|
|
|
|
message,
|
|
|
|
reaction_info.emoji_code,
|
|
|
|
reaction_info.reaction_type
|
|
|
|
);
|
|
|
|
var operation = has_reacted ? 'remove' : 'add';
|
2017-12-19 00:55:40 +01:00
|
|
|
var reaction = create_reaction(message_id, reaction_info);
|
|
|
|
|
|
|
|
if (operation === "add") {
|
|
|
|
exports.add_reaction(reaction);
|
|
|
|
} else {
|
|
|
|
exports.remove_reaction(reaction);
|
|
|
|
}
|
2017-10-31 22:33:28 +01:00
|
|
|
|
2016-12-02 13:23:23 +01:00
|
|
|
var args = {
|
2017-10-31 22:33:28 +01:00
|
|
|
url: '/json/messages/' + message_id + '/reactions',
|
|
|
|
data: reaction_info,
|
2016-12-02 13:23:23 +01:00
|
|
|
success: function () {},
|
|
|
|
error: function (xhr) {
|
|
|
|
var response = channel.xhr_error_message("Error sending reaction", xhr);
|
2017-03-24 23:46:20 +01:00
|
|
|
// Errors are somewhat commmon here, due to race conditions
|
|
|
|
// where the user tries to add/remove the reaction when there is already
|
|
|
|
// an in-flight request. We eventually want to make this a blueslip
|
|
|
|
// error, rather than a warning, but we need to implement either
|
|
|
|
// #4291 or #4295 first.
|
|
|
|
blueslip.warn(response);
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-12-02 13:23:23 +01:00
|
|
|
};
|
|
|
|
if (operation === 'add') {
|
2017-10-31 22:33:28 +01:00
|
|
|
channel.post(args);
|
2016-12-02 13:23:23 +01:00
|
|
|
} else if (operation === 'remove') {
|
|
|
|
channel.del(args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-31 22:33:28 +01:00
|
|
|
function get_user_list_for_message_reaction(message, local_id) {
|
2016-12-02 13:23:23 +01:00
|
|
|
var matching_reactions = message.reactions.filter(function (reaction) {
|
2017-10-31 22:33:28 +01:00
|
|
|
return reaction.local_id === local_id;
|
2016-12-02 13:23:23 +01:00
|
|
|
});
|
|
|
|
return matching_reactions.map(function (reaction) {
|
|
|
|
return reaction.user.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-29 21:18:59 +02:00
|
|
|
exports.toggle_emoji_reaction = function (message_id, emoji_name) {
|
2017-05-11 17:00:24 +02:00
|
|
|
// This toggles the current user's reaction to the clicked emoji.
|
2017-10-31 22:33:28 +01:00
|
|
|
var reaction_info = {
|
|
|
|
emoji_name: emoji_name,
|
|
|
|
};
|
2017-05-11 17:00:24 +02:00
|
|
|
|
2017-10-31 22:33:28 +01:00
|
|
|
if (emoji.all_realm_emojis.hasOwnProperty(emoji_name)) {
|
|
|
|
if (emoji_name === 'zulip') {
|
|
|
|
reaction_info.reaction_type = 'zulip_extra_emoji';
|
|
|
|
} else {
|
|
|
|
reaction_info.reaction_type = 'realm_emoji';
|
|
|
|
}
|
2017-12-15 16:54:07 +01:00
|
|
|
reaction_info.emoji_code = emoji.active_realm_emojis[emoji_name].id;
|
2017-10-31 22:33:28 +01:00
|
|
|
} else if (emoji_codes.name_to_codepoint.hasOwnProperty(emoji_name)) {
|
|
|
|
reaction_info.reaction_type = 'unicode_emoji';
|
|
|
|
reaction_info.emoji_code = emoji_codes.name_to_codepoint[emoji_name];
|
|
|
|
} else {
|
|
|
|
blueslip.warn('Bad emoji name: ' + emoji_name);
|
2017-05-11 17:00:24 +02:00
|
|
|
return;
|
2016-12-02 13:23:23 +01:00
|
|
|
}
|
2017-05-11 17:00:24 +02:00
|
|
|
|
2017-12-19 00:55:40 +01:00
|
|
|
update_ui_and_send_reaction_ajax(message_id, reaction_info);
|
2017-05-29 21:36:24 +02:00
|
|
|
|
|
|
|
// The next line isn't always necessary, but it is harmless/quick
|
|
|
|
// when no popovers are there.
|
|
|
|
emoji_picker.hide_emoji_popover();
|
2016-12-02 13:23:23 +01:00
|
|
|
};
|
|
|
|
|
2017-10-31 22:33:28 +01:00
|
|
|
exports.process_reaction_click = function (message_id, local_id) {
|
|
|
|
var reaction_info = exports.get_reaction_info(local_id);
|
|
|
|
|
2017-12-19 00:55:40 +01:00
|
|
|
update_ui_and_send_reaction_ajax(message_id, reaction_info);
|
2017-10-31 22:33:28 +01:00
|
|
|
};
|
|
|
|
|
2016-12-02 13:23:23 +01:00
|
|
|
function full_name(user_id) {
|
|
|
|
if (user_id === page_params.user_id) {
|
|
|
|
return 'You (click to remove)';
|
|
|
|
}
|
|
|
|
return people.get_person_from_user_id(user_id).full_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
function generate_title(emoji_name, user_ids) {
|
|
|
|
var i = user_ids.indexOf(page_params.user_id);
|
|
|
|
if (i !== -1) {
|
|
|
|
// Move current user's id to start of list
|
|
|
|
user_ids.splice(i, 1);
|
|
|
|
user_ids.unshift(page_params.user_id);
|
|
|
|
}
|
|
|
|
var reacted_with_string = ' reacted with :' + emoji_name + ':';
|
|
|
|
var user_names = user_ids.map(full_name);
|
|
|
|
if (user_names.length === 1) {
|
|
|
|
return user_names[0] + reacted_with_string;
|
|
|
|
}
|
|
|
|
return _.initial(user_names).join(', ') + ' and ' + _.last(user_names) + reacted_with_string;
|
|
|
|
}
|
|
|
|
|
2017-05-29 16:31:51 +02:00
|
|
|
exports.get_reaction_section = function (message_id) {
|
|
|
|
var message_element = $('.message_table').find("[zid='" + message_id + "']");
|
|
|
|
var section = message_element.find('.message_reactions');
|
|
|
|
return section;
|
|
|
|
};
|
|
|
|
|
2017-10-31 22:33:28 +01:00
|
|
|
exports.find_reaction = function (message_id, local_id) {
|
2017-05-29 16:31:51 +02:00
|
|
|
var reaction_section = exports.get_reaction_section(message_id);
|
2017-10-31 22:33:28 +01:00
|
|
|
var reaction = reaction_section.find("[data-reaction-id='" + local_id + "']");
|
2017-05-29 16:31:51 +02:00
|
|
|
return reaction;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.get_add_reaction_button = function (message_id) {
|
|
|
|
var reaction_section = exports.get_reaction_section(message_id);
|
|
|
|
var add_button = reaction_section.find('.reaction_button');
|
|
|
|
return add_button;
|
|
|
|
};
|
|
|
|
|
2017-05-29 19:24:31 +02:00
|
|
|
exports.set_reaction_count = function (reaction, count) {
|
|
|
|
var count_element = reaction.find('.message_reaction_count');
|
|
|
|
count_element.html(count);
|
|
|
|
};
|
|
|
|
|
2016-12-02 13:23:23 +01:00
|
|
|
exports.add_reaction = function (event) {
|
2017-05-29 16:31:51 +02:00
|
|
|
var message_id = event.message_id;
|
|
|
|
var message = message_store.get(message_id);
|
2017-10-31 22:33:28 +01:00
|
|
|
|
2017-01-17 09:10:41 +01:00
|
|
|
if (message === undefined) {
|
|
|
|
// If we don't have the message in cache, do nothing; if we
|
|
|
|
// ever fetch it from the server, it'll come with the
|
|
|
|
// latest reactions attached
|
|
|
|
return;
|
|
|
|
}
|
2017-05-29 16:31:51 +02:00
|
|
|
|
2017-12-19 00:55:40 +01:00
|
|
|
var reacted = exports.current_user_has_reacted_to_emoji(message,
|
|
|
|
event.emoji_code,
|
|
|
|
event.reaction_type);
|
|
|
|
if (reacted && (event.user.user_id === page_params.user_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-29 16:31:51 +02:00
|
|
|
event.user.id = event.user.user_id;
|
2017-10-31 22:33:28 +01:00
|
|
|
event.local_id = exports.get_local_reaction_id(event);
|
2017-05-29 16:31:51 +02:00
|
|
|
|
2017-01-17 09:10:41 +01:00
|
|
|
message.reactions.push(event);
|
2017-05-29 16:31:51 +02:00
|
|
|
|
2017-10-31 22:33:28 +01:00
|
|
|
var user_list = get_user_list_for_message_reaction(message, event.local_id);
|
|
|
|
var opts = {
|
|
|
|
message_id: event.message_id,
|
|
|
|
reaction_type: event.reaction_type,
|
|
|
|
emoji_name: event.emoji_name,
|
|
|
|
emoji_code: event.emoji_code,
|
|
|
|
user_id: event.user.id,
|
|
|
|
};
|
2017-05-29 16:31:51 +02:00
|
|
|
|
|
|
|
if (user_list.length > 1) {
|
2017-10-31 22:33:28 +01:00
|
|
|
opts.user_list = user_list;
|
|
|
|
exports.view.update_existing_reaction(opts);
|
2016-12-02 13:23:23 +01:00
|
|
|
} else {
|
2017-10-31 22:33:28 +01:00
|
|
|
exports.view.insert_new_reaction(opts);
|
2016-12-02 13:23:23 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-28 20:10:05 +02:00
|
|
|
exports.view.update_existing_reaction = function (opts) {
|
2017-05-29 16:31:51 +02:00
|
|
|
// Our caller ensures that this message already has a reaction
|
|
|
|
// for this emoji and sets up our user_list. This function
|
|
|
|
// simply updates the DOM.
|
|
|
|
|
2017-06-28 20:10:05 +02:00
|
|
|
var message_id = opts.message_id;
|
|
|
|
var emoji_name = opts.emoji_name;
|
|
|
|
var user_list = opts.user_list;
|
|
|
|
var user_id = opts.user_id;
|
2017-10-31 22:33:28 +01:00
|
|
|
var local_id = exports.get_local_reaction_id(opts);
|
|
|
|
var reaction = exports.find_reaction(message_id, local_id);
|
2017-05-29 16:31:51 +02:00
|
|
|
|
2017-05-29 19:24:31 +02:00
|
|
|
exports.set_reaction_count(reaction, user_list.length);
|
2017-05-29 16:31:51 +02:00
|
|
|
|
|
|
|
var new_title = generate_title(emoji_name, user_list);
|
|
|
|
reaction.prop('title', new_title);
|
|
|
|
|
2017-06-28 20:10:05 +02:00
|
|
|
if (user_id === page_params.user_id) {
|
2017-05-29 16:31:51 +02:00
|
|
|
reaction.addClass("reacted");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-28 21:29:45 +02:00
|
|
|
exports.view.insert_new_reaction = function (opts) {
|
2017-05-29 16:31:51 +02:00
|
|
|
// Our caller ensures we are the first user to react to this
|
|
|
|
// message with this emoji, and it populates user_list for
|
|
|
|
// us. We then render the emoji/title/count and insert it
|
|
|
|
// before the add button.
|
|
|
|
|
2017-06-28 21:29:45 +02:00
|
|
|
var message_id = opts.message_id;
|
|
|
|
var emoji_name = opts.emoji_name;
|
2017-10-31 22:33:28 +01:00
|
|
|
var emoji_code = opts.emoji_code;
|
2017-06-28 21:29:45 +02:00
|
|
|
var user_id = opts.user_id;
|
|
|
|
var user_list = [user_id];
|
2017-05-29 16:31:51 +02:00
|
|
|
|
2017-06-28 21:07:26 +02:00
|
|
|
var context = {
|
|
|
|
message_id: message_id,
|
|
|
|
emoji_name: emoji_name,
|
2017-10-31 22:33:28 +01:00
|
|
|
emoji_code: emoji_code,
|
2017-06-28 21:07:26 +02:00
|
|
|
};
|
|
|
|
|
2017-05-29 16:31:51 +02:00
|
|
|
var new_title = generate_title(emoji_name, user_list);
|
|
|
|
|
2017-10-31 22:33:28 +01:00
|
|
|
if (opts.reaction_type !== 'unicode_emoji') {
|
2017-06-28 21:07:26 +02:00
|
|
|
context.is_realm_emoji = true;
|
2017-12-15 16:54:07 +01:00
|
|
|
context.url = emoji.all_realm_emojis[emoji_name].emoji_url;
|
2017-05-29 16:31:51 +02:00
|
|
|
}
|
|
|
|
|
2017-06-28 21:07:26 +02:00
|
|
|
context.count = 1;
|
|
|
|
context.title = new_title;
|
2017-10-31 22:33:28 +01:00
|
|
|
context.local_id = exports.get_local_reaction_id(opts);
|
2018-01-02 13:02:13 +01:00
|
|
|
context.emoji_alt_code = (page_params.emojiset === 'text');
|
2017-05-29 16:31:51 +02:00
|
|
|
|
2017-06-28 21:29:45 +02:00
|
|
|
if (opts.user_id === page_params.user_id) {
|
2017-06-28 21:07:26 +02:00
|
|
|
context.class = "message_reaction reacted";
|
2017-05-29 16:31:51 +02:00
|
|
|
} else {
|
2017-06-28 21:07:26 +02:00
|
|
|
context.class = "message_reaction";
|
2017-05-29 16:31:51 +02:00
|
|
|
}
|
|
|
|
|
2017-06-28 21:07:26 +02:00
|
|
|
var new_reaction = $(templates.render('message_reaction', context));
|
2017-05-29 16:31:51 +02:00
|
|
|
|
|
|
|
// Now insert it before the add button.
|
|
|
|
var reaction_button_element = exports.get_add_reaction_button(message_id);
|
|
|
|
new_reaction.insertBefore(reaction_button_element);
|
|
|
|
};
|
|
|
|
|
2016-12-02 13:23:23 +01:00
|
|
|
exports.remove_reaction = function (event) {
|
2017-10-31 22:33:28 +01:00
|
|
|
var reaction_type = event.reaction_type;
|
2016-12-02 13:23:23 +01:00
|
|
|
var emoji_name = event.emoji_name;
|
2017-10-31 22:33:28 +01:00
|
|
|
var emoji_code = event.emoji_code;
|
2016-12-02 13:23:23 +01:00
|
|
|
var message_id = event.message_id;
|
|
|
|
var user_id = event.user.user_id;
|
|
|
|
var i = -1;
|
2017-01-17 09:10:41 +01:00
|
|
|
var message = message_store.get(message_id);
|
2017-10-31 22:33:28 +01:00
|
|
|
var local_id = exports.get_local_reaction_id(event);
|
2017-05-29 16:56:13 +02:00
|
|
|
|
2017-01-17 09:10:41 +01:00
|
|
|
if (message === undefined) {
|
|
|
|
// If we don't have the message in cache, do nothing; if we
|
|
|
|
// ever fetch it from the server, it'll come with the
|
|
|
|
// latest reactions attached
|
|
|
|
return;
|
|
|
|
}
|
2017-05-29 16:56:13 +02:00
|
|
|
|
2017-12-19 00:55:40 +01:00
|
|
|
var not_reacted = !exports.current_user_has_reacted_to_emoji(message,
|
|
|
|
emoji_code,
|
|
|
|
reaction_type);
|
|
|
|
if (not_reacted && (event.user.user_id === page_params.user_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-29 16:56:13 +02:00
|
|
|
// Do the data part first:
|
|
|
|
// Remove reactions from our message object.
|
2016-12-02 13:23:23 +01:00
|
|
|
_.each(message.reactions, function (reaction, index) {
|
2017-10-31 22:33:28 +01:00
|
|
|
if (reaction.local_id === local_id && reaction.user.id === user_id) {
|
2016-12-02 13:23:23 +01:00
|
|
|
i = index;
|
|
|
|
}
|
|
|
|
});
|
2017-05-29 16:56:13 +02:00
|
|
|
|
2016-12-02 13:23:23 +01:00
|
|
|
if (i !== -1) {
|
|
|
|
message.reactions.splice(i, 1);
|
|
|
|
}
|
2017-05-29 16:56:13 +02:00
|
|
|
|
|
|
|
// Compute the new user list for this reaction.
|
2017-10-31 22:33:28 +01:00
|
|
|
var user_list = get_user_list_for_message_reaction(message, local_id);
|
2017-05-29 16:56:13 +02:00
|
|
|
|
2017-06-28 21:41:35 +02:00
|
|
|
exports.view.remove_reaction({
|
|
|
|
message_id: message_id,
|
2017-10-31 22:33:28 +01:00
|
|
|
reaction_type: reaction_type,
|
2017-06-28 21:41:35 +02:00
|
|
|
emoji_name: emoji_name,
|
2017-10-31 22:33:28 +01:00
|
|
|
emoji_code: emoji_code,
|
2017-06-28 21:41:35 +02:00
|
|
|
user_list: user_list,
|
|
|
|
user_id: user_id,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.view.remove_reaction = function (opts) {
|
|
|
|
|
|
|
|
var message_id = opts.message_id;
|
|
|
|
var emoji_name = opts.emoji_name;
|
|
|
|
var user_list = opts.user_list;
|
|
|
|
var user_id = opts.user_id;
|
2017-10-31 22:33:28 +01:00
|
|
|
var local_id = exports.get_local_reaction_id(opts);
|
|
|
|
var reaction = exports.find_reaction(message_id, local_id);
|
2017-05-29 16:56:13 +02:00
|
|
|
|
|
|
|
if (user_list.length === 0) {
|
|
|
|
// If this user was the only one reacting for this emoji, we simply
|
|
|
|
// remove the reaction and exit.
|
|
|
|
reaction.remove();
|
|
|
|
return;
|
2017-02-13 07:51:40 +01:00
|
|
|
}
|
2017-05-29 16:56:13 +02:00
|
|
|
|
|
|
|
// The emoji still has reactions from other users, so we need to update
|
|
|
|
// the title/count and, if the user is the current user, turn off the
|
|
|
|
// "reacted" class.
|
|
|
|
|
|
|
|
var new_title = generate_title(emoji_name, user_list);
|
|
|
|
reaction.prop('title', new_title);
|
|
|
|
|
2017-05-29 19:24:31 +02:00
|
|
|
exports.set_reaction_count(reaction, user_list.length);
|
2017-05-29 16:56:13 +02:00
|
|
|
|
|
|
|
if (user_id === page_params.user_id) {
|
|
|
|
reaction.removeClass("reacted");
|
2016-12-02 13:23:23 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.get_emojis_used_by_user_for_message_id = function (message_id) {
|
|
|
|
var user_id = page_params.user_id;
|
|
|
|
var message = message_store.get(message_id);
|
|
|
|
var reactions_by_user = message.reactions.filter(function (reaction) {
|
|
|
|
return reaction.user.id === user_id;
|
|
|
|
});
|
|
|
|
return reactions_by_user.map(function (reaction) {
|
|
|
|
return reaction.emoji_name;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.get_message_reactions = function (message) {
|
|
|
|
var message_reactions = new Dict();
|
|
|
|
_.each(message.reactions, function (reaction) {
|
2017-03-26 20:38:47 +02:00
|
|
|
var user_id = reaction.user.id;
|
2017-10-31 22:33:28 +01:00
|
|
|
reaction.local_id = exports.get_local_reaction_id(reaction);
|
2017-03-26 20:38:47 +02:00
|
|
|
if (!people.is_known_user_id(user_id)) {
|
|
|
|
blueslip.warn('Unknown user_id ' + user_id +
|
|
|
|
'in reaction for message ' + message.id);
|
|
|
|
return;
|
|
|
|
}
|
2017-05-01 07:29:56 +02:00
|
|
|
reaction.user_ids = [];
|
|
|
|
var collapsed_reaction = message_reactions.setdefault(
|
2017-10-31 22:33:28 +01:00
|
|
|
reaction.local_id,
|
2017-05-01 07:29:56 +02:00
|
|
|
_.omit(reaction, 'user')
|
|
|
|
);
|
|
|
|
collapsed_reaction.user_ids.push(user_id);
|
2016-12-02 13:23:23 +01:00
|
|
|
});
|
|
|
|
var reactions = message_reactions.items().map(function (item) {
|
2017-05-01 07:29:56 +02:00
|
|
|
var reaction = item[1];
|
2017-10-31 22:33:28 +01:00
|
|
|
reaction.local_id = reaction.local_id;
|
|
|
|
reaction.reaction_type = reaction.reaction_type;
|
|
|
|
reaction.emoji_name = reaction.emoji_name;
|
|
|
|
reaction.emoji_code = reaction.emoji_code;
|
2017-05-01 07:29:56 +02:00
|
|
|
reaction.count = reaction.user_ids.length;
|
|
|
|
reaction.title = generate_title(reaction.emoji_name, reaction.user_ids);
|
2018-01-02 13:02:13 +01:00
|
|
|
reaction.emoji_alt_code = (page_params.emojiset === 'text');
|
2017-05-01 07:29:56 +02:00
|
|
|
|
|
|
|
if (reaction.reaction_type !== 'unicode_emoji') {
|
2016-12-02 13:23:23 +01:00
|
|
|
reaction.is_realm_emoji = true;
|
2017-06-23 23:41:41 +02:00
|
|
|
reaction.url = emoji.all_realm_emojis[reaction.emoji_name].emoji_url;
|
2016-12-02 13:23:23 +01:00
|
|
|
}
|
2017-05-01 07:29:56 +02:00
|
|
|
if (reaction.user_ids.indexOf(page_params.user_id) !== -1) {
|
2017-02-13 07:51:40 +01:00
|
|
|
reaction.class = "message_reaction reacted";
|
|
|
|
} else {
|
|
|
|
reaction.class = "message_reaction";
|
|
|
|
}
|
2016-12-02 13:23:23 +01:00
|
|
|
return reaction;
|
|
|
|
});
|
|
|
|
return reactions;
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = reactions;
|
|
|
|
}
|