<commit_before>import $ from "jquery";

import {all_messages_data} from "./all_messages_data";
import * as channel from "./channel";
import {Filter} from "./filter";
import * as huddle_data from "./huddle_data";
import * as message_helper from "./message_helper";
import * as message_list from "./message_list";
import * as message_lists from "./message_lists";
import * as message_scroll from "./message_scroll";
import * as message_util from "./message_util";
import * as narrow_banner from "./narrow_banner";
import {page_params} from "./page_params";
import * as people from "./people";
import * as recent_topics_ui from "./recent_topics_ui";
import * as stream_data from "./stream_data";
import * as stream_list from "./stream_list";
import * as ui_report from "./ui_report";

const consts = {
    backfill_idle_time: 10 * 1000,
    backfill_batch_size: 1000,
    narrow_before: 50,
    narrow_after: 50,
    num_before_home_anchor: 200,
    num_after_home_anchor: 200,
    recent_topics_initial_fetch_size: 400,
    backward_batch_size: 100,
    forward_batch_size: 100,
    catch_up_batch_size: 1000,
};

function process_result(data, opts) {
    let messages = data.messages;

    if (!$("#connection-error").hasClass("get-events-error")) {
        ui_report.hide_error($("#connection-error"));
    }

    messages = messages.map((message) => message_helper.process_new_message(message));

    // In some rare situations, we expect to discover new unread
    // messages not tracked in unread.js during this fetching process.
    message_util.do_unread_count_updates(messages, true);

    // If we're loading more messages into the home view, save them to
    // the all_messages_data as well, as the message_lists.home is
    // reconstructed from all_messages_data.
    if (opts.msg_list === message_lists.home) {
        all_messages_data.add_messages(messages);
    }

    if (messages.length !== 0) {
        message_util.add_old_messages(messages, opts.msg_list);
    }

    if (message_lists.current === message_list.narrowed && message_list.narrowed.empty()) {
        // Even after loading more messages, we have
        // no messages to display in this narrow.
        narrow_banner.show_empty_narrow_message();
    }

    huddle_data.process_loaded_messages(messages);
    stream_list.update_streams_sidebar();
    recent_topics_ui.process_messages(messages);

    stream_list.maybe_scroll_narrow_into_view();

    if (opts.cont !== undefined) {
        opts.cont(data, opts);
    }
}

function get_messages_success(data, opts) {
    const update_loading_indicator = opts.msg_list === message_lists.current;
    if (opts.num_before > 0) {
        opts.msg_list.data.fetch_status.finish_older_batch({
            update_loading_indicator,
            found_oldest: data.found_oldest,
            history_limited: data.history_limited,
        });<commit_msg>message-fetch: Update empty narrow check to include opts message list.<commit_after>import $ from "jquery";

import {all_messages_data} from "./all_messages_data";
import * as channel from "./channel";
import {Filter} from "./filter";
import * as huddle_data from "./huddle_data";
import * as message_helper from "./message_helper";
import * as message_list from "./message_list";
import * as message_lists from "./message_lists";
import * as message_scroll from "./message_scroll";
import * as message_util from "./message_util";
import * as narrow_banner from "./narrow_banner";
import {page_params} from "./page_params";
import * as people from "./people";
import * as recent_topics_ui from "./recent_topics_ui";
import * as stream_data from "./stream_data";
import * as stream_list from "./stream_list";
import * as ui_report from "./ui_report";

const consts = {
    backfill_idle_time: 10 * 1000,
    backfill_batch_size: 1000,
    narrow_before: 50,
    narrow_after: 50,
    num_before_home_anchor: 200,
    num_after_home_anchor: 200,
    recent_topics_initial_fetch_size: 400,
    backward_batch_size: 100,
    forward_batch_size: 100,
    catch_up_batch_size: 1000,
};

function process_result(data, opts) {
    let messages = data.messages;

    if (!$("#connection-error").hasClass("get-events-error")) {
        ui_report.hide_error($("#connection-error"));
    }

    messages = messages.map((message) => message_helper.process_new_message(message));

    // In some rare situations, we expect to discover new unread
    // messages not tracked in unread.js during this fetching process.
    message_util.do_unread_count_updates(messages, true);

    // If we're loading more messages into the home view, save them to
    // the all_messages_data as well, as the message_lists.home is
    // reconstructed from all_messages_data.
    if (opts.msg_list === message_lists.home) {
        all_messages_data.add_messages(messages);
    }

    if (messages.length !== 0) {
        message_util.add_old_messages(messages, opts.msg_list);
    }

    if (
        opts.msg_list === message_list.narrowed &&
        message_lists.current === message_list.narrowed &&
        message_list.narrowed.empty()
    ) {
        // Even after loading more messages, we have
        // no messages to display in this narrow.
        narrow_banner.show_empty_narrow_message();
    }

    huddle_data.process_loaded_messages(messages);
    stream_list.update_streams_sidebar();
    recent_topics_ui.process_messages(messages);

    stream_list.maybe_scroll_narrow_into_view();

    if (opts.cont !== undefined) {
        opts.cont(data, opts);
    }
}

function get_messages_success(data, opts) {
    const update_loading_indicator = opts.msg_list === message_lists.current;
    if (opts.num_before > 0) {
        opts.msg_list.data.fetch_status.finish_older_batch({
            update_loading_indicator,
            found_oldest: data.found_oldest,
            history_limited: data.history_limited,
        });
{'fraction_non_alphanumeric': 0.10944935418082936, 'fraction_numerical': 0.011896668932698844, 'mean_word_length': 3.6706349206349205, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7558813', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1763, 'n_words': 435}