Use server-highlighted subject and content when narrowed to a search

(imported from commit 0579193da040db77f9c7937d3714cb9ffeaf7ed8)
This commit is contained in:
Zev Benjamin
2013-04-29 16:56:50 -04:00
parent fca8f84c14
commit c08a86aeb9
5 changed files with 20 additions and 44 deletions

View File

@@ -383,7 +383,8 @@ MessageList.prototype = {
var rendered_elems = $(templates.render('message', {
messages: messages_to_render,
include_layout_row: (table.find('tr:first').length === 0)
include_layout_row: (table.find('tr:first').length === 0),
use_match_properties: this.filter.is_search()
}));
$.each(rendered_elems, function (index, elem) {
@@ -395,10 +396,6 @@ MessageList.prototype = {
if (ids_where_next_is_same_sender[id]) {
row.find('.messagebox').addClass("next_is_same_sender");
}
if (self === narrowed_msg_list) {
// If narrowed, we may need to highlight the message
search.maybe_highlight_message(row);
}
});
// The message that was last before this batch came in has to be

View File

@@ -36,16 +36,20 @@ Filter.prototype = {
}
},
can_apply_locally: function Filter_can_apply_locally() {
var retval = true;
is_search: function Filter_is_search() {
var retval = false;
$.each(this._operators, function (idx, elem) {
if (elem[0] === "search") {
retval = false;
retval = true;
return false;
}});
return retval;
},
can_apply_locally: function Filter_can_apply_locally() {
return ! this.is_search();
},
_canonicalize_operators: function Filter__canonicalize_operators(operators_mixed_case) {
var new_operators = [];
// We don't use $.map because it flattens returned arrays.
@@ -424,7 +428,6 @@ exports.activate = function (operators, opts) {
}
return undefined;
}
search.update_highlighting(extract_search_terms(operators));
// Put the narrow operators in the URL fragment.
// Disabled when the URL fragment was the source
@@ -528,8 +531,6 @@ exports.deactivate = function () {
// view since leaving it the old selected id might no longer be there
home_msg_list.select_id(home_msg_list.selected_id(), {then_scroll: true, use_closest: true});
search.clear_highlighting();
hashchange.save_narrow();
$("ul.filters li").removeClass('active-filter active-subject-filter');

View File

@@ -268,35 +268,6 @@ function match_on_visible_text(row, search_term) {
.text().toLowerCase().indexOf(search_term) !== -1;
}
exports.update_highlighting = function(search_term) {
if (current_search_term !== undefined) {
exports.clear_highlighting();
}
current_search_term = search_term;
if (search_term === undefined) {
return;
}
var focused_table = $('table.focused_table');
focused_table.find('.message_row').each(function (index, row) {
row = $(row);
exports.maybe_highlight_message(row);
});
};
exports.maybe_highlight_message = function(row) {
row.find('.message_content').highlight(current_search_term);
if (current_msg_list.get(rows.id(row)).type === "stream") {
row = row.prev('.recipient_row');
row.find('.message_label_clickable').highlight(current_search_term);
}
};
exports.clear_highlighting = function () {
current_search_term = undefined;
return $(".message_content .message_label_clickable").removeHighlight();
};
exports.focus_search = function () {
// The search bar is not focused yet, but will be.
update_buttons_with_focus(true);

View File

@@ -501,8 +501,15 @@ function process_message_for_recent_subjects(message) {
}
function add_message_metadata(message, dummy) {
if (all_msg_list.get(message.id)) {
return all_msg_list.get(message.id);
var cached_msg = all_msg_list.get(message.id);
if (cached_msg !== undefined) {
// Copy the match subject and content over if they exist on
// the new message
if (message.match_subject !== undefined) {
cached_msg.match_subject = message.match_subject;
cached_msg.match_content = message.match_content;
}
return cached_msg;
}
get_updates_params.last = Math.max(get_updates_params.last || 0, message.id);

View File

@@ -41,7 +41,7 @@
title="Narrow to stream &quot;{{display_recipient}}&quot;">{{display_recipient}}</span>
&nbsp; &gt; &nbsp;
<span class="message_label_clickable narrows_by_subject"
title="Narrow to stream &quot;{{display_recipient}}&quot;, subject &quot;{{subject}}&quot;">{{subject}}</span>
title="Narrow to stream &quot;{{display_recipient}}&quot;, subject &quot;{{subject}}&quot;">{{#if ../../../../use_match_properties}}{{{match_subject}}}{{else}}{{subject}}{{/if}}</span>
</td>
</tr>
{{else}}
@@ -84,7 +84,7 @@
<span class="message_time">{{{timestr}}}</span>
</div>
</div>
<div class="message_content">{{{content}}}</div>
<div class="message_content">{{#if ../../use_match_properties}}{{{match_content}}}{{else}}{{{content}}}{{/if}}</div>
<div class="message_expander message_length_controller" title="See the rest of this message">[More...]</div>
<div class="message_collapser message_length_controller" title="Make this message take up less space on the screen">[Collapse this message]</div>
</td>