Skip to content

Commit

Permalink
Fixed all message recipts
Browse files Browse the repository at this point in the history
  • Loading branch information
shirioko committed Mar 16, 2014
1 parent 7d740f3 commit 3928845
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 83 deletions.
9 changes: 5 additions & 4 deletions src/php/WhatsAppEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,11 +702,12 @@ function fireProfilePictureDeleted(

function fireSendMessageReceived(
$phone,
$time,
$from
$id,
$from,
$type
) {
$callbackEvent = function(WhatsAppEventListener $listener) use ($phone, $time, $from) {
$listener->onSendMessageReceived($phone, $time, $from);
$callbackEvent = function(WhatsAppEventListener $listener) use ($phone, $id, $from, $type) {
$listener->onSendMessageReceived($phone, $id, $from, $type);
};
$this->fireCallback($callbackEvent);
}
Expand Down
5 changes: 3 additions & 2 deletions src/php/events/WhatsAppEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,9 @@ function onSendMessage(

function onSendMessageReceived(
$phone, // The user phone number including the country code.
$time, // The unix time when send message notification.
$from // The sender JID.
$id, // Message ID
$from, // The sender JID.
$type // Message type
);

function onSendPong(
Expand Down
5 changes: 3 additions & 2 deletions src/php/events/WhatsAppEventListenerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ function onPresence(

function onSendMessageReceived(
$phone,
$time,
$from
$id,
$from,
$type
) {}

function onSendPong(
Expand Down
5 changes: 3 additions & 2 deletions src/php/events/WhatsAppEventListenerProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,9 @@ function onPresence(

function onSendMessageReceived(
$phone,
$time,
$from
$id,
$from,
$type
) {
$this->handleEvent(__FUNCTION__, func_get_args());
}
Expand Down
137 changes: 64 additions & 73 deletions src/php/whatsprot.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ protected function processInboundDataNode(ProtocolNode $node, $autoReceipt = tru
if ($this->newMsgBind && $node->getChild('body')) {
$this->newMsgBind->process($node);
}
if ($node->getChild('notify') != null && $node->getChild(0)->getAttribute('name') != '' && $node->getChild('body') != null) {
if ($node->getAttribute("type") == "text" && $node->getChild('body') != null) {
$author = $node->getAttribute("author");
if($author == "")
{
Expand All @@ -1829,7 +1829,7 @@ protected function processInboundDataNode(ProtocolNode $node, $autoReceipt = tru
$node->getAttribute('id'),
$node->getAttribute('type'),
$node->getAttribute('t'),
$node->getChild("notify")->getAttribute('name'),
$node->getAttribute("notify"),
$node->getChild("body")->getData()
);
}
Expand All @@ -1843,7 +1843,7 @@ protected function processInboundDataNode(ProtocolNode $node, $autoReceipt = tru
$node->getAttribute('id'),
$node->getAttribute('type'),
$node->getAttribute('t'),
$node->getChild("notify")->getAttribute('name'),
$node->getAttribute("notify"),
$node->getChild("body")->getData()
);
}
Expand All @@ -1870,89 +1870,92 @@ protected function processInboundDataNode(ProtocolNode $node, $autoReceipt = tru
);
}
}
if ($node->getChild('notify') != null && $node->getChild(0)->getAttribute('name') != null && $node->getChild('media') != null) {
if ($node->getChild(2)->getAttribute('type') == 'image') {
if ($node->getAttribute("type") == "media" && $node->getChild('media') != null) {
if ($node->getChild("media")->getAttribute('type') == 'image') {
$this->eventManager()->fireGetImage(
$this->phoneNumber,
$node->getAttribute('from'),
$node->getAttribute('id'),
$node->getAttribute('type'),
$node->getAttribute('t'),
$node->getChild(0)->getAttribute('name'),
$node->getChild(2)->getAttribute('size'),
$node->getChild(2)->getAttribute('url'),
$node->getChild(2)->getAttribute('file'),
$node->getChild(2)->getAttribute('mimetype'),
$node->getChild(2)->getAttribute('filehash'),
$node->getChild(2)->getAttribute('width'),
$node->getChild(2)->getAttribute('height'),
$node->getChild(2)->getData()
$node->getAttribute('notify'),
$node->getChild("media")->getAttribute('size'),
$node->getChild("media")->getAttribute('url'),
$node->getChild("media")->getAttribute('file'),
$node->getChild("media")->getAttribute('mimetype'),
$node->getChild("media")->getAttribute('filehash'),
$node->getChild("media")->getAttribute('width'),
$node->getChild("media")->getAttribute('height'),
$node->getChild("media")->getData()
);
} elseif ($node->getChild(2)->getAttribute('type') == 'video') {
} elseif ($node->getChild("media")->getAttribute('type') == 'video') {
$this->eventManager()->fireGetVideo(
$this->phoneNumber,
$node->getAttribute('from'),
$node->getAttribute('id'),
$node->getAttribute('type'),
$node->getAttribute('t'),
$node->getChild(0)->getAttribute('name'),
$node->getChild(2)->getAttribute('url'),
$node->getChild(2)->getAttribute('file'),
$node->getChild(2)->getAttribute('size'),
$node->getChild(2)->getAttribute('mimetype'),
$node->getChild(2)->getAttribute('filehash'),
$node->getChild(2)->getAttribute('duration'),
$node->getChild(2)->getAttribute('vcodec'),
$node->getChild(2)->getAttribute('acodec'),
$node->getChild(2)->getData()
$node->getAttribute('notify'),
$node->getChild("media")->getAttribute('url'),
$node->getChild("media")->getAttribute('file'),
$node->getChild("media")->getAttribute('size'),
$node->getChild("media")->getAttribute('mimetype'),
$node->getChild("media")->getAttribute('filehash'),
$node->getChild("media")->getAttribute('duration'),
$node->getChild("media")->getAttribute('vcodec'),
$node->getChild("media")->getAttribute('acodec'),
$node->getChild("media")->getData()
);
} elseif ($node->getChild(2)->getAttribute('type') == 'audio') {
} elseif ($node->getChild("media")->getAttribute('type') == 'audio') {
$this->eventManager()->fireGetAudio(
$this->phoneNumber,
$node->getAttribute('from'),
$node->getAttribute('id'),
$node->getAttribute('type'),
$node->getAttribute('t'),
$node->getChild(0)->getAttribute('name'),
$node->getChild(2)->getAttribute('size'),
$node->getChild(2)->getAttribute('url'),
$node->getChild(2)->getAttribute('file'),
$node->getChild(2)->getAttribute('mimetype'),
$node->getChild(2)->getAttribute('filehash'),
$node->getChild(2)->getAttribute('duration'),
$node->getChild(2)->getAttribute('acodec')
$node->getAttribute('notify'),
$node->getChild("media")->getAttribute('size'),
$node->getChild("media")->getAttribute('url'),
$node->getChild("media")->getAttribute('file'),
$node->getChild("media")->getAttribute('mimetype'),
$node->getChild("media")->getAttribute('filehash'),
$node->getChild("media")->getAttribute('duration'),
$node->getChild("media")->getAttribute('acodec')
);
} elseif ($node->getChild(2)->getAttribute('type') == 'vcard') {
} elseif ($node->getChild("media")->getAttribute('type') == 'vcard') {
$this->eventManager()->fireGetvCard(
$this->phoneNumber,
$node->getAttribute('from'),
$node->getAttribute('id'),
$node->getAttribute('type'),
$node->getAttribute('t'),
$node->getChild(0)->getAttribute('name'),
$node->getChild(2)->getChild(0)->getAttribute('name'),
$node->getChild(2)->getChild(0)->getData()
$node->getAttribute('notify'),
$node->getChild("media")->getChild("vcard")->getAttribute('name'),
$node->getChild("media")->getChild("vcard")->getData()
);
} elseif ($node->getChild(2)->getAttribute('type') == 'location') {
$url = $node->getChild(2)->getAttribute('url');
$name = $node->getChild(2)->getAttribute('name');
} elseif ($node->getChild("media")->getAttribute('type') == 'location') {
$url = $node->getChild("media")->getAttribute('url');
$name = $node->getChild("media")->getAttribute('name');

$this->eventManager()->fireGetLocation(
$this->phoneNumber,
$node->getAttribute('from'),
$node->getAttribute('id'),
$node->getAttribute('type'),
$node->getAttribute('t'),
$node->getChild(0)->getAttribute('name'),
$node->getAttribute('notify'),
$name,
$node->getChild(2)->getAttribute('longitude'),
$node->getChild(2)->getAttribute('latitude'),
$node->getChild("media")->getAttribute('longitude'),
$node->getChild("media")->getAttribute('latitude'),
$url,
$node->getChild(2)->getData()
$node->getChild("media")->getData()
);
}

$this->sendMessageReceived($node);
if($autoReceipt)
{
$this->sendMessageReceived($node);
}
}
if ($node->getChild('x') != null) {
$this->serverReceivedId = $node->getAttribute('id');
Expand Down Expand Up @@ -2669,35 +2672,23 @@ protected function sendMessageNode($to, $node, $id = null)
* @param ProtocolNode $msg
* The ProtocolTreeNode that contains the message.
*/
protected function sendMessageReceived($msg)
protected function sendMessageReceived($msg, $type = null)
{
$requestNode = $msg->getChild("request");
$receivedNode = $msg->getChild("received");
if ($requestNode != null || $receivedNode != null) {
$receivedHash = array();
$receivedHash["xmlns"] = "urn:xmpp:receipts";

$response = "received";
if($receivedNode != null)
{
$response = "ack";
}

$receivedNode = new ProtocolNode($response, $receivedHash, null, "");

$messageHash = array();
$messageHash["to"] = $msg->getAttribute("from");
$messageHash["type"] = "chat";
$messageHash["id"] = $msg->getAttribute("id");
$messageHash["t"] = time();
$messageNode = new ProtocolNode("message", $messageHash, array($receivedNode), "");
$this->sendNode($messageNode);
$this->eventManager()->fireSendMessageReceived(
$this->phoneNumber,
$messageHash["t"],
$msg->getAttribute("from")
);
if($type)
{
$messageHash["type"] = $type;
}
$messageHash = array();
$messageHash["to"] = $msg->getAttribute("from");
$messageHash["id"] = $msg->getAttribute("id");
$messageNode = new ProtocolNode("receipt", $messageHash, null, null);
$this->sendNode($messageNode);
$this->eventManager()->fireSendMessageReceived(
$this->phoneNumber,
$msg->getAttribute("id"),
$msg->getAttribute("from"),
$type
);
}

/**
Expand Down

0 comments on commit 3928845

Please sign in to comment.