Rewrite respond_to_zephyr.

The new version is now the only codepath that we use in order to start
a reply to a message.

(imported from commit dd28316d2640fd5fd712f326690d480b7db59c4c)
This commit is contained in:
Tim Abbott 2012-10-09 09:51:12 -04:00
parent 19a0e4a690
commit ad9f58d90a
4 changed files with 25 additions and 41 deletions

View File

@ -38,7 +38,7 @@ var globals =
// zephyr.js // zephyr.js
+ ' zephyr_array zephyr_dict' + ' zephyr_array zephyr_dict'
+ ' status_classes clear_table add_to_table instance_list' + ' status_classes clear_table add_to_table instance_list'
+ ' keep_pointer_in_view prepare_huddle respond_to_zephyr' + ' keep_pointer_in_view respond_to_zephyr'
+ ' select_zephyr select_zephyr_by_id' + ' select_zephyr select_zephyr_by_id'
+ ' scroll_to_selected select_and_show_by_id' + ' scroll_to_selected select_and_show_by_id'
+ ' selected_zephyr selected_zephyr_id' + ' selected_zephyr selected_zephyr_id'

View File

@ -82,8 +82,7 @@ function process_hotkey(code) {
respond_to_zephyr(); respond_to_zephyr();
return process_key_in_input; return process_key_in_input;
case 82: // 'R': respond to author case 82: // 'R': respond to author
$('#zephyr-type-tabs a[href="#personal-message"]').tab('show'); respond_to_zephyr("personal");
prepare_huddle(zephyr_dict[selected_zephyr_id].sender_email);
return process_key_in_input; return process_key_in_input;
case 103: // 'g': start of "go to" command case 103: // 'g': start of "go to" command
return process_goto_hotkey; return process_goto_hotkey;

View File

@ -8,16 +8,11 @@ function register_huddle_onclick(zephyr_row, sender) {
zephyr_row.find(".zephyr_sender").click(function (e) { zephyr_row.find(".zephyr_sender").click(function (e) {
select_zephyr_by_id(zephyr_row.attr('zid')); select_zephyr_by_id(zephyr_row.attr('zid'));
// populate the stream box // populate the stream box
respond_to_zephyr(); respond_to_zephyr("personal");
// but we really want to be in huddle mode
prepare_huddle(sender);
// The sender span is inside the messagebox, which also has an // The sender span is inside the messagebox, which also has an
// onclick handler. We don't want to trigger the messagebox // onclick handler. We don't want to trigger the messagebox
// handler. // handler.
e.stopPropagation(); e.stopPropagation();
// switch to the replybox hotkey handler
set_keydown_in_input(true);
}); });
} }
@ -27,7 +22,6 @@ function register_onclick(zephyr_row, zephyr_id) {
// Was a click (not a click-and-drag). // Was a click (not a click-and-drag).
select_zephyr_by_id(zephyr_id); select_zephyr_by_id(zephyr_id);
respond_to_zephyr(); respond_to_zephyr();
set_keydown_in_input(true);
} }
mouse_moved = false; mouse_moved = false;
clicking = false; clicking = false;
@ -117,6 +111,8 @@ function update_autocomplete() {
$(function () { $(function () {
// NB: This just binds to current elements, and won't bind to elements // NB: This just binds to current elements, and won't bind to elements
// created after ready() is called. // created after ready() is called.
// Enable our hotkeys when we're not focused on a data entry box
$('input, textarea, button').focus(function () { $('input, textarea, button').focus(function () {
set_keydown_in_input(true); set_keydown_in_input(true);
}); });

View File

@ -107,33 +107,27 @@ function get_huddle_recipient_names(zephyr) {
return recipient; return recipient;
} }
function respond_to_zephyr() { function respond_to_zephyr(reply_type) {
var zephyr, recipient, recipients; var zephyr, tabname;
zephyr = zephyr_dict[selected_zephyr_id]; zephyr = zephyr_dict[selected_zephyr_id];
$("#class").val(zephyr.display_recipient);
switch (zephyr.type) { $("#instance").val(zephyr.instance);
case 'class': $("#huddle_recipient").val(zephyr.reply_to);
$('#zephyr-type-tabs a[href="#class-message"]').tab('show'); if (reply_type === "personal" && zephyr.type === "huddle") {
$("#class").val(zephyr.display_recipient); // reply_to for huddle messages is the whole huddle, so for
$("#instance").val(zephyr.instance); // personals replies we need to set the the huddle recipient
show_compose('class', $("#new_zephyr")); // to just the sender
$("#huddle_recipient").val(zephyr.sender); $("#huddle_recipient").val(zephyr.sender_email);
break;
case 'huddle':
$('#zephyr-type-tabs a[href="#personal-message"]').tab('show');
show_compose('personal', $("#new_zephyr"));
$("#huddle_recipient").val(zephyr.reply_to);
break;
case 'personal':
// Until we allow sending zephyrs based on multiple meaningful
// representations of a user (name, username, email, etc.), just
// deal with emails.
show_compose('personal', $("#new_zephyr"));
$("#huddle_recipient").val(zephyr.reply_to);
break;
} }
tabname = reply_type;
if (tabname === undefined) {
tabname = zephyr.type;
}
if (tabname === "huddle") {
// Huddle messages use the personals compose box
tabname = "personal";
}
show_compose(tabname, $("#new_zephyr"));
} }
// Called by mouseover etc. // Called by mouseover etc.
@ -191,12 +185,6 @@ function select_zephyr(next_zephyr, scroll_to) {
} }
} }
function prepare_huddle(recipients) {
// Used for both personals and huddles.
show_compose('personal', $("#new_zephyr"));
$("#huddle_recipient").val(recipients);
}
function same_recipient(a, b) { function same_recipient(a, b) {
if ((a === undefined) || (b === undefined)) if ((a === undefined) || (b === undefined))
return false; return false;
@ -376,6 +364,7 @@ function add_zephyr_metadata(dummy, zephyr) {
instance_list.push(zephyr.instance); instance_list.push(zephyr.instance);
autocomplete_needs_update = true; autocomplete_needs_update = true;
} }
zephyr.reply_to = zephyr.sender_email;
break; break;
case 'huddle': case 'huddle':