mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 09:27:43 +00:00
refactor: Add util.sorted_ids().
We borrowed this from typing_data.js and gave it a slightly different name (sorted -> sorted_ids).
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
zrequire("util");
|
||||||
zrequire("typing_data");
|
zrequire("typing_data");
|
||||||
|
|
||||||
(function test_basics() {
|
(function test_basics() {
|
||||||
|
|||||||
@@ -10,20 +10,8 @@ function to_int(s) {
|
|||||||
return parseInt(s, 10);
|
return parseInt(s, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sorted(user_ids) {
|
|
||||||
// This mapping makes sure we are using ints, and
|
|
||||||
// it also makes sure we don't mutate the list.
|
|
||||||
var id_list = _.map(user_ids, to_int);
|
|
||||||
id_list.sort(function (a, b) {
|
|
||||||
return a - b;
|
|
||||||
});
|
|
||||||
id_list = _.uniq(id_list, true);
|
|
||||||
|
|
||||||
return id_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_key(group) {
|
function get_key(group) {
|
||||||
var ids = sorted(group);
|
var ids = util.sorted_ids(group);
|
||||||
return ids.join(',');
|
return ids.join(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +22,7 @@ exports.add_typist = function (group, typist) {
|
|||||||
if (!_.contains(current, typist)) {
|
if (!_.contains(current, typist)) {
|
||||||
current.push(typist);
|
current.push(typist);
|
||||||
}
|
}
|
||||||
typist_dct.set(key, sorted(current));
|
typist_dct.set(key, util.sorted_ids(current));
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.remove_typist = function (group, typist) {
|
exports.remove_typist = function (group, typist) {
|
||||||
@@ -61,7 +49,7 @@ exports.get_group_typists = function (group) {
|
|||||||
|
|
||||||
exports.get_all_typists = function () {
|
exports.get_all_typists = function () {
|
||||||
var typists = _.flatten(typist_dct.values(), true);
|
var typists = _.flatten(typist_dct.values(), true);
|
||||||
typists = sorted(typists);
|
typists = util.sorted_ids(typists);
|
||||||
typists = _.uniq(typists, true);
|
typists = _.uniq(typists, true);
|
||||||
return typists;
|
return typists;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -270,6 +270,22 @@ exports.emoji_prefix_sort = function (query, objs, get_item) {
|
|||||||
return { matches: popular_emoji_matches.concat(other_emoji_matches), rest: prefix_sort.rest };
|
return { matches: popular_emoji_matches.concat(other_emoji_matches), rest: prefix_sort.rest };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function to_int(s) {
|
||||||
|
return parseInt(s, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.sorted_ids = function (ids) {
|
||||||
|
// This mapping makes sure we are using ints, and
|
||||||
|
// it also makes sure we don't mutate the list.
|
||||||
|
var id_list = _.map(ids, to_int);
|
||||||
|
id_list.sort(function (a, b) {
|
||||||
|
return a - b;
|
||||||
|
});
|
||||||
|
id_list = _.uniq(id_list, true);
|
||||||
|
|
||||||
|
return id_list;
|
||||||
|
};
|
||||||
|
|
||||||
return exports;
|
return exports;
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user