public function processRequest() { $request = $this->getRequest(); $author_phid = $request->getUser()->getPHID(); $action = $request->getStr('action'); $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(); $comment = new DifferentialComment(); $comment->setContent($request->getStr('content')); $comment->setAction($action); $comment->setAuthorPHID($author_phid); $handles = array($author_phid); $reviewers = $request->getStr('reviewers'); if (($action == DifferentialAction::ACTION_ADDREVIEWERS || $action == DifferentialAction::ACTION_REQUEST) && $reviewers) { $reviewers = explode(',', $reviewers); $comment->setMetadata(array(DifferentialComment::METADATA_ADDED_REVIEWERS => $reviewers)); $handles = array_merge($handles, $reviewers); } $ccs = $request->getStr('ccs'); if ($action == DifferentialAction::ACTION_ADDCCS && $ccs) { $ccs = explode(',', $ccs); $comment->setMetadata(array(DifferentialComment::METADATA_ADDED_CCS => $ccs)); $handles = array_merge($handles, $ccs); } $handles = id(new PhabricatorObjectHandleData($handles))->loadHandles(); $view = new DifferentialRevisionCommentView(); $view->setUser($request->getUser()); $view->setComment($comment); $view->setHandles($handles); $view->setMarkupEngine($engine); $view->setPreview(true); $view->setTargetDiff(null); $draft = new PhabricatorDraft(); $draft->setAuthorPHID($author_phid)->setDraftKey('differential-comment-' . $this->id)->setDraft($comment->getContent())->replace(); return id(new AphrontAjaxResponse())->setContent($view->render()); }
public function processRequest() { $request = $this->getRequest(); $author_phid = $request->getUser()->getPHID(); $handles = id(new PhabricatorObjectHandleData(array($author_phid)))->loadHandles(); $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(); $comment = new DifferentialComment(); $comment->setContent($request->getStr('content')); $comment->setAction($request->getStr('action')); $comment->setAuthorPHID($author_phid); $view = new DifferentialRevisionCommentView(); $view->setUser($request->getUser()); $view->setComment($comment); $view->setHandles($handles); $view->setMarkupEngine($engine); $view->setPreview(true); $view->setTargetDiff(null); $draft = new PhabricatorDraft(); $draft->setAuthorPHID($author_phid)->setDraftKey('differential-comment-' . $this->id)->setDraft($comment->getContent())->replace(); return id(new AphrontAjaxResponse())->setContent($view->render()); }
public function processRequest() { $request = $this->getRequest(); $author_phid = $request->getUser()->getPHID(); $action = $request->getStr('action'); $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(); $comment = new DifferentialComment(); $comment->setContent($request->getStr('content')); $comment->setAction($action); $comment->setAuthorPHID($author_phid); $handles = array($author_phid); $reviewers = $request->getStrList('reviewers'); if (DifferentialAction::allowReviewers($action) && $reviewers) { $comment->setMetadata(array(DifferentialComment::METADATA_ADDED_REVIEWERS => $reviewers)); $handles = array_merge($handles, $reviewers); } $ccs = $request->getStrList('ccs'); if ($action == DifferentialAction::ACTION_ADDCCS && $ccs) { $comment->setMetadata(array(DifferentialComment::METADATA_ADDED_CCS => $ccs)); $handles = array_merge($handles, $ccs); } $handles = $this->loadViewerHandles($handles); $view = new DifferentialRevisionCommentView(); $view->setUser($request->getUser()); $view->setComment($comment); $view->setHandles($handles); $view->setMarkupEngine($engine); $view->setPreview(true); $view->setTargetDiff(null); $metadata = array('reviewers' => $reviewers, 'ccs' => $ccs); if ($action != DifferentialAction::ACTION_COMMENT) { $metadata['action'] = $action; } id(new PhabricatorDraft())->setAuthorPHID($author_phid)->setDraftKey('differential-comment-' . $this->id)->setDraft($comment->getContent())->setMetadata($metadata)->replaceOrDelete(); return id(new AphrontAjaxResponse())->setContent($view->render()); }
public function render() { require_celerity_resource('differential-revision-comment-list-css'); $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(array('differential.diff' => $this->target)); $inlines = mgroup($this->inlines, 'getCommentID'); $num = 1; $html = array(); foreach ($this->comments as $comment) { $view = new DifferentialRevisionCommentView(); $view->setComment($comment); $view->setUser($this->user); $view->setHandles($this->handles); $view->setMarkupEngine($engine); $view->setInlineComments(idx($inlines, $comment->getID(), array())); $view->setChangesets($this->changesets); $view->setTargetDiff($this->target); $view->setVersusDiffID($this->versusDiffID); $view->setCommentNumber($num++); $html[] = $view->render(); } $objs = array_reverse(array_values($this->comments)); $html = array_reverse(array_values($html)); $user = $this->user; $last_comment = null; // Find the most recent comment by the viewer. foreach ($objs as $position => $comment) { if ($user && $comment->getAuthorPHID() == $user->getPHID()) { if ($last_comment === null) { $last_comment = $position; } else { if ($last_comment == $position - 1) { // If the viewer made several comments in a row, show them all. This // is a spaz rule for epriestley. $last_comment = $position; } } } } $header = array(); $hidden = array(); if ($last_comment !== null) { foreach ($objs as $position => $comment) { if (!$comment->getID()) { // These are synthetic comments with summary/test plan information. $header[] = $html[$position]; unset($html[$position]); continue; } if ($position <= $last_comment) { // Always show comments after the viewer's last comment. continue; } if ($position < 3) { // Always show the 3 most recent comments. continue; } $hidden[] = $position; } } if (count($hidden) <= 3) { // Don't hide if there's not much to hide. $hidden = array(); } $header = array_reverse($header); $hidden = array_select_keys($html, $hidden); $visible = array_diff_key($html, $hidden); $hidden = array_reverse($hidden); $visible = array_reverse($visible); if ($hidden) { Javelin::initBehavior('differential-show-all-comments', array('markup' => implode("\n", $hidden))); $hidden = javelin_render_tag('div', array('sigil' => "differential-all-comments-container"), '<div class="differential-older-comments-are-hidden">' . number_format(count($hidden)) . ' older comments are hidden. ' . javelin_render_tag('a', array('href' => '#', 'mustcapture' => true, 'sigil' => 'differential-show-all-comments'), 'Show all comments.') . '</div>'); } else { $hidden = null; } return '<div class="differential-comment-list">' . implode("\n", $header) . $hidden . implode("\n", $visible) . '</div>'; }