Changeset View
Changeset View
Standalone View
Standalone View
src/applications/conpherence/query/ConpherenceThreadQuery.php
<?php | <?php | ||||
final class ConpherenceThreadQuery | final class ConpherenceThreadQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
const TRANSACTION_LIMIT = 100; | const TRANSACTION_LIMIT = 100; | ||||
private $phids; | private $phids; | ||||
private $ids; | private $ids; | ||||
private $participantPHIDs; | private $participantPHIDs; | ||||
private $needParticipants; | private $needParticipants; | ||||
private $needWidgetData; | |||||
private $needCropPics; | private $needCropPics; | ||||
private $needOrigPics; | private $needOrigPics; | ||||
private $needTransactions; | private $needTransactions; | ||||
private $needParticipantCache; | private $needParticipantCache; | ||||
private $needFilePHIDs; | private $needFilePHIDs; | ||||
private $afterTransactionID; | private $afterTransactionID; | ||||
private $beforeTransactionID; | private $beforeTransactionID; | ||||
private $transactionLimit; | private $transactionLimit; | ||||
Show All 9 Lines | public function needParticipantCache($participant_cache) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needParticipants($need) { | public function needParticipants($need) { | ||||
$this->needParticipants = $need; | $this->needParticipants = $need; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needWidgetData($need_widget_data) { | |||||
$this->needWidgetData = $need_widget_data; | |||||
return $this; | |||||
} | |||||
public function needCropPics($need) { | public function needCropPics($need) { | ||||
$this->needCropPics = $need; | $this->needCropPics = $need; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needOrigPics($need_widget_data) { | public function needOrigPics($need_widget_data) { | ||||
$this->needOrigPics = $need_widget_data; | $this->needOrigPics = $need_widget_data; | ||||
return $this; | return $this; | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | protected function loadPage() { | ||||
$conpherences = $table->loadAllFromArray($data); | $conpherences = $table->loadAllFromArray($data); | ||||
if ($conpherences) { | if ($conpherences) { | ||||
$conpherences = mpull($conpherences, null, 'getPHID'); | $conpherences = mpull($conpherences, null, 'getPHID'); | ||||
$this->loadParticipantsAndInitHandles($conpherences); | $this->loadParticipantsAndInitHandles($conpherences); | ||||
if ($this->needParticipantCache) { | if ($this->needParticipantCache) { | ||||
$this->loadCoreHandles($conpherences, 'getRecentParticipantPHIDs'); | $this->loadCoreHandles($conpherences, 'getRecentParticipantPHIDs'); | ||||
} | } | ||||
if ($this->needWidgetData || $this->needParticipants) { | if ($this->needParticipants) { | ||||
$this->loadCoreHandles($conpherences, 'getParticipantPHIDs'); | $this->loadCoreHandles($conpherences, 'getParticipantPHIDs'); | ||||
} | } | ||||
if ($this->needTransactions) { | if ($this->needTransactions) { | ||||
$this->loadTransactionsAndHandles($conpherences); | $this->loadTransactionsAndHandles($conpherences); | ||||
} | } | ||||
if ($this->needFilePHIDs || $this->needWidgetData) { | if ($this->needFilePHIDs) { | ||||
$this->loadFilePHIDs($conpherences); | $this->loadFilePHIDs($conpherences); | ||||
} | } | ||||
if ($this->needWidgetData) { | |||||
$this->loadWidgetData($conpherences); | |||||
} | |||||
if ($this->needOrigPics || $this->needCropPics) { | if ($this->needOrigPics || $this->needCropPics) { | ||||
$this->initImages($conpherences); | $this->initImages($conpherences); | ||||
} | } | ||||
if ($this->needOrigPics) { | if ($this->needOrigPics) { | ||||
$this->loadOrigPics($conpherences); | $this->loadOrigPics($conpherences); | ||||
} | } | ||||
if ($this->needCropPics) { | if ($this->needCropPics) { | ||||
$this->loadCropPics($conpherences); | $this->loadCropPics($conpherences); | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | $file_edges = id(new PhabricatorEdgeQuery()) | ||||
->execute(); | ->execute(); | ||||
foreach ($file_edges as $conpherence_phid => $data) { | foreach ($file_edges as $conpherence_phid => $data) { | ||||
$conpherence = $conpherences[$conpherence_phid]; | $conpherence = $conpherences[$conpherence_phid]; | ||||
$conpherence->attachFilePHIDs(array_keys($data[$edge_type])); | $conpherence->attachFilePHIDs(array_keys($data[$edge_type])); | ||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
private function loadWidgetData(array $conpherences) { | |||||
$participant_phids = array(); | |||||
$file_phids = array(); | |||||
foreach ($conpherences as $conpherence) { | |||||
$participant_phids[] = array_keys($conpherence->getParticipants()); | |||||
$file_phids[] = $conpherence->getFilePHIDs(); | |||||
} | |||||
$participant_phids = array_mergev($participant_phids); | |||||
$file_phids = array_mergev($file_phids); | |||||
$epochs = CalendarTimeUtil::getCalendarEventEpochs( | |||||
$this->getViewer()); | |||||
$start_epoch = $epochs['start_epoch']; | |||||
$end_epoch = $epochs['end_epoch']; | |||||
$events = array(); | |||||
if ($participant_phids) { | |||||
// TODO: All of this Calendar code is probably extra-broken, but none | |||||
// of it is currently reachable in the UI. | |||||
$events = id(new PhabricatorCalendarEventQuery()) | |||||
->setViewer($this->getViewer()) | |||||
->withInvitedPHIDs($participant_phids) | |||||
->withIsCancelled(false) | |||||
->withDateRange($start_epoch, $end_epoch) | |||||
->execute(); | |||||
$events = mpull($events, null, 'getPHID'); | |||||
} | |||||
$invitees = array(); | |||||
foreach ($events as $event_phid => $event) { | |||||
foreach ($event->getInvitees() as $invitee) { | |||||
$invitees[$invitee->getInviteePHID()][$event_phid] = true; | |||||
} | |||||
} | |||||
// attached files | |||||
$files = array(); | |||||
$file_author_phids = array(); | |||||
$authors = array(); | |||||
if ($file_phids) { | |||||
$files = id(new PhabricatorFileQuery()) | |||||
->setViewer($this->getViewer()) | |||||
->withPHIDs($file_phids) | |||||
->execute(); | |||||
$files = mpull($files, null, 'getPHID'); | |||||
$file_author_phids = mpull($files, 'getAuthorPHID', 'getPHID'); | |||||
$authors = id(new PhabricatorHandleQuery()) | |||||
->setViewer($this->getViewer()) | |||||
->withPHIDs($file_author_phids) | |||||
->execute(); | |||||
$authors = mpull($authors, null, 'getPHID'); | |||||
} | |||||
foreach ($conpherences as $phid => $conpherence) { | |||||
$participant_phids = array_keys($conpherence->getParticipants()); | |||||
$widget_data = array(); | |||||
$event_phids = array(); | |||||
$participant_invites = array_select_keys($invitees, $participant_phids); | |||||
foreach ($participant_invites as $invite_set) { | |||||
$event_phids += $invite_set; | |||||
} | |||||
$thread_events = array_select_keys($events, array_keys($event_phids)); | |||||
$thread_events = msort($thread_events, 'getDateFrom'); | |||||
$widget_data['events'] = $thread_events; | |||||
$conpherence_files = array(); | |||||
$files_authors = array(); | |||||
foreach ($conpherence->getFilePHIDs() as $curr_phid) { | |||||
$curr_file = idx($files, $curr_phid); | |||||
if (!$curr_file) { | |||||
// this file was deleted or user doesn't have permission to see it | |||||
// this is generally weird | |||||
continue; | |||||
} | |||||
$conpherence_files[$curr_phid] = $curr_file; | |||||
// some files don't have authors so be careful | |||||
$current_author = null; | |||||
$current_author_phid = idx($file_author_phids, $curr_phid); | |||||
if ($current_author_phid) { | |||||
$current_author = $authors[$current_author_phid]; | |||||
} | |||||
$files_authors[$curr_phid] = $current_author; | |||||
} | |||||
$widget_data += array( | |||||
'files' => $conpherence_files, | |||||
'files_authors' => $files_authors, | |||||
); | |||||
$conpherence->attachWidgetData($widget_data); | |||||
} | |||||
return $this; | |||||
} | |||||
private function loadOrigPics(array $conpherences) { | private function loadOrigPics(array $conpherences) { | ||||
return $this->loadPics( | return $this->loadPics( | ||||
$conpherences, | $conpherences, | ||||
ConpherenceImageData::SIZE_ORIG); | ConpherenceImageData::SIZE_ORIG); | ||||
} | } | ||||
private function loadCropPics(array $conpherences) { | private function loadCropPics(array $conpherences) { | ||||
return $this->loadPics( | return $this->loadPics( | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |