<commit_before>var subs = (function () {

var exports = {};

var stream_info = {}; // Maps lowercase stream name to stream properties object
// We fetch the stream colors asynchronous while the message feed is
// getting constructed, so we may need to go back and color streams
// that have already been rendered.
var initial_color_fetch = true;

var default_color = "#c2c2c2";
// Auto-assigned colors should be from the default palette so it's easy to undo
// changes, so if that pallete changes, change these colors.
var stream_assignment_colors = ["#76ce90", "#fae589", "#a6c7e5", "#e79ab5",
                                "#bfd56f", "#f4ae55", "#b0a5fd", "#addfe5",
                                "#f5ce6e", "#c2726a", "#94c849", "#bd86e5",
                                "#ee7e4a", "#a6dcbf", "#95a5fd", "#53a063",
                                "#9987e1", "#e4523d", "#c2c2c2", "#4f8de4",
                                "#c6a8ad", "#e7cc4d", "#c8bebf", "#a47462"];

// Clone stream_assignement_colors
var available_colors = stream_assignment_colors.slice(0);

var next_sub_id = 0;

function add_sub(stream_name, sub) {
    stream_info[stream_name.toLowerCase()] = sub;
}

function get_sub(stream_name) {
    return stream_info[stream_name.toLowerCase()];
}

// Classes which could be returned by get_color_class.
exports.color_classes = 'dark_background';

exports.stream_info = function (new_stream_info) {
    if (new_stream_info !== undefined) {
        stream_info = new_stream_info;
    } else {
        return stream_info;
    }
};

function pick_color() {
    if (available_colors.length === 0) {
        // We've used all the palette colors, so start re-using them.
        return stream_assignment_colors[exports.subscribed_streams().length
                                        % stream_assignment_colors.length];
    }

    return available_colors[0];
}

function mark_color_used(color) {
    var i;
    for (i = 0; i < available_colors.length; ++i) {
        if (available_colors[i] === color) {
            available_colors.splice(i, 1);
            return;
        }
    }
}

exports.subscribed_streams = function () {
    // TODO: Object.keys() compatibility
    var list = [];
    $.each(Object.keys(stream_info), function (idx, key) {
        var sub = stream_info[key];
        if (sub.subscribed) {
            list.push(sub.name);
        }
    });
    list.sort();
    return list;
};

exports.maybe_toggle_all_messages = function () {
    var show_all_messages = false;
    $.each(stream_info, function (idx, stream) {
        if (!stream.in_home_view) {
            show_all_messages = true;
            return false;
        }
    });

    var all_messages = $("#global_filters [data-name='all']")[0];
    if (!show_all_messages) {
        $(all_messages).addClass('hidden-filter');
    } else {
        $(all_messages).removeClass('hidden-filter');
    }
};

function should_render_subscribers() {
    return page_params.domain !== 'mit.edu';
}

function should_list_all_streams() {
    return page_params.domain !== 'mit.edu';
}

function update_table_stream_color(table, stream_name, color) {
    var color_class = exports.get_color_class(color);
    function fixup(elem) {
        elem.css("background-color", color)
            .removeClass(exports.color_classes)
            .addClass(color_class);
    }

    $.each(table.find(".stream_label"), function () {
        if ($(this).text() === stream_name) {
            fixup($(this).parent("td").parent("tr").prev("tr").nextUntil(".bookend_tr")
                         .children(".messagebox_colorblock,.message_header_colorblock"));
        }
    });
}

exports.stream_id = function (stream_name) {
    var sub = get_sub(stream_name);
    if (sub === undefined) {
        blueslip.error("Tried to get subs.stream_id for a stream user is not subscribed to!");
        return 0;
    }
    return parseInt(sub.id, 10);
};

exports.canonicalized_name = function (stream_name) {
   return stream_name.toString().toLowerCase();
};

function update_stream_sidebar_swatch_color(stream_name, color) {
    var id = exports.stream_id(stream_name);
    $("#stream_sidebar_swatch_" + id).css('background-color', color);
}

function update_historical_message_color(stream_name, color) {
    update_table_stream_color($(".focused_table"), stream_name, color);<commit_msg>When you change a stream color, also update the floating recipient bar if applicable.<commit_after>var subs = (function () {

var exports = {};

var stream_info = {}; // Maps lowercase stream name to stream properties object
// We fetch the stream colors asynchronous while the message feed is
// getting constructed, so we may need to go back and color streams
// that have already been rendered.
var initial_color_fetch = true;

var default_color = "#c2c2c2";
// Auto-assigned colors should be from the default palette so it's easy to undo
// changes, so if that pallete changes, change these colors.
var stream_assignment_colors = ["#76ce90", "#fae589", "#a6c7e5", "#e79ab5",
                                "#bfd56f", "#f4ae55", "#b0a5fd", "#addfe5",
                                "#f5ce6e", "#c2726a", "#94c849", "#bd86e5",
                                "#ee7e4a", "#a6dcbf", "#95a5fd", "#53a063",
                                "#9987e1", "#e4523d", "#c2c2c2", "#4f8de4",
                                "#c6a8ad", "#e7cc4d", "#c8bebf", "#a47462"];

// Clone stream_assignement_colors
var available_colors = stream_assignment_colors.slice(0);

var next_sub_id = 0;

function add_sub(stream_name, sub) {
    stream_info[stream_name.toLowerCase()] = sub;
}

function get_sub(stream_name) {
    return stream_info[stream_name.toLowerCase()];
}

// Classes which could be returned by get_color_class.
exports.color_classes = 'dark_background';

exports.stream_info = function (new_stream_info) {
    if (new_stream_info !== undefined) {
        stream_info = new_stream_info;
    } else {
        return stream_info;
    }
};

function pick_color() {
    if (available_colors.length === 0) {
        // We've used all the palette colors, so start re-using them.
        return stream_assignment_colors[exports.subscribed_streams().length
                                        % stream_assignment_colors.length];
    }

    return available_colors[0];
}

function mark_color_used(color) {
    var i;
    for (i = 0; i < available_colors.length; ++i) {
        if (available_colors[i] === color) {
            available_colors.splice(i, 1);
            return;
        }
    }
}

exports.subscribed_streams = function () {
    // TODO: Object.keys() compatibility
    var list = [];
    $.each(Object.keys(stream_info), function (idx, key) {
        var sub = stream_info[key];
        if (sub.subscribed) {
            list.push(sub.name);
        }
    });
    list.sort();
    return list;
};

exports.maybe_toggle_all_messages = function () {
    var show_all_messages = false;
    $.each(stream_info, function (idx, stream) {
        if (!stream.in_home_view) {
            show_all_messages = true;
            return false;
        }
    });

    var all_messages = $("#global_filters [data-name='all']")[0];
    if (!show_all_messages) {
        $(all_messages).addClass('hidden-filter');
    } else {
        $(all_messages).removeClass('hidden-filter');
    }
};

function should_render_subscribers() {
    return page_params.domain !== 'mit.edu';
}

function should_list_all_streams() {
    return page_params.domain !== 'mit.edu';
}

function update_table_stream_color(table, stream_name, color) {
    var color_class = exports.get_color_class(color);
    function fixup(elem) {
        elem.css("background-color", color)
            .removeClass(exports.color_classes)
            .addClass(color_class);
    }

    $.each($("#floating_recipient_bar").add(table).find(".stream_label"), function () {
        if ($(this).text() === stream_name) {
            fixup($(this).parent("td").parent("tr").prev("tr").nextUntil(".bookend_tr")
                         .children(".messagebox_colorblock,.message_header_colorblock"));
        }
    });
}

exports.stream_id = function (stream_name) {
    var sub = get_sub(stream_name);
    if (sub === undefined) {
        blueslip.error("Tried to get subs.stream_id for a stream user is not subscribed to!");
        return 0;
    }
    return parseInt(sub.id, 10);
};

exports.canonicalized_name = function (stream_name) {
   return stream_name.toString().toLowerCase();
};

function update_stream_sidebar_swatch_color(stream_name, color) {
    var id = exports.stream_id(stream_name);
    $("#stream_sidebar_swatch_" + id).css('background-color', color);
}

function update_historical_message_color(stream_name, color) {
    update_table_stream_color($(".focused_table"), stream_name, color);
{'fraction_non_alphanumeric': 0.1343402225755167, 'fraction_numerical': 0.019077901430842606, 'mean_word_length': 2.8763204225352115, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2940243', 'n_tokens_mistral': 2794, 'n_tokens_neox': 2717, 'n_words': 592}