mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	Add curly braces for all javascript if statements lacking them.
(imported from commit 32c7643d1a6ecdfaf634424d217938c8a368dade)
This commit is contained in:
		@@ -4,7 +4,9 @@ var exports = {};
 | 
			
		||||
 | 
			
		||||
function is_image_format(file) {
 | 
			
		||||
    var type = file.type;
 | 
			
		||||
    if (!type) return false;
 | 
			
		||||
    if (!type) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var supported_types = [
 | 
			
		||||
        'image/jpeg',
 | 
			
		||||
 
 | 
			
		||||
@@ -16,8 +16,9 @@ function autofocus(selector) {
 | 
			
		||||
// and also from the in-app password change interface.
 | 
			
		||||
function password_quality(password, bar) {
 | 
			
		||||
    // We load zxcvbn.js asynchronously, so the variable might not be set.
 | 
			
		||||
    if (typeof zxcvbn === 'undefined')
 | 
			
		||||
    if (typeof zxcvbn === 'undefined') {
 | 
			
		||||
        return undefined;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Consider the password acceptable if it's at least 6 characters.
 | 
			
		||||
    var acceptable = password.length >= 6;
 | 
			
		||||
@@ -29,8 +30,9 @@ function password_quality(password, bar) {
 | 
			
		||||
 | 
			
		||||
        // Even if zxcvbn loves your short password, the bar should be filled
 | 
			
		||||
        // at most 1/3 of the way, because we won't accept it.
 | 
			
		||||
        if (!acceptable)
 | 
			
		||||
        if (!acceptable) {
 | 
			
		||||
            quality = Math.min(quality, 0.33);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Display the password quality score on a progress bar
 | 
			
		||||
        // which bottoms out at 10% so there's always something
 | 
			
		||||
 
 | 
			
		||||
@@ -159,7 +159,9 @@ exports.update_recipient_on_narrow = function () {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
function update_fade () {
 | 
			
		||||
    if (!is_composing_message) return;
 | 
			
		||||
    if (!is_composing_message) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Construct focused_recipient as a mocked up element which has all the
 | 
			
		||||
    // fields of a message used by util.same_recipient()
 | 
			
		||||
 
 | 
			
		||||
@@ -74,7 +74,9 @@ function handle_keydown(e) {
 | 
			
		||||
        if (e.target.id === "stream") {
 | 
			
		||||
            nextFocus = "subject";
 | 
			
		||||
        } else if (e.target.id === "subject") {
 | 
			
		||||
            if (code === 13) e.preventDefault();
 | 
			
		||||
            if (code === 13) {
 | 
			
		||||
                e.preventDefault();
 | 
			
		||||
            }
 | 
			
		||||
            nextFocus = "new_message_content";
 | 
			
		||||
        } else if (e.target.id === "private_message_recipient") {
 | 
			
		||||
            nextFocus = "new_message_content";
 | 
			
		||||
@@ -182,7 +184,9 @@ exports.initialize = function () {
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
    $("#enter_sends").prop('checked', page_params.enter_sends);
 | 
			
		||||
    if (page_params.enter_sends) $("#compose-send-button").hide();
 | 
			
		||||
    if (page_params.enter_sends) {
 | 
			
		||||
        $("#compose-send-button").hide();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // limit number of items so the list doesn't fall off the screen
 | 
			
		||||
    $( "#stream" ).typeahead({
 | 
			
		||||
@@ -281,12 +285,14 @@ exports.initialize = function () {
 | 
			
		||||
            // Don't autocomplete more than this many characters.
 | 
			
		||||
            var max_chars = 30;
 | 
			
		||||
            var last_at = q.lastIndexOf('@');
 | 
			
		||||
            if (last_at === -1 || last_at < q.length-1 - max_chars)
 | 
			
		||||
            if (last_at === -1 || last_at < q.length-1 - max_chars) {
 | 
			
		||||
                return false;  // No '@', or too far back
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            current_token = q.substring(last_at + 1);
 | 
			
		||||
            if (current_token.length < 1 || current_token.lastIndexOf('*') !== -1)
 | 
			
		||||
            if (current_token.length < 1 || current_token.lastIndexOf('*') !== -1) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            this.completing = 'mention';
 | 
			
		||||
            this.token = current_token.substring(current_token.indexOf("@")+1);
 | 
			
		||||
 
 | 
			
		||||
@@ -104,8 +104,9 @@ function get_event_name(e) {
 | 
			
		||||
function process_hotkey(e) {
 | 
			
		||||
    // Disable hotkeys on settings page etc., and when a modal pop-up
 | 
			
		||||
    // is visible.
 | 
			
		||||
    if (ui.home_tab_obscured())
 | 
			
		||||
    if (ui.home_tab_obscured()) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var event_name = get_event_name(e);
 | 
			
		||||
 | 
			
		||||
@@ -290,9 +291,10 @@ function process_hotkey(e) {
 | 
			
		||||
$(document).keydown(function (e) {
 | 
			
		||||
    // Restrict to non-alphanumeric keys
 | 
			
		||||
    if (48 > e.which || 90 < e.which) {
 | 
			
		||||
        if (process_hotkey(e))
 | 
			
		||||
        if (process_hotkey(e)) {
 | 
			
		||||
            e.preventDefault();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
$(document).keypress(function (e) {
 | 
			
		||||
@@ -303,9 +305,10 @@ $(document).keypress(function (e) {
 | 
			
		||||
    // keypress event with keycode 0 after processing the original
 | 
			
		||||
    // event.
 | 
			
		||||
    if (e.which !== 0 && e.charCode !== 0) {
 | 
			
		||||
        if (process_hotkey(e))
 | 
			
		||||
        if (process_hotkey(e)) {
 | 
			
		||||
            e.preventDefault();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
return exports;
 | 
			
		||||
 
 | 
			
		||||
@@ -288,8 +288,9 @@ MessageList.prototype = {
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    _render: function MessageList__render(messages, where, messages_are_new) {
 | 
			
		||||
        if (messages.length === 0 || this.table_name === undefined)
 | 
			
		||||
        if (messages.length === 0 || this.table_name === undefined) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var self = this;
 | 
			
		||||
        var table_name = this.table_name;
 | 
			
		||||
@@ -347,8 +348,9 @@ MessageList.prototype = {
 | 
			
		||||
                // prev is no longer the last element in this block
 | 
			
		||||
                prev.include_footer = false;
 | 
			
		||||
            } else {
 | 
			
		||||
                if (current_group.length > 0)
 | 
			
		||||
                if (current_group.length > 0) {
 | 
			
		||||
                    new_message_groups.push(current_group);
 | 
			
		||||
                }
 | 
			
		||||
                current_group = [message.id];
 | 
			
		||||
 | 
			
		||||
                // Add a space to the table, but not for the first element.
 | 
			
		||||
@@ -408,8 +410,9 @@ MessageList.prototype = {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (current_group.length > 0)
 | 
			
		||||
        if (current_group.length > 0) {
 | 
			
		||||
            new_message_groups.push(current_group);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (where === 'top') {
 | 
			
		||||
            this._message_groups = new_message_groups.concat(this._message_groups);
 | 
			
		||||
 
 | 
			
		||||
@@ -38,8 +38,9 @@ Filter.prototype = {
 | 
			
		||||
            // Currently just filter out the "in" keyword.
 | 
			
		||||
            return value[0] !== 'in';
 | 
			
		||||
        });
 | 
			
		||||
        if (safe_to_return.length !== 0)
 | 
			
		||||
        if (safe_to_return.length !== 0) {
 | 
			
		||||
            return safe_to_return;
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    operands: function Filter_get_operands(operator) {
 | 
			
		||||
@@ -96,8 +97,9 @@ Filter.prototype = {
 | 
			
		||||
                switch (operators[i][0]) {
 | 
			
		||||
                case 'is':
 | 
			
		||||
                    if (operand === 'private') {
 | 
			
		||||
                        if (message.type !== 'private')
 | 
			
		||||
                        if (message.type !== 'private') {
 | 
			
		||||
                            return false;
 | 
			
		||||
                        }
 | 
			
		||||
                    } else if (operand === 'starred') {
 | 
			
		||||
                        if (!message.starred) {
 | 
			
		||||
                            return false;
 | 
			
		||||
@@ -126,8 +128,9 @@ Filter.prototype = {
 | 
			
		||||
                    return message.id.toString() === operand;
 | 
			
		||||
 | 
			
		||||
                case 'stream':
 | 
			
		||||
                    if (message.type !== 'stream')
 | 
			
		||||
                    if (message.type !== 'stream') {
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if (page_params.domain === "mit.edu") {
 | 
			
		||||
                        // MIT users expect narrowing to "social" to also show messages to /^(un)*social(.d)*$/
 | 
			
		||||
@@ -148,8 +151,9 @@ Filter.prototype = {
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
                case 'topic':
 | 
			
		||||
                    if (message.type !== 'stream')
 | 
			
		||||
                    if (message.type !== 'stream') {
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if (page_params.domain === "mit.edu") {
 | 
			
		||||
                        // MIT users expect narrowing to topic "foo" to also show messages to /^foo(.d)*$/
 | 
			
		||||
@@ -181,14 +185,16 @@ Filter.prototype = {
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
                case 'sender':
 | 
			
		||||
                    if ((message.sender_email.toLowerCase() !== operand))
 | 
			
		||||
                    if ((message.sender_email.toLowerCase() !== operand)) {
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
                case 'pm-with':
 | 
			
		||||
                    if ((message.type !== 'private') ||
 | 
			
		||||
                        message.reply_to.toLowerCase() !== operand.split(',').sort().join(','))
 | 
			
		||||
                        message.reply_to.toLowerCase() !== operand.split(',').sort().join(',')) {
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@@ -306,12 +312,14 @@ exports.set_compose_defaults = function (opts) {
 | 
			
		||||
    // Set the stream, subject, and/or PM recipient if they are
 | 
			
		||||
    // uniquely specified in the narrow view.
 | 
			
		||||
    _.each(['stream', 'topic'], function (key) {
 | 
			
		||||
        if (single[key] !== undefined)
 | 
			
		||||
        if (single[key] !== undefined) {
 | 
			
		||||
            opts[key] = single[key];
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (single['pm-with'] !== undefined)
 | 
			
		||||
    if (single['pm-with'] !== undefined) {
 | 
			
		||||
        opts.private_message_recipient = single['pm-with'];
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Parse a string into a list of operators (see below).
 | 
			
		||||
@@ -324,8 +332,9 @@ exports.parse = function (str) {
 | 
			
		||||
    }
 | 
			
		||||
    _.each(matches, function (token) {
 | 
			
		||||
        var parts, operator;
 | 
			
		||||
        if (token.length === 0)
 | 
			
		||||
        if (token.length === 0) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        parts = token.split(':');
 | 
			
		||||
        if (token[0] === '"' || parts.length === 1) {
 | 
			
		||||
            // Looks like a normal search term.
 | 
			
		||||
@@ -338,8 +347,9 @@ exports.parse = function (str) {
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
    // NB: Callers of 'parse' can assume that the 'search' operator is last.
 | 
			
		||||
    if (search_term.length > 0)
 | 
			
		||||
    if (search_term.length > 0) {
 | 
			
		||||
        operators.push(['search', search_term.join(' ')]);
 | 
			
		||||
    }
 | 
			
		||||
    return operators;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -426,9 +436,10 @@ exports.activate = function (operators, opts) {
 | 
			
		||||
                then_select_id = narrowed_msg_list.last().id;
 | 
			
		||||
                var first_unread = _.find(narrowed_msg_list.all(),
 | 
			
		||||
                                          unread.message_unread);
 | 
			
		||||
                if (first_unread)
 | 
			
		||||
                if (first_unread) {
 | 
			
		||||
                    then_select_id = first_unread.id;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var preserve_pre_narrowing_screen_position =
 | 
			
		||||
                !opts.select_first_unread &&
 | 
			
		||||
@@ -492,8 +503,9 @@ exports.activate = function (operators, opts) {
 | 
			
		||||
    // Put the narrow operators in the URL fragment.
 | 
			
		||||
    // Disabled when the URL fragment was the source
 | 
			
		||||
    // of this narrow.
 | 
			
		||||
    if (opts.change_hash)
 | 
			
		||||
    if (opts.change_hash) {
 | 
			
		||||
        hashchange.save_narrow(operators);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Put the narrow operators in the search bar.
 | 
			
		||||
    $('#search_query').val(exports.unparse(operators));
 | 
			
		||||
 
 | 
			
		||||
@@ -102,8 +102,9 @@ exports.update_title_count = function (new_message_count) {
 | 
			
		||||
            // measure.  And we don't have images above 99, so display those as
 | 
			
		||||
            // 'infinite'.
 | 
			
		||||
            n = (+new_message_count);
 | 
			
		||||
            if (n > 99)
 | 
			
		||||
            if (n > 99) {
 | 
			
		||||
                n = 'infinite';
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            current_favicon = previous_favicon = '/static/images/favicon/favicon-'+n+'.png';
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -277,14 +278,17 @@ function message_is_notifiable(message) {
 | 
			
		||||
 | 
			
		||||
exports.received_messages = function (messages) {
 | 
			
		||||
    _.each(messages, function (message) {
 | 
			
		||||
        if (!message_is_notifiable(message)) return;
 | 
			
		||||
        if (!unread.message_unread(message)) return;
 | 
			
		||||
        if (!message_is_notifiable(message)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if (!unread.message_unread(message)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (page_params.desktop_notifications_enabled &&
 | 
			
		||||
            browser_desktop_notifications_on()) {
 | 
			
		||||
            process_notification({message: message, webkit_notify: true});
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
        } else {
 | 
			
		||||
            process_notification({message: message, webkit_notify: false});
 | 
			
		||||
        }
 | 
			
		||||
        if (page_params.sounds_enabled && supports_sound) {
 | 
			
		||||
 
 | 
			
		||||
@@ -8,8 +8,9 @@ var bar_selector = "#notifications-bar"; // the selector jQuery can use to pick
 | 
			
		||||
var area_selector = "#notifications-area"; // the selector jQuery can use to pick the container
 | 
			
		||||
 | 
			
		||||
function show() {
 | 
			
		||||
    if (disabled)
 | 
			
		||||
    if (disabled) {
 | 
			
		||||
        return; // we should never show the bar when disabled
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!displayed) {
 | 
			
		||||
        // If the bar wasn't already displayed, simply show it
 | 
			
		||||
@@ -20,8 +21,9 @@ function show() {
 | 
			
		||||
 | 
			
		||||
// Hide the notifications bar
 | 
			
		||||
function hide() {
 | 
			
		||||
    if (!displayed)
 | 
			
		||||
    if (!displayed) {
 | 
			
		||||
        return; // don't unnecessarily add to the element's fx queue
 | 
			
		||||
    }
 | 
			
		||||
    displayed = false;
 | 
			
		||||
    $(bar_selector).slideUp(50);
 | 
			
		||||
}
 | 
			
		||||
@@ -33,10 +35,11 @@ exports.update = function (num_unread) {
 | 
			
		||||
    if (last_row
 | 
			
		||||
        && last_row.offset() !== null // otherwise the next line will error
 | 
			
		||||
        && viewport.is_below_visible_bottom(last_row.offset().top + last_row.height())
 | 
			
		||||
        && num_unread > 0)
 | 
			
		||||
        && num_unread > 0) {
 | 
			
		||||
        show();
 | 
			
		||||
    else
 | 
			
		||||
    } else {
 | 
			
		||||
        hide();
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// We disable the notifications bar if it overlaps with the composebox
 | 
			
		||||
 
 | 
			
		||||
@@ -6,8 +6,9 @@ var rows = (function () {
 | 
			
		||||
    // that our next element is *not* a message_row, so this
 | 
			
		||||
    // isn't going to end up empty unless we're at the bottom or top.
 | 
			
		||||
    exports.next_visible = function (message_row) {
 | 
			
		||||
        if (message_row === undefined)
 | 
			
		||||
        if (message_row === undefined) {
 | 
			
		||||
            return $();
 | 
			
		||||
        }
 | 
			
		||||
        var row = message_row.next('.message_row');
 | 
			
		||||
        if (row.length !== 0) {
 | 
			
		||||
            return row;
 | 
			
		||||
@@ -16,8 +17,9 @@ var rows = (function () {
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    exports.prev_visible = function (message_row) {
 | 
			
		||||
        if (message_row === undefined)
 | 
			
		||||
        if (message_row === undefined) {
 | 
			
		||||
            return $();
 | 
			
		||||
        }
 | 
			
		||||
        var row = message_row.prev('.message_row');
 | 
			
		||||
        if (row.length !== 0) {
 | 
			
		||||
            return row;
 | 
			
		||||
@@ -46,20 +48,23 @@ var rows = (function () {
 | 
			
		||||
        // Make sure message_id is just an int, because we build
 | 
			
		||||
        // a jQuery selector using it.
 | 
			
		||||
        message_id = parseInt(message_id, 10);
 | 
			
		||||
        if (isNaN(message_id))
 | 
			
		||||
        if (isNaN(message_id)) {
 | 
			
		||||
            return $();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // To avoid attacks and bizarre errors, we have a whitelist
 | 
			
		||||
        // of valid table names.
 | 
			
		||||
        if (! valid_table_names.hasOwnProperty(table_name))
 | 
			
		||||
        if (! valid_table_names.hasOwnProperty(table_name)) {
 | 
			
		||||
            return $();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $('#' + table_name + message_id);
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    exports.get_table = function (table_name) {
 | 
			
		||||
        if (! valid_table_names.hasOwnProperty(table_name))
 | 
			
		||||
        if (! valid_table_names.hasOwnProperty(table_name)) {
 | 
			
		||||
            return $();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $('#' + table_name);
 | 
			
		||||
    };
 | 
			
		||||
 
 | 
			
		||||
@@ -3,8 +3,9 @@ var templates = (function () {
 | 
			
		||||
var exports = {};
 | 
			
		||||
 | 
			
		||||
exports.render = function (name, arg) {
 | 
			
		||||
    if (Handlebars.templates === undefined)
 | 
			
		||||
    if (Handlebars.templates === undefined) {
 | 
			
		||||
        Handlebars.templates = {};
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (Handlebars.templates[name] === undefined) {
 | 
			
		||||
        // Fetch the template using a synchronous AJAX request.
 | 
			
		||||
 
 | 
			
		||||
@@ -51,7 +51,9 @@ exports.highlight_query_in_phrase = function (query, phrase) {
 | 
			
		||||
    var result = "";
 | 
			
		||||
    var parts = phrase.split(' ');
 | 
			
		||||
    for (i = 0; i < parts.length; i++) {
 | 
			
		||||
        if (i > 0) result += " ";
 | 
			
		||||
        if (i > 0) {
 | 
			
		||||
            result += " ";
 | 
			
		||||
        }
 | 
			
		||||
        result += exports.highlight_with_escaping_and_regex(regex, parts[i]);
 | 
			
		||||
    }
 | 
			
		||||
    return result;
 | 
			
		||||
@@ -122,12 +124,13 @@ function prefix_sort(query, objs, get_item) {
 | 
			
		||||
        else {
 | 
			
		||||
            item = obj;
 | 
			
		||||
        }
 | 
			
		||||
        if (item.indexOf(query) === 0)
 | 
			
		||||
        if (item.indexOf(query) === 0) {
 | 
			
		||||
            beginswithCaseSensitive.push(obj);
 | 
			
		||||
        else if (item.toLowerCase().indexOf(query.toLowerCase()) === 0)
 | 
			
		||||
        } else if (item.toLowerCase().indexOf(query.toLowerCase()) === 0) {
 | 
			
		||||
            beginswithCaseInsensitive.push(obj);
 | 
			
		||||
        else
 | 
			
		||||
        } else {
 | 
			
		||||
            noMatch.push(obj);
 | 
			
		||||
        }
 | 
			
		||||
        obj = objs.shift();
 | 
			
		||||
    }
 | 
			
		||||
    return { matches: beginswithCaseSensitive.concat(beginswithCaseInsensitive),
 | 
			
		||||
@@ -149,12 +152,13 @@ exports.compare_by_pms = function (user_a, user_b) {
 | 
			
		||||
 | 
			
		||||
    // We use alpha sort as a tiebreaker, which might be helpful for
 | 
			
		||||
    // new users.
 | 
			
		||||
    if (user_a.full_name < user_b.full_name)
 | 
			
		||||
    if (user_a.full_name < user_b.full_name) {
 | 
			
		||||
        return -1;
 | 
			
		||||
    else if (user_a === user_b)
 | 
			
		||||
    } else if (user_a === user_b) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    else
 | 
			
		||||
    } else {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.sort_by_pms = function (objs) {
 | 
			
		||||
 
 | 
			
		||||
@@ -10,10 +10,12 @@ exports.actively_scrolling = function () {
 | 
			
		||||
 | 
			
		||||
// What, if anything, obscures the home tab?
 | 
			
		||||
exports.home_tab_obscured = function () {
 | 
			
		||||
    if ($('.modal:visible').length > 0)
 | 
			
		||||
    if ($('.modal:visible').length > 0) {
 | 
			
		||||
        return 'modal';
 | 
			
		||||
    if (! $('#home').hasClass('active'))
 | 
			
		||||
    }
 | 
			
		||||
    if (! $('#home').hasClass('active')) {
 | 
			
		||||
        return 'other_tab';
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -59,7 +61,9 @@ function amount_to_paginate() {
 | 
			
		||||
    // If the user has shrunk their browser a whole lot, pagination
 | 
			
		||||
    // is not going to be very pleasant, but we can at least
 | 
			
		||||
    // ensure they go in the right direction.
 | 
			
		||||
    if (delta < 1) delta = 1;
 | 
			
		||||
    if (delta < 1) {
 | 
			
		||||
        delta = 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return delta;
 | 
			
		||||
}
 | 
			
		||||
@@ -235,8 +239,9 @@ $(function () {
 | 
			
		||||
 | 
			
		||||
var current_message_hover;
 | 
			
		||||
function message_unhover() {
 | 
			
		||||
    if (current_message_hover === undefined)
 | 
			
		||||
    if (current_message_hover === undefined) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    current_message_hover.removeClass('message_hovered');
 | 
			
		||||
    current_message_hover = undefined;
 | 
			
		||||
}
 | 
			
		||||
@@ -248,8 +253,9 @@ function message_hover(message_row) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.report_message = function (response, status_box, cls) {
 | 
			
		||||
    if (cls === undefined)
 | 
			
		||||
    if (cls === undefined) {
 | 
			
		||||
        cls = 'alert';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    status_box.removeClass(status_classes).addClass(cls)
 | 
			
		||||
              .text(response).stop(true).fadeTo(0, 1);
 | 
			
		||||
@@ -1349,8 +1355,9 @@ var presence_descriptions = {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.set_presence_list = function (users, presence_info) {
 | 
			
		||||
    if (page_params.domain === 'mit.edu')
 | 
			
		||||
    if (page_params.domain === 'mit.edu') {
 | 
			
		||||
        return;  // MIT realm doesn't have a presence list
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var my_info = {
 | 
			
		||||
        name: page_params.fullname,
 | 
			
		||||
 
 | 
			
		||||
@@ -193,10 +193,12 @@ exports.same_stream_and_subject = function util_same_stream_and_subject(a, b) {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.same_recipient = function util_same_recipient(a, b) {
 | 
			
		||||
    if ((a === undefined) || (b === undefined))
 | 
			
		||||
    if ((a === undefined) || (b === undefined)) {
 | 
			
		||||
        return false;
 | 
			
		||||
    if (a.type !== b.type)
 | 
			
		||||
    }
 | 
			
		||||
    if (a.type !== b.type) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    switch (a.type) {
 | 
			
		||||
    case 'private':
 | 
			
		||||
@@ -234,8 +236,9 @@ exports.robust_uri_decode = function (str) {
 | 
			
		||||
        try {
 | 
			
		||||
            return decodeURIComponent(str.substring(0, end));
 | 
			
		||||
        } catch (e) {
 | 
			
		||||
            if (!(e instanceof URIError))
 | 
			
		||||
            if (!(e instanceof URIError)) {
 | 
			
		||||
                throw e;
 | 
			
		||||
            }
 | 
			
		||||
            end--;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -126,8 +126,9 @@ function keep_pointer_in_view() {
 | 
			
		||||
    var candidate;
 | 
			
		||||
    var next_row = current_msg_list.selected_row();
 | 
			
		||||
 | 
			
		||||
    if (next_row.length === 0)
 | 
			
		||||
    if (next_row.length === 0) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var info = viewport.message_viewport_info();
 | 
			
		||||
    var top_threshold = info.visible_top + (1/10 * info.visible_height);
 | 
			
		||||
@@ -143,19 +144,22 @@ function keep_pointer_in_view() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function adjust(past_threshold, at_end, advance) {
 | 
			
		||||
        if (!past_threshold(next_row) || at_end())
 | 
			
		||||
        if (!past_threshold(next_row) || at_end()) {
 | 
			
		||||
            return false;  // try other side
 | 
			
		||||
        }
 | 
			
		||||
        while (past_threshold(next_row)) {
 | 
			
		||||
            candidate = advance(next_row);
 | 
			
		||||
            if (candidate.length === 0)
 | 
			
		||||
            if (candidate.length === 0) {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            next_row = candidate;
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (! adjust(above_view_threshold, viewport.at_top, rows.next_visible))
 | 
			
		||||
    if (! adjust(above_view_threshold, viewport.at_top, rows.next_visible)) {
 | 
			
		||||
        adjust(below_view_threshold, viewport.at_bottom, rows.prev_visible);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    current_msg_list.select_id(rows.id(next_row), {from_scroll: true});
 | 
			
		||||
}
 | 
			
		||||
@@ -202,8 +206,9 @@ function recenter_view(message, opts) {
 | 
			
		||||
 | 
			
		||||
function scroll_to_selected() {
 | 
			
		||||
    var selected_row = current_msg_list.selected_row();
 | 
			
		||||
    if (selected_row && (selected_row.length !== 0))
 | 
			
		||||
    if (selected_row && (selected_row.length !== 0)) {
 | 
			
		||||
        recenter_view(selected_row);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function maybe_scroll_to_selected() {
 | 
			
		||||
@@ -253,7 +258,9 @@ function send_queued_flags() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function on_success(data, status, jqXHR) {
 | 
			
		||||
        if (data ===  undefined || data.messages === undefined) return;
 | 
			
		||||
        if (data ===  undefined || data.messages === undefined) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        queued_mark_as_read = _.filter(queued_mark_as_read, function (message) {
 | 
			
		||||
            return data.messages.indexOf(message) === -1;
 | 
			
		||||
@@ -673,8 +680,9 @@ function add_messages_helper(messages, msg_list, predicate, messages_are_new) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function add_messages(messages, msg_list, messages_are_new) {
 | 
			
		||||
    if (!messages)
 | 
			
		||||
    if (!messages) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    util.destroy_loading_indicator($('#page_loading_indicator'));
 | 
			
		||||
    util.destroy_first_run_message();
 | 
			
		||||
@@ -910,7 +918,9 @@ function get_updates_success(data) {
 | 
			
		||||
            // the pointer position.
 | 
			
		||||
            for (i = messages.length-1; i>=0; i--){
 | 
			
		||||
                var id = messages[i].id;
 | 
			
		||||
                if (id <= selected_id) break;
 | 
			
		||||
                if (id <= selected_id) {
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
                if (messages[i].sent_by_me && current_msg_list.get(id) !== undefined) {
 | 
			
		||||
                    // If this is a reply we just sent, advance the pointer to it.
 | 
			
		||||
                    current_msg_list.select_id(messages[i].id, {then_scroll: true,
 | 
			
		||||
@@ -1024,8 +1034,9 @@ function load_old_messages(opts) {
 | 
			
		||||
                num_before: opts.num_before,
 | 
			
		||||
                num_after: opts.num_after};
 | 
			
		||||
 | 
			
		||||
    if (opts.msg_list.narrowed && narrow.active())
 | 
			
		||||
    if (opts.msg_list.narrowed && narrow.active()) {
 | 
			
		||||
        data.narrow = JSON.stringify(narrow.public_operators());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function process_result(messages) {
 | 
			
		||||
        $('#get_old_messages_error').hide();
 | 
			
		||||
@@ -1179,11 +1190,13 @@ $(function () {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
function restart_get_updates(options) {
 | 
			
		||||
    if (get_updates_xhr !== undefined)
 | 
			
		||||
    if (get_updates_xhr !== undefined) {
 | 
			
		||||
        get_updates_xhr.abort();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (get_updates_timeout !== undefined)
 | 
			
		||||
    if (get_updates_timeout !== undefined) {
 | 
			
		||||
        clearTimeout(get_updates_timeout);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    get_updates(options);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user