]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Msn/msnmanager.php
More info for a proper, fancy-url lighttpd setup
[quix0rs-gnu-social.git] / plugins / Msn / msnmanager.php
index 9014501e7ee72438b935e36524e0aa86100c76c1..82d40d69c92e80eff7d5e42d51b76b159d75ba82 100644 (file)
@@ -29,11 +29,10 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
  * In a multi-site queuedaemon.php run, one connection will be instantiated\r
  * for each site being handled by the current process that has MSN enabled.\r
  */\r
-\r
 class MsnManager extends ImManager {\r
     public $conn = null;\r
-    private $lastping = null;\r
-    private $pingInterval;\r
+    protected $lastPing = null;\r
+    protected $pingInterval;\r
 \r
     /**\r
      * Initialise connection to server.\r
@@ -42,6 +41,7 @@ class MsnManager extends ImManager {
      */\r
     public function start($master) {\r
         if (parent::start($master)) {\r
+            $this->requeue_waiting_messages();\r
             $this->connect();\r
             return true;\r
         } else {\r
@@ -71,7 +71,7 @@ class MsnManager extends ImManager {
      * @return void\r
      */\r
     public function idle($timeout = 0) {\r
-        if (empty($this->lastping) || time() - $this->lastping > $this->pingInterval) {\r
+        if (empty($this->lastPing) || time() - $this->lastPing > $this->pingInterval) {\r
             $this->send_ping();\r
         }\r
     }\r
@@ -80,7 +80,7 @@ class MsnManager extends ImManager {
      * Message pump is triggered on socket input, so we only need an idle()\r
      * call often enough to trigger our outgoing pings.\r
      */\r
-    function timeout() {\r
+    public function timeout() {\r
         return $this->pingInterval;\r
     }\r
 \r
@@ -108,8 +108,9 @@ class MsnManager extends ImManager {
                     'user' => $this->plugin->user,\r
                     'password' => $this->plugin->password,\r
                     'alias' => $this->plugin->nickname,\r
-                    'psm' => 'Send me a message to post a notice',\r
-                    'debug' => true\r
+                    // TRANS: MSN bot status message.\r
+                    'psm' => _m('Send me a message to post a notice'),\r
+                    'debug' => false\r
                 )\r
             );\r
             $this->conn->registerHandler('IMin', array($this, 'handle_msn_message'));\r
@@ -118,7 +119,7 @@ class MsnManager extends ImManager {
             $this->conn->registerHandler('ConnectFailed', array($this, 'handle_connect_failed'));\r
             $this->conn->registerHandler('Reconnect', array($this, 'handle_reconnect'));\r
             $this->conn->signon();\r
-            $this->lastping = time();\r
+            $this->lastPing = time();\r
         }\r
         return $this->conn;\r
     }\r
@@ -129,14 +130,14 @@ class MsnManager extends ImManager {
     *\r
     * @return void\r
     */\r
-    private function send_ping() {\r
+    protected function send_ping() {\r
         $this->connect();\r
         if (!$this->conn) {\r
             return false;\r
         }\r
 \r
         $this->conn->sendPing();\r
-        $this->lastping = time();\r
+        $this->lastPing = time();\r
         $this->pingInterval = 50;\r
         return true;\r
     }\r
@@ -160,7 +161,7 @@ class MsnManager extends ImManager {
     * @return boolean\r
     */\r
     public function handle_msn_message($data) {\r
-        $this->plugin->enqueue_incoming_raw($data);\r
+        $this->plugin->enqueueIncomingRaw($data);\r
         return true;\r
     }\r
 \r
@@ -170,24 +171,44 @@ class MsnManager extends ImManager {
     * @param array $data Data\r
     */\r
     public function handle_session_ready($data) {\r
-        while (($wm = Msn_waiting_message::top($data['to']) != NULL)) {\r
-            if ($this->conn->sendMessage($wm->screenname, $wm->message, $ignore)) {\r
-                $wm->delete();\r
-            } else {\r
-                // Requeue the message in the regular queue\r
-                $this->plugin->send_message($wm->screenname, $wm->message);\r
+        $sessionFailed = false;\r
+        $wm = Msn_waiting_message::top($data['to']);\r
+        while ($wm != NULL) {\r
+            if ($sessionFailed) {\r
+                $this->plugin->sendMessage($wm->screenname, $wm->message);\r
+                $sessionFailed = true;\r
+            } elseif (!$this->conn->sendMessage($wm->screenname, $wm->message, $ignore)) {\r
+                $this->plugin->sendMessage($wm->screenname, $wm->message);\r
             }\r
+\r
+            $wm->delete();\r
+            $wm = Msn_waiting_message::top($data['to']);\r
+        }\r
+    }\r
+\r
+    /**\r
+    * Requeue messages from the waiting table so we try\r
+    * to send them again\r
+    *\r
+    * @return void\r
+    */\r
+    protected function requeue_waiting_messages() {\r
+        $wm = Msn_waiting_message::top();\r
+        while ($wm != NULL) {\r
+            $this->plugin->sendMessage($wm->screenname, $wm->message);\r
+            $wm->delete();\r
+            $wm = Msn_waiting_message::top();\r
         }\r
     }\r
 \r
     /**\r
     * Called by callback to log failure during connect\r
     *\r
-    * @param void $data Not used (there to keep callback happy)\r
+    * @param string $message error message reported\r
     * @return void\r
     */\r
-    public function handle_connect_failed($data) {\r
-        common_log(LOG_NOTICE, 'MSN connect failed, retrying');\r
+    public function handle_connect_failed($message) {\r
+        common_log(LOG_NOTICE, 'MSN connect failed, retrying: ' . $message);\r
     }\r
 \r
     /**\r
@@ -198,6 +219,8 @@ class MsnManager extends ImManager {
     */\r
     public function handle_reconnect($data) {\r
         common_log(LOG_NOTICE, 'MSN reconnecting');\r
+        // Requeue messages waiting in the DB\r
+        $this->requeue_waiting_messages();\r
     }\r
 \r
     /**\r
@@ -207,7 +230,7 @@ class MsnManager extends ImManager {
     * @param string $to Intended recipient\r
     * @param string $message Message\r
     */\r
-    private function enqueue_waiting_message($to, $message) {\r
+    protected function enqueue_waiting_message($to, $message) {\r
         $wm = new Msn_waiting_message();\r
 \r
         $wm->screenname = $to;\r
@@ -217,7 +240,8 @@ class MsnManager extends ImManager {
 \r
         if (!$result) {\r
             common_log_db_error($wm, 'INSERT', __FILE__);\r
-            throw new ServerException('DB error inserting queue item');\r
+            // TRANS: Server exception thrown when a message to be sent through MSN cannot be added to the database queue.\r
+            throw new ServerException(_m('Database error inserting queue item.'));\r
         }\r
 \r
         return true;\r
@@ -245,7 +269,7 @@ class MsnManager extends ImManager {
         }\r
 \r
         // Sending a command updates the time till next ping\r
-        $this->lastping = time();\r
+        $this->lastPing = time();\r
         $this->pingInterval = 50;\r
         return true;\r
     }\r