mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-14 02:42:40 +01:00
Conpherence - make attaching files work better
Summary: unifies the code and presentation between adding files via email and web. Also makes it possible to "attach" the same file multiple times, either by just talking about it in the different messages or multiple times in the same message. Test Plan: sent message with attachment - it worked! sent a message referencing previous attachment - it work! sent a message with the same attachment in it like 12 times - it worked! Reviewers: epriestley, chad Reviewed By: chad CC: aran, Korvin Maniphest Tasks: T2399 Differential Revision: https://secure.phabricator.com/D4679
This commit is contained in:
parent
c046aa64c1
commit
24b274ded3
4 changed files with 66 additions and 55 deletions
|
@ -43,41 +43,21 @@ final class ConpherenceUpdateController extends
|
||||||
array(
|
array(
|
||||||
'ip' => $request->getRemoteAddr()
|
'ip' => $request->getRemoteAddr()
|
||||||
));
|
));
|
||||||
|
$editor = id(new ConpherenceEditor())
|
||||||
|
->setContentSource($content_source)
|
||||||
|
->setActor($user);
|
||||||
|
|
||||||
$action = $request->getStr('action');
|
$action = $request->getStr('action');
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'message':
|
case 'message':
|
||||||
$message = $request->getStr('text');
|
$message = $request->getStr('text');
|
||||||
$files = array();
|
$xactions = $editor->generateTransactionsFromText(
|
||||||
$file_phids =
|
$conpherence,
|
||||||
PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles(
|
$message
|
||||||
array($message)
|
|
||||||
);
|
|
||||||
if ($file_phids) {
|
|
||||||
$files = id(new PhabricatorFileQuery())
|
|
||||||
->setViewer($user)
|
|
||||||
->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($message)
|
|
||||||
->setConpherencePHID($conpherence->getPHID())
|
|
||||||
);
|
);
|
||||||
$time = time();
|
$time = time();
|
||||||
$conpherence->openTransaction();
|
$conpherence->openTransaction();
|
||||||
$xactions = id(new ConpherenceEditor())
|
$xactions = $editor->applyTransactions($conpherence, $xactions);
|
||||||
->setContentSource($content_source)
|
|
||||||
->setActor($user)
|
|
||||||
->applyTransactions($conpherence, $xactions);
|
|
||||||
$last_xaction = end($xactions);
|
$last_xaction = end($xactions);
|
||||||
$xaction_phid = $last_xaction->getPHID();
|
$xaction_phid = $last_xaction->getPHID();
|
||||||
$behind = ConpherenceParticipationStatus::BEHIND;
|
$behind = ConpherenceParticipationStatus::BEHIND;
|
||||||
|
@ -135,9 +115,7 @@ final class ConpherenceUpdateController extends
|
||||||
|
|
||||||
if ($xactions) {
|
if ($xactions) {
|
||||||
$conpherence->openTransaction();
|
$conpherence->openTransaction();
|
||||||
$xactions = id(new ConpherenceEditor())
|
$xactions = $editor
|
||||||
->setContentSource($content_source)
|
|
||||||
->setActor($user)
|
|
||||||
->setContinueOnNoEffect(true)
|
->setContinueOnNoEffect(true)
|
||||||
->applyTransactions($conpherence, $xactions);
|
->applyTransactions($conpherence, $xactions);
|
||||||
$updated = $conpherence->saveTransaction();
|
$updated = $conpherence->saveTransaction();
|
||||||
|
|
|
@ -5,6 +5,42 @@
|
||||||
*/
|
*/
|
||||||
final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
|
final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
|
|
||||||
|
public function generateTransactionsFromText(
|
||||||
|
ConpherenceThread $conpherence,
|
||||||
|
$text) {
|
||||||
|
|
||||||
|
$files = array();
|
||||||
|
$file_phids =
|
||||||
|
PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles(
|
||||||
|
array($text)
|
||||||
|
);
|
||||||
|
// 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)
|
||||||
|
->setConpherencePHID($conpherence->getPHID())
|
||||||
|
);
|
||||||
|
return $xactions;
|
||||||
|
}
|
||||||
|
|
||||||
public function getTransactionTypes() {
|
public function getTransactionTypes() {
|
||||||
$types = parent::getTransactionTypes();
|
$types = parent::getTransactionTypes();
|
||||||
|
|
||||||
|
|
|
@ -48,25 +48,6 @@ final class ConpherenceReplyHandler extends PhabricatorMailReplyHandler {
|
||||||
$conpherence->attachParticipants($participants);
|
$conpherence->attachParticipants($participants);
|
||||||
}
|
}
|
||||||
|
|
||||||
$body = $mail->getCleanTextBody();
|
|
||||||
$body = trim($body);
|
|
||||||
$file_phids = $mail->getAttachments();
|
|
||||||
$body = $this->enhanceBodyWithAttachments($body, $file_phids);
|
|
||||||
|
|
||||||
$xactions = array();
|
|
||||||
if ($file_phids) {
|
|
||||||
$xactions[] = id(new ConpherenceTransaction())
|
|
||||||
->setTransactionType(ConpherenceTransactionType::TYPE_FILES)
|
|
||||||
->setNewValue(array('+' => $file_phids));
|
|
||||||
}
|
|
||||||
$xactions[] = id(new ConpherenceTransaction())
|
|
||||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
||||||
->attachComment(
|
|
||||||
id(new ConpherenceTransactionComment())
|
|
||||||
->setContent($body)
|
|
||||||
->setConpherencePHID($conpherence->getPHID())
|
|
||||||
);
|
|
||||||
|
|
||||||
$content_source = PhabricatorContentSource::newForSource(
|
$content_source = PhabricatorContentSource::newForSource(
|
||||||
PhabricatorContentSource::SOURCE_EMAIL,
|
PhabricatorContentSource::SOURCE_EMAIL,
|
||||||
array(
|
array(
|
||||||
|
@ -76,8 +57,22 @@ final class ConpherenceReplyHandler extends PhabricatorMailReplyHandler {
|
||||||
$editor = id(new ConpherenceEditor())
|
$editor = id(new ConpherenceEditor())
|
||||||
->setActor($user)
|
->setActor($user)
|
||||||
->setContentSource($content_source)
|
->setContentSource($content_source)
|
||||||
->setParentMessageID($mail->getMessageID())
|
->setParentMessageID($mail->getMessageID());
|
||||||
->applyTransactions($conpherence, $xactions);
|
|
||||||
|
$body = $mail->getCleanTextBody();
|
||||||
|
$body = trim($body);
|
||||||
|
$file_phids = $mail->getAttachments();
|
||||||
|
$body = $this->enhanceBodyWithAttachments(
|
||||||
|
$body,
|
||||||
|
$file_phids,
|
||||||
|
'{F%d}'
|
||||||
|
);
|
||||||
|
$xactions = $editor->generateTransactionsFromText(
|
||||||
|
$conpherence,
|
||||||
|
$body
|
||||||
|
);
|
||||||
|
|
||||||
|
$editor->applyTransactions($conpherence, $xactions);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,8 +295,10 @@ EOBODY;
|
||||||
return $this->getSingleReplyHandlerPrefix($address);
|
return $this->getSingleReplyHandlerPrefix($address);
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected function enhanceBodyWithAttachments($body,
|
final protected function enhanceBodyWithAttachments(
|
||||||
array $attachments) {
|
$body,
|
||||||
|
array $attachments,
|
||||||
|
$format = '- {F%d, layout=link}') {
|
||||||
if (!$attachments) {
|
if (!$attachments) {
|
||||||
return $body;
|
return $body;
|
||||||
}
|
}
|
||||||
|
@ -310,7 +312,7 @@ EOBODY;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$file_str = sprintf('- {F%d, layout=link}', $file->getID());
|
$file_str = sprintf($format, $file->getID());
|
||||||
$body .= $file_str."\n";
|
$body .= $file_str."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue