mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-12 00:26:13 +01:00
33e7038b96
Summary: Ref T7708. Rather than invoking the general client -> server dropdown refresh path, return the data with the various conpherence requests and update the dropdowns that way. Saves 2 client -> server requests per conpherence action. Test Plan: loaded up /conpherence/ and noted message count deduct correctly. clicked specific message and noted message count deduct successfully. did same two tests via durable column and again saw message counts deduct successfully. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T7708 Differential Revision: https://secure.phabricator.com/D12761
109 lines
3.5 KiB
PHP
109 lines
3.5 KiB
PHP
<?php
|
|
|
|
final class ConpherenceColumnViewController extends
|
|
ConpherenceController {
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
$user = $request->getUser();
|
|
|
|
$latest_conpherences = array();
|
|
$latest_participant = id(new ConpherenceParticipantQuery())
|
|
->withParticipantPHIDs(array($user->getPHID()))
|
|
->setLimit(6)
|
|
->execute();
|
|
if ($latest_participant) {
|
|
$conpherence_phids = mpull($latest_participant, 'getConpherencePHID');
|
|
$latest_conpherences = id(new ConpherenceThreadQuery())
|
|
->setViewer($user)
|
|
->withPHIDs($conpherence_phids)
|
|
->needCropPics(true)
|
|
->needParticipantCache(true)
|
|
->execute();
|
|
$latest_conpherences = mpull($latest_conpherences, null, 'getPHID');
|
|
$latest_conpherences = array_select_keys(
|
|
$latest_conpherences,
|
|
$conpherence_phids);
|
|
}
|
|
|
|
$conpherence = null;
|
|
$should_404 = false;
|
|
if ($request->getInt('id')) {
|
|
$conpherence = id(new ConpherenceThreadQuery())
|
|
->setViewer($user)
|
|
->withIDs(array($request->getInt('id')))
|
|
->needCropPics(true)
|
|
->needTransactions(true)
|
|
->setTransactionLimit(ConpherenceThreadQuery::TRANSACTION_LIMIT)
|
|
->executeOne();
|
|
$should_404 = true;
|
|
} else if ($latest_participant) {
|
|
$participant = head($latest_participant);
|
|
$conpherence = id(new ConpherenceThreadQuery())
|
|
->setViewer($user)
|
|
->withPHIDs(array($participant->getConpherencePHID()))
|
|
->needCropPics(true)
|
|
->needTransactions(true)
|
|
->setTransactionLimit(ConpherenceThreadQuery::TRANSACTION_LIMIT)
|
|
->executeOne();
|
|
$should_404 = true;
|
|
}
|
|
|
|
$durable_column = id(new ConpherenceDurableColumnView())
|
|
->setUser($user)
|
|
->setVisible(true);
|
|
if (!$conpherence) {
|
|
if ($should_404) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$conpherence_id = null;
|
|
$conpherence_phid = null;
|
|
$latest_transaction_id = null;
|
|
$can_edit = false;
|
|
|
|
} else {
|
|
$this->setConpherence($conpherence);
|
|
|
|
$participant = $conpherence->getParticipant($user->getPHID());
|
|
$transactions = $conpherence->getTransactions();
|
|
$latest_transaction = head($transactions);
|
|
$write_guard = AphrontWriteGuard::beginScopedUnguardedWrites();
|
|
$participant->markUpToDate($conpherence, $latest_transaction);
|
|
unset($write_guard);
|
|
|
|
$draft = PhabricatorDraft::newFromUserAndKey(
|
|
$user,
|
|
$conpherence->getPHID());
|
|
|
|
$durable_column
|
|
->setDraft($draft)
|
|
->setSelectedConpherence($conpherence)
|
|
->setConpherences($latest_conpherences);
|
|
$conpherence_id = $conpherence->getID();
|
|
$conpherence_phid = $conpherence->getPHID();
|
|
$latest_transaction_id = $latest_transaction->getID();
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
$user,
|
|
$conpherence,
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
}
|
|
|
|
$dropdown_query = id(new AphlictDropdownDataQuery())
|
|
->setViewer($user);
|
|
$dropdown_query->execute();
|
|
$response = array(
|
|
'content' => hsprintf('%s', $durable_column),
|
|
'threadID' => $conpherence_id,
|
|
'threadPHID' => $conpherence_phid,
|
|
'latestTransactionID' => $latest_transaction_id,
|
|
'canEdit' => $can_edit,
|
|
'aphlictDropdownData' => array(
|
|
$dropdown_query->getNotificationData(),
|
|
$dropdown_query->getConpherenceData(),
|
|
),
|
|
);
|
|
|
|
return id(new AphrontAjaxResponse())->setContent($response);
|
|
}
|
|
|
|
}
|