1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-11 17:32:41 +01:00
phorge-phorge/src/applications/chatlog/controller/channellog/PhabricatorChatLogChannelLogController.php
epriestley 7200040479 Add a basic chatlog
Summary:
This is pretty simple and unpolished, but it's getting pretty big and it seems
like a reasonable starting point.

  - Log chat in various "channels".
  - Conduit record and query methods.
  - IRCBot integration for IRC logging

Major TODO:

  - Web UI is really unpolished and has no search, paging, anchor-linking, etc.
Basically all presentation stuff, though.
  - I think the bot should have a map of channels to log with channel aliases?
  - The "channels" should probably be in a separate table.
  - The "authors" should probably be correlated to Phabricator accounts somehow,
where possible.

Test Plan: Used phabotlocal to log #phabricator.

Reviewers: kdeggelman, btrahan, Koolvin

Reviewed By: btrahan

CC: aran, epriestley

Maniphest Tasks: T837

Differential Revision: https://secure.phabricator.com/D1625
2012-02-17 10:21:38 -08:00

86 lines
2.4 KiB
PHP

<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorChatLogChannelLogController
extends PhabricatorChatLogController {
private $channel;
public function willProcessRequest(array $data) {
$this->channel = $data['channel'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$query = new PhabricatorChatLogQuery();
$query->withChannels(array($this->channel));
$query->setLimit(1000);
$logs = $query->execute();
require_celerity_resource('phabricator-chatlog-css');
$last_author = null;
$last_epoch = null;
$row_idx = 0;
$row_colors = array(
'normal',
'alternate',
);
$out = array();
$out[] = '<table class="phabricator-chat-log">';
foreach ($logs as $log) {
$this_author = $log->getAuthor();
$this_epoch = $log->getEpoch();
if (($this_author !== $last_author) ||
($this_epoch - (60 * 5) > $last_epoch)) {
++$row_idx;
$out[] = '<tr class="initial '.$row_colors[$row_idx % 2].'">';
$out[] = '<td class="timestamp">'.
phabricator_datetime($log->getEpoch(), $user).'</td>';
$author = $log->getAuthor();
$author = phutil_utf8_shorten($author, 18);
$out[] = '<td class="author">'.
phutil_escape_html($author).'</td>';
} else {
$out[] = '<tr class="'.$row_colors[$row_idx % 2].'">';
$out[] = '<td class="similar" colspan="2"></td>';
}
$out[] = '<td class="message">'.
phutil_escape_html($log->getMessage()).'</td>';
$out[] = '</tr>';
$last_author = $this_author;
$last_epoch = $this_epoch;
}
$out[] = '</table>';
return $this->buildStandardPageResponse(
implode("\n", $out),
array(
'title' => 'Channel Log',
));
}
}