/** * @TODO * @param callable $cb * @callback $cb ( ) */ public function fetch($cb = null) { $this->xmpp->queryGet($this->ns, function ($xml) use($cb) { $status = "result"; $xmlroster = $xml->sub('query'); $contacts = []; foreach ($xmlroster->subs as $item) { $groups = []; if ($item->name === 'item') { $jid = $item->attrs['jid']; //REQUIRED $name = isset($item->attrs['name']) ? $item->attrs['name'] : ''; //MAY $subscription = $item->attrs['subscription']; foreach ($item->subs as $subitem) { if ($subitem->name === 'group') { $groups[] = $subitem->data; } } $contacts[] = [$jid, $subscription, $name, $groups]; //Store for action if no errors happen } else { $status = 'error'; } } if ($status === 'result') { //No errors, add contacts foreach ($contacts as $contact) { $this->_addContact($contact[0], $contact[1], $contact[2], $contact[3]); } } if ($xml->attrs['type'] === 'set') { $this->xmpp->sendXML('<iq type="reply" id="' . $xml->attrs['id'] . '" to="' . $xml->attrs['from'] . '" />'); } if ($cb) { call_user_func($cb, $status); } }); }
/** * @TODO * @param string $xml * @param callable $cb * @callback $cb ( ) */ public function rosterSet($xml, $cb = null) { $this->xmpp->querySetTo($this->xmpp->fulljid, $this->ns, $xml, $cb); }