2012-10-04 07:13:28 +02:00
|
|
|
// For tracking where you were before you narrowed.
|
2012-10-10 00:10:05 +02:00
|
|
|
var persistent_message_id = 0;
|
2012-10-04 07:13:28 +02:00
|
|
|
|
2012-10-03 20:49:58 +02:00
|
|
|
// Narrowing predicate, or 'false' for the home view.
|
|
|
|
var narrowed = false;
|
|
|
|
|
|
|
|
function do_narrow(description, filter_function) {
|
|
|
|
narrowed = filter_function;
|
|
|
|
|
|
|
|
// Your pointer isn't changed when narrowed.
|
2012-10-10 00:10:05 +02:00
|
|
|
persistent_message_id = selected_message_id;
|
2012-10-03 20:49:58 +02:00
|
|
|
|
|
|
|
// Empty the filtered table right before we fill it again
|
|
|
|
clear_table('zfilt');
|
2012-10-09 23:48:41 +02:00
|
|
|
add_to_table(message_array, 'zfilt', filter_function, 'bottom');
|
2012-10-03 20:49:58 +02:00
|
|
|
|
|
|
|
// Show the new set of messages.
|
|
|
|
$("#zfilt").addClass("focused_table");
|
|
|
|
|
|
|
|
$("#show_all_messages").removeAttr("disabled");
|
2012-10-11 22:34:57 +02:00
|
|
|
$(".narrowcontent").show();
|
2012-10-03 20:49:58 +02:00
|
|
|
$("#main_div").addClass("narrowed_view");
|
2012-10-09 21:10:20 +02:00
|
|
|
$("#currently_narrowed_to").html(description).attr("title", description);
|
2012-10-03 20:49:58 +02:00
|
|
|
$("#zhome").removeClass("focused_table");
|
|
|
|
|
2012-10-10 00:09:25 +02:00
|
|
|
select_and_show_by_id(selected_message_id);
|
2012-10-03 20:49:58 +02:00
|
|
|
scroll_to_selected();
|
|
|
|
}
|
|
|
|
|
|
|
|
function narrow_huddle() {
|
2012-10-10 00:09:25 +02:00
|
|
|
var original = message_dict[selected_message_id];
|
2012-10-09 21:11:10 +02:00
|
|
|
do_narrow("Huddles with " + original.reply_to, function (other) {
|
2012-10-03 20:49:58 +02:00
|
|
|
return other.reply_to === original.reply_to;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function narrow_all_personals() {
|
|
|
|
do_narrow("All huddles with you", function (other) {
|
|
|
|
return other.type === "personal" || other.type === "huddle";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function narrow_personals() {
|
|
|
|
// Narrow to personals with a specific user
|
2012-10-10 00:09:25 +02:00
|
|
|
var original = message_dict[selected_message_id];
|
2012-10-03 20:49:58 +02:00
|
|
|
var other_party;
|
2012-10-12 16:47:01 +02:00
|
|
|
if (original.display_recipient.email === email) {
|
2012-10-03 20:49:58 +02:00
|
|
|
other_party = original.sender_email;
|
|
|
|
} else {
|
2012-10-12 16:47:01 +02:00
|
|
|
other_party = original.display_recipient.email;
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
do_narrow("Huddles with " + other_party, function (other) {
|
|
|
|
return (other.type === 'personal') &&
|
2012-10-12 16:47:01 +02:00
|
|
|
(((other.display_recipient.email === original.display_recipient.email) && (other.sender_email === original.sender_email)) ||
|
|
|
|
((other.display_recipient.email === original.sender_email) && (other.sender_email === original.display_recipient.email)));
|
2012-10-03 20:49:58 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-10 23:24:11 +02:00
|
|
|
function narrow_stream() {
|
2012-10-10 00:09:25 +02:00
|
|
|
var original = message_dict[selected_message_id];
|
2012-10-03 20:49:58 +02:00
|
|
|
var message = original.display_recipient;
|
|
|
|
do_narrow(message, function (other) {
|
2012-10-10 23:09:16 +02:00
|
|
|
return (other.type === 'stream' &&
|
2012-10-03 20:49:58 +02:00
|
|
|
original.recipient_id === other.recipient_id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-10-11 00:01:39 +02:00
|
|
|
function narrow_subject() {
|
2012-10-10 00:09:25 +02:00
|
|
|
var original = message_dict[selected_message_id];
|
2012-10-10 23:09:16 +02:00
|
|
|
if (original.type !== 'stream')
|
2012-10-03 20:49:58 +02:00
|
|
|
return;
|
|
|
|
|
2012-10-11 00:01:39 +02:00
|
|
|
var message = original.display_recipient + " | " + original.subject;
|
2012-10-03 20:49:58 +02:00
|
|
|
do_narrow(message, function (other) {
|
2012-10-10 23:09:16 +02:00
|
|
|
return (other.type === 'stream' &&
|
2012-10-03 20:49:58 +02:00
|
|
|
original.recipient_id === other.recipient_id &&
|
2012-10-11 00:01:39 +02:00
|
|
|
original.subject === other.subject);
|
2012-10-03 20:49:58 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-10-10 23:24:11 +02:00
|
|
|
// Called for the 'narrow by stream' hotkey.
|
2012-10-03 20:49:58 +02:00
|
|
|
function narrow_by_recipient() {
|
2012-10-10 00:09:25 +02:00
|
|
|
switch (message_dict[selected_message_id].type) {
|
2012-10-03 20:49:58 +02:00
|
|
|
case 'personal': narrow_personals(); break;
|
|
|
|
case 'huddle': narrow_huddle(); break;
|
2012-10-10 23:24:11 +02:00
|
|
|
case 'stream': narrow_stream(); break;
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_all_messages() {
|
|
|
|
if (!narrowed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
narrowed = false;
|
|
|
|
|
|
|
|
$("#zfilt").removeClass('focused_table');
|
|
|
|
$("#zhome").addClass('focused_table');
|
2012-10-11 22:34:57 +02:00
|
|
|
$(".narrowcontent").hide();
|
2012-10-03 20:49:58 +02:00
|
|
|
$("#main_div").removeClass('narrowed_view');
|
|
|
|
$("#show_all_messages").attr("disabled", "disabled");
|
|
|
|
$("#currently_narrowed_to").html("");
|
|
|
|
|
|
|
|
// Includes scrolling.
|
2012-10-10 00:10:05 +02:00
|
|
|
select_and_show_by_id(persistent_message_id);
|
2012-10-03 20:49:58 +02:00
|
|
|
|
|
|
|
scroll_to_selected();
|
|
|
|
}
|