Extract message_store.insert_recent_private_message().

This function is slightly easier to unit test, and it isolates us
from changing message formats.  This removes some extraneous
code that would ensure that message timestamps were >= 0 that
probaby dates back to some really old migrations.
This commit is contained in:
Steve Howell 2017-04-13 11:34:21 -07:00 committed by Tim Abbott
parent 6b549248e8
commit f5550301cf
1 changed files with 4 additions and 3 deletions

View File

@ -57,8 +57,6 @@ exports.get_pm_full_names = function (message) {
};
exports.process_message_for_recent_private_messages = function (message) {
var current_timestamp = 0;
var user_ids = people.pm_with_user_ids(message);
if (!user_ids) {
return;
@ -70,7 +68,10 @@ exports.process_message_for_recent_private_messages = function (message) {
blueslip.warn('Unknown reply_to in message: ' + user_ids_string);
return;
}
exports.insert_recent_private_message(user_ids_string, message.timestamp);
};
exports.insert_recent_private_message = function (user_ids_string, timestamp) {
// If this conversation is already tracked, we'll replace with new timestamp,
// so remove it from the current list.
exports.recent_private_messages = _.filter(exports.recent_private_messages,
@ -79,7 +80,7 @@ exports.process_message_for_recent_private_messages = function (message) {
});
var new_conversation = {user_ids_string: user_ids_string,
timestamp: Math.max(message.timestamp, current_timestamp)};
timestamp: timestamp};
exports.recent_private_messages.push(new_conversation);
exports.recent_private_messages.sort(function (a, b) {