{"size": 1050, "ext": "js", "max_stars_repo_path": "assets/js/messages/update_messages/read_status.js", "max_stars_repo_name": "MatthiasApsel/cforum_ex", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assets/js/messages/update_messages/read_status.js", "max_issues_repo_name": "MatthiasApsel/cforum_ex", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assets/js/messages/update_messages/read_status.js", "max_forks_repo_name": "MatthiasApsel/cforum_ex", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.3783783784, "max_line_length": 112, "alphanum_fraction": 0.599047619}
import { conf } from "../../modules/helpers";
import { getMessageTreeElement } from "./index";
import { updateTitleInfos } from "../../title_infos";

const threadIsVisited = thread => {
  return thread.querySelectorAll(".cf-message-header:not(.visited)").length === 0;
};
const shouldFold = thread => threadIsVisited(thread) && document.body.dataset.controller === "ThreadController";

if (document.body.dataset.userId) {
  document.addEventListener("cf:userPrivate", event => {
    const channel = event.detail;

    channel.on("message_marked_read", ({ message_ids }) => {
      updateTitleInfos();

      message_ids.forEach(id => {
        const elem = getMessageTreeElement(id);
        if (!elem) {
          return;
        }

        elem.classList.add("visited");

        const thread = elem.closest(".cf-thread");

        if (conf("open_close_close_when_read") === "yes" && shouldFold(thread)) {
          const ol = thread.querySelector("ol");
          if (ol) {
            ol.remove();
          }
        }
      });
    });
  });
}
