diff --git a/src/applications/conpherence/controller/ConpherenceNewRoomController.php b/src/applications/conpherence/controller/ConpherenceNewRoomController.php index 03df0859bd..25ae99a468 100644 --- a/src/applications/conpherence/controller/ConpherenceNewRoomController.php +++ b/src/applications/conpherence/controller/ConpherenceNewRoomController.php @@ -1,141 +1,141 @@ getUser(); $title = pht('New Room'); $e_title = true; $v_message = null; $validation_exception = null; $conpherence = ConpherenceThread::initializeNewRoom($user); $participants = array(); if ($request->isFormPost()) { $editor = new ConpherenceEditor(); $xactions = array(); + $xactions[] = id(new ConpherenceTransaction()) + ->setTransactionType(ConpherenceTransaction::TYPE_TITLE) + ->setNewValue($request->getStr('title')); + $participants = $request->getArr('participants'); $participants[] = $user->getPHID(); $participants = array_unique($participants); $xactions[] = id(new ConpherenceTransaction()) ->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS) ->setNewValue(array('+' => $participants)); - - $xactions[] = id(new ConpherenceTransaction()) - ->setTransactionType(ConpherenceTransaction::TYPE_TITLE) - ->setNewValue($request->getStr('title')); $xactions[] = id(new ConpherenceTransaction()) ->setTransactionType(ConpherenceTransaction::TYPE_TOPIC) ->setNewValue($request->getStr('topic')); $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')); $v_message = $request->getStr('message'); if (strlen($v_message)) { $message_xactions = $editor->generateTransactionsFromText( $user, $conpherence, $v_message); $xactions = array_merge($xactions, $message_xactions); } try { $editor ->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')); } } else { if ($request->getStr('participant')) { $participants[] = $request->getStr('participant'); } } $policies = id(new PhabricatorPolicyQuery()) ->setViewer($user) ->setObject($conpherence) ->execute(); $submit_uri = $this->getApplicationURI('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) ->appendChild( id(new AphrontFormTextControl()) ->setError($e_title) ->setLabel(pht('Name')) ->setName('title') ->setValue($request->getStr('title'))) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Topic')) ->setName('topic') ->setValue($request->getStr('topic'))) ->appendChild( id(new AphrontFormTokenizerControl()) ->setName('participants') ->setUser($user) ->setDatasource(new PhabricatorPeopleDatasource()) ->setValue($participants) ->setLabel(pht('Other Participants'))) ->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)) ->appendChild( id(new PhabricatorRemarkupControl()) ->setUser($user) ->setName('message') ->setLabel(pht('First Message')) ->setValue($v_message)); $dialog->appendChild($form); return id(new AphrontDialogResponse())->setDialog($dialog); } } diff --git a/src/applications/conpherence/editor/ConpherenceEditor.php b/src/applications/conpherence/editor/ConpherenceEditor.php index d1826ef98a..b7b37a3e6d 100644 --- a/src/applications/conpherence/editor/ConpherenceEditor.php +++ b/src/applications/conpherence/editor/ConpherenceEditor.php @@ -1,720 +1,731 @@ getPHID(); $participant_phids = array_unique($participant_phids); } if (empty($message)) { $errors[] = self::ERROR_EMPTY_MESSAGE; } $file_phids = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles( $creator, array($message)); if ($file_phids) { $files = id(new PhabricatorFileQuery()) ->setViewer($creator) ->withPHIDs($file_phids) ->execute(); } if (!$errors) { $xactions = array(); $xactions[] = id(new ConpherenceTransaction()) ->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS) ->setNewValue(array('+' => $participant_phids)); if ($files) { $xactions[] = id(new ConpherenceTransaction()) ->setTransactionType(ConpherenceTransaction::TYPE_FILES) ->setNewValue(array('+' => mpull($files, 'getPHID'))); } if ($title) { $xactions[] = id(new ConpherenceTransaction()) ->setTransactionType(ConpherenceTransaction::TYPE_TITLE) ->setNewValue($title); } if (strlen($topic)) { $xactions[] = id(new ConpherenceTransaction()) ->setTransactionType(ConpherenceTransaction::TYPE_TOPIC) ->setNewValue($topic); } $xactions[] = id(new ConpherenceTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) ->attachComment( id(new ConpherenceTransactionComment()) ->setContent($message) ->setConpherencePHID($conpherence->getPHID())); id(new ConpherenceEditor()) ->setActor($creator) ->setContentSource($source) ->setContinueOnNoEffect(true) ->applyTransactions($conpherence, $xactions); } return array($errors, $conpherence); } 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; } public function getTransactionTypes() { $types = parent::getTransactionTypes(); $types[] = PhabricatorTransactions::TYPE_COMMENT; $types[] = ConpherenceTransaction::TYPE_TITLE; $types[] = ConpherenceTransaction::TYPE_TOPIC; $types[] = ConpherenceTransaction::TYPE_PARTICIPANTS; $types[] = ConpherenceTransaction::TYPE_FILES; $types[] = ConpherenceTransaction::TYPE_PICTURE; $types[] = ConpherenceTransaction::TYPE_PICTURE_CROP; $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; $types[] = PhabricatorTransactions::TYPE_JOIN_POLICY; return $types; } protected function getCustomTransactionOldValue( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { switch ($xaction->getTransactionType()) { case ConpherenceTransaction::TYPE_TITLE: return $object->getTitle(); case ConpherenceTransaction::TYPE_TOPIC: return $object->getTopic(); case ConpherenceTransaction::TYPE_PICTURE: return $object->getImagePHID(ConpherenceImageData::SIZE_ORIG); case ConpherenceTransaction::TYPE_PICTURE_CROP: return $object->getImagePHID(ConpherenceImageData::SIZE_CROP); case ConpherenceTransaction::TYPE_PARTICIPANTS: if ($this->getIsNewObject()) { return array(); } return $object->getParticipantPHIDs(); case ConpherenceTransaction::TYPE_FILES: return $object->getFilePHIDs(); } } protected function getCustomTransactionNewValue( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { switch ($xaction->getTransactionType()) { case ConpherenceTransaction::TYPE_TITLE: case ConpherenceTransaction::TYPE_TOPIC: case ConpherenceTransaction::TYPE_PICTURE_CROP: return $xaction->getNewValue(); case ConpherenceTransaction::TYPE_PICTURE: $file = $xaction->getNewValue(); return $file->getPHID(); case ConpherenceTransaction::TYPE_PARTICIPANTS: case ConpherenceTransaction::TYPE_FILES: return $this->getPHIDTransactionNewValue($xaction); } } /** * We really only need a read lock if we have a comment. In that case, we * must update the messagesCount field on the conpherence and * seenMessagesCount(s) for the participant(s). */ protected function shouldReadLock( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { $lock = false; switch ($xaction->getTransactionType()) { case PhabricatorTransactions::TYPE_COMMENT: $lock = true; break; } return $lock; } /** * We need to apply initial effects IFF the conpherence is new. We must * save the conpherence first thing to make sure we have an id and a phid, as * well as create the initial set of participants so that we pass policy * checks. */ protected function shouldApplyInitialEffects( PhabricatorLiskDAO $object, array $xactions) { return $this->getIsNewObject(); } protected function applyInitialEffects( PhabricatorLiskDAO $object, array $xactions) { $object->save(); foreach ($xactions as $xaction) { switch ($xaction->getTransactionType()) { case ConpherenceTransaction::TYPE_PARTICIPANTS: // Since this is a new ConpherenceThread, we have to create the // participation data asap to pass policy checks. For existing // ConpherenceThreads, the existing participation is correct // at this stage. Note that later in applyCustomExternalTransaction // this participation data will be updated, particularly the // behindTransactionPHID which is just a generated dummy for now. $participants = array(); $phids = $this->getPHIDTransactionNewValue($xaction, array()); foreach ($phids as $phid) { if ($phid == $this->getActor()->getPHID()) { $status = ConpherenceParticipationStatus::UP_TO_DATE; $message_count = 1; } else { $status = ConpherenceParticipationStatus::BEHIND; $message_count = 0; } $participants[$phid] = id(new ConpherenceParticipant()) ->setConpherencePHID($object->getPHID()) ->setParticipantPHID($phid) ->setParticipationStatus($status) ->setDateTouched(time()) ->setBehindTransactionPHID($xaction->generatePHID()) ->setSeenMessageCount($message_count) ->save(); $object->attachParticipants($participants); $object->setRecentParticipantPHIDs(array_keys($participants)); } break; } } } protected function applyCustomInternalTransaction( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { $make_author_recent_participant = true; switch ($xaction->getTransactionType()) { case ConpherenceTransaction::TYPE_TITLE: $object->setTitle($xaction->getNewValue()); break; case ConpherenceTransaction::TYPE_TOPIC: $object->setTopic($xaction->getNewValue()); break; case ConpherenceTransaction::TYPE_PICTURE: $object->setImagePHID( $xaction->getNewValue(), ConpherenceImageData::SIZE_ORIG); break; case ConpherenceTransaction::TYPE_PICTURE_CROP: $object->setImagePHID( $xaction->getNewValue(), ConpherenceImageData::SIZE_CROP); break; case ConpherenceTransaction::TYPE_PARTICIPANTS: if (!$this->getIsNewObject()) { $old_map = array_fuse($xaction->getOldValue()); $new_map = array_fuse($xaction->getNewValue()); // if we added people, add them to the end of "recent" participants $add = array_keys(array_diff_key($new_map, $old_map)); // if we remove people, then definintely remove them from "recent" // participants $del = array_keys(array_diff_key($old_map, $new_map)); if ($add || $del) { $participants = $object->getRecentParticipantPHIDs(); if ($add) { $participants = array_merge($participants, $add); } if ($del) { $participants = array_diff($participants, $del); $actor = $this->requireActor(); if (in_array($actor->getPHID(), $del)) { $make_author_recent_participant = false; } } $participants = array_slice(array_unique($participants), 0, 10); $object->setRecentParticipantPHIDs($participants); } } break; } if ($make_author_recent_participant) { $this->makeAuthorMostRecentParticipant($object, $xaction); } } protected function applyBuiltinInternalTransaction( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { switch ($xaction->getTransactionType()) { case PhabricatorTransactions::TYPE_COMMENT: $object->setMessageCount((int)$object->getMessageCount() + 1); break; } return parent::applyBuiltinInternalTransaction($object, $xaction); } private function makeAuthorMostRecentParticipant( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { $participants = $object->getRecentParticipantPHIDs(); array_unshift($participants, $xaction->getAuthorPHID()); $participants = array_slice(array_unique($participants), 0, 10); $object->setRecentParticipantPHIDs($participants); } protected function applyCustomExternalTransaction( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { switch ($xaction->getTransactionType()) { case ConpherenceTransaction::TYPE_FILES: $editor = new PhabricatorEdgeEditor(); $edge_type = PhabricatorObjectHasFileEdgeType::EDGECONST; $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) { $editor->addEdge( $object->getPHID(), $edge_type, $file_phid); } foreach ($remove_edges as $file_phid) { $editor->removeEdge( $object->getPHID(), $edge_type, $file_phid); } $editor->save(); break; case ConpherenceTransaction::TYPE_PARTICIPANTS: if ($this->getIsNewObject()) { continue; } $participants = $object->getParticipants(); $old_map = array_fuse($xaction->getOldValue()); $new_map = array_fuse($xaction->getNewValue()); $remove = array_keys(array_diff_key($old_map, $new_map)); foreach ($remove as $phid) { $remove_participant = $participants[$phid]; $remove_participant->delete(); unset($participants[$phid]); } $add = array_keys(array_diff_key($new_map, $old_map)); foreach ($add as $phid) { if ($phid == $this->getActor()->getPHID()) { $status = ConpherenceParticipationStatus::UP_TO_DATE; $message_count = $object->getMessageCount(); } else { $status = ConpherenceParticipationStatus::BEHIND; $message_count = 0; } $participants[$phid] = id(new ConpherenceParticipant()) ->setConpherencePHID($object->getPHID()) ->setParticipantPHID($phid) ->setParticipationStatus($status) ->setDateTouched(time()) ->setBehindTransactionPHID($xaction->getPHID()) ->setSeenMessageCount($message_count) ->save(); } $object->attachParticipants($participants); break; } } protected function applyFinalEffects( PhabricatorLiskDAO $object, array $xactions) { $message_count = 0; foreach ($xactions as $xaction) { switch ($xaction->getTransactionType()) { case PhabricatorTransactions::TYPE_COMMENT: $message_count++; break; } } // update everyone's participation status on the last xaction -only- $xaction = end($xactions); $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->setSeenMessageCount( $object->getMessageCount() - $message_count); } $participant->setParticipationStatus($behind); $participant->setDateTouched($time); } else { $participant->setSeenMessageCount($object->getMessageCount()); $participant->setBehindTransactionPHID($xaction_phid); $participant->setParticipationStatus($up_to_date); $participant->setDateTouched($time); } $participant->save(); } PhabricatorUserCache::clearCaches( PhabricatorUserMessageCountCacheType::KEY_COUNT, array_keys($participants)); if ($xactions) { $data = array( 'type' => 'message', 'threadPHID' => $object->getPHID(), 'messageID' => last($xactions)->getID(), 'subscribers' => array($object->getPHID()), ); PhabricatorNotificationClient::tryToPostMessage($data); } return $xactions; } protected function requireCapabilities( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { parent::requireCapabilities($object, $xaction); switch ($xaction->getTransactionType()) { case ConpherenceTransaction::TYPE_PARTICIPANTS: $old_map = array_fuse($xaction->getOldValue()); $new_map = array_fuse($xaction->getNewValue()); $add = array_keys(array_diff_key($new_map, $old_map)); $rem = array_keys(array_diff_key($old_map, $new_map)); $actor_phid = $this->requireActor()->getPHID(); $is_join = (($add === array($actor_phid)) && !$rem); $is_leave = (($rem === array($actor_phid)) && !$add); if ($is_join) { // You need CAN_JOIN to join a room. PhabricatorPolicyFilter::requireCapability( $this->requireActor(), $object, PhabricatorPolicyCapability::CAN_JOIN); } else if ($is_leave) { // You don't need any capabilities to leave a conpherence thread. } else { // You need CAN_EDIT to change participants other than yourself. PhabricatorPolicyFilter::requireCapability( $this->requireActor(), $object, PhabricatorPolicyCapability::CAN_EDIT); } break; // This is similar to PhabricatorTransactions::TYPE_COMMENT so // use CAN_VIEW case ConpherenceTransaction::TYPE_FILES: PhabricatorPolicyFilter::requireCapability( $this->requireActor(), $object, PhabricatorPolicyCapability::CAN_VIEW); break; case ConpherenceTransaction::TYPE_TITLE: case ConpherenceTransaction::TYPE_TOPIC: PhabricatorPolicyFilter::requireCapability( $this->requireActor(), $object, PhabricatorPolicyCapability::CAN_EDIT); break; } } protected function mergeTransactions( PhabricatorApplicationTransaction $u, PhabricatorApplicationTransaction $v) { $type = $u->getTransactionType(); switch ($type) { case ConpherenceTransaction::TYPE_TITLE: return $v; case ConpherenceTransaction::TYPE_FILES: case ConpherenceTransaction::TYPE_PARTICIPANTS: return $this->mergePHIDOrEdgeTransactions($u, $v); } return parent::mergeTransactions($u, $v); } protected function shouldSendMail( PhabricatorLiskDAO $object, array $xactions) { return true; } protected function buildReplyHandler(PhabricatorLiskDAO $object) { return id(new ConpherenceReplyHandler()) ->setActor($this->getActor()) ->setMailReceiver($object); } protected function buildMailTemplate(PhabricatorLiskDAO $object) { $id = $object->getID(); $title = $object->getTitle(); if (!$title) { $title = pht( '%s sent you a message.', $this->getActor()->getUserName()); } $phid = $object->getPHID(); return id(new PhabricatorMetaMTAMail()) ->setSubject("Z{$id}: {$title}") ->addHeader('Thread-Topic', "Z{$id}: {$phid}"); } protected function getMailTo(PhabricatorLiskDAO $object) { $to_phids = array(); $participants = $object->getParticipants(); if (!$participants) { return $to_phids; } $participant_phids = mpull($participants, 'getParticipantPHID'); $users = id(new PhabricatorPeopleQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withPHIDs($participant_phids) ->needUserSettings(true) ->execute(); $users = mpull($users, null, 'getPHID'); $notification_key = PhabricatorConpherenceNotificationsSetting::SETTINGKEY; $notification_email = PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_EMAIL; foreach ($participants as $phid => $participant) { $user = idx($users, $phid); if ($user) { $default = $user->getUserSetting($notification_key); } else { $default = $notification_email; } $settings = $participant->getSettings(); $notifications = idx($settings, 'notifications', $default); if ($notifications == $notification_email) { $to_phids[] = $phid; } } return $to_phids; } protected function getMailCC(PhabricatorLiskDAO $object) { return array(); } protected function buildMailBody( PhabricatorLiskDAO $object, array $xactions) { $body = parent::buildMailBody($object, $xactions); $body->addLinkSection( pht('CONPHERENCE DETAIL'), PhabricatorEnv::getProductionURI('/'.$object->getMonogram())); return $body; } protected function addEmailPreferenceSectionToMailBody( PhabricatorMetaMTAMailBody $body, PhabricatorLiskDAO $object, array $xactions) { $href = PhabricatorEnv::getProductionURI( '/'.$object->getMonogram().'?settings'); $label = pht('EMAIL PREFERENCES FOR THIS ROOM'); $body->addLinkSection($label, $href); } protected function getMailSubjectPrefix() { return PhabricatorEnv::getEnvConfig('metamta.conpherence.subject-prefix'); } protected function shouldPublishFeedStory( PhabricatorLiskDAO $object, array $xactions) { + + foreach ($xactions as $xaction) { + switch ($xaction->getTransactionType()) { + case ConpherenceTransaction::TYPE_TITLE: + case ConpherenceTransaction::TYPE_TOPIC: + case ConpherenceTransaction::TYPE_PICTURE: + return true; + default: + return false; + } + } return false; } protected function supportsSearch() { return true; } protected function extractFilePHIDsFromCustomTransaction( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { switch ($xaction->getTransactionType()) { case ConpherenceTransaction::TYPE_PICTURE: case ConpherenceTransaction::TYPE_PICTURE_CROP: return array($xaction->getNewValue()); } return parent::extractFilePHIDsFromCustomTransaction($object, $xaction); } protected function validateTransaction( PhabricatorLiskDAO $object, $type, array $xactions) { $errors = parent::validateTransaction($object, $type, $xactions); switch ($type) { case ConpherenceTransaction::TYPE_TITLE: if (empty($xactions)) { break; } $missing = $this->validateIsEmptyTextField( $object->getTitle(), $xactions); if ($missing) { $detail = pht('Room title is required.'); $error = new PhabricatorApplicationTransactionValidationError( $type, pht('Required'), $detail, last($xactions)); $error->setIsMissingFieldError(true); $errors[] = $error; } break; case ConpherenceTransaction::TYPE_PICTURE: foreach ($xactions as $xaction) { $file = $xaction->getNewValue(); if (!$file->isTransformableImage()) { $detail = pht('This server only supports these image formats: %s.', implode(', ', PhabricatorFile::getTransformableImageFormats())); $error = new PhabricatorApplicationTransactionValidationError( $type, pht('Invalid'), $detail, last($xactions)); $errors[] = $error; } } break; case ConpherenceTransaction::TYPE_PARTICIPANTS: foreach ($xactions as $xaction) { $new_phids = $this->getPHIDTransactionNewValue($xaction, array()); $old_phids = nonempty($object->getParticipantPHIDs(), array()); $phids = array_diff($new_phids, $old_phids); if (!$phids) { continue; } $users = id(new PhabricatorPeopleQuery()) ->setViewer($this->requireActor()) ->withPHIDs($phids) ->execute(); $users = mpull($users, null, 'getPHID'); foreach ($phids as $phid) { if (isset($users[$phid])) { continue; } $errors[] = new PhabricatorApplicationTransactionValidationError( $type, pht('Invalid'), pht('New room participant "%s" is not a valid user.', $phid), $xaction); } } break; } return $errors; } } diff --git a/src/applications/conpherence/storage/ConpherenceTransaction.php b/src/applications/conpherence/storage/ConpherenceTransaction.php index 4364276564..1090be43c8 100644 --- a/src/applications/conpherence/storage/ConpherenceTransaction.php +++ b/src/applications/conpherence/storage/ConpherenceTransaction.php @@ -1,217 +1,266 @@ getTransactionType()) { case self::TYPE_PARTICIPANTS: return pht( 'You can not add a participant who has already been added.'); break; } return parent::getNoEffectDescription(); } public function shouldHide() { $old = $this->getOldValue(); switch ($this->getTransactionType()) { case self::TYPE_PARTICIPANTS: return ($old === null); case self::TYPE_TITLE: case self::TYPE_TOPIC: case self::TYPE_PICTURE: case self::TYPE_DATE_MARKER: return false; case self::TYPE_FILES: return true; case self::TYPE_PICTURE_CROP: return true; } return parent::shouldHide(); } public function getTitle() { $author_phid = $this->getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_TITLE: case self::TYPE_TOPIC: case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: case PhabricatorTransactions::TYPE_JOIN_POLICY: case self::TYPE_PICTURE: return $this->getRoomTitle(); break; case self::TYPE_FILES: $add = array_diff($new, $old); $rem = array_diff($old, $new); if ($add && $rem) { $title = pht( '%s edited files(s), added %d and removed %d.', $this->renderHandleLink($author_phid), count($add), count($rem)); } else if ($add) { $title = pht( '%s added %s files(s).', $this->renderHandleLink($author_phid), phutil_count($add)); } else { $title = pht( '%s removed %s file(s).', $this->renderHandleLink($author_phid), phutil_count($rem)); } return $title; break; case self::TYPE_PARTICIPANTS: $add = array_diff($new, $old); $rem = array_diff($old, $new); if ($add && $rem) { $title = pht( '%s edited participant(s), added %d: %s; removed %d: %s.', $this->renderHandleLink($author_phid), count($add), $this->renderHandleList($add), count($rem), $this->renderHandleList($rem)); } else if ($add) { $title = pht( '%s added %d participant(s): %s.', $this->renderHandleLink($author_phid), count($add), $this->renderHandleList($add)); } else { $title = pht( '%s removed %d participant(s): %s.', $this->renderHandleLink($author_phid), count($rem), $this->renderHandleList($rem)); } return $title; break; } return parent::getTitle(); } + public function getTitleForFeed() { + $author_phid = $this->getAuthorPHID(); + $object_phid = $this->getObjectPHID(); + + $old = $this->getOldValue(); + $new = $this->getNewValue(); + + $type = $this->getTransactionType(); + switch ($type) { + case self::TYPE_TITLE: + if (strlen($old) && strlen($new)) { + return pht( + '%s renamed %s from "%s" to "%s".', + $this->renderHandleLink($author_phid), + $this->renderHandleLink($object_phid), + $old, + $new); + } else { + return pht( + '%s created the room %s.', + $this->renderHandleLink($author_phid), + $this->renderHandleLink($object_phid)); + } + break; + break; + case self::TYPE_TOPIC: + if (strlen($new)) { + return pht( + '%s set the topic of %s to "%s".', + $this->renderHandleLink($author_phid), + $this->renderHandleLink($object_phid), + $new); + } else if (strlen($old)) { + return pht( + '%s deleted the topic in %s', + $this->renderHandleLink($author_phid), + $this->renderHandleLink($object_phid)); + } + break; + case self::TYPE_PICTURE: + return pht( + '%s updated the room image for %s.', + $this->renderHandleLink($author_phid), + $this->renderHandleLink($object_phid)); + break; + } + return parent::getTitleForFeed(); + } + private function getRoomTitle() { $author_phid = $this->getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_TITLE: if ($old && $new) { $title = pht( '%s renamed this room from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new); } else if ($old) { $title = pht( '%s deleted the room name "%s".', $this->renderHandleLink($author_phid), $old); } else { $title = pht( '%s named this room "%s".', $this->renderHandleLink($author_phid), $new); } return $title; break; case self::TYPE_TOPIC: if ($new) { $title = pht( '%s set the topic of this room to "%s".', $this->renderHandleLink($author_phid), $new); } else if ($old) { $title = pht( '%s deleted the room topic "%s"', $this->renderHandleLink($author_phid), $old); } return $title; break; case self::TYPE_PICTURE: return pht( '%s updated the room image.', $this->renderHandleLink($author_phid)); break; case PhabricatorTransactions::TYPE_VIEW_POLICY: return pht( '%s changed the visibility of this room from "%s" to "%s".', $this->renderHandleLink($author_phid), $this->renderPolicyName($old, 'old'), $this->renderPolicyName($new, 'new')); break; case PhabricatorTransactions::TYPE_EDIT_POLICY: return pht( '%s changed the edit policy of this room from "%s" to "%s".', $this->renderHandleLink($author_phid), $this->renderPolicyName($old, 'old'), $this->renderPolicyName($new, 'new')); break; case PhabricatorTransactions::TYPE_JOIN_POLICY: return pht( '%s changed the join policy of this room from "%s" to "%s".', $this->renderHandleLink($author_phid), $this->renderPolicyName($old, 'old'), $this->renderPolicyName($new, 'new')); break; } } public function getRequiredHandlePHIDs() { $phids = parent::getRequiredHandlePHIDs(); $old = $this->getOldValue(); $new = $this->getNewValue(); $phids[] = $this->getAuthorPHID(); switch ($this->getTransactionType()) { case self::TYPE_TITLE: case self::TYPE_PICTURE: case self::TYPE_FILES: case self::TYPE_DATE_MARKER: break; case self::TYPE_PARTICIPANTS: $phids = array_merge($phids, $this->getOldValue()); $phids = array_merge($phids, $this->getNewValue()); break; } return $phids; } }