@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+60 -10
+11 -10
src/applications/chatlog/conduit/ConduitAPI_chatlog_record_Method.php
··· 44 44 $service_name = idx($log, 'serviceName'); 45 45 $service_type = idx($log, 'serviceType'); 46 46 47 - $channel = id(new PhabricatorChatLogChannel()) 48 - ->loadOneWhere( 49 - 'channelName = %s AND serviceName = %s 50 - AND serviceType = %s', $channel_name, 51 - $service_name, $service_type 52 - ); 47 + $channel = id(new PhabricatorChatLogChannel())->loadOneWhere( 48 + 'channelName = %s AND serviceName = %s AND serviceType = %s', 49 + $channel_name, 50 + $service_name, 51 + $service_type); 53 52 54 53 if (!$channel) { 55 54 $channel = id(new PhabricatorChatLogChannel()) 56 - ->setChannelName($channel_name) 57 - ->setserviceName($service_name) 58 - ->setServiceType($service_type) 59 - ->save(); 55 + ->setChannelName($channel_name) 56 + ->setserviceName($service_name) 57 + ->setServiceType($service_type) 58 + ->setViewPolicy(PhabricatorPolicies::POLICY_USER) 59 + ->setEditPolicy(PhabricatorPolicies::POLICY_USER) 60 + ->save(); 60 61 } 61 62 62 63 $obj = clone $template;
+4
src/infrastructure/daemon/bot/PhabricatorBot.php
··· 120 120 } 121 121 } 122 122 123 + public function getAdapter() { 124 + return $this->protocolAdapter; 125 + } 126 + 123 127 public function getConduit() { 124 128 if (empty($this->conduit)) { 125 129 throw new Exception(
+14
src/infrastructure/daemon/bot/adapter/PhabricatorBaseProtocolAdapter.php
··· 38 38 * @param PhabricatorBotMessage $message The message to write 39 39 */ 40 40 abstract public function writeMessage(PhabricatorBotMessage $message); 41 + 42 + /** 43 + * String identifying the service type the adapter provides access to, like 44 + * "irc", "campfire", "flowdock", "hipchat", etc. 45 + */ 46 + abstract public function getServiceType(); 47 + 48 + /** 49 + * String identifying the service name the adapter is connecting to. This is 50 + * used to distinguish between instances of a service. For example, for IRC, 51 + * this should return the IRC network the client is connecting to. 52 + */ 53 + abstract public function getServiceName(); 54 + 41 55 }
+5
src/infrastructure/daemon/bot/adapter/PhabricatorBotBaseStreamingProtocolAdapter.php
··· 11 11 private $active; 12 12 private $inRooms = array(); 13 13 14 + public function getServiceName() { 15 + $uri = new PhutilURI($this->server); 16 + return $uri->getDomain(); 17 + } 18 + 14 19 public function connect() { 15 20 $this->server = $this->getConfig('server'); 16 21 $this->authtoken = $this->getConfig('authtoken');
+4
src/infrastructure/daemon/bot/adapter/PhabricatorBotFlowdockProtocolAdapter.php
··· 3 3 final class PhabricatorBotFlowdockProtocolAdapter 4 4 extends PhabricatorBotBaseStreamingProtocolAdapter { 5 5 6 + public function getServiceType() { 7 + return 'Flowdock'; 8 + } 9 + 6 10 protected function buildStreamingUrl($channel) { 7 11 $organization = $this->getConfig('organization'); 8 12 $ssl = $this->getConfig('ssl');
+4
src/infrastructure/daemon/bot/adapter/PhabricatorCampfireProtocolAdapter.php
··· 3 3 final class PhabricatorCampfireProtocolAdapter 4 4 extends PhabricatorBotBaseStreamingProtocolAdapter { 5 5 6 + public function getServiceType() { 7 + return 'Campfire'; 8 + } 9 + 6 10 protected function buildStreamingUrl($channel) { 7 11 $ssl = $this->getConfig('ssl'); 8 12
+8
src/infrastructure/daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php
··· 8 8 private $writeBuffer; 9 9 private $readBuffer; 10 10 11 + public function getServiceType() { 12 + return 'IRC'; 13 + } 14 + 15 + public function getServiceName() { 16 + return $this->getConfig('network', $this->getConfig('server')); 17 + } 18 + 11 19 // Hash map of command translations 12 20 public static $commandTranslations = array( 13 21 'PRIVMSG' => 'MESSAGE');
+8
src/infrastructure/daemon/bot/handler/PhabricatorBotHandler.php
··· 33 33 return (string)$base_uri; 34 34 } 35 35 36 + final protected function getServiceName() { 37 + return $this->bot->getAdapter()->getServiceName(); 38 + } 39 + 40 + final protected function getServiceType() { 41 + return $this->bot->getAdapter()->getServiceType(); 42 + } 43 + 36 44 abstract public function receiveMessage(PhabricatorBotMessage $message); 37 45 38 46 public function runBackgroundTasks() {
+2
src/infrastructure/daemon/bot/handler/PhabricatorBotLogHandler.php
··· 28 28 'epoch' => time(), 29 29 'author' => $message->getSender()->getName(), 30 30 'message' => $message->getBody(), 31 + 'serviceName' => $this->getServiceName(), 32 + 'serviceType' => $this->getServiceType(), 31 33 ), 32 34 ); 33 35