mirror of
https://github.com/zulip/zulip.git
synced 2025-10-29 19:13:53 +00:00
refactor: Extract huddle_data.js.
This makes it so that search_suggestion.js
does not depend on activity.js.
That dependency hasn't really been "elegant"
for quite some time, but it will become particularly
unnecessary when we go to remove the "Group PMs"
section from the right sidebar.
This commit introduces a temporary wart
where we have these two functions with the
same name in a sort of unnecessarily
complicated code stack:
activity.process_loaded_messages
huddle_data.process_loaded_messages
But we will eliminate the former function
very soon, and our message-related codepaths
will just call the `huddle_data` version
directly.
TESTING NOTES:
Now that `huddle_data` is a tiny leaf
module, it's super easy to just use the
real implementation of what was formerly
called `activity.get_huddles()` (and is
now in `huddle_data`).
When I first wrote this commit, introducing
the real implementation of `get_huddles` exposed
some bugs that I fixed in the immediately
prior commits to this.
When the tests were originally written,
I believe `activity.js` had some annoying
`jQuery` dependencies that made it hard
to unit test against. We've slimmed it over
time to be mostly just a "controller" module.
But even in its current state it would have
been a bit of a bloated dependency.
The other friction for using the actual
version of `get_huddles` was setting up
the message data, but that's pretty minor.
This commit is contained in:
30
static/js/huddle_data.js
Normal file
30
static/js/huddle_data.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const huddle_timestamps = new Map();
|
||||
|
||||
exports.process_loaded_messages = function (messages) {
|
||||
let need_resize = false;
|
||||
|
||||
for (const message of messages) {
|
||||
const huddle_string = people.huddle_string(message);
|
||||
|
||||
if (huddle_string) {
|
||||
const old_timestamp = huddle_timestamps.get(huddle_string);
|
||||
|
||||
if (!old_timestamp || old_timestamp < message.timestamp) {
|
||||
huddle_timestamps.set(huddle_string, message.timestamp);
|
||||
need_resize = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return need_resize;
|
||||
};
|
||||
|
||||
exports.get_huddles = function () {
|
||||
let huddles = Array.from(huddle_timestamps.keys());
|
||||
huddles = _.sortBy(huddles, function (huddle) {
|
||||
return huddle_timestamps.get(huddle);
|
||||
});
|
||||
return huddles.reverse();
|
||||
};
|
||||
|
||||
window.huddle_data = exports;
|
||||
Reference in New Issue
Block a user