IM cleanup on 1.0.x branch:

* Fake_XMPP back to Queued_XMPP, refactor how we use it and don't create objects and load classes until we need them.
* fix fatal error in IM settings while waiting for a Jabber confirmation.
* Caching fix for user_im_prefs
* fix for saving multiple transport settings
* some fixes for AIM & using normalized addresses for lookups
This commit is contained in:
Brion Vibber
2010-04-30 14:41:54 -07:00
parent e3e90b4c27
commit 5414396a2e
8 changed files with 89 additions and 37 deletions

View File

@@ -2,7 +2,7 @@
/**
* StatusNet, the distributed open-source microblogging tool
*
* Instead of sending XMPP messages, retrieve the raw XML that would be sent
* Queue-mediated proxy class for outgoing XMPP messages.
*
* PHP version 5
*
@@ -31,13 +31,17 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
class Fake_XMPP extends XMPPHP_XMPP
class Queued_XMPP extends XMPPHP_XMPP
{
public $would_be_sent = null;
/**
* Reference to the XmppPlugin object we're hooked up to.
*/
public $plugin;
/**
* Constructor
*
* @param XmppPlugin $plugin
* @param string $host
* @param integer $port
* @param string $user
@@ -47,8 +51,10 @@ class Fake_XMPP extends XMPPHP_XMPP
* @param boolean $printlog
* @param string $loglevel
*/
public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null)
public function __construct($plugin, $host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null)
{
$this->plugin = $plugin;
parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel);
// We use $host to connect, but $server to build JIDs if specified.
@@ -73,7 +79,7 @@ class Fake_XMPP extends XMPPHP_XMPP
*/
public function send($msg, $timeout=NULL)
{
$this->would_be_sent = $msg;
$this->plugin->enqueue_outgoing_raw($msg);
}
//@{
@@ -110,5 +116,6 @@ class Fake_XMPP extends XMPPHP_XMPP
throw new Exception("Can't read stream from fake XMPP.");
}
//@}
}

View File

@@ -60,8 +60,6 @@ class XmppPlugin extends ImPlugin
public $transport = 'xmpp';
protected $fake_xmpp;
function getDisplayName(){
return _m('XMPP/Jabber/GTalk');
}
@@ -292,7 +290,7 @@ class XmppPlugin extends ImPlugin
require_once 'XMPP.php';
return false;
case 'Sharing_XMPP':
case 'Fake_XMPP':
case 'Queued_XMPP':
require_once $dir . '/'.$cls.'.php';
return false;
case 'XmppManager':
@@ -317,9 +315,7 @@ class XmppPlugin extends ImPlugin
function send_message($screenname, $body)
{
$this->fake_xmpp->message($screenname, $body, 'chat');
$this->enqueue_outgoing_raw($this->fake_xmpp->would_be_sent);
return true;
$this->queuedConnection()->message($screenname, $body, 'chat');
}
function send_notice($screenname, $notice)
@@ -327,8 +323,7 @@ class XmppPlugin extends ImPlugin
$msg = $this->format_notice($notice);
$entry = $this->format_entry($notice);
$this->fake_xmpp->message($screenname, $msg, 'chat', null, $entry);
$this->enqueue_outgoing_raw($this->fake_xmpp->would_be_sent);
$this->queuedConnection()->message($screenname, $msg, 'chat', null, $entry);
return true;
}
@@ -385,10 +380,19 @@ class XmppPlugin extends ImPlugin
return true;
}
return $this->handle_incoming($from, $pl['body']);
$this->handle_incoming($from, $pl['body']);
return true;
}
function initialize(){
/**
* Build a queue-proxied XMPP interface object. Any outgoing messages
* will be run back through us for enqueing rather than sent directly.
*
* @return Queued_XMPP
* @throws Exception if server settings are invalid.
*/
function queuedConnection(){
if(!isset($this->server)){
throw new Exception("must specify a server");
}
@@ -402,7 +406,7 @@ class XmppPlugin extends ImPlugin
throw new Exception("must specify a password");
}
$this->fake_xmpp = new Fake_XMPP($this->host ?
return new Queued_XMPP($this, $this->host ?
$this->host :
$this->server,
$this->port,
@@ -415,7 +419,6 @@ class XmppPlugin extends ImPlugin
$this->debug ?
XMPPHP_Log::LEVEL_VERBOSE : null
);
return true;
}
function onPluginVersion(&$versions)