<commit_before>var all_msg_list = new MessageList(
    undefined, undefined,
    {muting_enabled: false}
);
var home_msg_list = new MessageList('zhome',
    new Filter([["in", "home"]]),
    {
        muting_enabled: true,
        summarize_read: feature_flags.summarize_read_while_narrowed?'home':false
    }
);
var narrowed_msg_list;
var current_msg_list = home_msg_list;

// The following three Dicts point to the same objects
// All people we've seen
var people_dict = new Dict();
var people_by_name_dict = new Dict();
// People in this realm
var realm_people_dict = new Dict();

var recent_subjects = new Dict({fold_case: true});

var queued_mark_as_read = [];
var queued_flag_timer;

var get_updates_params = {
    pointer: -1
};
var get_updates_failures = 0;

var load_more_enabled = true;
// If the browser hasn't scrolled away from the top of the page
// since the last time that we ran load_more_messages(), we do
// not load_more_messages().
var have_scrolled_away_from_top = true;

// Toggles re-centering the pointer in the window
// when Home is next clicked by the user
var recenter_pointer_on_display = false;
var suppress_scroll_pointer_update = false;
// Includes both scroll and arrow events. Negative means scroll up,
// positive means scroll down.
var last_viewport_movement_direction = 1;

var furthest_read = -1;
var server_furthest_read = -1;
var unread_messages_read_in_narrow = false;
var pointer_update_in_flight = false;
var suppress_unread_counts = true;

var events_stored_during_tutorial = [];

var waiting_on_browser_scroll = true;

function add_person(person, in_realm) {
    page_params.people_list.push(person);
    people_dict.set(person.email, person);
    people_by_name_dict.set(person.full_name, person);
    person.pm_recipient_count = 0;
}

function add_person_in_realm(person) {
    realm_people_dict.set(person.email, person);
    add_person(person);
}

function remove_person(person) {
    var i;
    for (i = 0; i < page_params.people_list.length; i++) {
        if (page_params.people_list[i].email === person.email) {
            page_params.people_list.splice(i, 1);
            break;
        }
    }
    people_dict.del(person.email);
    people_by_name_dict.del(person.full_name);
    realm_people_dict.del(person.email);
}

function update_person(person) {
    // Currently the only attribute that can change is full_name, so
    // we just push out changes to that field.  As we add more things
    // that can change, this will need to either get complicated or be
    // replaced by MVC
    if (! people_dict.has(person.email)) {
        blueslip.error("Got update_person event for unexpected user",
                       {email: person.email});
        return;
    }
    var person_obj = people_dict.get(person.email);

    if (people_by_name_dict.has(person_obj.full_name)) {
        people_by_name_dict.set(person.full_name, person_obj);
        people_by_name_dict.del(person_obj.full_name);
    }

    person_obj.full_name = person.full_name;

    if (person.email === page_params.email) {
        page_params.fullname = person.full_name;
    }

    activity.set_user_statuses([]);

    // TODO: update sender names on messages
}

function within_viewport(row_offset, row_height) {
    // Returns true if a message is fully within the effectively visible
    // part of the viewport.
    var message_top = row_offset.top;
    var message_bottom  = message_top + row_height;
    var info = viewport.message_viewport_info();
    var viewport_top = info.visible_top;
    var viewport_bottom = viewport_top + info.visible_height;
    return (message_top > viewport_top) && (message_bottom < viewport_bottom);
}

function keep_pointer_in_view() {
    // See recenter_view() for related logic to keep the pointer onscreen.
    // This function mostly comes into place for mouse scrollers, and it
    // keeps the pointer in view.  For people who purely scroll with the
    // mouse, the pointer is kind of meaningless to them, but keyboard
    // users will occasionally do big mouse scrolls, so this gives them
    // a pointer reasonably close to the middle of the screen.
    var candidate;
    var next_row = current_msg_list.selected_row();

    if (next_row.length === 0) {<commit_msg>Account for update_user not having a full_name field.<commit_after>var all_msg_list = new MessageList(
    undefined, undefined,
    {muting_enabled: false}
);
var home_msg_list = new MessageList('zhome',
    new Filter([["in", "home"]]),
    {
        muting_enabled: true,
        summarize_read: feature_flags.summarize_read_while_narrowed?'home':false
    }
);
var narrowed_msg_list;
var current_msg_list = home_msg_list;

// The following three Dicts point to the same objects
// All people we've seen
var people_dict = new Dict();
var people_by_name_dict = new Dict();
// People in this realm
var realm_people_dict = new Dict();

var recent_subjects = new Dict({fold_case: true});

var queued_mark_as_read = [];
var queued_flag_timer;

var get_updates_params = {
    pointer: -1
};
var get_updates_failures = 0;

var load_more_enabled = true;
// If the browser hasn't scrolled away from the top of the page
// since the last time that we ran load_more_messages(), we do
// not load_more_messages().
var have_scrolled_away_from_top = true;

// Toggles re-centering the pointer in the window
// when Home is next clicked by the user
var recenter_pointer_on_display = false;
var suppress_scroll_pointer_update = false;
// Includes both scroll and arrow events. Negative means scroll up,
// positive means scroll down.
var last_viewport_movement_direction = 1;

var furthest_read = -1;
var server_furthest_read = -1;
var unread_messages_read_in_narrow = false;
var pointer_update_in_flight = false;
var suppress_unread_counts = true;

var events_stored_during_tutorial = [];

var waiting_on_browser_scroll = true;

function add_person(person, in_realm) {
    page_params.people_list.push(person);
    people_dict.set(person.email, person);
    people_by_name_dict.set(person.full_name, person);
    person.pm_recipient_count = 0;
}

function add_person_in_realm(person) {
    realm_people_dict.set(person.email, person);
    add_person(person);
}

function remove_person(person) {
    var i;
    for (i = 0; i < page_params.people_list.length; i++) {
        if (page_params.people_list[i].email === person.email) {
            page_params.people_list.splice(i, 1);
            break;
        }
    }
    people_dict.del(person.email);
    people_by_name_dict.del(person.full_name);
    realm_people_dict.del(person.email);
}

function update_person(person) {
    // Currently the only attribute that can change is full_name, so
    // we just push out changes to that field.  As we add more things
    // that can change, this will need to either get complicated or be
    // replaced by MVC
    if (! people_dict.has(person.email)) {
        blueslip.error("Got update_person event for unexpected user",
                       {email: person.email});
        return;
    }
    var person_obj = people_dict.get(person.email);

    if (_.has(person, 'full_name')) {
        if (people_by_name_dict.has(person_obj.full_name)) {
            people_by_name_dict.set(person.full_name, person_obj);
            people_by_name_dict.del(person_obj.full_name);
        }

        person_obj.full_name = person.full_name;

        if (person.email === page_params.email) {
            page_params.fullname = person.full_name;
        }
    }

    activity.set_user_statuses([]);

    // TODO: update sender names on messages
}

function within_viewport(row_offset, row_height) {
    // Returns true if a message is fully within the effectively visible
    // part of the viewport.
    var message_top = row_offset.top;
    var message_bottom  = message_top + row_height;
    var info = viewport.message_viewport_info();
    var viewport_top = info.visible_top;
    var viewport_bottom = viewport_top + info.visible_height;
    return (message_top > viewport_top) && (message_bottom < viewport_bottom);
}

function keep_pointer_in_view() {
    // See recenter_view() for related logic to keep the pointer onscreen.
    // This function mostly comes into place for mouse scrollers, and it
    // keeps the pointer in view.  For people who purely scroll with the
    // mouse, the pointer is kind of meaningless to them, but keyboard
    // users will occasionally do big mouse scrolls, so this gives them
    // a pointer reasonably close to the middle of the screen.
    var candidate;
    var next_row = current_msg_list.selected_row();

    if (next_row.length === 0) {
{'fraction_non_alphanumeric': 0.09094076655052265, 'fraction_numerical': 0.0020905923344947735, 'mean_word_length': 3.548864236661384, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '6674733', 'n_tokens_mistral': 2714, 'n_tokens_neox': 2675, 'n_words': 768}