mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
refactor: Use a Set for away_user_ids.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
set_global('blueslip', global.make_zblueslip());
|
||||||
set_global('channel', {});
|
set_global('channel', {});
|
||||||
set_global('page_params', {});
|
set_global('page_params', {});
|
||||||
zrequire('user_status');
|
zrequire('user_status');
|
||||||
@@ -70,3 +71,9 @@ run_test('server', () => {
|
|||||||
success();
|
success();
|
||||||
assert(called);
|
assert(called);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
run_test('defensive checks', () => {
|
||||||
|
blueslip.set_test_data('error', 'need ints for user_id');
|
||||||
|
user_status.set_away('string');
|
||||||
|
user_status.revoke_away('string');
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const Dict = require('./dict').Dict;
|
|
||||||
const IntDict = require('./int_dict').IntDict;
|
const IntDict = require('./int_dict').IntDict;
|
||||||
|
|
||||||
const away_user_ids = new Dict();
|
const away_user_ids = new Set();
|
||||||
const user_info = new IntDict();
|
const user_info = new IntDict();
|
||||||
|
|
||||||
exports.server_update = function (opts) {
|
exports.server_update = function (opts) {
|
||||||
@@ -29,11 +28,17 @@ exports.server_revoke_away = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.set_away = function (user_id) {
|
exports.set_away = function (user_id) {
|
||||||
away_user_ids.set(user_id, true);
|
if (typeof user_id !== 'number') {
|
||||||
|
blueslip.error('need ints for user_id');
|
||||||
|
}
|
||||||
|
away_user_ids.add(user_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.revoke_away = function (user_id) {
|
exports.revoke_away = function (user_id) {
|
||||||
away_user_ids.del(user_id);
|
if (typeof user_id !== 'number') {
|
||||||
|
blueslip.error('need ints for user_id');
|
||||||
|
}
|
||||||
|
away_user_ids.delete(user_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.is_away = function (user_id) {
|
exports.is_away = function (user_id) {
|
||||||
@@ -60,7 +65,7 @@ exports.initialize = function () {
|
|||||||
const user_id = parseInt(str_user_id, 10);
|
const user_id = parseInt(str_user_id, 10);
|
||||||
|
|
||||||
if (dct.away) {
|
if (dct.away) {
|
||||||
away_user_ids.set(user_id, true);
|
away_user_ids.add(user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dct.status_text) {
|
if (dct.status_text) {
|
||||||
|
|||||||
Reference in New Issue
Block a user