mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	@brockwhittaker wrote the original prototype for having
pills in the recipient box when users compose PMs (either
1:1 or huddle).  The prototype was test deloyed on our
main realm for several weeks.
This commit includes all the original CSS and HTML from
the prototype.
After some things changed with the codebase after the initial
test deployment, I made the following changes:
    * In prior commits I refactored out a module called
      `user_pill.js` that implemented some common functions
      against a more streamlined version of `input_pill.js`,
      and this commit largely integrates with that.
    * I made changes in a prior commit to handle Zephyr
      semantics (emails don't get validated) and tested
      this commit with zephyr.
    * I fixed a reload bug by extracting code out to
      `compose_pm_pill.js` and re-ordering some
      calls to `initialize`.
There are still two flaws related to un-pill-ified text in the
input:
    * We could be more aggressive about trying to pill-ify
      emails when you blur or tab away.
    * We only look at the pills when you send the message,
      instead of complaining about the un-pill-ified text.
      (Some folks may consider that a feature, but it's
      probably surprising to others.)
		
	
		
			
				
	
	
		
			66 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
var compose_state = (function () {
 | 
						|
 | 
						|
var exports = {};
 | 
						|
 | 
						|
var message_type = false; // 'stream', 'private', or false-y
 | 
						|
 | 
						|
exports.set_message_type = function (msg_type) {
 | 
						|
    message_type = msg_type;
 | 
						|
};
 | 
						|
 | 
						|
exports.get_message_type = function () {
 | 
						|
    return message_type;
 | 
						|
};
 | 
						|
 | 
						|
exports.composing = function () {
 | 
						|
    // This is very similar to get_message_type(), but it returns
 | 
						|
    // a boolean.
 | 
						|
    return !!message_type;
 | 
						|
};
 | 
						|
 | 
						|
exports.focus_in_empty_compose = function () {
 | 
						|
    return (
 | 
						|
        exports.composing() &&
 | 
						|
        exports.message_content() === "" &&
 | 
						|
        $('#compose-textarea').is(':focus'));
 | 
						|
};
 | 
						|
 | 
						|
function get_or_set(fieldname, keep_leading_whitespace) {
 | 
						|
    // We can't hoist the assignment of 'elem' out of this lambda,
 | 
						|
    // because the DOM element might not exist yet when get_or_set
 | 
						|
    // is called.
 | 
						|
    return function (newval) {
 | 
						|
        var elem = $('#'+fieldname);
 | 
						|
        var oldval = elem.val();
 | 
						|
        if (newval !== undefined) {
 | 
						|
            elem.val(newval);
 | 
						|
        }
 | 
						|
        return keep_leading_whitespace ? util.rtrim(oldval) : $.trim(oldval);
 | 
						|
    };
 | 
						|
}
 | 
						|
 | 
						|
// TODO: Break out setters and getter into their own functions.
 | 
						|
exports.stream_name     = get_or_set('stream');
 | 
						|
exports.subject         = get_or_set('subject');
 | 
						|
// We can't trim leading whitespace in `compose_textarea` because
 | 
						|
// of the indented syntax for multi-line code blocks.
 | 
						|
exports.message_content = get_or_set('compose-textarea', true);
 | 
						|
exports.recipient = function (value) {
 | 
						|
    if (typeof value === "string") {
 | 
						|
        compose_pm_pill.set_from_emails(value);
 | 
						|
    } else {
 | 
						|
        return compose_pm_pill.get_emails();
 | 
						|
    }
 | 
						|
};
 | 
						|
 | 
						|
exports.has_message_content = function () {
 | 
						|
    return exports.message_content() !== "";
 | 
						|
};
 | 
						|
 | 
						|
return exports;
 | 
						|
}());
 | 
						|
 | 
						|
if (typeof module !== 'undefined') {
 | 
						|
    module.exports = compose_state;
 | 
						|
}
 |