mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +01:00
Use PhabricatorTagView in user mentions
Summary: Refs T1048 - Use `PhabricatorTagView` in user mention remarkup rules. Emits hovercards now :D Also introduces `PhabricatorTagView::COLOR_INEXISTENT` Test Plan: Inspected HTML to find sigil & meta ref. Hovered above them (with hovercard patch, sold separately). Hovercard appeared. Reviewers: epriestley, chad, btrahan Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1048 Differential Revision: https://secure.phabricator.com/D5573
This commit is contained in:
parent
635bd1ef07
commit
f2828481aa
1 changed files with 39 additions and 28 deletions
|
@ -69,46 +69,57 @@ final class PhabricatorRemarkupRuleMention
|
|||
$original = $engine->getTextMetadata($original_key, array());
|
||||
|
||||
$usernames = array_keys($metadata);
|
||||
$user_table = new PhabricatorUser();
|
||||
$real_user_names = queryfx_all(
|
||||
$user_table->establishConnection('r'),
|
||||
'SELECT username, phid, realName, isDisabled
|
||||
FROM %T
|
||||
WHERE username IN (%Ls)',
|
||||
$user_table->getTableName(),
|
||||
$usernames);
|
||||
|
||||
$users = id(new PhabricatorPeopleQuery())
|
||||
->withUsernames($usernames)
|
||||
->execute();
|
||||
|
||||
if ($users) {
|
||||
$user_statuses = id(new PhabricatorUserStatus())
|
||||
->loadCurrentStatuses(mpull($users, 'getPHID'));
|
||||
$user_statuses = mpull($user_statuses, null, 'getUserPHID');
|
||||
} else {
|
||||
$user_statuses = array();
|
||||
}
|
||||
|
||||
$actual_users = array();
|
||||
|
||||
$mentioned_key = self::KEY_MENTIONED;
|
||||
$mentioned = $engine->getTextMetadata($mentioned_key, array());
|
||||
foreach ($real_user_names as $row) {
|
||||
$actual_users[strtolower($row['username'])] = $row;
|
||||
$mentioned[$row['phid']] = $row['phid'];
|
||||
foreach ($users as $row) {
|
||||
$actual_users[strtolower($row->getUserName())] = $row;
|
||||
$mentioned[$row->getPHID()] = $row->getPHID();
|
||||
}
|
||||
|
||||
$engine->setTextMetadata($mentioned_key, $mentioned);
|
||||
|
||||
foreach ($metadata as $username => $tokens) {
|
||||
$exists = isset($actual_users[$username]);
|
||||
if (!$exists) {
|
||||
$class = 'phabricator-remarkup-mention-unknown';
|
||||
} else if ($actual_users[$username]['isDisabled']) {
|
||||
$class = 'phabricator-remarkup-mention-disabled';
|
||||
} else {
|
||||
$class = 'phabricator-remarkup-mention-exists';
|
||||
}
|
||||
|
||||
if ($exists) {
|
||||
$tag = phutil_tag(
|
||||
'a',
|
||||
array(
|
||||
'class' => $class,
|
||||
'href' => '/p/'.$actual_users[$username]['username'].'/',
|
||||
'target' => '_blank',
|
||||
'title' => $actual_users[$username]['realName'],
|
||||
),
|
||||
'@'.$actual_users[$username]['username']);
|
||||
$user = $actual_users[$username];
|
||||
Javelin::initBehavior('phabricator-hovercards');
|
||||
|
||||
$tag = id(new PhabricatorTagView())
|
||||
->setType(PhabricatorTagView::TYPE_PERSON)
|
||||
->setPHID($user->getPHID())
|
||||
->setName('@'.$user->getUserName())
|
||||
->setHref('/p/'.$user->getUserName().'/');
|
||||
|
||||
if ($user->getIsDisabled()) {
|
||||
$tag->setDotColor(PhabricatorTagView::COLOR_GREY);
|
||||
} else {
|
||||
$status = idx($user_statuses, $user->getPHID());
|
||||
if ($status) {
|
||||
$status = $status->getStatus();
|
||||
if ($status == PhabricatorUserStatus::STATUS_AWAY) {
|
||||
$tag->setDotColor(PhabricatorTagView::COLOR_RED);
|
||||
} else if ($status == PhabricatorUserStatus::STATUS_AWAY) {
|
||||
$tag->setDotColor(PhabricatorTagView::COLOR_ORANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
$engine->overwriteStoredText($token, $tag);
|
||||
}
|
||||
|
@ -120,7 +131,7 @@ final class PhabricatorRemarkupRuleMention
|
|||
$tag = phutil_tag(
|
||||
'span',
|
||||
array(
|
||||
'class' => $class,
|
||||
'class' => 'phabricator-remarkup-mention-unknown',
|
||||
),
|
||||
'@'.idx($original, $token, $username));
|
||||
$engine->overwriteStoredText($token, $tag);
|
||||
|
|
Loading…
Reference in a new issue