diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.js index fa72264733..fecfad9ead 100644 --- a/frontend_tests/node_tests/popovers.js +++ b/frontend_tests/node_tests/popovers.js @@ -143,6 +143,8 @@ run_test('sender_hover', () => { case 'user_info_popover_content': assert.deepEqual(opts, { + can_set_away: false, + can_revoke_away: false, user_full_name: 'Alice Smith', user_email: 'alice@example.com', user_id: 42, diff --git a/static/js/popovers.js b/static/js/popovers.js index 43fa681cf2..13bee01fb5 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -114,10 +114,25 @@ function calculate_info_popover_placement(size, elt) { function render_user_info_popover(user, popover_element, is_sender_popover, private_msg_class, template_class, popover_placement) { + var is_me = people.is_my_user_id(user.user_id); + + var can_set_away = false; + var can_revoke_away = false; + + if (is_me) { + if (user_status.is_away(user.user_id)) { + can_revoke_away = true; + } else { + can_set_away = true; + } + } + var args = { + can_revoke_away: can_revoke_away, + can_set_away: can_set_away, is_active: people.is_active_user_for_popover(user.user_id), is_bot: user.is_bot, - is_me: people.is_current_user(user.email), + is_me: is_me, is_sender_popover: is_sender_popover, pm_with_uri: hash_util.pm_with_uri(user.email), presence_status: presence.get_status(user.user_id), @@ -761,6 +776,20 @@ exports.register_click_handlers = function () { e.preventDefault(); }); + $('body').on('click', '.set_away_status', function (e) { + popovers.hide_all(); + user_status.server_set_away(); + e.stopPropagation(); + e.preventDefault(); + }); + + $('body').on('click', '.revoke_away_status', function (e) { + popovers.hide_all(); + user_status.server_revoke_away(); + e.stopPropagation(); + e.preventDefault(); + }); + $('#user_presences').on('click', 'span.arrow', function (e) { e.stopPropagation(); diff --git a/static/templates/user_info_popover_content.handlebars b/static/templates/user_info_popover_content.handlebars index 84251c0866..075a806390 100644 --- a/static/templates/user_info_popover_content.handlebars +++ b/static/templates/user_info_popover_content.handlebars @@ -78,4 +78,18 @@ {{#tr this}}View messages sent{{/tr}} + {{#if can_set_away}} +