<commit_before><?php

final class ConpherenceThreadListView extends AphrontView {

  const SEE_MORE_LIMIT = 5;

  private $baseURI;
  private $threads;

  public function setThreads(array $threads) {
    assert_instances_of($threads, 'ConpherenceThread');
    $this->threads = $threads;
    return $this;
  }

  public function setBaseURI($base_uri) {
    $this->baseURI = $base_uri;
    return $this;
  }

  public function render() {
    require_celerity_resource('conpherence-menu-css');

    $menu = id(new PHUIListView())
      ->addClass('conpherence-menu')
      ->setID('conpherence-menu');

    $policy_objects = ConpherenceThread::loadPolicyObjects(
      $this->getUser(),
      $this->threads);

    $grouped = mgroup($this->threads, 'getIsRoom');
    $rooms = idx($grouped, 1, array());
    $this->addRoomsToMenu($menu, $rooms, $policy_objects);
    $messages = idx($grouped, 0, array());
    $this->addMessagesToMenu($menu, $messages);

    return $menu;
  }

  public function renderSingleThread(ConpherenceThread $thread) {
    $policy_objects = id(new PhabricatorPolicyQuery())
      ->setViewer($this->getUser())
      ->setObject($thread)
      ->execute();
    return $this->renderThread($thread, $policy_objects);
  }

  public function renderThreadsHTML() {
    $thread_html = array();

    foreach ($this->threads as $thread) {
      $thread_html[] = $this->renderSingleThread($thread);
    }

    return phutil_implode_html('', $thread_html);
  }

  private function renderThreadItem(
    ConpherenceThread $thread,
    $policy_objects = array()) {
    return id(new PHUIListItemView())
      ->setType(PHUIListItemView::TYPE_CUSTOM)
      ->setName($this->renderThread($thread, $policy_objects));
  }

  private function renderThread(
    ConpherenceThread $thread,
    array $policy_objects) {

    $user = $this->getUser();

    $uri = $this->baseURI.$thread->getID().'/';
    $data = $thread->getDisplayData($user);
    $icon = null;
    if ($thread->getIsRoom()) {
      $icon = id(new PHUIIconView())
        ->addClass('msr')
        ->setIconFont($thread->getPolicyIconName($policy_objects));
    }
    $title = phutil_tag(
      'span',
      array(),
      array(
        $icon,
        $data['title'],
      ));
    $subtitle = $data['subtitle'];
    $unread_count = $data['unread_count'];
    $epoch = $data['epoch'];
    $image = $data['image'];
    $dom_id = $thread->getPHID().'-nav-item';

    return id(new ConpherenceMenuItemView())
      ->setUser($user)
      ->setTitle($title)
      ->setSubtitle($subtitle)
      ->setHref($uri)
      ->setEpoch($epoch)
      ->setImageURI($image)
      ->setUnreadCount($unread_count)
      ->setID($thread->getPHID().'-nav-item')
      ->addSigil('conpherence-menu-click')
      ->setMetadata(
        array(
          'title' => $data['js_title'],
          'id' => $dom_id,
          'threadID' => $thread->getID(),
          ));<commit_msg>Conpherence - don't lose title glyph when switching between messages<commit_after><?php

final class ConpherenceThreadListView extends AphrontView {

  const SEE_MORE_LIMIT = 5;

  private $baseURI;
  private $threads;

  public function setThreads(array $threads) {
    assert_instances_of($threads, 'ConpherenceThread');
    $this->threads = $threads;
    return $this;
  }

  public function setBaseURI($base_uri) {
    $this->baseURI = $base_uri;
    return $this;
  }

  public function render() {
    require_celerity_resource('conpherence-menu-css');

    $menu = id(new PHUIListView())
      ->addClass('conpherence-menu')
      ->setID('conpherence-menu');

    $policy_objects = ConpherenceThread::loadPolicyObjects(
      $this->getUser(),
      $this->threads);

    $grouped = mgroup($this->threads, 'getIsRoom');
    $rooms = idx($grouped, 1, array());
    $this->addRoomsToMenu($menu, $rooms, $policy_objects);
    $messages = idx($grouped, 0, array());
    $this->addMessagesToMenu($menu, $messages);

    return $menu;
  }

  public function renderSingleThread(ConpherenceThread $thread) {
    $policy_objects = id(new PhabricatorPolicyQuery())
      ->setViewer($this->getUser())
      ->setObject($thread)
      ->execute();
    return $this->renderThread($thread, $policy_objects);
  }

  public function renderThreadsHTML() {
    $thread_html = array();

    foreach ($this->threads as $thread) {
      $thread_html[] = $this->renderSingleThread($thread);
    }

    return phutil_implode_html('', $thread_html);
  }

  private function renderThreadItem(
    ConpherenceThread $thread,
    $policy_objects = array()) {
    return id(new PHUIListItemView())
      ->setType(PHUIListItemView::TYPE_CUSTOM)
      ->setName($this->renderThread($thread, $policy_objects));
  }

  private function renderThread(
    ConpherenceThread $thread,
    array $policy_objects) {

    $user = $this->getUser();

    $uri = $this->baseURI.$thread->getID().'/';
    $data = $thread->getDisplayData($user);
    $icon = null;
    if ($thread->getIsRoom()) {
      $icon = id(new PHUIIconView())
        ->addClass('msr')
        ->setIconFont($thread->getPolicyIconName($policy_objects));
    }
    $title = phutil_tag(
      'span',
      array(),
      array(
        $icon,
        $data['title'],
      ));
    $subtitle = $data['subtitle'];
    $unread_count = $data['unread_count'];
    $epoch = $data['epoch'];
    $image = $data['image'];
    $dom_id = $thread->getPHID().'-nav-item';
    $glyph_pref = PhabricatorUserPreferences::PREFERENCE_TITLES;
    $preferences = $user->loadPreferences();
    if ($preferences->getPreference($glyph_pref) == 'glyph') {
      $glyph = id(new PhabricatorConpherenceApplication())
        ->getTitleGlyph().' ';
    } else {
      $glyph = null;
    }

    return id(new ConpherenceMenuItemView())
      ->setUser($user)
      ->setTitle($title)
      ->setSubtitle($subtitle)
      ->setHref($uri)
      ->setEpoch($epoch)
      ->setImageURI($image)
      ->setUnreadCount($unread_count)
      ->setID($thread->getPHID().'-nav-item')
      ->addSigil('conpherence-menu-click')
      ->setMetadata(
        array(
          'title' => $glyph.$data['js_title'],
          'id' => $dom_id,
          'threadID' => $thread->getID(),
          ));
{'fraction_non_alphanumeric': 0.16470966704198167, 'fraction_numerical': 0.0009650957053241113, 'mean_word_length': 3.241473396998636, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 92, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5043444', 'n_tokens_mistral': 2046, 'n_tokens_neox': 1989, 'n_words': 342}