Track what user action triggered a narrow

(imported from commit 2b110dc27334e4b823810bfef13c3d10d36b3886)
This commit is contained in:
Zev Benjamin
2013-05-21 13:34:15 -04:00
parent d1ac16ee3f
commit d35c8f0c81
5 changed files with 35 additions and 29 deletions

View File

@@ -118,7 +118,8 @@ function do_hashchange() {
}
narrow.activate(operators, {
select_first_unread: true,
change_hash: false // already set
change_hash: false, // already set
trigger: 'hash change'
});
ui.update_floating_recipient_bar();
return true;

View File

@@ -18,8 +18,8 @@ var directional_hotkeys_id = {
var narrow_hotkeys = {
115: narrow.by_recipient, // 's'
83: narrow.by_subject, // 'S'
118: function () { // 'v'
narrow.by('is', 'private-message');
118: function (target, opts) { // 'v'
narrow.by('is', 'private-message', opts);
}
};
@@ -138,7 +138,7 @@ function process_hotkey(e) {
if (current_msg_list.empty()) {
return false;
}
narrow_hotkeys[code](current_msg_list.selected_id());
narrow_hotkeys[code](current_msg_list.selected_id(), {trigger: 'hotkey'});
return true;
}

View File

@@ -349,7 +349,8 @@ exports.activate = function (operators, opts) {
opts = $.extend({}, {
then_select_id: home_msg_list.selected_id(),
select_first_unread: false,
change_hash: true
change_hash: true,
trigger: 'unknown'
}, opts);
if (opts.then_select_id === -1) {
@@ -459,7 +460,8 @@ exports.activate = function (operators, opts) {
compose.update_faded_messages();
$(document).trigger($.Event('narrow_activated.zephyr', {msg_list: narrowed_msg_list,
filter: current_filter}));
filter: current_filter,
trigger: opts.trigger}));
};
// Activate narrowing with a single operator.
@@ -468,36 +470,39 @@ exports.by = function (operator, operand, opts) {
exports.activate([[operator, operand]], opts);
};
exports.by_subject = function (target_id) {
exports.by_subject = function (target_id, opts) {
var original = current_msg_list.get(target_id);
if (original.type !== 'stream') {
// Only stream messages have subjects, but the
// user wants us to narrow in some way.
exports.by_recipient(target_id);
exports.by_recipient(target_id, opts);
return;
}
opts = $.extend({}, {then_select_id: target_id}, opts);
exports.activate([
['stream', original.stream],
['subject', original.subject]
], { then_select_id: target_id });
], opts);
};
// Called for the 'narrow by stream' hotkey.
exports.by_recipient = function (target_id) {
exports.by_recipient = function (target_id, opts) {
opts = $.extend({}, {then_select_id: target_id}, opts);
var message = current_msg_list.get(target_id);
switch (message.type) {
case 'private':
exports.by('pm-with', message.reply_to, { then_select_id: target_id });
exports.by('pm-with', message.reply_to, opts);
break;
case 'stream':
exports.by('stream', message.stream, { then_select_id: target_id });
exports.by('stream', message.stream, opts);
break;
}
};
exports.by_time_travel = function (target_id) {
narrow.activate([], { then_select_id: target_id });
exports.by_time_travel = function (target_id, opts) {
opts = $.extend({}, {then_select_id: target_id}, opts);
narrow.activate([], opts);
};
exports.deactivate = function () {

View File

@@ -112,7 +112,7 @@ function narrow_or_search_for_term(item) {
ui.change_tab_to('#home');
switch (obj.action) {
case 'stream':
narrow.by('stream', obj.query);
narrow.by('stream', obj.query, {trigger: 'search'});
// It's sort of annoying that this is not in a position to
// blur the search box, because it means that Esc won't
// unnarrow, it'll leave the searchbox.
@@ -123,17 +123,17 @@ function narrow_or_search_for_term(item) {
return search_query_box.val();
case 'private_message':
narrow.by('pm-with', obj.query.email);
narrow.by('pm-with', obj.query.email, {trigger: 'search'});
search_query_box.blur();
return search_query_box.val();
case 'sender':
narrow.by('sender', obj.query.email);
narrow.by('sender', obj.query.email, {trigger: 'search'});
search_query_box.blur();
return search_query_box.val();
case 'operators':
narrow.activate(obj.operators);
narrow.activate(obj.operators, {trigger: 'search'});
search_query_box.blur();
return search_query_box.val();
}

View File

@@ -1121,9 +1121,9 @@ $(function () {
var nearest = current_msg_list.get(rows.id($(this).closest(".recipient_row")));
var selected = current_msg_list.selected_message();
if (util.same_recipient(nearest, selected)) {
narrow.by_recipient(selected.id);
narrow.by_recipient(selected.id, {trigger: 'message header'});
} else {
narrow.by_recipient(nearest.id);
narrow.by_recipient(nearest.id, {trigger: 'message header'});
}
});
@@ -1131,9 +1131,9 @@ $(function () {
var nearest = current_msg_list.get(rows.id($(this).closest(".recipient_row")));
var selected = current_msg_list.selected_message();
if (util.same_recipient(nearest, selected)) {
narrow.by_subject(selected.id);
narrow.by_subject(selected.id, {trigger: 'message header'});
} else {
narrow.by_subject(nearest.id);
narrow.by_subject(nearest.id, {trigger: 'message header'});
}
});
@@ -1233,7 +1233,7 @@ $(function () {
ui.change_tab_to('#home');
}
var stream = $(e.target).parents('li').attr('data-name');
narrow.by('stream', stream, {select_first_unread: true});
narrow.by('stream', stream, {select_first_unread: true, trigger: 'sidebar'});
e.preventDefault();
});
@@ -1264,7 +1264,7 @@ $(function () {
narrow.activate([['stream', stream],
['subject', subject]],
{select_first_unread: true});
{select_first_unread: true, trigger: 'sidebar'});
e.preventDefault();
});
@@ -1343,26 +1343,26 @@ $(function () {
$('body').on('click', '.popover_narrow_by_subject_button', function (e) {
var msgid = $(e.currentTarget).data('msgid');
ui.hide_actions_popover();
narrow.by_subject(msgid);
narrow.by_subject(msgid, {trigger: 'popover'});
e.stopPropagation();
});
$('body').on('click', '.popover_narrow_by_recipient_button', function (e) {
var msgid = $(e.currentTarget).data('msgid');
ui.hide_actions_popover();
narrow.by_recipient(msgid);
narrow.by_recipient(msgid, {trigger: 'popover'});
e.stopPropagation();
});
$('body').on('click', '.popover_narrow_by_sender_button', function (e) {
var msgid = $(e.currentTarget).data('msgid');
var sender_email = $(e.currentTarget).data('sender_email');
ui.hide_actions_popover();
narrow.by('sender', sender_email, {then_select_id: msgid});
narrow.by('sender', sender_email, {then_select_id: msgid, trigger: 'popover'});
e.stopPropagation();
});
$('body').on('click', '.popover_narrow_by_time_travel_button', function (e) {
var msgid = $(e.currentTarget).data('msgid');
ui.hide_actions_popover();
narrow.by_time_travel(msgid);
narrow.by_time_travel(msgid, {trigger: 'popover'});
e.stopPropagation();
});
$('body').on('click', '.popover_toggle_collapse', function (e) {
@@ -1415,7 +1415,7 @@ $(function () {
$('body').on('click', '.narrow_to_stream', function (e) {
var stream = $(e.currentTarget).parents('ul').attr('data-name');
ui.hide_sidebar_popover();
narrow.by('stream', stream, {select_first_unread: true});
narrow.by('stream', stream, {select_first_unread: true, trigger: 'sidebar popover'});
e.stopPropagation();
});