2013-01-25 02:23:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group conpherence
|
|
|
|
*/
|
|
|
|
final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
|
|
|
|
|
2013-01-27 04:56:39 +01:00
|
|
|
public function generateTransactionsFromText(
|
|
|
|
ConpherenceThread $conpherence,
|
|
|
|
$text) {
|
|
|
|
|
|
|
|
$files = array();
|
|
|
|
$file_phids =
|
|
|
|
PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles(
|
2013-02-19 22:33:10 +01:00
|
|
|
array($text));
|
2013-01-27 04:56:39 +01:00
|
|
|
// Since these are extracted from text, we might be re-including the
|
|
|
|
// same file -- e.g. a mock under discussion. Filter files we
|
|
|
|
// already have.
|
|
|
|
$existing_file_phids = $conpherence->getFilePHIDs();
|
|
|
|
$file_phids = array_diff($file_phids, $existing_file_phids);
|
|
|
|
if ($file_phids) {
|
|
|
|
$files = id(new PhabricatorFileQuery())
|
|
|
|
->setViewer($this->getActor())
|
|
|
|
->withPHIDs($file_phids)
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
$xactions = array();
|
|
|
|
if ($files) {
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(ConpherenceTransactionType::TYPE_FILES)
|
|
|
|
->setNewValue(array('+' => mpull($files, 'getPHID')));
|
|
|
|
}
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
|
|
->attachComment(
|
|
|
|
id(new ConpherenceTransactionComment())
|
|
|
|
->setContent($text)
|
2013-02-19 22:33:10 +01:00
|
|
|
->setConpherencePHID($conpherence->getPHID()));
|
2013-01-27 04:56:39 +01:00
|
|
|
return $xactions;
|
|
|
|
}
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
public function getTransactionTypes() {
|
|
|
|
$types = parent::getTransactionTypes();
|
|
|
|
|
|
|
|
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
|
|
|
|
|
|
|
$types[] = ConpherenceTransactionType::TYPE_TITLE;
|
|
|
|
$types[] = ConpherenceTransactionType::TYPE_PICTURE;
|
2013-02-06 23:03:52 +01:00
|
|
|
$types[] = ConpherenceTransactionType::TYPE_PICTURE_CROP;
|
2013-01-25 02:23:05 +01:00
|
|
|
$types[] = ConpherenceTransactionType::TYPE_PARTICIPANTS;
|
|
|
|
$types[] = ConpherenceTransactionType::TYPE_FILES;
|
|
|
|
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCustomTransactionOldValue(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case ConpherenceTransactionType::TYPE_TITLE:
|
|
|
|
return $object->getTitle();
|
|
|
|
case ConpherenceTransactionType::TYPE_PICTURE:
|
2013-02-06 23:03:52 +01:00
|
|
|
return $object->getImagePHID(ConpherenceImageData::SIZE_ORIG);
|
|
|
|
case ConpherenceTransactionType::TYPE_PICTURE_CROP:
|
|
|
|
return $object->getImagePHID(ConpherenceImageData::SIZE_HEAD);
|
2013-01-25 02:23:05 +01:00
|
|
|
case ConpherenceTransactionType::TYPE_PARTICIPANTS:
|
|
|
|
return $object->getParticipantPHIDs();
|
|
|
|
case ConpherenceTransactionType::TYPE_FILES:
|
|
|
|
return $object->getFilePHIDs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCustomTransactionNewValue(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case ConpherenceTransactionType::TYPE_TITLE:
|
|
|
|
case ConpherenceTransactionType::TYPE_PICTURE:
|
2013-02-06 23:03:52 +01:00
|
|
|
case ConpherenceTransactionType::TYPE_PICTURE_CROP:
|
2013-01-25 02:23:05 +01:00
|
|
|
return $xaction->getNewValue();
|
|
|
|
case ConpherenceTransactionType::TYPE_PARTICIPANTS:
|
|
|
|
case ConpherenceTransactionType::TYPE_FILES:
|
|
|
|
return $this->getPHIDTransactionNewValue($xaction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function applyCustomInternalTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case ConpherenceTransactionType::TYPE_TITLE:
|
|
|
|
$object->setTitle($xaction->getNewValue());
|
|
|
|
break;
|
|
|
|
case ConpherenceTransactionType::TYPE_PICTURE:
|
2013-02-06 23:03:52 +01:00
|
|
|
$object->setImagePHID(
|
|
|
|
$xaction->getNewValue(),
|
2013-02-19 22:33:10 +01:00
|
|
|
ConpherenceImageData::SIZE_ORIG);
|
2013-02-06 23:03:52 +01:00
|
|
|
break;
|
|
|
|
case ConpherenceTransactionType::TYPE_PICTURE_CROP:
|
|
|
|
$object->setImagePHID(
|
|
|
|
$xaction->getNewValue(),
|
2013-02-19 22:33:10 +01:00
|
|
|
ConpherenceImageData::SIZE_HEAD);
|
2013-01-25 02:23:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For now this only supports adding more files and participants.
|
|
|
|
*/
|
|
|
|
protected function applyCustomExternalTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case ConpherenceTransactionType::TYPE_FILES:
|
|
|
|
$editor = id(new PhabricatorEdgeEditor())
|
|
|
|
->setActor($this->getActor());
|
|
|
|
$edge_type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_FILE;
|
2013-03-08 19:40:06 +01:00
|
|
|
$old = array_fill_keys($xaction->getOldValue(), true);
|
|
|
|
$new = array_fill_keys($xaction->getNewValue(), true);
|
|
|
|
$add_edges = array_keys(array_diff_key($new, $old));
|
|
|
|
$remove_edges = array_keys(array_diff_key($old, $new));
|
|
|
|
foreach ($add_edges as $file_phid) {
|
2013-01-25 02:23:05 +01:00
|
|
|
$editor->addEdge(
|
|
|
|
$object->getPHID(),
|
|
|
|
$edge_type,
|
2013-02-19 22:33:10 +01:00
|
|
|
$file_phid);
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
2013-03-08 19:40:06 +01:00
|
|
|
foreach ($remove_edges as $file_phid) {
|
|
|
|
$editor->removeEdge(
|
|
|
|
$object->getPHID(),
|
|
|
|
$edge_type,
|
|
|
|
$file_phid);
|
|
|
|
}
|
2013-01-25 02:23:05 +01:00
|
|
|
$editor->save();
|
2013-01-30 01:53:57 +01:00
|
|
|
// fallthrough
|
|
|
|
case PhabricatorTransactions::TYPE_COMMENT:
|
|
|
|
$xaction_phid = $xaction->getPHID();
|
|
|
|
$behind = ConpherenceParticipationStatus::BEHIND;
|
|
|
|
$up_to_date = ConpherenceParticipationStatus::UP_TO_DATE;
|
|
|
|
$participants = $object->getParticipants();
|
|
|
|
$user = $this->getActor();
|
|
|
|
$time = time();
|
|
|
|
foreach ($participants as $phid => $participant) {
|
|
|
|
if ($phid != $user->getPHID()) {
|
|
|
|
if ($participant->getParticipationStatus() != $behind) {
|
|
|
|
$participant->setBehindTransactionPHID($xaction_phid);
|
|
|
|
}
|
|
|
|
$participant->setParticipationStatus($behind);
|
|
|
|
$participant->setDateTouched($time);
|
|
|
|
} else {
|
|
|
|
$participant->setParticipationStatus($up_to_date);
|
|
|
|
$participant->setDateTouched($time);
|
|
|
|
}
|
|
|
|
$participant->save();
|
|
|
|
}
|
2013-01-25 02:23:05 +01:00
|
|
|
break;
|
|
|
|
case ConpherenceTransactionType::TYPE_PARTICIPANTS:
|
2013-03-26 21:30:35 +01:00
|
|
|
$participants = array();
|
2013-01-25 02:23:05 +01:00
|
|
|
foreach ($xaction->getNewValue() as $participant) {
|
|
|
|
if ($participant == $this->getActor()->getPHID()) {
|
|
|
|
$status = ConpherenceParticipationStatus::UP_TO_DATE;
|
|
|
|
} else {
|
|
|
|
$status = ConpherenceParticipationStatus::BEHIND;
|
|
|
|
}
|
2013-03-26 21:30:35 +01:00
|
|
|
$participants[] =
|
|
|
|
id(new ConpherenceParticipant())
|
2013-01-25 02:23:05 +01:00
|
|
|
->setConpherencePHID($object->getPHID())
|
|
|
|
->setParticipantPHID($participant)
|
|
|
|
->setParticipationStatus($status)
|
|
|
|
->setDateTouched(time())
|
|
|
|
->setBehindTransactionPHID($xaction->getPHID())
|
|
|
|
->save();
|
|
|
|
}
|
2013-03-26 21:30:35 +01:00
|
|
|
$participants = mpull($participants, null, 'getParticipantPHID');
|
|
|
|
$object->attachParticipants($participants);
|
2013-01-25 02:23:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function mergeTransactions(
|
|
|
|
PhabricatorApplicationTransaction $u,
|
|
|
|
PhabricatorApplicationTransaction $v) {
|
|
|
|
|
|
|
|
$type = $u->getTransactionType();
|
|
|
|
switch ($type) {
|
|
|
|
case ConpherenceTransactionType::TYPE_TITLE:
|
|
|
|
case ConpherenceTransactionType::TYPE_PICTURE:
|
|
|
|
return $v;
|
|
|
|
case ConpherenceTransactionType::TYPE_FILES:
|
|
|
|
case ConpherenceTransactionType::TYPE_PARTICIPANTS:
|
|
|
|
return $this->mergePHIDTransactions($u, $v);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::mergeTransactions($u, $v);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function supportsMail() {
|
2013-01-26 01:03:54 +01:00
|
|
|
return true;
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
|
|
|
|
return id(new ConpherenceReplyHandler())
|
2013-01-26 01:03:54 +01:00
|
|
|
->setActor($this->getActor())
|
2013-01-25 02:23:05 +01:00
|
|
|
->setMailReceiver($object);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildMailTemplate(PhabricatorLiskDAO $object) {
|
|
|
|
$id = $object->getID();
|
|
|
|
$title = $object->getTitle();
|
2013-01-26 01:03:54 +01:00
|
|
|
if (!$title) {
|
|
|
|
$title = pht(
|
|
|
|
'%s sent you a message.',
|
2013-02-19 22:33:10 +01:00
|
|
|
$this->getActor()->getUserName());
|
2013-01-26 01:03:54 +01:00
|
|
|
}
|
2013-01-25 02:23:05 +01:00
|
|
|
$phid = $object->getPHID();
|
|
|
|
|
|
|
|
return id(new PhabricatorMetaMTAMail())
|
2013-01-26 01:03:54 +01:00
|
|
|
->setSubject("E{$id}: {$title}")
|
|
|
|
->addHeader('Thread-Topic', "E{$id}: {$phid}");
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getMailTo(PhabricatorLiskDAO $object) {
|
|
|
|
$participants = $object->getParticipants();
|
2013-03-26 21:30:35 +01:00
|
|
|
$preferences = id(new PhabricatorUserPreferences())
|
|
|
|
->loadAllWhere('userPHID in (%Ls)', array_keys($participants));
|
|
|
|
$preferences = mpull($preferences, null, 'getUserPHID');
|
|
|
|
$to_phids = array();
|
|
|
|
foreach ($participants as $phid => $participant) {
|
|
|
|
$default = ConpherenceSettings::EMAIL_ALWAYS;
|
|
|
|
$preference = idx($preferences, $phid);
|
|
|
|
if ($preference) {
|
|
|
|
$default = $preference->getPreference(
|
|
|
|
PhabricatorUserPreferences::PREFERENCE_CONPH_NOTIFICATIONS,
|
|
|
|
ConpherenceSettings::EMAIL_ALWAYS);
|
|
|
|
}
|
|
|
|
$settings = $participant->getSettings();
|
|
|
|
$notifications = idx(
|
|
|
|
$settings,
|
|
|
|
'notifications',
|
|
|
|
$default);
|
|
|
|
if ($notifications == ConpherenceSettings::EMAIL_ALWAYS) {
|
|
|
|
$to_phids[] = $phid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $to_phids;
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
|
2013-01-26 01:03:54 +01:00
|
|
|
protected function getMailCC(PhabricatorLiskDAO $object) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
protected function buildMailBody(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
array $xactions) {
|
|
|
|
|
|
|
|
$body = parent::buildMailBody($object, $xactions);
|
|
|
|
$body->addTextSection(
|
|
|
|
pht('CONPHERENCE DETAIL'),
|
|
|
|
PhabricatorEnv::getProductionURI('/conpherence/'.$object->getID().'/'));
|
|
|
|
|
|
|
|
return $body;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getMailSubjectPrefix() {
|
|
|
|
return PhabricatorEnv::getEnvConfig('metamta.conpherence.subject-prefix');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function supportsFeed() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function supportsSearch() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|