diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 2a932d6296..019e750bdc 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -754,6 +754,7 @@ phutil_register_library_map(array( 'PhabricatorChatLogChannel' => 'applications/chatlog/storage/PhabricatorChatLogChannel.php', 'PhabricatorChatLogChannelListController' => 'applications/chatlog/controller/PhabricatorChatLogChannelListController.php', 'PhabricatorChatLogChannelLogController' => 'applications/chatlog/controller/PhabricatorChatLogChannelLogController.php', + 'PhabricatorChatLogChannelQuery' => 'applications/chatlog/PhabricatorChatLogChannelQuery.php', 'PhabricatorChatLogConstants' => 'applications/chatlog/constants/PhabricatorChatLogConstants.php', 'PhabricatorChatLogController' => 'applications/chatlog/controller/PhabricatorChatLogController.php', 'PhabricatorChatLogDAO' => 'applications/chatlog/storage/PhabricatorChatLogDAO.php', @@ -2253,6 +2254,7 @@ phutil_register_library_map(array( ), 'PhabricatorChatLogChannelListController' => 'PhabricatorChatLogController', 'PhabricatorChatLogChannelLogController' => 'PhabricatorChatLogController', + 'PhabricatorChatLogChannelQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorChatLogController' => 'PhabricatorController', 'PhabricatorChatLogDAO' => 'PhabricatorLiskDAO', 'PhabricatorChatLogEvent' => diff --git a/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php index 6b38ee1600..df85f35030 100644 --- a/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php @@ -95,13 +95,6 @@ class AphrontDefaultApplicationConfiguration 'keyboardshortcut/' => 'PhabricatorHelpKeyboardShortcutController', ), - '/chatlog/' => array( - '' => - 'PhabricatorChatLogChannelListController', - 'channel/(?P[^/]+)/' => - 'PhabricatorChatLogChannelLogController', - ), - '/notification/' => array( '(?:(?Pall|unread)/)?' => 'PhabricatorNotificationListController', diff --git a/src/applications/chatlog/PhabricatorChatLogChannelQuery.php b/src/applications/chatlog/PhabricatorChatLogChannelQuery.php new file mode 100644 index 0000000000..e1f38f3562 --- /dev/null +++ b/src/applications/chatlog/PhabricatorChatLogChannelQuery.php @@ -0,0 +1,44 @@ +channels = $channels; + return $this; + } + + public function loadPage() { + $table = new PhabricatorChatLogChannel(); + $conn_r = $table->establishConnection('r'); + + $data = queryfx_all( + $conn_r, + 'SELECT * FROM %T c %Q %Q %Q', + $table->getTableName(), + $this->buildWhereClause($conn_r), + $this->buildOrderClause($conn_r), + $this->buildLimitClause($conn_r)); + + $logs = $table->loadAllFromArray($data); + + return $logs; + } + + private function buildWhereClause($conn_r) { + $where = array(); + + $where[] = $this->buildPagingClause($conn_r); + + if ($this->channels) { + $where[] = qsprintf( + $conn_r, + 'channelName IN (%Ls)', + $this->channels); + } + + return $this->formatWhereClause($where); + } +} diff --git a/src/applications/chatlog/PhabricatorChatLogQuery.php b/src/applications/chatlog/PhabricatorChatLogQuery.php index 93674edec8..9a488f87a4 100644 --- a/src/applications/chatlog/PhabricatorChatLogQuery.php +++ b/src/applications/chatlog/PhabricatorChatLogQuery.php @@ -3,11 +3,11 @@ final class PhabricatorChatLogQuery extends PhabricatorCursorPagedPolicyAwareQuery { - private $channels; + private $channelIDs; private $maximumEpoch; - public function withChannels(array $channels) { - $this->channels = $channels; + public function withChannelIDs(array $channel_ids) { + $this->channelIDs = $channel_ids; return $this; } @@ -45,11 +45,11 @@ final class PhabricatorChatLogQuery $this->maximumEpoch); } - if ($this->channels) { + if ($this->channelIDs) { $where[] = qsprintf( $conn_r, - 'channel IN (%Ls)', - $this->channels); + 'channelID IN (%Ld)', + $this->channelIDs); } return $this->formatWhereClause($where); diff --git a/src/applications/chatlog/applications/PhabricatorApplicationChatLog.php b/src/applications/chatlog/applications/PhabricatorApplicationChatLog.php index ff4ba94e8a..5c5a813288 100644 --- a/src/applications/chatlog/applications/PhabricatorApplicationChatLog.php +++ b/src/applications/chatlog/applications/PhabricatorApplicationChatLog.php @@ -30,7 +30,9 @@ final class PhabricatorApplicationChatLog extends PhabricatorApplication { return array( '/chatlog/' => array( '' => 'PhabricatorChatLogChannelListController', - ), + 'channel/(?P[^/]+)/' => + 'PhabricatorChatLogChannelLogController', + ), ); } diff --git a/src/applications/chatlog/conduit/ConduitAPI_chatlog_query_Method.php b/src/applications/chatlog/conduit/ConduitAPI_chatlog_query_Method.php index 41faf9fd93..b3c01b0d21 100644 --- a/src/applications/chatlog/conduit/ConduitAPI_chatlog_query_Method.php +++ b/src/applications/chatlog/conduit/ConduitAPI_chatlog_query_Method.php @@ -33,9 +33,9 @@ final class ConduitAPI_chatlog_query_Method $query = new PhabricatorChatLogQuery(); - $channels = $request->getValue('channels'); - if ($channels) { - $query->withChannels($channels); + $channel_ids = $request->getValue('channelIDs'); + if ($channel_ids) { + $query->withChannelIDs($channel_ids); } $limit = $request->getValue('limit'); @@ -49,12 +49,12 @@ final class ConduitAPI_chatlog_query_Method $results = array(); foreach ($logs as $log) { $results[] = array( - 'channel' => $log->getChannel(), - 'epoch' => $log->getEpoch(), - 'author' => $log->getAuthor(), - 'type' => $log->getType(), - 'message' => $log->getMessage(), - 'loggedByPHID' => $log->getLoggedByPHID(), + 'channelID' => $log->getChannelID(), + 'epoch' => $log->getEpoch(), + 'author' => $log->getAuthor(), + 'type' => $log->getType(), + 'message' => $log->getMessage(), + 'loggedByPHID' => $log->getLoggedByPHID(), ); } diff --git a/src/applications/chatlog/conduit/ConduitAPI_chatlog_record_Method.php b/src/applications/chatlog/conduit/ConduitAPI_chatlog_record_Method.php index ca9f22c746..a72b635263 100644 --- a/src/applications/chatlog/conduit/ConduitAPI_chatlog_record_Method.php +++ b/src/applications/chatlog/conduit/ConduitAPI_chatlog_record_Method.php @@ -61,7 +61,6 @@ final class ConduitAPI_chatlog_record_Method } $obj = clone $template; - $obj->setChannel($channel_name); $obj->setChannelID($channel->getID()); $obj->setType(idx($log, 'type')); $obj->setAuthor(idx($log, 'author')); diff --git a/src/applications/chatlog/controller/PhabricatorChatLogChannelListController.php b/src/applications/chatlog/controller/PhabricatorChatLogChannelListController.php index 1745e1f274..5416b1baee 100644 --- a/src/applications/chatlog/controller/PhabricatorChatLogChannelListController.php +++ b/src/applications/chatlog/controller/PhabricatorChatLogChannelListController.php @@ -4,24 +4,23 @@ final class PhabricatorChatLogChannelListController extends PhabricatorChatLogController { public function processRequest() { + $request = $this->getRequest(); + $user = $request->getUser(); - $table = new PhabricatorChatLogEvent(); - - $channels = queryfx_all( - $table->establishConnection('r'), - 'SELECT DISTINCT channel FROM %T', - $table->getTableName()); + $channels = id(new PhabricatorChatLogChannelQuery()) + ->setViewer($user) + ->execute(); $rows = array(); foreach ($channels as $channel) { - $name = $channel['channel']; $rows[] = array( phutil_tag( 'a', array( - 'href' => '/chatlog/channel/'.phutil_escape_uri($name).'/', + 'href' => + '/chatlog/channel/'.$channel->getID().'/', ), - $name)); + $channel->getChannelName())); } $table = new AphrontTableView($rows); diff --git a/src/applications/chatlog/controller/PhabricatorChatLogChannelLogController.php b/src/applications/chatlog/controller/PhabricatorChatLogChannelLogController.php index 26dcadf1f8..c60c499cd9 100644 --- a/src/applications/chatlog/controller/PhabricatorChatLogChannelLogController.php +++ b/src/applications/chatlog/controller/PhabricatorChatLogChannelLogController.php @@ -3,10 +3,10 @@ final class PhabricatorChatLogChannelLogController extends PhabricatorChatLogController { - private $channel; + private $channelID; public function willProcessRequest(array $data) { - $this->channel = $data['channel']; + $this->channelID = $data['channelID']; } public function processRequest() { @@ -22,7 +22,7 @@ final class PhabricatorChatLogChannelLogController $query = id(new PhabricatorChatLogQuery()) ->setViewer($user) - ->withChannels(array($this->channel)); + ->withChannelIDs(array($this->channelID)); list($after, $before, $map) = $this->getPagingParameters($request, $query); @@ -140,9 +140,9 @@ final class PhabricatorChatLogChannelLogController array( hsprintf( '
%s
%s%s
', - $form, + $form->render(), phutil_tag('table', array('class' => 'phabricator-chat-log'), $out), - $pager), + $pager->render()), ), array( 'title' => 'Channel Log',