mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Transactions - add infrastructure for "mentions"
Summary: Fixes T4036. Now if you say something on diff X like "This reminds me of Tx and Dy and commitHashFoo and Px." each of those objects gets a little visible transaction that the mention occurred. No feed, email, or notifications. Test Plan: made a comment like above and verified transactions. also submitted a diff that "Fixes Tx" and Tx did not get the transaction as expected. Reviewers: epriestley Reviewed By: epriestley Subscribers: joshuaspence, epriestley, Korvin Maniphest Tasks: T4036 Differential Revision: https://secure.phabricator.com/D10451
This commit is contained in:
parent
0151c38b10
commit
c75495e63f
11 changed files with 155 additions and 14 deletions
|
@ -1723,6 +1723,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorMarkupPreviewController' => 'infrastructure/markup/PhabricatorMarkupPreviewController.php',
|
||||
'PhabricatorMemeRemarkupRule' => 'applications/macro/markup/PhabricatorMemeRemarkupRule.php',
|
||||
'PhabricatorMentionRemarkupRule' => 'applications/people/markup/PhabricatorMentionRemarkupRule.php',
|
||||
'PhabricatorMentionableInterface' => 'applications/transactions/interface/PhabricatorMentionableInterface.php',
|
||||
'PhabricatorMercurialGraphStream' => 'applications/repository/daemon/PhabricatorMercurialGraphStream.php',
|
||||
'PhabricatorMetaMTAActor' => 'applications/metamta/query/PhabricatorMetaMTAActor.php',
|
||||
'PhabricatorMetaMTAActorQuery' => 'applications/metamta/query/PhabricatorMetaMTAActorQuery.php',
|
||||
|
@ -1808,6 +1809,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorObjectListQueryTestCase' => 'applications/phid/query/__tests__/PhabricatorObjectListQueryTestCase.php',
|
||||
'PhabricatorObjectMailReceiver' => 'applications/metamta/receiver/PhabricatorObjectMailReceiver.php',
|
||||
'PhabricatorObjectMailReceiverTestCase' => 'applications/metamta/receiver/__tests__/PhabricatorObjectMailReceiverTestCase.php',
|
||||
'PhabricatorObjectMentionedByObject' => 'applications/transactions/edges/PhabricatorObjectMentionedByObject.php',
|
||||
'PhabricatorObjectMentionsObject' => 'applications/transactions/edges/PhabricatorObjectMentionsObject.php',
|
||||
'PhabricatorObjectQuery' => 'applications/phid/query/PhabricatorObjectQuery.php',
|
||||
'PhabricatorObjectRemarkupRule' => 'infrastructure/markup/rule/PhabricatorObjectRemarkupRule.php',
|
||||
'PhabricatorObjectSelectorDialog' => 'view/control/PhabricatorObjectSelectorDialog.php',
|
||||
|
@ -3084,6 +3087,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSubscribableInterface',
|
||||
'PhabricatorCustomFieldInterface',
|
||||
'PhabricatorApplicationTransactionInterface',
|
||||
'PhabricatorMentionableInterface',
|
||||
'PhabricatorDestructibleInterface',
|
||||
'PhabricatorProjectInterface',
|
||||
),
|
||||
|
@ -3698,6 +3702,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPolicyInterface',
|
||||
'PhabricatorTokenReceiverInterface',
|
||||
'PhabricatorFlaggableInterface',
|
||||
'PhabricatorMentionableInterface',
|
||||
'PhrequentTrackableInterface',
|
||||
'PhabricatorCustomFieldInterface',
|
||||
'PhabricatorDestructibleInterface',
|
||||
|
@ -4658,6 +4663,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorObjectListQueryTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorObjectMailReceiver' => 'PhabricatorMailReceiver',
|
||||
'PhabricatorObjectMailReceiverTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorObjectMentionedByObject' => 'PhabricatorEdgeType',
|
||||
'PhabricatorObjectMentionsObject' => 'PhabricatorEdgeType',
|
||||
'PhabricatorObjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorObjectRemarkupRule' => 'PhutilRemarkupRule',
|
||||
'PhabricatorOffsetPagedQuery' => 'PhabricatorQuery',
|
||||
|
@ -4693,6 +4700,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSubscribableInterface',
|
||||
'PhabricatorTokenReceiverInterface',
|
||||
'PhabricatorFlaggableInterface',
|
||||
'PhabricatorMentionableInterface',
|
||||
'PhabricatorPolicyInterface',
|
||||
'PhabricatorProjectInterface',
|
||||
),
|
||||
|
@ -4908,6 +4916,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFlaggableInterface',
|
||||
'PhabricatorTokenReceiverInterface',
|
||||
'PhabricatorSubscribableInterface',
|
||||
'PhabricatorMentionableInterface',
|
||||
'HarbormasterBuildableInterface',
|
||||
'PhabricatorCustomFieldInterface',
|
||||
'PhabricatorApplicationTransactionInterface',
|
||||
|
|
|
@ -1270,8 +1270,10 @@ final class DifferentialTransactionEditor
|
|||
->execute();
|
||||
|
||||
if ($tasks) {
|
||||
$phid_map = mpull($tasks, 'getPHID', 'getPHID');
|
||||
$edge_related = DifferentialRevisionHasTaskEdgeType::EDGECONST;
|
||||
$edges[$edge_related] = mpull($tasks, 'getPHID', 'getPHID');
|
||||
$edges[$edge_related] = $phid_map;
|
||||
$this->setUnmentionablePHIDMap($phid_map);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ final class DifferentialRevision extends DifferentialDAO
|
|||
PhabricatorSubscribableInterface,
|
||||
PhabricatorCustomFieldInterface,
|
||||
PhabricatorApplicationTransactionInterface,
|
||||
PhabricatorMentionableInterface,
|
||||
PhabricatorDestructibleInterface,
|
||||
PhabricatorProjectInterface {
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ final class ManiphestTask extends ManiphestDAO
|
|||
PhabricatorPolicyInterface,
|
||||
PhabricatorTokenReceiverInterface,
|
||||
PhabricatorFlaggableInterface,
|
||||
PhabricatorMentionableInterface,
|
||||
PhrequentTrackableInterface,
|
||||
PhabricatorCustomFieldInterface,
|
||||
PhabricatorDestructibleInterface,
|
||||
|
|
|
@ -5,6 +5,7 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
|
|||
PhabricatorSubscribableInterface,
|
||||
PhabricatorTokenReceiverInterface,
|
||||
PhabricatorFlaggableInterface,
|
||||
PhabricatorMentionableInterface,
|
||||
PhabricatorPolicyInterface,
|
||||
PhabricatorProjectInterface {
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ final class PhabricatorRepositoryCommit
|
|||
PhabricatorFlaggableInterface,
|
||||
PhabricatorTokenReceiverInterface,
|
||||
PhabricatorSubscribableInterface,
|
||||
PhabricatorMentionableInterface,
|
||||
HarbormasterBuildableInterface,
|
||||
PhabricatorCustomFieldInterface,
|
||||
PhabricatorApplicationTransactionInterface {
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorObjectMentionedByObject extends PhabricatorEdgeType {
|
||||
|
||||
const EDGECONST = 51;
|
||||
|
||||
public function getInverseEdgeConstant() {
|
||||
return PhabricatorObjectMentionsObject::EDGECONST;
|
||||
}
|
||||
|
||||
public function shouldWriteInverseTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getTransactionAddString(
|
||||
$actor,
|
||||
$add_count,
|
||||
$add_edges) {
|
||||
|
||||
return pht(
|
||||
'%s mentioned this in %s.',
|
||||
$actor,
|
||||
$add_edges);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorObjectMentionsObject extends PhabricatorEdgeType {
|
||||
|
||||
const EDGECONST = 52;
|
||||
|
||||
public function getInverseEdgeConstant() {
|
||||
return PhabricatorObjectMentionedByObject::EDGECONST;
|
||||
}
|
||||
|
||||
public function shouldWriteInverseTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
private $heraldAdapter;
|
||||
private $heraldTranscript;
|
||||
private $subscribers;
|
||||
private $unmentionablePHIDMap = array();
|
||||
|
||||
private $isPreview;
|
||||
private $isHeraldEditor;
|
||||
|
@ -175,6 +176,15 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
return $this->disableEmail;
|
||||
}
|
||||
|
||||
public function setUnmentionablePHIDMap(array $map) {
|
||||
$this->unmentionablePHIDMap = $map;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUnmentionablePHIDMap() {
|
||||
return $this->unmentionablePHIDMap;
|
||||
}
|
||||
|
||||
public function getTransactionTypes() {
|
||||
$types = array();
|
||||
|
||||
|
@ -1013,7 +1023,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
}
|
||||
}
|
||||
|
||||
private function buildMentionTransaction(
|
||||
private function buildSubscribeTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions,
|
||||
array $blocks) {
|
||||
|
@ -1119,12 +1129,12 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
$blocks[$key] = $this->getRemarkupBlocksFromTransaction($xaction);
|
||||
}
|
||||
|
||||
$mention_xaction = $this->buildMentionTransaction(
|
||||
$subscribe_xaction = $this->buildSubscribeTransaction(
|
||||
$object,
|
||||
$xactions,
|
||||
$blocks);
|
||||
if ($mention_xaction) {
|
||||
$xactions[] = $mention_xaction;
|
||||
if ($subscribe_xaction) {
|
||||
$xactions[] = $subscribe_xaction;
|
||||
}
|
||||
|
||||
// TODO: For now, this is just a placeholder.
|
||||
|
@ -1156,17 +1166,22 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
$blocks,
|
||||
$engine);
|
||||
|
||||
if ($object instanceof PhabricatorProjectInterface) {
|
||||
$phids = array();
|
||||
foreach ($blocks as $key => $xaction_blocks) {
|
||||
foreach ($xaction_blocks as $block) {
|
||||
$engine->markupText($block);
|
||||
$phids += $engine->getTextMetadata(
|
||||
PhabricatorObjectRemarkupRule::KEY_MENTIONED_OBJECTS,
|
||||
array());
|
||||
}
|
||||
$mentioned_phids = array();
|
||||
foreach ($blocks as $key => $xaction_blocks) {
|
||||
foreach ($xaction_blocks as $block) {
|
||||
$engine->markupText($block);
|
||||
$mentioned_phids += $engine->getTextMetadata(
|
||||
PhabricatorObjectRemarkupRule::KEY_MENTIONED_OBJECTS,
|
||||
array());
|
||||
}
|
||||
}
|
||||
|
||||
if (!$mentioned_phids) {
|
||||
return $block_xactions;
|
||||
}
|
||||
|
||||
if ($object instanceof PhabricatorProjectInterface) {
|
||||
$phids = $mentioned_phids;
|
||||
$project_type = PhabricatorProjectProjectPHIDType::TYPECONST;
|
||||
foreach ($phids as $key => $phid) {
|
||||
if (phid_get_type($phid) != $project_type) {
|
||||
|
@ -1184,6 +1199,29 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
}
|
||||
}
|
||||
|
||||
$objects = id(new PhabricatorObjectQuery())
|
||||
->setViewer($this->getActor())
|
||||
->withPHIDs($mentioned_phids)
|
||||
->execute();
|
||||
|
||||
$mentionable_phids = array();
|
||||
foreach ($objects as $object) {
|
||||
if ($object instanceof PhabricatorMentionableInterface) {
|
||||
if (idx($this->getUnmentionablePHIDMap(), $object->getPHID())) {
|
||||
continue;
|
||||
}
|
||||
$mentionable_phids[$object->getPHID()] = $object->getPHID();
|
||||
}
|
||||
}
|
||||
if ($mentionable_phids) {
|
||||
$edge_type = PhabricatorObjectMentionsObject::EDGECONST;
|
||||
$block_xactions[] = newv(get_class(head($xactions)), array())
|
||||
->setIgnoreOnNoEffect(true)
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
||||
->setMetadataValue('edge:type', $edge_type)
|
||||
->setNewValue(array('+' => $mentionable_phids));
|
||||
}
|
||||
|
||||
return $block_xactions;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Allow infrastructure to automagically create "mentioned" transactions
|
||||
* - actually TYPE_EDGE transactions that add "mentioned" edges - to the
|
||||
* implementing object.
|
||||
*/
|
||||
interface PhabricatorMentionableInterface {
|
||||
|
||||
public function getPHID();
|
||||
|
||||
}
|
|
@ -438,6 +438,19 @@ abstract class PhabricatorApplicationTransaction
|
|||
if ($field) {
|
||||
return $field->shouldHideInApplicationTransactions($this);
|
||||
}
|
||||
case PhabricatorTransactions::TYPE_EDGE:
|
||||
$edge_type = $this->getMetadataValue('edge:type');
|
||||
switch ($edge_type) {
|
||||
case PhabricatorObjectMentionsObject::EDGECONST:
|
||||
return true;
|
||||
break;
|
||||
case PhabricatorObjectMentionedByObject::EDGECONST:
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -456,6 +469,17 @@ abstract class PhabricatorApplicationTransaction
|
|||
return false;
|
||||
}
|
||||
return true;
|
||||
case PhabricatorTransactions::TYPE_EDGE:
|
||||
$edge_type = $this->getMetadataValue('edge:type');
|
||||
switch ($edge_type) {
|
||||
case PhabricatorObjectMentionsObject::EDGECONST:
|
||||
case PhabricatorObjectMentionedByObject::EDGECONST:
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $this->shouldHide();
|
||||
|
@ -475,6 +499,17 @@ abstract class PhabricatorApplicationTransaction
|
|||
return false;
|
||||
}
|
||||
return true;
|
||||
case PhabricatorTransactions::TYPE_EDGE:
|
||||
$edge_type = $this->getMetadataValue('edge:type');
|
||||
switch ($edge_type) {
|
||||
case PhabricatorObjectMentionsObject::EDGECONST:
|
||||
case PhabricatorObjectMentionedByObject::EDGECONST:
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $this->shouldHide();
|
||||
|
|
Loading…
Reference in a new issue