mirror of https://github.com/zulip/zulip.git
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
|
import * as user_groups from "./user_groups";
|
||
|
|
||
|
function get_user_ids_from_user_groups(items) {
|
||
|
let user_ids = [];
|
||
|
const group_ids = items.map((item) => item.id).filter(Boolean);
|
||
|
for (const group_id of group_ids) {
|
||
|
const user_group = user_groups.get_user_group_from_id(group_id);
|
||
|
user_ids = user_ids.concat(Array.from(user_group.members));
|
||
|
}
|
||
|
return user_ids;
|
||
|
}
|
||
|
|
||
|
export function get_user_ids(pill_widget) {
|
||
|
const items = pill_widget.items();
|
||
|
let user_ids = get_user_ids_from_user_groups(items);
|
||
|
user_ids = Array.from(new Set(user_ids));
|
||
|
|
||
|
user_ids = user_ids.filter(Boolean);
|
||
|
return user_ids;
|
||
|
}
|
||
|
|
||
|
export function append_user_group(group, pill_widget) {
|
||
|
if (group !== undefined && group !== null) {
|
||
|
pill_widget.appendValidatedData({
|
||
|
display_value: group.name + ": " + group.members.size + " users",
|
||
|
id: group.id,
|
||
|
});
|
||
|
pill_widget.clear_text();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export function get_group_ids(pill_widget) {
|
||
|
const items = pill_widget.items();
|
||
|
let group_ids = items.map((item) => item.id);
|
||
|
group_ids = group_ids.filter(Boolean);
|
||
|
|
||
|
return group_ids;
|
||
|
}
|
||
|
|
||
|
export function filter_taken_groups(items, pill_widget) {
|
||
|
const taken_group_ids = get_group_ids(pill_widget);
|
||
|
items = items.filter((item) => !taken_group_ids.includes(item.id));
|
||
|
return items;
|
||
|
}
|
||
|
|
||
|
export function typeahead_source(pill_widget) {
|
||
|
const groups = user_groups.get_realm_user_groups();
|
||
|
return filter_taken_groups(groups, pill_widget);
|
||
|
}
|