zulip/web/src/huddle_data.js
Anders Kaseorg 2a70c11c5f eslint: Fix unicorn/prefer-spread.
This was initially disabled for IE/Babel-related reasons that no
longer apply.

Signed-off-by: Anders Kaseorg <[email protected]>
2023-03-02 12:16:56 -08:00

30 lines
792 B
JavaScript

import _ from "lodash";
import * as people from "./people";
const huddle_timestamps = new Map();
export function clear_for_testing() {
huddle_timestamps.clear();
}
export function process_loaded_messages(messages) {
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);
}
}
}
}
export function get_huddles() {
let huddles = [...huddle_timestamps.keys()];
huddles = _.sortBy(huddles, (huddle) => huddle_timestamps.get(huddle));
return huddles.reverse();
}