mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 20:02:15 +00:00
user status: Add frontend data layer for "status_text".
This sets up the frontend to handle "status_text" data like "out to lunch" or "in a meeting".
This commit is contained in:
@@ -4,7 +4,7 @@ zrequire('user_status');
|
||||
|
||||
function initialize() {
|
||||
page_params.user_status = {
|
||||
1: {away: true},
|
||||
1: {away: true, status_text: 'in a meeting'},
|
||||
2: {away: true},
|
||||
3: {away: true},
|
||||
};
|
||||
@@ -21,23 +21,38 @@ run_test('basics', () => {
|
||||
assert(user_status.is_away(4));
|
||||
user_status.revoke_away(4);
|
||||
assert(!user_status.is_away(4));
|
||||
|
||||
// use value from page_params
|
||||
assert.equal(user_status.get_status_text(1), 'in a meeting');
|
||||
|
||||
user_status.set_status_text({
|
||||
user_id: 2,
|
||||
status_text: 'out to lunch',
|
||||
});
|
||||
assert.equal(user_status.get_status_text(2), 'out to lunch');
|
||||
|
||||
user_status.set_status_text({
|
||||
user_id: 2,
|
||||
status_text: '',
|
||||
});
|
||||
assert.equal(user_status.get_status_text(2), undefined);
|
||||
});
|
||||
|
||||
run_test('server', () => {
|
||||
initialize();
|
||||
|
||||
var away_arg;
|
||||
var sent_data;
|
||||
|
||||
channel.post = (opts) => {
|
||||
away_arg = opts.data.away;
|
||||
sent_data = opts.data;
|
||||
assert.equal(opts.url, '/json/users/me/status');
|
||||
};
|
||||
|
||||
assert.equal(away_arg, undefined);
|
||||
assert.equal(sent_data, undefined);
|
||||
|
||||
user_status.server_set_away();
|
||||
assert.equal(away_arg, true);
|
||||
assert.deepEqual(sent_data, {away: true, status_text: undefined});
|
||||
|
||||
user_status.server_revoke_away();
|
||||
assert.equal(away_arg, false);
|
||||
assert.deepEqual(sent_data, {away: false, status_text: undefined});
|
||||
});
|
||||
|
||||
@@ -458,10 +458,19 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
|
||||
break;
|
||||
|
||||
case 'user_status':
|
||||
if (event.away) {
|
||||
activity.on_set_away(event.user_id);
|
||||
} else {
|
||||
activity.on_revoke_away(event.user_id);
|
||||
if (event.away !== undefined) {
|
||||
if (event.away) {
|
||||
activity.on_set_away(event.user_id);
|
||||
} else {
|
||||
activity.on_revoke_away(event.user_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (event.info !== undefined) {
|
||||
user_status.set_status_text({
|
||||
user_id: event.user_id,
|
||||
status_text: event.info,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3,21 +3,25 @@ var user_status = (function () {
|
||||
var exports = {};
|
||||
|
||||
var away_user_ids = new Dict();
|
||||
var user_info = new Dict();
|
||||
|
||||
exports.server_set_away = function () {
|
||||
exports.server_update = function (opts) {
|
||||
channel.post({
|
||||
url: '/json/users/me/status',
|
||||
data: {away: true},
|
||||
data: {
|
||||
away: opts.away,
|
||||
status_text: opts.status_text,
|
||||
},
|
||||
idempotent: true,
|
||||
});
|
||||
};
|
||||
|
||||
exports.server_set_away = function () {
|
||||
exports.server_update({away: true});
|
||||
};
|
||||
|
||||
exports.server_revoke_away = function () {
|
||||
channel.post({
|
||||
url: '/json/users/me/status',
|
||||
data: {away: false},
|
||||
idempotent: true,
|
||||
});
|
||||
exports.server_update({away: false});
|
||||
};
|
||||
|
||||
exports.set_away = function (user_id) {
|
||||
@@ -32,11 +36,28 @@ exports.is_away = function (user_id) {
|
||||
return away_user_ids.has(user_id);
|
||||
};
|
||||
|
||||
exports.get_status_text = function (user_id) {
|
||||
return user_info.get(user_id);
|
||||
};
|
||||
|
||||
exports.set_status_text = function (opts) {
|
||||
if (!opts.status_text) {
|
||||
user_info.del(opts.user_id);
|
||||
return;
|
||||
}
|
||||
|
||||
user_info.set(opts.user_id, opts.status_text);
|
||||
};
|
||||
|
||||
exports.initialize = function () {
|
||||
_.each(page_params.user_status, function (dct, user_id) {
|
||||
if (dct.away) {
|
||||
away_user_ids.set(user_id, true);
|
||||
}
|
||||
|
||||
if (dct.status_text) {
|
||||
user_info.set(user_id, dct.status_text);
|
||||
}
|
||||
});
|
||||
|
||||
delete page_params.user_status;
|
||||
|
||||
Reference in New Issue
Block a user