From 650780463782bd679e3f195b61a3153a345a6f5b Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 19 Dec 2018 20:16:03 +0000 Subject: [PATCH] status: buddy list: Add basic UI to show away status. Right now we do very simple things: you: make the green circle empty them: make the circle empty and demote to last group --- frontend_tests/node_tests/buddy_data.js | 20 ++++++++++++++++++-- static/js/buddy_data.js | 25 +++++++++++++++++++++---- static/styles/right-sidebar.scss | 4 ++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/frontend_tests/node_tests/buddy_data.js b/frontend_tests/node_tests/buddy_data.js index 8a820a8d92..f4e0c18da3 100644 --- a/frontend_tests/node_tests/buddy_data.js +++ b/frontend_tests/node_tests/buddy_data.js @@ -4,6 +4,7 @@ set_global('page_params', _page_params); zrequire('people'); zrequire('presence'); zrequire('util'); +zrequire('user_status'); zrequire('buddy_data'); zrequire('user_status'); @@ -76,6 +77,20 @@ function activate_people() { make_people(); activate_people(); +run_test('buddy_status', () => { + assert.equal(buddy_data.buddy_status(selma.user_id), 'active'); + user_status.set_away(selma.user_id); + assert.equal(buddy_data.buddy_status(selma.user_id), 'away_them'); + user_status.revoke_away(selma.user_id); + assert.equal(buddy_data.buddy_status(selma.user_id), 'active'); + + assert.equal(buddy_data.buddy_status(me.user_id), 'active'); + user_status.set_away(me.user_id); + assert.equal(buddy_data.buddy_status(me.user_id), 'away_me'); + user_status.revoke_away(me.user_id); + assert.equal(buddy_data.buddy_status(me.user_id), 'active'); +}); + run_test('simple search', () => { const user_ids = buddy_data.get_filtered_and_sorted_user_ids('sel'); @@ -137,7 +152,8 @@ run_test('level', () => { user_status.set_away(me.user_id); user_status.set_away(selma.user_id); - // This will change soon for Selma. + // Selma gets demoted to level 3, but "me" + // stays in level 0. assert.equal(buddy_data.level(me.user_id), 0); - assert.equal(buddy_data.level(selma.user_id), 1); + assert.equal(buddy_data.level(selma.user_id), 3); }); diff --git a/static/js/buddy_data.js b/static/js/buddy_data.js index e9a381c3ff..ca47d9fc32 100644 --- a/static/js/buddy_data.js +++ b/static/js/buddy_data.js @@ -14,6 +14,8 @@ var exports = {}; exports.max_size_before_shrinking = 600; var presence_descriptions = { + away_me: 'is away', + away_them: 'is away', active: 'is active', idle: 'is not active', }; @@ -36,18 +38,33 @@ exports.level = function (user_id) { return 0; } - var status = presence.get_status(user_id); + var status = exports.buddy_status(user_id); switch (status) { case 'active': return 1; case 'idle': return 2; + case 'away_them': + return 3; default: return 3; } }; +exports.buddy_status = function (user_id) { + if (user_status.is_away(user_id)) { + if (people.is_my_user_id(user_id)) { + return 'away_me'; + } + + return 'away_them'; + } + + // get active/idle/etc. + return presence.get_status(user_id); +}; + exports.compare_function = function (a, b) { var level_a = exports.level(a); var level_b = exports.level(b); @@ -106,7 +123,7 @@ function get_num_unread(user_id) { } exports.info_for = function (user_id) { - var status = presence.get_status(user_id); + var buddy_status = exports.buddy_status(user_id); var person = people.get_person_from_user_id(user_id); return { @@ -115,8 +132,8 @@ exports.info_for = function (user_id) { user_id: user_id, is_current_user: people.is_my_user_id(user_id), num_unread: get_num_unread(user_id), - type: status, - type_desc: presence_descriptions[status], + type: buddy_status, + type_desc: presence_descriptions[buddy_status], }; }; diff --git a/static/styles/right-sidebar.scss b/static/styles/right-sidebar.scss index af183ba2d5..d760da62e8 100644 --- a/static/styles/right-sidebar.scss +++ b/static/styles/right-sidebar.scss @@ -91,6 +91,10 @@ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ec7e18', GradientType=0 ); /* IE6-9; filters only work with hex colors */ } +// We show "away" users identically to long-gone +// users, but this may change. +.user_away_me .user-status-indicator, +.user_away_them .user-status-indicator, .user-status-indicator { background-color: none; border-color: hsl(0, 0%, 50%);