zulip.subject_dict -> composebox_typeahead.seen_topics

Move zulip.subject_dict into composebox_typeahead.seen_topics,
and encapsulate the use of seen_topics inside composebox_typeahead
with add_topic() and topics_seen_for().

(imported from commit 2bc2d1714fabdc07a661cbf815d14b36a08990e2)
This commit is contained in:
Steve Howell 2013-08-13 19:02:22 -04:00
parent 34e0c1e696
commit 050c8ad103
3 changed files with 30 additions and 21 deletions

View File

@ -28,6 +28,32 @@ exports.get_cleaned_pm_recipients = function (query_string) {
return recipients;
};
function case_insensitive_find(term, array) {
var lowered_term = term.toLowerCase();
return _.filter(array, function (elt) {
return elt.toLowerCase() === lowered_term;
}).length !== 0;
}
var seen_topics = new Dict();
exports.add_topic = function (stream, topic) {
if (! seen_topics.has(stream)) {
seen_topics.set(stream, []);
}
if (! case_insensitive_find(topic, seen_topics.get(stream))) {
seen_topics.get(stream).push(topic);
seen_topics.get(stream).sort();
}
};
exports.topics_seen_for = function (stream) {
if (seen_topics.has(stream)) {
return seen_topics.get(stream);
}
return [];
};
function get_last_recipient_in_pm(query_string) {
var recipients = get_pm_recipients(query_string);
return recipients[recipients.length-1];
@ -202,11 +228,8 @@ exports.initialize = function () {
$( "#subject" ).typeahead({
source: function (query, process) {
var stream_name = $("#stream").val(), i;
if (subject_dict.has(stream_name)) {
return subject_dict.get(stream_name);
}
return [];
var stream_name = $("#stream").val();
return exports.topics_seen_for(stream_name);
},
items: 3,
highlighter: composebox_typeahead_highlighter,

View File

@ -5,7 +5,6 @@ var home_msg_list = new MessageList('zhome',
);
var narrowed_msg_list;
var current_msg_list = home_msg_list;
var subject_dict = new Dict();
var people_dict = new Dict();
var recent_subjects = new Dict();
@ -474,13 +473,6 @@ function unconditionally_send_pointer_update() {
}
}
function case_insensitive_find(term, array) {
var lowered_term = term.toLowerCase();
return _.filter(array, function (elt) {
return elt.toLowerCase() === lowered_term;
}).length !== 0;
}
function process_message_for_recent_subjects(message, remove_message) {
var current_timestamp = 0;
var count = 0;
@ -554,13 +546,7 @@ function add_message_metadata(message) {
case 'stream':
message.is_stream = true;
message.stream = message.display_recipient;
if (! subject_dict.has(message.stream)) {
subject_dict.set(message.stream, []);
}
if (! case_insensitive_find(message.subject, subject_dict.get(message.stream))) {
subject_dict.get(message.stream).push(message.subject);
subject_dict.get(message.stream).sort();
}
composebox_typeahead.add_topic(message.stream, message.subject);
message.reply_to = message.sender_email;
process_message_for_recent_subjects(message);

View File

@ -40,7 +40,7 @@ var globals =
// zulip.js
+ ' all_msg_list home_msg_list narrowed_msg_list current_msg_list get_updates_params'
+ ' add_messages'
+ ' subject_dict people_dict'
+ ' people_dict'
+ ' keep_pointer_in_view'
+ ' respond_to_message recenter_view last_viewport_movement_direction'
+ ' scroll_to_selected get_private_message_recipient'