/away awayMessage
command.
When a user issues this command, " (Away)" appears beside their name in the nicklist and a notice is sent to chat saying they are now away and gives their awayMessage. A user can issue the /away command with no parameters to return from being away.
Outstanding issues:
-when a user times out, and returns, their away status disappears.. i think this is a result of all metadata being lost..
-there is a lag ( a few seonds) between when they're set to away and when (Away) appears beside their name.. if you look in my Away.class.php file you can see how I tried to fix it, but the issues I ran into.. maybe theres another way to do it?
-not internationalized..
Any comments, suggestions or improvements are welcomed!
Here are the necessary changes, including a couple lines before changes I made.:
/data/public/js/pfcclient.js - around line 1100, added the if metadata lines.
- Code: Select all
buildNickItem: function(nickid)
{
var nick = this.getUserMeta(nickid, 'nick');
if(this.getUserMeta(nickid, 'Away') != ''){
nick = nick+" (Away)";
}
/src/pfccontainer.class.php - around line 579, added a rmUserMeta function
- Code: Select all
function rmUserMeta($nickid, $key){
$ret = $this->rmMeta("nickid-to-metadata", $nickid, $key);
return $ret;
}
/src/commands/Away.class.php - create this file
- Code: Select all
<?php
require_once(dirname(__FILE__)."/../pfccommand.class.php");
class pfcCommand_away extends pfcCommand
{
var $usage = "/away {away message}";
function run(&$xml_reponse, $p)
{
$clientid = $p["clientid"];
$param = $p["param"];
$sender = $p["sender"];
$recipient = $p["recipient"];
$recipientid = $p["recipientid"];
$c =& pfcGlobalConfig::Instance();
$u =& pfcUserConfig::Instance();
$container =& pfcContainer::Instance();
$awayMessage = trim($param);
if ($awayMessage == ""){
//user must be away for us to bring them back..
if($container->getUserMeta($u->nickid, 'Away') == NULL){
$cmdp = $p;
$cmdp["param"] = "Use (".$this->usage.") to set yourself away. Use (/away) to return.";
$cmd =& pfcCommand::Factory("error");
$cmd->run($xml_reponse, $cmdp);
return;
}else{
// remove an away message
$cmdp = $p;
$cmdp["param"] = "$u->nick has returned";
$cmdp["flag"] = 1;
$cmd =& pfcCommand::Factory("notice");
foreach($u->channels as $id => $chan)
{
$cmdp["recipient"] = $chan["recipient"];
$cmdp["recipientid"] = $id;
$cmd->run($xml_reponse, $cmdp);
}
//send message to PMs
foreach( $u->privmsg as $id => $pv )
{
$cmdp["recipient"] = $pv["recipient"];
$cmdp["recipientid"] = $id;
$cmd->run($xml_reponse, $cmdp);
}
//remove the metadata
$container->rmUserMeta($u->nickid, 'Away');
$this->forceWhoisReload($u->nick);
//force update of nicklist here
//this doesn't work for some reason..
// $xml_reponse->script("pfc.handleResponse('nick', 'changed', '".addslashes($u->nick)."');");
}
}else{
// show an away message
$cmdp = $p;
$cmdp["param"] = "$u->nick is now away ($awayMessage)";
$cmdp["flag"] = 1;
$cmd =& pfcCommand::Factory("notice");
//send message to channels
foreach($u->channels as $id => $chan)
{
$cmdp["recipient"] = $chan["recipient"];
$cmdp["recipientid"] = $id;
$cmd->run($xml_reponse, $cmdp);
}
//send message to PMs
foreach( $u->privmsg as $id => $pv )
{
$cmdp["recipient"] = $pv["recipient"];
$cmdp["recipientid"] = $id;
$cmd->run($xml_reponse, $cmdp);
}
//set user's Away metadata
$container->setUserMeta($u->nickid, 'Away', $awayMessage);
$this->forceWhoisReload($u->nick);
//force update of nicklist here..
//doesn't work as intended.. gives double (Away) when changing away text..
//also changes name beside text box too.. for now we'll let it update slowly
// $xml_reponse->script("pfc.handleResponse('nick', 'changed', '".addslashes($nickChange)." (Away)');");
}
}
}
?>