3 final class ConpherenceEditor
extends PhabricatorApplicationTransactionEditor
{
5 const ERROR_EMPTY_PARTICIPANTS
= 'error-empty-participants';
6 const ERROR_EMPTY_MESSAGE
= 'error-empty-message';
8 public function getEditorApplicationClass() {
9 return 'PhabricatorConpherenceApplication';
12 public function getEditorObjectsDescription() {
13 return pht('Conpherence Rooms');
16 public static function createThread(
17 PhabricatorUser
$creator,
18 array $participant_phids,
21 PhabricatorContentSource
$source,
24 $conpherence = ConpherenceThread
::initializeNewRoom($creator);
26 if (empty($participant_phids)) {
27 $errors[] = self
::ERROR_EMPTY_PARTICIPANTS
;
29 $participant_phids[] = $creator->getPHID();
30 $participant_phids = array_unique($participant_phids);
33 if (empty($message)) {
34 $errors[] = self
::ERROR_EMPTY_MESSAGE
;
39 $xactions[] = id(new ConpherenceTransaction())
41 ConpherenceThreadParticipantsTransaction
::TRANSACTIONTYPE
)
42 ->setNewValue(array('+' => $participant_phids));
44 $xactions[] = id(new ConpherenceTransaction())
46 ConpherenceThreadTitleTransaction
::TRANSACTIONTYPE
)
47 ->setNewValue($title);
50 $xactions[] = id(new ConpherenceTransaction())
52 ConpherenceThreadTopicTransaction
::TRANSACTIONTYPE
)
53 ->setNewValue($topic);
56 $xactions[] = id(new ConpherenceTransaction())
57 ->setTransactionType(PhabricatorTransactions
::TYPE_COMMENT
)
59 id(new ConpherenceTransactionComment())
60 ->setContent($message)
61 ->setConpherencePHID($conpherence->getPHID()));
63 id(new ConpherenceEditor())
65 ->setContentSource($source)
66 ->setContinueOnNoEffect(true)
67 ->applyTransactions($conpherence, $xactions);
70 return array($errors, $conpherence);
73 public function generateTransactionsFromText(
74 PhabricatorUser
$viewer,
75 ConpherenceThread
$conpherence,
79 $xactions[] = id(new ConpherenceTransaction())
80 ->setTransactionType(PhabricatorTransactions
::TYPE_COMMENT
)
82 id(new ConpherenceTransactionComment())
84 ->setConpherencePHID($conpherence->getPHID()));
88 public function getTransactionTypes() {
89 $types = parent
::getTransactionTypes();
91 $types[] = PhabricatorTransactions
::TYPE_COMMENT
;
92 $types[] = PhabricatorTransactions
::TYPE_VIEW_POLICY
;
93 $types[] = PhabricatorTransactions
::TYPE_EDIT_POLICY
;
98 public function getCreateObjectTitle($author, $object) {
99 return pht('%s created this room.', $author);
103 protected function applyBuiltinInternalTransaction(
104 PhabricatorLiskDAO
$object,
105 PhabricatorApplicationTransaction
$xaction) {
107 switch ($xaction->getTransactionType()) {
108 case PhabricatorTransactions
::TYPE_COMMENT
:
109 $object->setMessageCount((int)$object->getMessageCount() +
1);
113 return parent
::applyBuiltinInternalTransaction($object, $xaction);
117 protected function applyFinalEffects(
118 PhabricatorLiskDAO
$object,
121 $acting_phid = $this->getActingAsPHID();
122 $participants = $object->getParticipants();
123 foreach ($participants as $participant) {
124 if ($participant->getParticipantPHID() == $acting_phid) {
125 $participant->markUpToDate($object);
130 PhabricatorUserCache
::clearCaches(
131 PhabricatorUserMessageCountCacheType
::KEY_COUNT
,
132 array_keys($participants));
138 'threadPHID' => $object->getPHID(),
139 'messageID' => last($xactions)->getID(),
140 'subscribers' => array($object->getPHID()),
143 PhabricatorNotificationClient
::tryToPostMessage($data);
149 protected function shouldSendMail(
150 PhabricatorLiskDAO
$object,
155 protected function buildReplyHandler(PhabricatorLiskDAO
$object) {
156 return id(new ConpherenceReplyHandler())
157 ->setActor($this->getActor())
158 ->setMailReceiver($object);
161 protected function buildMailTemplate(PhabricatorLiskDAO
$object) {
162 $id = $object->getID();
163 $title = $object->getTitle();
166 '%s sent you a message.',
167 $this->getActor()->getUserName());
170 return id(new PhabricatorMetaMTAMail())
171 ->setSubject("Z{$id}: {$title}");
174 protected function getMailTo(PhabricatorLiskDAO
$object) {
177 $participants = $object->getParticipants();
178 if (!$participants) {
182 $participant_phids = mpull($participants, 'getParticipantPHID');
184 $users = id(new PhabricatorPeopleQuery())
185 ->setViewer(PhabricatorUser
::getOmnipotentUser())
186 ->withPHIDs($participant_phids)
187 ->needUserSettings(true)
189 $users = mpull($users, null, 'getPHID');
191 $notification_key = PhabricatorConpherenceNotificationsSetting
::SETTINGKEY
;
192 $notification_email =
193 PhabricatorConpherenceNotificationsSetting
::VALUE_CONPHERENCE_EMAIL
;
195 foreach ($participants as $phid => $participant) {
196 $user = idx($users, $phid);
198 $default = $user->getUserSetting($notification_key);
200 $default = $notification_email;
203 $settings = $participant->getSettings();
204 $notifications = idx($settings, 'notifications', $default);
206 if ($notifications == $notification_email) {
214 protected function getMailCC(PhabricatorLiskDAO
$object) {
218 protected function buildMailBody(
219 PhabricatorLiskDAO
$object,
222 $body = parent
::buildMailBody($object, $xactions);
223 $body->addLinkSection(
224 pht('CONPHERENCE DETAIL'),
225 PhabricatorEnv
::getProductionURI('/'.$object->getMonogram()));
230 protected function addEmailPreferenceSectionToMailBody(
231 PhabricatorMetaMTAMailBody
$body,
232 PhabricatorLiskDAO
$object,
235 $href = PhabricatorEnv
::getProductionURI(
236 '/'.$object->getMonogram().'?settings');
237 $label = pht('EMAIL PREFERENCES FOR THIS ROOM');
238 $body->addLinkSection($label, $href);
241 protected function getMailSubjectPrefix() {
242 return pht('[Conpherence]');
245 protected function supportsSearch() {