Path: blob/master/src/applications/conpherence/editor/ConpherenceEditor.php
12256 views
<?php12final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {34const ERROR_EMPTY_PARTICIPANTS = 'error-empty-participants';5const ERROR_EMPTY_MESSAGE = 'error-empty-message';67public function getEditorApplicationClass() {8return 'PhabricatorConpherenceApplication';9}1011public function getEditorObjectsDescription() {12return pht('Conpherence Rooms');13}1415public static function createThread(16PhabricatorUser $creator,17array $participant_phids,18$title,19$message,20PhabricatorContentSource $source,21$topic) {2223$conpherence = ConpherenceThread::initializeNewRoom($creator);24$errors = array();25if (empty($participant_phids)) {26$errors[] = self::ERROR_EMPTY_PARTICIPANTS;27} else {28$participant_phids[] = $creator->getPHID();29$participant_phids = array_unique($participant_phids);30}3132if (empty($message)) {33$errors[] = self::ERROR_EMPTY_MESSAGE;34}3536if (!$errors) {37$xactions = array();38$xactions[] = id(new ConpherenceTransaction())39->setTransactionType(40ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)41->setNewValue(array('+' => $participant_phids));42if ($title) {43$xactions[] = id(new ConpherenceTransaction())44->setTransactionType(45ConpherenceThreadTitleTransaction::TRANSACTIONTYPE)46->setNewValue($title);47}48if (strlen($topic)) {49$xactions[] = id(new ConpherenceTransaction())50->setTransactionType(51ConpherenceThreadTopicTransaction::TRANSACTIONTYPE)52->setNewValue($topic);53}5455$xactions[] = id(new ConpherenceTransaction())56->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)57->attachComment(58id(new ConpherenceTransactionComment())59->setContent($message)60->setConpherencePHID($conpherence->getPHID()));6162id(new ConpherenceEditor())63->setActor($creator)64->setContentSource($source)65->setContinueOnNoEffect(true)66->applyTransactions($conpherence, $xactions);67}6869return array($errors, $conpherence);70}7172public function generateTransactionsFromText(73PhabricatorUser $viewer,74ConpherenceThread $conpherence,75$text) {7677$xactions = array();78$xactions[] = id(new ConpherenceTransaction())79->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)80->attachComment(81id(new ConpherenceTransactionComment())82->setContent($text)83->setConpherencePHID($conpherence->getPHID()));84return $xactions;85}8687public function getTransactionTypes() {88$types = parent::getTransactionTypes();8990$types[] = PhabricatorTransactions::TYPE_COMMENT;91$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;92$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;9394return $types;95}9697public function getCreateObjectTitle($author, $object) {98return pht('%s created this room.', $author);99}100101102protected function applyBuiltinInternalTransaction(103PhabricatorLiskDAO $object,104PhabricatorApplicationTransaction $xaction) {105106switch ($xaction->getTransactionType()) {107case PhabricatorTransactions::TYPE_COMMENT:108$object->setMessageCount((int)$object->getMessageCount() + 1);109break;110}111112return parent::applyBuiltinInternalTransaction($object, $xaction);113}114115116protected function applyFinalEffects(117PhabricatorLiskDAO $object,118array $xactions) {119120$acting_phid = $this->getActingAsPHID();121$participants = $object->getParticipants();122foreach ($participants as $participant) {123if ($participant->getParticipantPHID() == $acting_phid) {124$participant->markUpToDate($object);125}126}127128if ($participants) {129PhabricatorUserCache::clearCaches(130PhabricatorUserMessageCountCacheType::KEY_COUNT,131array_keys($participants));132}133134if ($xactions) {135$data = array(136'type' => 'message',137'threadPHID' => $object->getPHID(),138'messageID' => last($xactions)->getID(),139'subscribers' => array($object->getPHID()),140);141142PhabricatorNotificationClient::tryToPostMessage($data);143}144145return $xactions;146}147148protected function shouldSendMail(149PhabricatorLiskDAO $object,150array $xactions) {151return true;152}153154protected function buildReplyHandler(PhabricatorLiskDAO $object) {155return id(new ConpherenceReplyHandler())156->setActor($this->getActor())157->setMailReceiver($object);158}159160protected function buildMailTemplate(PhabricatorLiskDAO $object) {161$id = $object->getID();162$title = $object->getTitle();163if (!$title) {164$title = pht(165'%s sent you a message.',166$this->getActor()->getUserName());167}168169return id(new PhabricatorMetaMTAMail())170->setSubject("Z{$id}: {$title}");171}172173protected function getMailTo(PhabricatorLiskDAO $object) {174$to_phids = array();175176$participants = $object->getParticipants();177if (!$participants) {178return $to_phids;179}180181$participant_phids = mpull($participants, 'getParticipantPHID');182183$users = id(new PhabricatorPeopleQuery())184->setViewer(PhabricatorUser::getOmnipotentUser())185->withPHIDs($participant_phids)186->needUserSettings(true)187->execute();188$users = mpull($users, null, 'getPHID');189190$notification_key = PhabricatorConpherenceNotificationsSetting::SETTINGKEY;191$notification_email =192PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_EMAIL;193194foreach ($participants as $phid => $participant) {195$user = idx($users, $phid);196if ($user) {197$default = $user->getUserSetting($notification_key);198} else {199$default = $notification_email;200}201202$settings = $participant->getSettings();203$notifications = idx($settings, 'notifications', $default);204205if ($notifications == $notification_email) {206$to_phids[] = $phid;207}208}209210return $to_phids;211}212213protected function getMailCC(PhabricatorLiskDAO $object) {214return array();215}216217protected function buildMailBody(218PhabricatorLiskDAO $object,219array $xactions) {220221$body = parent::buildMailBody($object, $xactions);222$body->addLinkSection(223pht('CONPHERENCE DETAIL'),224PhabricatorEnv::getProductionURI('/'.$object->getMonogram()));225226return $body;227}228229protected function addEmailPreferenceSectionToMailBody(230PhabricatorMetaMTAMailBody $body,231PhabricatorLiskDAO $object,232array $xactions) {233234$href = PhabricatorEnv::getProductionURI(235'/'.$object->getMonogram().'?settings');236$label = pht('EMAIL PREFERENCES FOR THIS ROOM');237$body->addLinkSection($label, $href);238}239240protected function getMailSubjectPrefix() {241return pht('[Conpherence]');242}243244protected function supportsSearch() {245return true;246}247248}249250251