[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class ConpherenceThread extends ConpherenceDAO 4 implements PhabricatorPolicyInterface { 5 6 protected $title; 7 protected $messageCount; 8 protected $recentParticipantPHIDs = array(); 9 protected $mailKey; 10 11 private $participants = self::ATTACHABLE; 12 private $transactions = self::ATTACHABLE; 13 private $handles = self::ATTACHABLE; 14 private $filePHIDs = self::ATTACHABLE; 15 private $widgetData = self::ATTACHABLE; 16 private $images = array(); 17 18 public static function initializeNewThread(PhabricatorUser $sender) { 19 return id(new ConpherenceThread()) 20 ->setMessageCount(0) 21 ->setTitle(''); 22 } 23 24 public function getConfiguration() { 25 return array( 26 self::CONFIG_AUX_PHID => true, 27 self::CONFIG_SERIALIZATION => array( 28 'recentParticipantPHIDs' => self::SERIALIZATION_JSON, 29 ), 30 self::CONFIG_COLUMN_SCHEMA => array( 31 'title' => 'text255?', 32 'messageCount' => 'uint64', 33 'mailKey' => 'text20', 34 ), 35 self::CONFIG_KEY_SCHEMA => array( 36 'key_phid' => null, 37 'phid' => array( 38 'columns' => array('phid'), 39 'unique' => true, 40 ), 41 ), 42 ) + parent::getConfiguration(); 43 } 44 45 public function generatePHID() { 46 return PhabricatorPHID::generateNewPHID( 47 PhabricatorConpherenceThreadPHIDType::TYPECONST); 48 } 49 50 public function save() { 51 if (!$this->getMailKey()) { 52 $this->setMailKey(Filesystem::readRandomCharacters(20)); 53 } 54 return parent::save(); 55 } 56 57 public function attachParticipants(array $participants) { 58 assert_instances_of($participants, 'ConpherenceParticipant'); 59 $this->participants = $participants; 60 return $this; 61 } 62 public function getParticipants() { 63 return $this->assertAttached($this->participants); 64 } 65 public function getParticipant($phid) { 66 $participants = $this->getParticipants(); 67 return $participants[$phid]; 68 } 69 public function getParticipantPHIDs() { 70 $participants = $this->getParticipants(); 71 return array_keys($participants); 72 } 73 74 public function attachHandles(array $handles) { 75 assert_instances_of($handles, 'PhabricatorObjectHandle'); 76 $this->handles = $handles; 77 return $this; 78 } 79 public function getHandles() { 80 return $this->assertAttached($this->handles); 81 } 82 83 public function attachTransactions(array $transactions) { 84 assert_instances_of($transactions, 'ConpherenceTransaction'); 85 $this->transactions = $transactions; 86 return $this; 87 } 88 public function getTransactions() { 89 return $this->assertAttached($this->transactions); 90 } 91 92 public function getTransactionsFrom($begin = 0, $amount = null) { 93 $length = count($this->transactions); 94 95 return array_slice( 96 $this->getTransactions(), 97 $length - $begin - $amount, 98 $amount); 99 } 100 101 public function attachFilePHIDs(array $file_phids) { 102 $this->filePHIDs = $file_phids; 103 return $this; 104 } 105 public function getFilePHIDs() { 106 return $this->assertAttached($this->filePHIDs); 107 } 108 109 public function attachWidgetData(array $widget_data) { 110 $this->widgetData = $widget_data; 111 return $this; 112 } 113 public function getWidgetData() { 114 return $this->assertAttached($this->widgetData); 115 } 116 117 public function getDisplayData(PhabricatorUser $user) { 118 $recent_phids = $this->getRecentParticipantPHIDs(); 119 $handles = $this->getHandles(); 120 121 // luck has little to do with it really; most recent participant who isn't 122 // the user.... 123 $lucky_phid = null; 124 $lucky_index = null; 125 foreach ($recent_phids as $index => $phid) { 126 if ($phid == $user->getPHID()) { 127 continue; 128 } 129 $lucky_phid = $phid; 130 break; 131 } 132 reset($recent_phids); 133 134 if ($lucky_phid) { 135 $lucky_handle = $handles[$lucky_phid]; 136 // this will be just the user talking to themselves. weirdos. 137 } else { 138 $lucky_handle = reset($handles); 139 } 140 141 $title = $js_title = $this->getTitle(); 142 if (!$title) { 143 $title = $lucky_handle->getName(); 144 $js_title = pht('[No Title]'); 145 } 146 $img_src = $lucky_handle->getImageURI(); 147 148 $count = 0; 149 $final = false; 150 $subtitle = null; 151 foreach ($recent_phids as $phid) { 152 if ($phid == $user->getPHID()) { 153 continue; 154 } 155 $handle = $handles[$phid]; 156 if ($subtitle) { 157 if ($final) { 158 $subtitle .= '...'; 159 break; 160 } else { 161 $subtitle .= ', '; 162 } 163 } 164 $subtitle .= $handle->getName(); 165 $count++; 166 $final = $count == 3; 167 } 168 169 $participants = $this->getParticipants(); 170 $user_participation = $participants[$user->getPHID()]; 171 $unread_count = $this->getMessageCount() - 172 $user_participation->getSeenMessageCount(); 173 174 return array( 175 'title' => $title, 176 'js_title' => $js_title, 177 'subtitle' => $subtitle, 178 'unread_count' => $unread_count, 179 'epoch' => $this->getDateModified(), 180 'image' => $img_src, 181 ); 182 } 183 184 /* -( PhabricatorPolicyInterface Implementation )-------------------------- */ 185 public function getCapabilities() { 186 return array( 187 PhabricatorPolicyCapability::CAN_VIEW, 188 PhabricatorPolicyCapability::CAN_EDIT, 189 ); 190 } 191 192 public function getPolicy($capability) { 193 return PhabricatorPolicies::POLICY_NOONE; 194 } 195 196 public function hasAutomaticCapability($capability, PhabricatorUser $user) { 197 // this bad boy isn't even created yet so go nuts $user 198 if (!$this->getID()) { 199 return true; 200 } 201 $participants = $this->getParticipants(); 202 return isset($participants[$user->getPHID()]); 203 } 204 205 public function describeAutomaticCapability($capability) { 206 return pht('Participants in a thread can always view and edit it.'); 207 } 208 209 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |