mirror of https://github.com/zulip/zulip.git
frontend: Add basic user_status module.
So far this processes page_params, but it's otherwise an unused internal API.
This commit is contained in:
parent
a2614956d5
commit
d8d703af45
|
@ -197,6 +197,7 @@
|
|||
"user_groups": false,
|
||||
"user_pill": false,
|
||||
"user_search": false,
|
||||
"user_status": false,
|
||||
"util": false,
|
||||
"poll_widget": false,
|
||||
"widgetize": false,
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
set_global('channel', {});
|
||||
set_global('page_params', {});
|
||||
zrequire('user_status');
|
||||
|
||||
function initialize() {
|
||||
page_params.away_user_ids = [1, 2, 3];
|
||||
user_status.initialize();
|
||||
}
|
||||
|
||||
run_test('basics', () => {
|
||||
initialize();
|
||||
assert(user_status.is_away(2));
|
||||
assert(!user_status.is_away(99));
|
||||
|
||||
assert(!user_status.is_away(4));
|
||||
user_status.set_away(4);
|
||||
assert(user_status.is_away(4));
|
||||
user_status.revoke_away(4);
|
||||
assert(!user_status.is_away(4));
|
||||
});
|
||||
|
||||
run_test('server', () => {
|
||||
initialize();
|
||||
|
||||
var away_arg;
|
||||
|
||||
channel.post = (opts) => {
|
||||
away_arg = opts.data.away;
|
||||
assert.equal(opts.url, '/json/users/me/status');
|
||||
};
|
||||
|
||||
assert.equal(away_arg, undefined);
|
||||
|
||||
user_status.server_set_away();
|
||||
assert.equal(away_arg, true);
|
||||
|
||||
user_status.server_revoke_away();
|
||||
assert.equal(away_arg, false);
|
||||
});
|
|
@ -152,6 +152,7 @@ import "js/server_events_dispatch.js";
|
|||
import "js/zulip.js";
|
||||
import "js/presence.js";
|
||||
import "js/user_search.js";
|
||||
import "js/user_status.js";
|
||||
import "js/buddy_data.js";
|
||||
import "js/padded_widget.js";
|
||||
import "js/buddy_list.js";
|
||||
|
|
|
@ -297,6 +297,7 @@ $(function () {
|
|||
}
|
||||
server_events.initialize();
|
||||
people.initialize();
|
||||
user_status.initialize();
|
||||
compose_pm_pill.initialize();
|
||||
search_pill_widget.initialize();
|
||||
reload.initialize();
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
var user_status = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
var away_user_ids = new Dict();
|
||||
|
||||
exports.server_set_away = function () {
|
||||
channel.post({
|
||||
url: '/json/users/me/status',
|
||||
data: {away: true},
|
||||
idempotent: true,
|
||||
});
|
||||
};
|
||||
|
||||
exports.server_revoke_away = function () {
|
||||
channel.post({
|
||||
url: '/json/users/me/status',
|
||||
data: {away: false},
|
||||
idempotent: true,
|
||||
});
|
||||
};
|
||||
|
||||
exports.set_away = function (user_id) {
|
||||
away_user_ids.set(user_id, true);
|
||||
};
|
||||
|
||||
exports.revoke_away = function (user_id) {
|
||||
away_user_ids.del(user_id);
|
||||
};
|
||||
|
||||
exports.is_away = function (user_id) {
|
||||
return away_user_ids.has(user_id);
|
||||
};
|
||||
|
||||
exports.initialize = function () {
|
||||
_.each(page_params.away_user_ids, function (user_id) {
|
||||
away_user_ids.set(user_id, true);
|
||||
});
|
||||
|
||||
delete page_params.away_user_ids;
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
||||
}());
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = user_status;
|
||||
}
|
||||
window.user_status = user_status;
|
|
@ -83,6 +83,7 @@ enforce_fully_covered = {
|
|||
'static/js/user_groups.js',
|
||||
'static/js/user_pill.js',
|
||||
'static/js/user_search.js',
|
||||
'static/js/user_status.js',
|
||||
'static/js/util.js',
|
||||
'static/js/widgetize.js',
|
||||
'static/js/poll_widget.js',
|
||||
|
|
Loading…
Reference in New Issue