[Phpfreechat-svn] SF.net SVN: phpfreechat: [820] trunk/src/commands
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-10-04 11:26:22
|
Revision: 820 http://svn.sourceforge.net/phpfreechat/?rev=820&view=rev Author: kerphi Date: 2006-10-04 04:26:16 -0700 (Wed, 04 Oct 2006) Log Message: ----------- [en] Bandwidth optimization: store user's list in cache and send it to the browser only when it changes. [30min] [fr] Optimisation de la bande passante : la liste des utilisateurs est mise en cache et n'est envoy?\195?\169e au navigateur que lorsqu'elle a chang?\195?\169. [30min] Modified Paths: -------------- trunk/src/commands/who.class.php trunk/src/commands/who2.class.php Modified: trunk/src/commands/who.class.php =================================================================== --- trunk/src/commands/who.class.php 2006-10-04 09:40:34 UTC (rev 819) +++ trunk/src/commands/who.class.php 2006-10-04 11:26:16 UTC (rev 820) @@ -20,7 +20,6 @@ * Boston, MA 02110-1301 USA */ -require_once(dirname(__FILE__)."/../../lib/json/JSON.php"); require_once(dirname(__FILE__)."/../pfccommand.class.php"); class pfcCommand_who extends pfcCommand @@ -44,7 +43,15 @@ $recipient = pfcCommand_join::GetRecipient($param); $recipientid = pfcCommand_join::GetRecipientId($param); } + + $chanmeta = $this->_getChanMeta($recipient, $recipientid); + $xml_reponse->addScript("pfc.handleResponse('".$this->name."', 'ok', ".$chanmeta.");"); + } + + function _getChanMeta($recipient, $recipientid) + { + $c =& $this->c; $ct =& $c->getContainerInstance(); $chanmeta = array(); $chanmeta['chan'] = $recipient; @@ -55,9 +62,10 @@ $chanmeta['meta']['users']['nick'] = $users['nick']; $chanmeta['meta']['users']['nickid'] = $users['nickid']; + require_once(dirname(__FILE__)."/../../lib/json/JSON.php"); $json = new Services_JSON(); $js = $json->encode($chanmeta); - $xml_reponse->addScript("pfc.handleResponse('".$this->name."', 'ok', ".$js.");"); + return $js; } } Modified: trunk/src/commands/who2.class.php =================================================================== --- trunk/src/commands/who2.class.php 2006-10-04 09:40:34 UTC (rev 819) +++ trunk/src/commands/who2.class.php 2006-10-04 11:26:16 UTC (rev 820) @@ -24,6 +24,40 @@ class pfcCommand_who2 extends pfcCommand_who { + + function run(&$xml_reponse, $p) + { + $clientid = $p["clientid"]; + $param = $p["param"]; + $sender = $p["sender"]; + $recipient = $p["recipient"]; + $recipientid = $p["recipientid"]; + + $c =& $this->c; + $u =& $this->u; + + if ($param != "") + { + require_once dirname(__FILE__)."/join.class.php"; + $recipient = pfcCommand_join::GetRecipient($param); + $recipientid = pfcCommand_join::GetRecipientId($param); + } + + $chanmeta = $this->_getChanMeta($recipient, $recipientid); + + // check if info didn't change since last call + $sid = "pfc_who2_".$c->getId()."_".$clientid."_".$recipientid; + if (isset($_SESSION[$sid]) && $chanmeta == $_SESSION[$sid]) + { + // do not send the response to save bandwidth + //$xml_reponse->addScript("pfc.handleResponse('".$this->name."', 'unchanged', '');"); + } + else + { + $_SESSION[$sid] = $chanmeta; + $xml_reponse->addScript("pfc.handleResponse('".$this->name."', 'ok', ".$chanmeta.");"); + } + } } ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |