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_array zephyr_dict'
+ ' 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'
+ ' scroll_to_selected select_and_show_by_id'
+ ' selected_zephyr selected_zephyr_id'

View File

@ -82,8 +82,7 @@ function process_hotkey(code) {
respond_to_zephyr();
return process_key_in_input;
case 82: // 'R': respond to author
$('#zephyr-type-tabs a[href="#personal-message"]').tab('show');
prepare_huddle(zephyr_dict[selected_zephyr_id].sender_email);
respond_to_zephyr("personal");
return process_key_in_input;
case 103: // 'g': start of "go to" command
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) {
select_zephyr_by_id(zephyr_row.attr('zid'));
// populate the stream box
respond_to_zephyr();
// but we really want to be in huddle mode
prepare_huddle(sender);
respond_to_zephyr("personal");
// The sender span is inside the messagebox, which also has an
// onclick handler. We don't want to trigger the messagebox
// handler.
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).
select_zephyr_by_id(zephyr_id);
respond_to_zephyr();
set_keydown_in_input(true);
}
mouse_moved = false;
clicking = false;
@ -117,6 +111,8 @@ function update_autocomplete() {
$(function () {
// NB: This just binds to current elements, and won't bind to elements
// created after ready() is called.
// Enable our hotkeys when we're not focused on a data entry box
$('input, textarea, button').focus(function () {
set_keydown_in_input(true);
});

View File

@ -107,33 +107,27 @@ function get_huddle_recipient_names(zephyr) {
return recipient;
}
function respond_to_zephyr() {
var zephyr, recipient, recipients;
function respond_to_zephyr(reply_type) {
var zephyr, tabname;
zephyr = zephyr_dict[selected_zephyr_id];
switch (zephyr.type) {
case 'class':
$('#zephyr-type-tabs a[href="#class-message"]').tab('show');
$("#class").val(zephyr.display_recipient);
$("#instance").val(zephyr.instance);
show_compose('class', $("#new_zephyr"));
$("#huddle_recipient").val(zephyr.sender);
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;
$("#class").val(zephyr.display_recipient);
$("#instance").val(zephyr.instance);
$("#huddle_recipient").val(zephyr.reply_to);
if (reply_type === "personal" && zephyr.type === "huddle") {
// reply_to for huddle messages is the whole huddle, so for
// personals replies we need to set the the huddle recipient
// to just the sender
$("#huddle_recipient").val(zephyr.sender_email);
}
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.
@ -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) {
if ((a === undefined) || (b === undefined))
return false;
@ -376,6 +364,7 @@ function add_zephyr_metadata(dummy, zephyr) {
instance_list.push(zephyr.instance);
autocomplete_needs_update = true;
}
zephyr.reply_to = zephyr.sender_email;
break;
case 'huddle':