mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
Add "serviceName" and "serviceType" to bot and chat logger
Summary: Make each adapter provide a "serviceType" (campfire, flowdock, IRC) and "serviceName" (irc network / chat server) so that we can disambiguate between, e.g., "#phabricator on EFNet" and "#phabricator on FreeNode". Make the chatlog handler ship them over Conduit. Also fix some "policy can not be null" bugs with chatlog recording. Test Plan: Verified data inserted correctly: mysql> select * from chatlog_channel; +----+------------------+-------------+--------------+------------+------------+-------------+--------------+ | id | serviceName | serviceType | channelName | viewPolicy | editPolicy | dateCreated | dateModified | +----+------------------+-------------+--------------+------------+------------+-------------+--------------+ | 1 | irc.freenode.net | IRC | #phabricator | users | users | 1361201689 | 1361201689 | +----+------------------+-------------+--------------+------------+------------+-------------+--------------+ 1 row in set (0.00 sec) mysql> select * from chatlog_event where channelID = 1; +----+--------------+------------+------------+------+---------------+--------------------------------+-----------+ | id | channel | epoch | author | type | message | loggedByPHID | channelID | +----+--------------+------------+------------+------+---------------+--------------------------------+-----------+ | 45 | #phabricator | 1361201689 | epriestley | mesg | blip blip | PHID-USER-5bt2phfepag4cdvjtzg5 | 1 | | 46 | #phabricator | 1361201700 | epriestley | mesg | boop boop bip | PHID-USER-5bt2phfepag4cdvjtzg5 | 1 | +----+--------------+------------+------------+------+---------------+--------------------------------+-----------+ 2 rows in set (0.00 sec) Reviewers: Afaque_Hussain, indiefan Reviewed By: Afaque_Hussain CC: aran Maniphest Tasks: T837 Differential Revision: https://secure.phabricator.com/D4996
This commit is contained in:
parent
57a9c3f07c
commit
4f2aa99248
9 changed files with 60 additions and 10 deletions
|
@ -44,19 +44,20 @@ final class ConduitAPI_chatlog_record_Method
|
|||
$service_name = idx($log, 'serviceName');
|
||||
$service_type = idx($log, 'serviceType');
|
||||
|
||||
$channel = id(new PhabricatorChatLogChannel())
|
||||
->loadOneWhere(
|
||||
'channelName = %s AND serviceName = %s
|
||||
AND serviceType = %s', $channel_name,
|
||||
$service_name, $service_type
|
||||
);
|
||||
$channel = id(new PhabricatorChatLogChannel())->loadOneWhere(
|
||||
'channelName = %s AND serviceName = %s AND serviceType = %s',
|
||||
$channel_name,
|
||||
$service_name,
|
||||
$service_type);
|
||||
|
||||
if (!$channel) {
|
||||
$channel = id(new PhabricatorChatLogChannel())
|
||||
->setChannelName($channel_name)
|
||||
->setserviceName($service_name)
|
||||
->setServiceType($service_type)
|
||||
->save();
|
||||
->setChannelName($channel_name)
|
||||
->setserviceName($service_name)
|
||||
->setServiceType($service_type)
|
||||
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
|
||||
->setEditPolicy(PhabricatorPolicies::POLICY_USER)
|
||||
->save();
|
||||
}
|
||||
|
||||
$obj = clone $template;
|
||||
|
|
|
@ -120,6 +120,10 @@ final class PhabricatorBot extends PhabricatorDaemon {
|
|||
}
|
||||
}
|
||||
|
||||
public function getAdapter() {
|
||||
return $this->protocolAdapter;
|
||||
}
|
||||
|
||||
public function getConduit() {
|
||||
if (empty($this->conduit)) {
|
||||
throw new Exception(
|
||||
|
|
|
@ -38,4 +38,18 @@ abstract class PhabricatorBaseProtocolAdapter {
|
|||
* @param PhabricatorBotMessage $message The message to write
|
||||
*/
|
||||
abstract public function writeMessage(PhabricatorBotMessage $message);
|
||||
|
||||
/**
|
||||
* String identifying the service type the adapter provides access to, like
|
||||
* "irc", "campfire", "flowdock", "hipchat", etc.
|
||||
*/
|
||||
abstract public function getServiceType();
|
||||
|
||||
/**
|
||||
* String identifying the service name the adapter is connecting to. This is
|
||||
* used to distinguish between instances of a service. For example, for IRC,
|
||||
* this should return the IRC network the client is connecting to.
|
||||
*/
|
||||
abstract public function getServiceName();
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,11 @@ abstract class PhabricatorBotBaseStreamingProtocolAdapter
|
|||
private $active;
|
||||
private $inRooms = array();
|
||||
|
||||
public function getServiceName() {
|
||||
$uri = new PhutilURI($this->server);
|
||||
return $uri->getDomain();
|
||||
}
|
||||
|
||||
public function connect() {
|
||||
$this->server = $this->getConfig('server');
|
||||
$this->authtoken = $this->getConfig('authtoken');
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
final class PhabricatorBotFlowdockProtocolAdapter
|
||||
extends PhabricatorBotBaseStreamingProtocolAdapter {
|
||||
|
||||
public function getServiceType() {
|
||||
return 'Flowdock';
|
||||
}
|
||||
|
||||
protected function buildStreamingUrl($channel) {
|
||||
$organization = $this->getConfig('organization');
|
||||
$ssl = $this->getConfig('ssl');
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
final class PhabricatorCampfireProtocolAdapter
|
||||
extends PhabricatorBotBaseStreamingProtocolAdapter {
|
||||
|
||||
public function getServiceType() {
|
||||
return 'Campfire';
|
||||
}
|
||||
|
||||
protected function buildStreamingUrl($channel) {
|
||||
$ssl = $this->getConfig('ssl');
|
||||
|
||||
|
|
|
@ -8,6 +8,14 @@ final class PhabricatorIRCProtocolAdapter
|
|||
private $writeBuffer;
|
||||
private $readBuffer;
|
||||
|
||||
public function getServiceType() {
|
||||
return 'IRC';
|
||||
}
|
||||
|
||||
public function getServiceName() {
|
||||
return $this->getConfig('network', $this->getConfig('server'));
|
||||
}
|
||||
|
||||
// Hash map of command translations
|
||||
public static $commandTranslations = array(
|
||||
'PRIVMSG' => 'MESSAGE');
|
||||
|
|
|
@ -33,6 +33,14 @@ abstract class PhabricatorBotHandler {
|
|||
return (string)$base_uri;
|
||||
}
|
||||
|
||||
final protected function getServiceName() {
|
||||
return $this->bot->getAdapter()->getServiceName();
|
||||
}
|
||||
|
||||
final protected function getServiceType() {
|
||||
return $this->bot->getAdapter()->getServiceType();
|
||||
}
|
||||
|
||||
abstract public function receiveMessage(PhabricatorBotMessage $message);
|
||||
|
||||
public function runBackgroundTasks() {
|
||||
|
|
|
@ -28,6 +28,8 @@ final class PhabricatorBotLogHandler extends PhabricatorBotHandler {
|
|||
'epoch' => time(),
|
||||
'author' => $message->getSender()->getName(),
|
||||
'message' => $message->getBody(),
|
||||
'serviceName' => $this->getServiceName(),
|
||||
'serviceType' => $this->getServiceType(),
|
||||
),
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue