Last active
August 29, 2015 14:11
-
-
Save n00shie/e77e44b6a7d91fa70412 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$toData = $datum['to']['data']; | |
// rekey to use user id's as index | |
$rekeyedToData = []; | |
foreach($toData as $toUser) { | |
$key = $toUser['id']; | |
$rekeyedToData[$key] = $toUser; | |
} | |
// iterate through message_tags, remove the tagged user from $rekeyedToData | |
if(isset($datum['message_tags'])) { | |
foreach($datum['message_tags'] as $tag) { | |
// each tag object in FB's JSON response is actually wrapped in an array. | |
// if FB decides to change this structure in the future, then the following line will break. | |
$key = $tag[0]['id']; | |
$rekeyedToData[$key] = null; | |
} | |
} | |
// do the same with with_tags, remove the tagged user from $rekeyedToData | |
// filter out all null entries | |
$rekeyedToData = array_filter($rekeyedToData); | |
// if $rekeyedToData is empty, then this post was a self post, e.g the poster posted on their own wall and tagged a bunch of people | |
// otherwise the post has a definite recipient | |
if(!empty($rekeyedToData)) { | |
// should never be more than one element in the array | |
if(count($rekeyedToData) > 1){ | |
Logger::log("More than one element in recipient array."); | |
} | |
$recipient = end($rekeyedToData); // could have used reset, instead of end() to get the first element. Assumption is there would only by one element in the array | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment