protected function loadPage() { $table = new ConpherenceThread(); $conn_r = $table->establishConnection('r'); $data = queryfx_all($conn_r, 'SELECT thread.* FROM %T thread %Q %Q %Q %Q %Q', $table->getTableName(), $this->buildJoinClause($conn_r), $this->buildWhereClause($conn_r), $this->buildGroupClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r)); $conpherences = $table->loadAllFromArray($data); if ($conpherences) { $conpherences = mpull($conpherences, null, 'getPHID'); $this->loadParticipantsAndInitHandles($conpherences); if ($this->needParticipantCache) { $this->loadCoreHandles($conpherences, 'getRecentParticipantPHIDs'); } if ($this->needParticipants) { $this->loadCoreHandles($conpherences, 'getParticipantPHIDs'); } if ($this->needTransactions) { $this->loadTransactionsAndHandles($conpherences); } if ($this->needOrigPics || $this->needCropPics) { $this->initImages($conpherences); } if ($this->needOrigPics) { $this->loadOrigPics($conpherences); } if ($this->needCropPics) { $this->loadCropPics($conpherences); } } return $conpherences; }
protected function buildHeaderPaneContent(ConpherenceThread $conpherence, array $policy_objects) { assert_instances_of($policy_objects, 'PhabricatorPolicy'); $viewer = $this->getViewer(); $header = null; if ($conpherence->getID()) { $data = $conpherence->getDisplayData($this->getViewer()); $header = id(new PHUIHeaderView())->setHeader($data['title'])->setSubheader($data['topic'])->setImage($data['image']); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $conpherence, PhabricatorPolicyCapability::CAN_EDIT); if ($can_edit) { $header->setImageURL($this->getApplicationURI('picture/' . $conpherence->getID() . '/')); } $participating = $conpherence->getParticipantIfExists($viewer->getPHID()); $can_join = PhabricatorPolicyFilter::hasCapability($viewer, $conpherence, PhabricatorPolicyCapability::CAN_JOIN); $header->addActionItem(id(new PHUIIconCircleView())->setHref($this->getApplicationURI('update/' . $conpherence->getID()) . '/')->setIcon('fa-pencil')->addClass('hide-on-device')->setColor('violet')->setWorkflow(true)); $header->addActionItem(id(new PHUIIconCircleView())->setHref($this->getApplicationURI('update/' . $conpherence->getID()) . '/' . '?action=' . ConpherenceUpdateActions::NOTIFICATIONS)->setIcon('fa-gear')->addClass('hide-on-device')->setColor('pink')->setWorkflow(true)); $widget_key = PhabricatorConpherenceWidgetVisibleSetting::SETTINGKEY; $widget_view = (bool) $viewer->getUserSetting($widget_key, false); Javelin::initBehavior('toggle-widget', array('show' => (int) $widget_view, 'settingsURI' => '/settings/adjust/?key=' . $widget_key)); $header->addActionItem(id(new PHUIIconCircleView())->addSigil('conpherence-widget-toggle')->setIcon('fa-group')->setHref('#')->addClass('conpherence-participant-toggle')); Javelin::initBehavior('conpherence-search'); $header->addActionItem(id(new PHUIIconCircleView())->addSigil('conpherence-search-toggle')->setIcon('fa-search')->setHref('#')->setColor('green')->addClass('conpherence-search-toggle')); if ($can_join && !$participating) { $action = ConpherenceUpdateActions::JOIN_ROOM; $uri = $this->getApplicationURI('update/' . $conpherence->getID() . '/'); $button = phutil_tag('button', array('type' => 'SUBMIT', 'class' => 'button green mlr'), pht('Join Room')); $hidden = phutil_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => ConpherenceUpdateActions::JOIN_ROOM)); $form = phabricator_form($viewer, array('method' => 'POST', 'action' => (string) $uri), array($hidden, $button)); $header->addActionItem($form); } } return $header; }
protected function buildHeaderPaneContent(ConpherenceThread $conpherence, array $policy_objects) { assert_instances_of($policy_objects, 'PhabricatorPolicy'); $crumbs = $this->buildApplicationCrumbs(); $data = $conpherence->getDisplayData($this->getViewer()); $crumbs->addCrumb(id(new PHUICrumbView())->setName($data['title'])->setHref('/' . $conpherence->getMonogram())); return hsprintf('%s', array(phutil_tag('div', array('class' => 'header-loading-mask'), ''), $crumbs)); }
private function indexComment(ConpherenceThread $thread, ConpherenceTransaction $xaction) { $previous = id(new ConpherenceTransactionQuery())->setViewer($this->getViewer())->withObjectPHIDs(array($thread->getPHID()))->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))->setAfterID($xaction->getID())->setLimit(1)->executeOne(); $index = id(new ConpherenceIndex())->setThreadPHID($thread->getPHID())->setTransactionPHID($xaction->getPHID())->setPreviousTransactionPHID($previous ? $previous->getPHID() : null)->setCorpus($xaction->getComment()->getContent()); queryfx($index->establishConnection('w'), 'INSERT INTO %T (threadPHID, transactionPHID, previousTransactionPHID, corpus) VALUES (%s, %s, %ns, %s) ON DUPLICATE KEY UPDATE corpus = VALUES(corpus)', $index->getTableName(), $index->getThreadPHID(), $index->getTransactionPHID(), $index->getPreviousTransactionPHID(), $index->getCorpus()); }
public function handleRequest(AphrontRequest $request) { $user = $request->getUser(); $title = pht('New Room'); $e_title = true; $validation_exception = null; $conpherence = ConpherenceThread::initializeNewRoom($user); if ($request->isFormPost()) { $xactions = array(); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => array($user->getPHID()))); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_TITLE)->setNewValue($request->getStr('title')); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($request->getStr('viewPolicy')); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)->setNewValue($request->getStr('editPolicy')); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_JOIN_POLICY)->setNewValue($request->getStr('joinPolicy')); try { id(new ConpherenceEditor())->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setActor($user)->applyTransactions($conpherence, $xactions); return id(new AphrontRedirectResponse())->setURI('/' . $conpherence->getMonogram()); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $e_title = $ex->getShortMessage(ConpherenceTransaction::TYPE_TITLE); $conpherence->setViewPolicy($request->getStr('viewPolicy')); $conpherence->setEditPolicy($request->getStr('editPolicy')); $conpherence->setJoinPolicy($request->getStr('joinPolicy')); } } $policies = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($conpherence)->execute(); $submit_uri = $this->getApplicationURI('room/new/'); $cancel_uri = $this->getApplicationURI('search/'); $dialog = $this->newDialog()->setWidth(AphrontDialogView::WIDTH_FORM)->setValidationException($validation_exception)->setUser($user)->setTitle($title)->addCancelButton($cancel_uri)->addSubmitButton(pht('Create Room')); $form = id(new PHUIFormLayoutView())->setUser($user)->setFullWidth(true)->appendChild(id(new AphrontFormTextControl())->setError($e_title)->setLabel(pht('Title'))->setName('title')->setValue($request->getStr('title')))->appendChild(id(new AphrontFormPolicyControl())->setName('viewPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicies($policies))->appendChild(id(new AphrontFormPolicyControl())->setName('editPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicies($policies))->appendChild(id(new AphrontFormPolicyControl())->setName('joinPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_JOIN)->setPolicies($policies)); $dialog->appendChild($form); return id(new AphrontDialogResponse())->setDialog($dialog); }
protected function renderConpherenceTransactions(ConpherenceThread $conpherence) { $user = $this->getRequest()->getUser(); $transactions = $conpherence->getTransactions(); $oldest_transaction_id = 0; $too_many = ConpherenceThreadQuery::TRANSACTION_LIMIT + 1; if (count($transactions) == $too_many) { $last_transaction = end($transactions); unset($transactions[$last_transaction->getID()]); $oldest_transaction = end($transactions); $oldest_transaction_id = $oldest_transaction->getID(); } $transactions = array_reverse($transactions); $handles = $conpherence->getHandles(); $rendered_transactions = array(); $engine = id(new PhabricatorMarkupEngine())->setViewer($user); foreach ($transactions as $key => $transaction) { if ($transaction->shouldHide()) { unset($transactions[$key]); continue; } if ($transaction->getComment()) { $engine->addObject($transaction->getComment(), PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); } } $engine->process(); // we're going to insert a dummy date marker transaction for breaks // between days. some setup required! $previous_transaction = null; $date_marker_transaction = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransactionType::TYPE_DATE_MARKER)->makeEphemeral(); $date_marker_transaction_view = id(new ConpherenceTransactionView())->setUser($user)->setConpherenceTransaction($date_marker_transaction)->setHandles($handles)->setMarkupEngine($engine); foreach ($transactions as $transaction) { if ($previous_transaction) { $previous_day = phabricator_format_local_time($previous_transaction->getDateCreated(), $user, 'Ymd'); $current_day = phabricator_format_local_time($transaction->getDateCreated(), $user, 'Ymd'); // date marker transaction time! if ($previous_day != $current_day) { $date_marker_transaction->setDateCreated($transaction->getDateCreated()); $rendered_transactions[] = $date_marker_transaction_view->render(); } } $rendered_transactions[] = id(new ConpherenceTransactionView())->setUser($user)->setConpherenceTransaction($transaction)->setHandles($handles)->setMarkupEngine($engine)->render(); $previous_transaction = $transaction; } $latest_transaction_id = $transaction->getID(); return array('transactions' => $rendered_transactions, 'latest_transaction_id' => $latest_transaction_id, 'oldest_transaction_id' => $oldest_transaction_id); }
public function handleRequest(AphrontRequest $request) { $user = $request->getUser(); $title = pht('Conpherence'); $conpherence = null; $limit = ConpherenceThreadListView::SEE_MORE_LIMIT * 5; $all_participation = array(); $mode = $this->determineMode(); switch ($mode) { case self::SELECTED_MODE: $conpherence_id = $request->getURIData('id'); $conpherence = id(new ConpherenceThreadQuery())->setViewer($user)->withIDs(array($conpherence_id))->executeOne(); if (!$conpherence) { return new Aphront404Response(); } if ($conpherence->getTitle()) { $title = $conpherence->getTitle(); } $cursor = $conpherence->getParticipantIfExists($user->getPHID()); $data = $this->loadDefaultParticipation($limit); $all_participation = $data['all_participation']; if (!$cursor) { $menu_participation = id(new ConpherenceParticipant())->makeEphemeral()->setConpherencePHID($conpherence->getPHID())->setParticipantPHID($user->getPHID()); } else { $menu_participation = $cursor; } $all_participation = array($conpherence->getPHID() => $menu_participation) + $all_participation; break; case self::UNSELECTED_MODE: default: $data = $this->loadDefaultParticipation($limit); $all_participation = $data['all_participation']; break; } $threads = $this->loadConpherenceThreadData($all_participation); $thread_view = id(new ConpherenceThreadListView())->setUser($user)->setBaseURI($this->getApplicationURI())->setThreads($threads); switch ($mode) { case self::SELECTED_MODE: $response = id(new AphrontAjaxResponse())->setContent($thread_view); break; case self::UNSELECTED_MODE: default: $layout = id(new ConpherenceLayoutView())->setUser($user)->setBaseURI($this->getApplicationURI())->setThreadView($thread_view)->setRole('list'); if ($conpherence) { $policy_objects = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($conpherence)->execute(); $layout->setHeader($this->buildHeaderPaneContent($conpherence, $policy_objects)); $layout->setThread($conpherence); } else { $thread = ConpherenceThread::initializeNewThread($user); $thread->attachHandles(array()); $thread->attachTransactions(array()); $thread->makeEphemeral(); $layout->setHeader($this->buildHeaderPaneContent($thread, array())); } $response = $this->buildApplicationPage($layout, array('title' => $title)); break; } return $response; }
protected function buildHeaderPaneContent(ConpherenceThread $conpherence, array $policy_objects) { assert_instances_of($policy_objects, 'PhabricatorPolicy'); $viewer = $this->getViewer(); $header = null; if ($conpherence->getID()) { $data = $conpherence->getDisplayData($this->getViewer()); $header = id(new PHUIHeaderView())->setHeader($data['title'])->setSubheader($data['topic'])->addClass(!$data['topic'] ? 'conpherence-no-topic' : null); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $conpherence, PhabricatorPolicyCapability::CAN_EDIT); $header->addActionItem(id(new PHUIIconCircleView())->setHref($this->getApplicationURI('update/' . $conpherence->getID()) . '/')->setIcon('fa-pencil')->addClass('hide-on-device')->setColor('violet')->setWorkflow(true)); $header->addActionItem(id(new PHUIIconCircleView())->setHref($this->getApplicationURI('update/' . $conpherence->getID()) . '/' . '?action=' . ConpherenceUpdateActions::NOTIFICATIONS)->setIcon('fa-gear')->addClass('hide-on-device')->setColor('pink')->setWorkflow(true)); $widget_key = PhabricatorConpherenceWidgetVisibleSetting::SETTINGKEY; $widget_view = (bool) $viewer->getUserSetting($widget_key, false); Javelin::initBehavior('toggle-widget', array('show' => (int) $widget_view, 'settingsURI' => '/settings/adjust/?key=' . $widget_key)); $header->addActionItem(id(new PHUIIconCircleView())->addSigil('conpherence-widget-toggle')->setIcon('fa-group')->setHref('#')->addClass('conpherence-participant-toggle')); } return $header; }
private function createRoom(PhabricatorUser $creator, array $participant_phids) { $conpherence = ConpherenceThread::initializeNewRoom($creator); $xactions = array(); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => $participant_phids)); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_TITLE)->setNewValue(pht('Test')); id(new ConpherenceEditor())->setActor($creator)->setContentSource($this->newContentSource())->setContinueOnNoEffect(true)->applyTransactions($conpherence, $xactions); return $conpherence; }
protected function processReceivedMail(PhabricatorMetaMTAReceivedMail $mail, PhabricatorUser $sender) { $users = $this->loadMailUsers($mail); $phids = mpull($users, 'getPHID'); $conpherence = id(new ConpherenceReplyHandler())->setMailReceiver(ConpherenceThread::initializeNewThread($sender))->setMailAddedParticipantPHIDs($phids)->setActor($sender)->setExcludeMailRecipientPHIDs($mail->loadExcludeMailRecipientPHIDs())->processEmail($mail); if ($conpherence) { $mail->setRelatedPHID($conpherence->getPHID()); } }
public function generateTransactionsFromText(PhabricatorUser $viewer, ConpherenceThread $conpherence, $text) { $files = array(); $file_phids = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles($viewer, 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(ConpherenceTransaction::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; }
protected function loadPage() { $table = new ConpherenceThread(); $conn_r = $table->establishConnection('r'); $data = queryfx_all($conn_r, 'SELECT thread.* FROM %T thread %Q %Q %Q %Q %Q', $table->getTableName(), $this->buildJoinClause($conn_r), $this->buildWhereClause($conn_r), $this->buildGroupClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r)); $conpherences = $table->loadAllFromArray($data); if ($conpherences) { $conpherences = mpull($conpherences, null, 'getPHID'); $this->loadParticipantsAndInitHandles($conpherences); if ($this->needParticipantCache) { $this->loadCoreHandles($conpherences, 'getRecentParticipantPHIDs'); } if ($this->needParticipants) { $this->loadCoreHandles($conpherences, 'getParticipantPHIDs'); } if ($this->needTransactions) { $this->loadTransactionsAndHandles($conpherences); } if ($this->needProfileImage) { $default = null; $file_phids = mpull($conpherences, 'getProfileImagePHID'); $file_phids = array_filter($file_phids); if ($file_phids) { $files = id(new PhabricatorFileQuery())->setParentQuery($this)->setViewer($this->getViewer())->withPHIDs($file_phids)->execute(); $files = mpull($files, null, 'getPHID'); } else { $files = array(); } foreach ($conpherences as $conpherence) { $file = idx($files, $conpherence->getProfileImagePHID()); if (!$file) { if (!$default) { $default = PhabricatorFile::loadBuiltin($this->getViewer(), 'conpherence.png'); } $file = $default; } $conpherence->attachProfileImageFile($file); } } } return $conpherences; }
public function testObjectPolicyRuleThreadMembers() { $author = $this->generateNewTestUser(); $viewer = $this->generateNewTestUser(); $rule = new ConpherenceThreadMembersPolicyRule(); $thread = ConpherenceThread::initializeNewRoom($author); $thread->setViewPolicy($rule->getObjectPolicyFullKey()); $thread->save(); $this->assertFalse(PhabricatorPolicyFilter::hasCapability($author, $thread, PhabricatorPolicyCapability::CAN_VIEW)); $this->assertFalse(PhabricatorPolicyFilter::hasCapability($viewer, $thread, PhabricatorPolicyCapability::CAN_VIEW)); $participant = id(new ConpherenceParticipant())->setParticipantPHID($viewer->getPHID())->setConpherencePHID($thread->getPHID()); $thread->attachParticipants(array($viewer->getPHID() => $participant)); $this->assertTrue(PhabricatorPolicyFilter::hasCapability($viewer, $thread, PhabricatorPolicyCapability::CAN_VIEW)); }
private function renderThread(ConpherenceThread $thread, array $policy_objects) { $user = $this->getUser(); $uri = '/' . $thread->getMonogram(); $data = $thread->getDisplayData($user); $icon = id(new PHUIIconView())->addClass('msr')->setIcon($thread->getPolicyIconName($policy_objects)); $title = phutil_tag('span', array(), array($icon, $data['title'])); $subtitle = $data['subtitle']; $unread_count = $data['unread_count']; $epoch = $data['epoch']; $image = $data['image']; $dom_id = $thread->getPHID() . '-nav-item'; return id(new ConpherenceMenuItemView())->setUser($user)->setTitle($title)->setSubtitle($subtitle)->setHref($uri)->setEpoch($epoch)->setImageURI($image)->setUnreadCount($unread_count)->setID($thread->getPHID() . '-nav-item')->addSigil('conpherence-menu-click')->setMetadata(array('title' => $data['title'], 'id' => $dom_id, 'threadID' => $thread->getID())); }
private function renderThread(ConpherenceThread $thread) { $user = $this->getUser(); $uri = $this->baseURI . $thread->getID() . '/'; $data = $thread->getDisplayData($user); $title = $data['title']; $subtitle = $data['subtitle']; $unread_count = $data['unread_count']; $epoch = $data['epoch']; $image = $data['image']; $dom_id = $thread->getPHID() . '-nav-item'; return id(new ConpherenceMenuItemView())->setUser($user)->setTitle($title)->setSubtitle($subtitle)->setHref($uri)->setEpoch($epoch)->setImageURI($image)->setUnreadCount($unread_count)->setID($thread->getPHID() . '-nav-item')->addSigil('conpherence-menu-click')->setMetadata(array('title' => $data['js_title'], 'id' => $dom_id, 'threadID' => $thread->getID())); }
protected function buildHeaderPaneContent(ConpherenceThread $conpherence, array $policy_objects) { assert_instances_of($policy_objects, 'PhabricatorPolicy'); $crumbs = $this->buildApplicationCrumbs(); $data = $conpherence->getDisplayData($this->getViewer()); if ($conpherence->getID() && $conpherence->getIsRoom()) { $icon = $conpherence->getPolicyIconName($policy_objects); } else { $icon = null; } $crumbs->addCrumb(id(new PHUICrumbView())->setIcon($icon)->setName($data['title'])->setHref($this->getApplicationURI('update/' . $conpherence->getID() . '/'))->setWorkflow(true)); return hsprintf('%s', array(phutil_tag('div', array('class' => 'header-loading-mask'), ''), $crumbs)); }
private function renderThread(ConpherenceThread $thread, array $policy_objects) { $user = $this->getUser(); $uri = '/' . $thread->getMonogram(); $data = $thread->getDisplayData($user); $icon = null; if ($thread->getIsRoom()) { $icon = id(new PHUIIconView())->addClass('msr')->setIconFont($thread->getPolicyIconName($policy_objects)); } $title = phutil_tag('span', array(), array($icon, $data['title'])); $subtitle = $data['subtitle']; $unread_count = $data['unread_count']; $epoch = $data['epoch']; $image = $data['image']; $dom_id = $thread->getPHID() . '-nav-item'; $glyph_pref = PhabricatorUserPreferences::PREFERENCE_TITLES; $preferences = $user->loadPreferences(); if ($preferences->getPreference($glyph_pref) == 'glyph') { $glyph = id(new PhabricatorConpherenceApplication())->getTitleGlyph() . ' '; } else { $glyph = null; } return id(new ConpherenceMenuItemView())->setUser($user)->setTitle($title)->setSubtitle($subtitle)->setHref($uri)->setEpoch($epoch)->setImageURI($image)->setUnreadCount($unread_count)->setID($thread->getPHID() . '-nav-item')->addSigil('conpherence-menu-click')->setMetadata(array('title' => $glyph . $data['title'], 'id' => $dom_id, 'threadID' => $thread->getID())); }
<?php // Rebuild all Conpherence Room images to profile standards // $table = new ConpherenceThread(); $conn = $table->establishConnection('w'); $table_name = 'conpherence_thread'; foreach (new LiskRawMigrationIterator($conn, $table_name) as $row) { $images = phutil_json_decode($row['imagePHIDs']); if (!$images) { continue; } $file_phid = idx($images, 'original'); $file = id(new PhabricatorFileQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs(array($file_phid))->executeOne(); $xform = PhabricatorFileTransform::getTransformByKey(PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); $xformed = $xform->executeTransform($file); $new_phid = $xformed->getPHID(); queryfx($conn, 'UPDATE %T SET profileImagePHID = %s WHERE id = %d', $table->getTableName(), $new_phid, $row['id']); }
private function getNeededTransactions(ConpherenceThread $conpherence, $message_id) { if ($message_id) { $newer_transactions = $conpherence->getTransactions(); $query = id(new ConpherenceTransactionQuery())->setViewer($this->getRequest()->getUser())->withObjectPHIDs(array($conpherence->getPHID()))->setAfterID($message_id)->needHandles(true)->setLimit(self::OLDER_FETCH_LIMIT); $older_transactions = $query->execute(); $handles = array(); foreach ($older_transactions as $transaction) { $handles += $transaction->getHandles(); } $conpherence->attachHandles($conpherence->getHandles() + $handles); $transactions = array_merge($newer_transactions, $older_transactions); $conpherence->attachTransactions($transactions); } else { $transactions = $conpherence->getTransactions(); } return $transactions; }
protected function renderResultList(array $conpherences, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($conpherences, 'ConpherenceThread'); $viewer = $this->requireViewer(); $policy_objects = ConpherenceThread::loadViewPolicyObjects($viewer, $conpherences); $engines = array(); $fulltext = $query->getParameter('fulltext'); if (strlen($fulltext) && $conpherences) { $context = $this->loadContextMessages($conpherences, $fulltext); $author_phids = array(); foreach ($context as $phid => $messages) { $conpherence = $conpherences[$phid]; $engine = id(new PhabricatorMarkupEngine())->setViewer($viewer)->setContextObject($conpherence); foreach ($messages as $group) { foreach ($group as $message) { $xaction = $message['xaction']; if ($xaction) { $author_phids[] = $xaction->getAuthorPHID(); $engine->addObject($xaction->getComment(), PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); } } } $engine->process(); $engines[$phid] = $engine; } $handles = $viewer->loadHandles($author_phids); $handles = iterator_to_array($handles); } else { $context = array(); } $content = array(); $list = new PHUIObjectItemListView(); $list->setUser($viewer); foreach ($conpherences as $conpherence_phid => $conpherence) { $created = phabricator_date($conpherence->getDateCreated(), $viewer); $title = $conpherence->getDisplayTitle($viewer); $monogram = $conpherence->getMonogram(); $icon_name = $conpherence->getPolicyIconName($policy_objects); $icon = id(new PHUIIconView())->setIcon($icon_name); if (!strlen($fulltext)) { $item = id(new PHUIObjectItemView())->setObjectName($conpherence->getMonogram())->setHeader($title)->setHref('/' . $conpherence->getMonogram())->setObject($conpherence)->setImageURI($conpherence->getProfileImageURI())->addIcon('none', $created)->addIcon('none', pht('Messages: %d', $conpherence->getMessageCount()))->addAttribute(array($icon, ' ', pht('Last updated %s', phabricator_datetime($conpherence->getDateModified(), $viewer)))); $list->addItem($item); } else { $messages = idx($context, $conpherence_phid); $box = array(); $list = null; if ($messages) { foreach ($messages as $group) { $rows = array(); foreach ($group as $message) { $xaction = $message['xaction']; if (!$xaction) { continue; } $view = id(new ConpherenceTransactionView())->setUser($viewer)->setHandles($handles)->setMarkupEngine($engines[$conpherence_phid])->setConpherenceThread($conpherence)->setConpherenceTransaction($xaction)->setSearchResult(true)->addClass('conpherence-fulltext-result'); if ($message['match']) { $view->addClass('conpherence-fulltext-match'); } $rows[] = $view; } $box[] = id(new PHUIBoxView())->appendChild($rows)->addClass('conpherence-fulltext-results'); } } $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon($icon_name)->setHref('/' . $monogram); $content[] = id(new PHUIObjectBoxView())->setHeader($header)->appendChild($box); } } if ($list) { $content = $list; } else { $content = id(new PHUIBoxView())->addClass('conpherence-search-room-results')->appendChild($content); } $result = new PhabricatorApplicationSearchResultView(); $result->setContent($content); $result->setNoDataString(pht('No results found.')); return $result; }
private function getPolicyIcon(ConpherenceThread $conpherence, array $policy_objects) { assert_instances_of($policy_objects, 'PhabricatorPolicy'); $icon = $conpherence->getPolicyIconName($policy_objects); $icon = id(new PHUIIconView())->addClass('mmr')->setIconFont($icon); return $icon; }
protected final function getConpherenceURI(ConpherenceThread $conpherence) { $id = $conpherence->getID(); return PhabricatorEnv::getProductionURI($this->getApplication()->getApplicationURI($id)); }
<?php echo pht("Migrating data from conpherence transactions to conpherence 'cache'...\n"); $table = new ConpherenceThread(); $table->openTransaction(); $conn_w = $table->establishConnection('w'); $participant_table = new ConpherenceParticipant(); $conpherences = new LiskMigrationIterator($table); foreach ($conpherences as $conpherence) { echo pht('Migrating conpherence #%d', $conpherence->getID()) . "\n"; $participants = id(new ConpherenceParticipant())->loadAllWhere('conpherencePHID = %s', $conpherence->getPHID()); $transactions = id(new ConpherenceTransaction())->loadAllWhere('objectPHID = %s', $conpherence->getPHID()); $participation_hash = mgroup($participants, 'getBehindTransactionPHID'); $message_count = 0; $participants_to_cache = array(); foreach ($transactions as $transaction) { $participants_to_cache[] = $transaction->getAuthorPHID(); if ($transaction->getTransactionType() == PhabricatorTransactions::TYPE_COMMENT) { $message_count++; } $participants_to_update = idx($participation_hash, $transaction->getPHID(), array()); if ($participants_to_update) { queryfx($conn_w, 'UPDATE %T SET seenMessageCount = %d ' . 'WHERE conpherencePHID = %s AND participantPHID IN (%Ls)', $participant_table->getTableName(), $message_count, $conpherence->getPHID(), mpull($participants_to_update, 'getParticipantPHID')); } } $participants_to_cache = array_slice(array_unique(array_reverse($participants_to_cache)), 0, 10); queryfx($conn_w, 'UPDATE %T ' . 'SET recentParticipantPHIDs = %s, ' . 'messageCount = %d ' . 'WHERE phid = %s', $table->getTableName(), json_encode($participants_to_cache), $message_count, $conpherence->getPHID()); } $table->saveTransaction(); echo "\n" . pht('Done.') . "\n";
public function handleRequest(AphrontRequest $request) { $user = $request->getUser(); $title = pht('Conpherence'); $conpherence = null; $limit = ConpherenceThreadListView::SEE_MORE_LIMIT * 2 + 1; $all_participation = array(); $mode = $this->determineMode(); switch ($mode) { case self::SELECTED_MODE: $conpherence_id = $request->getURIData('id'); $conpherence = id(new ConpherenceThreadQuery())->setViewer($user)->withIDs(array($conpherence_id))->executeOne(); if (!$conpherence) { return new Aphront404Response(); } if ($conpherence->getTitle()) { $title = $conpherence->getTitle(); } $cursor = $conpherence->getParticipantIfExists($user->getPHID()); $data = $this->loadDefaultParticipation($limit); $all_participation = $data['all_participation']; if (!$cursor) { $menu_participation = id(new ConpherenceParticipant())->makeEphemeral()->setConpherencePHID($conpherence->getPHID())->setParticipantPHID($user->getPHID()); } else { $menu_participation = $cursor; } // check to see if the loaded conpherence is going to show up // within the SEE_MORE_LIMIT amount of conpherences. // If its not there, then we just pre-pend it as the "first" // conpherence so folks have a navigation item in the menu. $count = 0; $found = false; foreach ($all_participation as $phid => $curr_participation) { if ($conpherence->getPHID() == $phid) { $found = true; break; } $count++; if ($count > ConpherenceThreadListView::SEE_MORE_LIMIT) { break; } } if (!$found) { $all_participation = array($conpherence->getPHID() => $menu_participation) + $all_participation; } break; case self::UNSELECTED_MODE: default: $data = $this->loadDefaultParticipation($limit); $all_participation = $data['all_participation']; break; } $threads = $this->loadConpherenceThreadData($all_participation); $thread_view = id(new ConpherenceThreadListView())->setUser($user)->setBaseURI($this->getApplicationURI())->setThreads($threads); switch ($mode) { case self::SELECTED_MODE: $response = id(new AphrontAjaxResponse())->setContent($thread_view); break; case self::UNSELECTED_MODE: default: $layout = id(new ConpherenceLayoutView())->setUser($user)->setBaseURI($this->getApplicationURI())->setThreadView($thread_view)->setRole('list'); if ($conpherence) { $layout->setThread($conpherence); } else { // make a dummy conpherence so we can render something $conpherence = ConpherenceThread::initializeNewRoom($user); $conpherence->attachHandles(array()); $conpherence->attachTransactions(array()); $conpherence->makeEphemeral(); } $policy_objects = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($conpherence)->execute(); $layout->setHeader($this->buildHeaderPaneContent($conpherence, $policy_objects)); $response = $this->newPage()->setTitle($title)->appendChild($layout); break; } return $response; }
private function renderMetadataDialog(ConpherenceThread $conpherence, $error_view) { $request = $this->getRequest(); $user = $request->getUser(); $title = pht('Update Room'); $form = id(new PHUIFormLayoutView())->appendChild($error_view)->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Title'))->setName('title')->setValue($conpherence->getTitle()))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Topic'))->setName('topic')->setValue($conpherence->getTopic())); $policies = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($conpherence)->execute(); $form->appendChild(id(new AphrontFormPolicyControl())->setName('viewPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicies($policies))->appendChild(id(new AphrontFormPolicyControl())->setName('editPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicies($policies))->appendChild(id(new AphrontFormPolicyControl())->setName('joinPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_JOIN)->setPolicies($policies)); $view = id(new AphrontDialogView())->setTitle($title)->addHiddenInput('action', 'metadata')->addHiddenInput('latest_transaction_id', $request->getInt('latest_transaction_id'))->addHiddenInput('__continue__', true)->appendChild($form); if ($request->getExists('force_ajax')) { $view->addHiddenInput('force_ajax', true); } return $view; }
private function isUpToDate(ConpherenceThread $conpherence) { return $this->getSeenMessageCount() == $conpherence->getMessageCount() && $this->getParticipationStatus() == ConpherenceParticipationStatus::UP_TO_DATE; }
private function renderMetadataDialogue(ConpherenceThread $conpherence, $error_view) { $request = $this->getRequest(); $user = $request->getUser(); $title = pht('Update Room'); $form = id(new PHUIFormLayoutView())->appendChild($error_view)->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Title'))->setName('title')->setValue($conpherence->getTitle())); $nopic = $this->getRequest()->getExists('nopic'); $image = $conpherence->getImage(ConpherenceImageData::SIZE_ORIG); if ($nopic) { // do not render any pic related controls } else { if ($image) { $crop_uri = $conpherence->loadImageURI(ConpherenceImageData::SIZE_CROP); $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Image'))->setValue(phutil_tag('img', array('src' => $crop_uri))))->appendChild(id(new ConpherencePicCropControl())->setLabel(pht('Crop Image'))->setValue($image))->appendChild(id(new ConpherenceFormDragAndDropUploadControl())->setLabel(pht('Change Image'))); } else { $form->appendChild(id(new ConpherenceFormDragAndDropUploadControl())->setLabel(pht('Image'))); } } $policies = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($conpherence)->execute(); $form->appendChild(id(new AphrontFormPolicyControl())->setName('viewPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicies($policies))->appendChild(id(new AphrontFormPolicyControl())->setName('editPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicies($policies))->appendChild(id(new AphrontFormPolicyControl())->setName('joinPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_JOIN)->setPolicies($policies)); require_celerity_resource('conpherence-update-css'); $view = id(new AphrontDialogView())->setTitle($title)->addHiddenInput('action', 'metadata')->addHiddenInput('latest_transaction_id', $request->getInt('latest_transaction_id'))->addHiddenInput('__continue__', true)->appendChild($form); if ($request->getExists('minimal_display')) { $view->addHiddenInput('minimal_display', true); } if ($request->getExists('force_ajax')) { $view->addHiddenInput('force_ajax', true); } return $view; }
private function getHeaderActionsConfig(ConpherenceThread $conpherence) { if ($conpherence->getIsRoom()) { $rename_label = pht('Edit Room'); } else { $rename_label = pht('Rename Thread'); } $can_edit = PhabricatorPolicyFilter::hasCapability($this->getUser(), $conpherence, PhabricatorPolicyCapability::CAN_EDIT); return array(array('name' => pht('Add Participants'), 'disabled' => !$can_edit, 'href' => '/conpherence/update/' . $conpherence->getID() . '/', 'icon' => 'fa-plus', 'key' => ConpherenceUpdateActions::ADD_PERSON), array('name' => $rename_label, 'disabled' => !$can_edit, 'href' => '/conpherence/update/' . $conpherence->getID() . '/?nopic', 'icon' => 'fa-pencil', 'key' => ConpherenceUpdateActions::METADATA), array('name' => pht('View in Conpherence'), 'disabled' => false, 'href' => '/' . $conpherence->getMonogram(), 'icon' => 'fa-comments', 'key' => 'go_conpherence'), array('name' => pht('Hide Column'), 'disabled' => false, 'href' => '#', 'icon' => 'fa-times', 'key' => 'hide_column')); }
public static function renderTransactions(PhabricatorUser $user, ConpherenceThread $conpherence, $marker_type = 'older') { $transactions = $conpherence->getTransactions(); $oldest_transaction_id = 0; $newest_transaction_id = 0; $too_many = ConpherenceThreadQuery::TRANSACTION_LIMIT + 1; if (count($transactions) == $too_many) { if ($marker_type == 'olderandnewer') { $last_transaction = end($transactions); $first_transaction = reset($transactions); unset($transactions[$last_transaction->getID()]); unset($transactions[$first_transaction->getID()]); $oldest_transaction_id = $last_transaction->getID(); $newest_transaction_id = $first_transaction->getID(); } else { if ($marker_type == 'newer') { $first_transaction = reset($transactions); unset($transactions[$first_transaction->getID()]); $newest_transaction_id = $first_transaction->getID(); } else { if ($marker_type == 'older') { $last_transaction = end($transactions); unset($transactions[$last_transaction->getID()]); $oldest_transaction = end($transactions); $oldest_transaction_id = $oldest_transaction->getID(); } } } // we need **at least** the newer marker in this mode even if // we didn't get a full set of transactions } else { if ($marker_type == 'olderandnewer') { $first_transaction = reset($transactions); unset($transactions[$first_transaction->getID()]); $newest_transaction_id = $first_transaction->getID(); } } $transactions = array_reverse($transactions); $handles = $conpherence->getHandles(); $rendered_transactions = array(); $engine = id(new PhabricatorMarkupEngine())->setViewer($user)->setContextObject($conpherence); foreach ($transactions as $key => $transaction) { if ($transaction->shouldHide()) { unset($transactions[$key]); continue; } if ($transaction->getComment()) { $engine->addObject($transaction->getComment(), PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); } } $engine->process(); // we're going to insert a dummy date marker transaction for breaks // between days. some setup required! $previous_transaction = null; $date_marker_transaction = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_DATE_MARKER)->makeEphemeral(); $date_marker_transaction_view = id(new ConpherenceTransactionView())->setUser($user)->setConpherenceTransaction($date_marker_transaction)->setConpherenceThread($conpherence)->setHandles($handles)->setMarkupEngine($engine); $transaction_view_template = id(new ConpherenceTransactionView())->setUser($user)->setConpherenceThread($conpherence)->setHandles($handles)->setMarkupEngine($engine); foreach ($transactions as $transaction) { $collapsed = false; if ($previous_transaction) { $previous_day = phabricator_format_local_time($previous_transaction->getDateCreated(), $user, 'Ymd'); $current_day = phabricator_format_local_time($transaction->getDateCreated(), $user, 'Ymd'); // See if same user / time $previous_author = $previous_transaction->getAuthorPHID(); $current_author = $transaction->getAuthorPHID(); $previous_time = $previous_transaction->getDateCreated(); $current_time = $transaction->getDateCreated(); $previous_type = $previous_transaction->getTransactionType(); $current_type = $transaction->getTransactionType(); if ($previous_author == $current_author && $previous_type == $current_type) { // Group messages within the last x seconds if ($current_time - $previous_time < 120) { $collapsed = true; } } // date marker transaction time! if ($previous_day != $current_day) { $date_marker_transaction->setDateCreated($transaction->getDateCreated()); $date_marker_transaction->setID($previous_transaction->getID()); $rendered_transactions[] = $date_marker_transaction_view->render(); } } $transaction_view = id(clone $transaction_view_template)->setConpherenceTransaction($transaction); if ($collapsed) { $transaction_view->addClass('conpherence-transaction-collapsed'); } $rendered_transactions[] = $transaction_view->render(); $previous_transaction = $transaction; } $latest_transaction_id = $transaction->getID(); return array('transactions' => $rendered_transactions, 'latest_transaction' => $transaction, 'latest_transaction_id' => $latest_transaction_id, 'oldest_transaction_id' => $oldest_transaction_id, 'newest_transaction_id' => $newest_transaction_id); }
protected function getTagContent() { $column_key = PhabricatorConpherenceColumnVisibleSetting::SETTINGKEY; $minimize_key = PhabricatorConpherenceColumnMinimizeSetting::SETTINGKEY; Javelin::initBehavior('durable-column', array('visible' => $this->getVisible(), 'minimize' => $this->getMinimize(), 'visibleURI' => '/settings/adjust/?key=' . $column_key, 'minimizeURI' => '/settings/adjust/?key=' . $minimize_key, 'quicksandConfig' => $this->getQuicksandConfig())); $policy_objects = ConpherenceThread::loadViewPolicyObjects($this->getUser(), $this->getConpherences()); $this->setPolicyObjects($policy_objects); $classes = array(); $classes[] = 'conpherence-durable-column-header'; $classes[] = 'grouped'; $header = phutil_tag('div', array('class' => implode(' ', $classes), 'data-sigil' => 'conpherence-minimize-window'), $this->buildHeader()); $icon_bar = null; if ($this->conpherences) { $icon_bar = $this->buildIconBar(); } $icon_bar = phutil_tag('div', array('class' => 'conpherence-durable-column-icon-bar'), $icon_bar); $transactions = $this->buildTransactions(); $content = javelin_tag('div', array('class' => 'conpherence-durable-column-main', 'sigil' => 'conpherence-durable-column-main'), phutil_tag('div', array('id' => 'conpherence-durable-column-content', 'class' => 'conpherence-durable-column-frame'), javelin_tag('div', array('class' => 'conpherence-durable-column-transactions', 'sigil' => 'conpherence-durable-column-transactions'), $transactions))); $input = $this->buildTextInput(); return array($header, javelin_tag('div', array('class' => 'conpherence-durable-column-body', 'sigil' => 'conpherence-durable-column-body'), array($icon_bar, $content, $input))); }