]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Realtime/RealtimePlugin.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / plugins / Realtime / RealtimePlugin.php
index a7750e005ed0d64e89f6e3c77aa228059ce29ff2..eca3a8b029be1f90ebee22158f761f68c9117460 100644 (file)
@@ -73,6 +73,10 @@ class RealtimePlugin extends Plugin
 
         switch ($cls)
         {
+        case 'KeepalivechannelAction':
+        case 'ClosechannelAction':
+            include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
+            return false;
         case 'Realtime_channel':
             include_once $dir.'/'.$cls.'.php';
             return false;
@@ -81,9 +85,32 @@ class RealtimePlugin extends Plugin
         }
     }
 
+    /**
+     * Hook for RouterInitialized event.
+     *
+     * @param Net_URL_Mapper $m path-to-action mapper
+     * @return boolean hook return
+     */
+    function onRouterInitialized($m)
+    {
+        $m->connect('main/channel/:channelkey/keepalive',
+                    array('action' => 'keepalivechannel'),
+                    array('channelkey' => '[a-z0-9]{32}'));
+        $m->connect('main/channel/:channelkey/close',
+                    array('action' => 'closechannel'),
+                    array('channelkey' => '[a-z0-9]{32}'));
+        return true;
+    }
+
     function onEndShowScripts($action)
     {
-        $timeline = $this->_getTimeline($action);
+        $channel = $this->_getChannel($action);
+
+        if (empty($channel)) {
+            return true;
+        }
+
+        $timeline = $this->_pathToChannel(array($channel->channel_key));
 
         // If there's not a timeline on this page,
         // just return true
@@ -118,12 +145,14 @@ class RealtimePlugin extends Plugin
         }
         else {
             $pluginPath = common_path('plugins/Realtime/');
-            $realtimeUI = ' RealtimeUpdate.initActions("'.$url.'", "'.$timeline.'", "'. $pluginPath .'");';
+            $keepalive = common_local_url('keepalivechannel', array('channelkey' => $channel->channel_key));
+            $close = common_local_url('closechannel', array('channelkey' => $channel->channel_key));
+            $realtimeUI = ' RealtimeUpdate.initActions("'.$url.'", "'.$timeline.'", "'. $pluginPath .'", "'.$keepalive.'", "'.$close.'"); ';
         }
 
         $script = ' $(document).ready(function() { '.
           $realtimeUI.
-          $this->_updateInitialize($timeline, $user_id).
+            $this->_updateInitialize($timeline, $user_id).
           '}); ';
         $action->inlineScript($script);
 
@@ -209,6 +238,9 @@ class RealtimePlugin extends Plugin
             $json = $this->noticeAsJson($notice);
 
             $this->_connect();
+            
+            // XXX: We should probably fan-out here and do a
+            // new queue item for each path
 
             foreach ($paths as $path) {
                
@@ -217,6 +249,10 @@ class RealtimePlugin extends Plugin
                $channels = Realtime_channel::getAllChannels($action, $arg1, $arg2);
                
                foreach ($channels as $channel) {
+                       
+                       // XXX: We should probably fan-out here and do a
+                       // new queue item for each user/path combo
+            
                        if (is_null($channel->user_id)) {
                                $profile = null;
                        } else {
@@ -405,7 +441,18 @@ class RealtimePlugin extends Plugin
         return '';
     }
 
+
     function _getTimeline($action)
+    {
+        $channel = $this->_getChannel($action);
+        if (empty($channel)) {
+            return null;
+        }
+
+        return $this->_pathToChannel(array($channel->channel_key));
+    }
+
+    function _getChannel($action)
     {
         $timeline = null;
                $arg1     = null;
@@ -454,11 +501,13 @@ class RealtimePlugin extends Plugin
                                                                                                $action_name,
                                                                                                $arg1,
                                                                                                $arg2);
-               
-               if (!empty($channel)) {
-                       $timeline = $this->_pathToChannel(array($channel->channel_key));
-               }
-                               
-        return $timeline;
+
+        return $channel;
+    }
+    
+    function onStartReadWriteTables(&$alwaysRW, &$rwdb)
+    {
+       $alwaysRW[] = 'realtime_channel';
+       return true;
     }
 }