User = $User; $this->Roster = $Roster; } public function isOnline () { return ($this->Status >= 0); } public function setStatus ($TLVData = array (), $Status = null, $Warnlevel = null, $Debug = true) { if ($Debug) print "Status-Update on user " . $this->User . " / " . $this->Alias . "\n"; $Changed = false; // Handle TLVs foreach ($TLVData as $TLV) // Handle BART-Information if ($TLV instanceof Oscar_TLV_BartID) { foreach ($TLV->Items as $Item) if ($Item->Type == Oscar_TLV_BartID::TYPE_STATUS_STR) { $Changed = $Changed || ($this->Message != $Item->Data); $this->Message = $Item->Data; print " New Away " . $Item->Data . "\n"; } else print " BART 0x" . dechex ($Item->Type) . " / Flag 0x" . dechex ($Item->Flag) . " / Length " . strlen ($Item->Data) . "\n"; // Update Status from TLV } elseif ($TLV instanceof Oscar_TLV_Status) { if ($Status === null) { $Status = $TLV->Status; print " Using Status from TLV " . $TLV->Status . "\n"; } else print " Preset Status $Status / TLV-Status " . $TLV->Status . "\n"; } // Debug this TLV elseif ($Debug) print " " . $TLV->toString () . "\n"; // Set new status if ($Status !== null) { // Check for changes $Changed = $Changed || ($this->Status != $Status); // Set new Status $this->Status = $Status; } if ($Changed) print " Changed\n"; return $Changed; } // {{{ update /** * Try to update this contact from a SNAC carrying Nick_Info-TLVs * * @param object $Item * * @access public * @return void **/ public function update ($Item) { // Check if the parameter is of the right type if (!($Item instanceof Oscar_SNAC_Helper_TLV)) return false; print "Updating user " . $this->User . " / " . $this->Alias . "\n"; // Preserve old online-status $oldOn = $this->isOnline (); // Load all TLVs from SNAC $TLVs = $Item->getTLVs (); foreach ($TLVs as $TLV) // Handle nicknames if ($TLV instanceof Oscar_TLV_Feedbag_Alias) $this->Alias = $TLV->Value; // Handle pending authorizations elseif ($TLV instanceof Oscar_TLV_Feedbag_Pending) $this->Pending = true; elseif ($TLV instanceof Oscar_TLV_NickInfo_MemberSince) $this->RegistrationDate = $TLV->Value; elseif ($TLV instanceof Oscar_TLV_NickInfo_AwayTime) $this->AwayDate = $TLV->Value; elseif ($TLV instanceof Oscar_TLV_NickInfo_SignonTime) $this->OnlineDate = $TLV->Value; elseif ($TLV instanceof Oscar_TLV_NickInfo_OnlineTime) $this->OnlineTime = $TLV->Value; elseif ($TLV instanceof Oscar_TLV_NickInfo_IdleTime) $this->IdleTime = $TLV->Value; else print " " . $TLV->toString () . "\n"; // Update status $State = null; if ($Item instanceof Oscar_SNAC_Buddy_Offline) $State = Oscar_TLV_Status::STATUS_OFFLINE; elseif (($Item instanceof Oscar_SNAC_Buddy_Online) && !$oldOn) $this->Status = Oscar_TLV_Status::STATUS_ONLINE; $rc = self::setStatus ($TLVs, $State, (isset ($Item->Warnlevel) ? $Item->Warnlevel : null), false); if (!($rc || ($Item instanceof Oscar_SNAC_Buddy_Online))) return; // Run callbacks if (!is_object ($this->Roster) || !is_object ($Oscar = $this->Roster->getOscar ())) return; if ($this->isOnline () && !$oldOn) $Oscar->contactOnline ($this->User, $this->getStatus ()); elseif (!$this->isOnline ()) $Oscar->contactOffline ($this->User); else $Oscar->contactStatus ($this->User, $this->getStatus ()); } // }}} public function getRoster () { return $this->Roster; } public function getName () { return $this->User; } public function getStatus () { return $this->Status; } public function getAwaymessage () { return $this->Message; } // {{{ typingStarted /** * Callback is invoked when user starts typing * * @access public * @return void **/ public function typingStarted () { } // }}} // {{{ typingPaused /** * Callback is invoked when user pauses typing * * @access public * @return void **/ public function typingPaused () { } // }}} // {{{ typingStopped /** * Callback is invoked when user stops typing * * @access public * @return void **/ public function typingStopped () { } // }}} // {{{ typingEnded /** * Callback is invoked when user closed chatting-window * * @access public * @return void **/ public function typingEnded () { } // }}} } ?>