2017-06-01 07:42:57 +02:00
|
|
|
var recent_senders = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var senders = new Dict(); // key is stream-id, value is Dict
|
|
|
|
|
|
|
|
exports.process_message_for_senders = function (message) {
|
|
|
|
var stream_id = message.stream_id.toString();
|
|
|
|
var topic_dict = senders.get(stream_id) || new Dict({fold_case: true});
|
|
|
|
var sender_timestamps = topic_dict.get(message.subject) || new Dict();
|
|
|
|
var old_timestamp = sender_timestamps.get(message.sender_id);
|
|
|
|
|
|
|
|
if (old_timestamp === undefined || old_timestamp < message.timestamp) {
|
|
|
|
sender_timestamps.set(message.sender_id, message.timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
topic_dict.set(message.subject, sender_timestamps);
|
|
|
|
senders.set(stream_id, topic_dict);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.compare_by_recency = function (user_a, user_b, stream_id, topic) {
|
|
|
|
stream_id = stream_id.toString();
|
|
|
|
|
|
|
|
var topic_dict = senders.get(stream_id);
|
2017-07-28 19:39:44 +02:00
|
|
|
if (topic !== undefined && topic_dict !== undefined) {
|
2017-06-01 07:42:57 +02:00
|
|
|
var sender_timestamps = topic_dict.get(topic);
|
|
|
|
if (sender_timestamps !== undefined) {
|
|
|
|
var b_timestamp = sender_timestamps.get(user_b.user_id) || Number.NEGATIVE_INFINITY;
|
|
|
|
var a_timestamp = sender_timestamps.get(user_a.user_id) || Number.NEGATIVE_INFINITY;
|
|
|
|
return b_timestamp - a_timestamp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 19:39:44 +02:00
|
|
|
// TODO: We should also compare by stream (and maybe also by
|
|
|
|
// overall message recency in the realm) in the common case where
|
|
|
|
// there's no traffic on the current topic from this user.
|
|
|
|
|
2017-06-01 07:42:57 +02:00
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = recent_senders;
|
|
|
|
}
|