mirror of https://github.com/zulip/zulip.git
Add activity.process_loaded_messages() and get_huddles().
Activity.js now has the capability to track huddles that come through in loaded messages and return them in reverse chronological order by their most recent message. Right now this only connected to a unit test, not any production code. (imported from commit 59957086fa2e454e5711472df091f178217aed2b)
This commit is contained in:
parent
a4ff7320fb
commit
6d511486cb
|
@ -39,6 +39,30 @@ $("html").on("mousemove", function () {
|
|||
|
||||
var presence_info = {};
|
||||
|
||||
var huddle_timestamps = new Dict();
|
||||
|
||||
exports.process_loaded_messages = function (messages) {
|
||||
_.each(messages, function (message) {
|
||||
if (message.type === 'private') {
|
||||
if (message.reply_to.indexOf(',') > 0) {
|
||||
var old_timestamp = huddle_timestamps.get(message.reply_to);
|
||||
|
||||
if (!old_timestamp || (old_timestamp < message.timestamp)) {
|
||||
huddle_timestamps.set(message.reply_to, message.timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.get_huddles = function () {
|
||||
var huddles = huddle_timestamps.keys();
|
||||
huddles = _.sortBy(huddles, function (huddle) {
|
||||
return huddle_timestamps.get(huddle);
|
||||
});
|
||||
return huddles.reverse();
|
||||
};
|
||||
|
||||
function sort_users(users, presence_info) {
|
||||
// TODO sort by unread count first, once we support that
|
||||
users.sort(function (a, b) {
|
||||
|
|
|
@ -46,3 +46,45 @@ var activity = require('js/activity.js');
|
|||
'alice@zulip.com'
|
||||
]);
|
||||
}());
|
||||
|
||||
(function test_process_loaded_messages() {
|
||||
|
||||
var huddle1 = 'bar@zulip.com,foo@zulip.com';
|
||||
var timestamp1 = 1382479029; // older
|
||||
|
||||
var huddle2 = 'alice@zulip.com,bob@zulip.com';
|
||||
var timestamp2 = 1382479033; // newer
|
||||
|
||||
var old_timestamp = 1382479000;
|
||||
|
||||
var messages = [
|
||||
{
|
||||
type: 'private',
|
||||
reply_to: huddle1,
|
||||
timestamp: timestamp1
|
||||
},
|
||||
{
|
||||
type: 'stream'
|
||||
},
|
||||
{
|
||||
type: 'private',
|
||||
reply_to: 'ignore@zulip.com'
|
||||
},
|
||||
{
|
||||
type: 'private',
|
||||
reply_to: huddle2,
|
||||
timestamp: timestamp2
|
||||
},
|
||||
{
|
||||
type: 'private',
|
||||
reply_to: huddle2,
|
||||
timestamp: old_timestamp
|
||||
}
|
||||
];
|
||||
|
||||
activity.process_loaded_messages(messages);
|
||||
|
||||
assert.deepEqual(activity.get_huddles(), [huddle2, huddle1]);
|
||||
}());
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue