示例#1
0
 /**
  * @param  array $data
  * @return Group
  */
 public static function factory(array $data)
 {
     $group = new self();
     $group->setId($data['id']);
     $group->setOwner(Identity::parseJID($data['owner']));
     $creation = new DateTime();
     $creation->setTimestamp((int) $data['creation']);
     $group->setCreation($creation);
     $group->setSubject($data['subject']);
     return $group;
 }
示例#2
0
 protected function parseGroupPresence(Client $client, NodeInterface $node)
 {
     $groupId = Identity::parseJID($node->getAttribute('from'));
     if (null != $node->getAttribute('add')) {
         $added = Identity::parseJID($node->getAttribute('add'));
         $client->getEventManager()->trigger('onGroupParticipantAdded', $client, ['group' => $groupId, 'participant' => $added]);
     } elseif (null != $node->getAttribute('remove')) {
         $removed = Identity::parseJID($node->getAttribute('remove'));
         $author = Identity::parseJID($node->getAttribute('author'));
         $client->getEventManager()->trigger('onGroupParticipantRemoved', $client, ['group' => $groupId, 'participant' => $removed, 'author' => $author]);
     }
 }
示例#3
0
 /**
  * @param  NodeInterface $node
  * @return Presence
  */
 public function createPresence(NodeInterface $node)
 {
     $presence = new Presence();
     $presence->setFrom(Identity::parseJID($node->getAttribute('from')));
     $presence->setLast($node->getAttribute('last'));
     switch ($node->getAttribute('type')) {
         case 'unavailable':
             $presence->setType(Presence::TYPE_UNAVAILABLE);
             break;
         default:
             $presence->setType(Presence::TYPE_AVAILABLE);
     }
     return $presence;
 }
示例#4
0
 /**
  * @param EventInterface $e
  */
 public function onReceivedNode(EventInterface $e)
 {
     /** @var NodeInterface $node */
     $node = $e->getParam('node');
     /** @var Client $client */
     $client = $e->getTarget();
     $identity = $client->getIdentity();
     if ($this->isNodeFromMyNumber($identity, $node) || $this->isNodeFromGroup($node)) {
         return;
     }
     if ($node->hasChild('composing')) {
         $client->getEventManager()->trigger('onMessageComposing', $client, array('node' => $node, 'from' => Identity::parseJID($node->getAttribute('from')), 'id' => $node->getAttribute('id'), 'timestamp' => (int) $node->getAttribute('t')));
     } elseif ($node->hasChild('paused')) {
         $client->getEventManager()->trigger('onMessagePaused', $client, array('node' => $node, 'from' => Identity::parseJID($node->getAttribute('from')), 'id' => $node->getAttribute('id'), 'timestamp' => (int) $node->getAttribute('t')));
     }
 }
示例#5
0
 /**
  * @param  NodeInterface $node
  * @return MessageText
  */
 public function createMessage(NodeInterface $node)
 {
     $message = new MessageText();
     $message->setBody($node->getChild('body')->getData());
     $participant = $node->getAttribute('participant');
     $from = $node->getAttribute('from');
     if ($participant) {
         $message->setFrom(Identity::parseJID($participant));
         $message->setGroupId(Identity::parseJID($from));
     } else {
         $message->setFrom(Identity::parseJID($from));
     }
     $message->setId($node->getAttribute('id'));
     $dateTime = new DateTime();
     $dateTime->setTimestamp((int) $node->getAttribute('t'));
     $message->setDateTime($dateTime);
     $message->setNotify($node->getAttribute('notify'));
     $message->setType($node->getAttribute('type'));
     return $message;
 }
示例#6
0
 public function testParseJID()
 {
     $number = '393921234567';
     $ret = Identity::parseJID($number);
     $this->assertEquals($number, $ret);
 }