diff options
author | friendica <redmatrix@redmatrix.me> | 2015-04-19 18:14:17 -0700 |
---|---|---|
committer | friendica <redmatrix@redmatrix.me> | 2015-04-19 18:14:17 -0700 |
commit | 185ce2da69836a66644bfab4941eba82af19f651 (patch) | |
tree | 44c18f933543dc1c7620c1a8ef9c28213bace994 /include/api.php | |
parent | 8757789213e99f0719994619589498bbdf3db1e4 (diff) | |
download | volse-hubzilla-185ce2da69836a66644bfab4941eba82af19f651.tar.gz volse-hubzilla-185ce2da69836a66644bfab4941eba82af19f651.tar.bz2 volse-hubzilla-185ce2da69836a66644bfab4941eba82af19f651.zip |
assorted fixes to api direct messages
Diffstat (limited to 'include/api.php')
-rw-r--r-- | include/api.php | 66 |
1 files changed, 35 insertions, 31 deletions
diff --git a/include/api.php b/include/api.php index 605c57827..5347d498d 100644 --- a/include/api.php +++ b/include/api.php @@ -267,40 +267,46 @@ require_once('include/items.php'); * Returns user info array. */ - function api_get_user(&$a, $contact_id = null){ + function api_get_user(&$a, $contact_id = null, $contact_xchan = null){ global $called_api; $user = null; $extra_query = ""; - if(!is_null($contact_id)){ - $user=$contact_id; - $extra_query = " AND abook_id = %d "; - } - - if(is_null($user) && x($_GET, 'user_id')) { - $user = intval($_GET['user_id']); - $extra_query = " AND abook_id = %d "; - } - if(is_null($user) && x($_GET, 'screen_name')) { - $user = dbesc($_GET['screen_name']); - $extra_query = " AND xchan_addr like '%s@%%' "; - if (api_user()!==false) - $extra_query .= " AND abook_channel = ".intval(api_user()); + if(! is_null($contact_xchan)) { + $user = local_channel(); + $extra_query = " and abook_xchan = '" . dbesc($contact_xchan) . "' "; } + else { + if(!is_null($contact_id)){ + $user=$contact_id; + $extra_query = " AND abook_id = %d "; + } - if (is_null($user) && argc() > (count($called_api)-1)){ - $argid = count($called_api); - list($user, $null) = explode(".",argv($argid)); - if(is_numeric($user)){ - $user = intval($user); + if(is_null($user) && x($_GET, 'user_id')) { + $user = intval($_GET['user_id']); $extra_query = " AND abook_id = %d "; - } else { - $user = dbesc($user); + } + if(is_null($user) && x($_GET, 'screen_name')) { + $user = dbesc($_GET['screen_name']); $extra_query = " AND xchan_addr like '%s@%%' "; - if (api_user() !== false) + if (api_user()!==false) $extra_query .= " AND abook_channel = ".intval(api_user()); } + + if (is_null($user) && argc() > (count($called_api)-1)){ + $argid = count($called_api); + list($user, $null) = explode(".",argv($argid)); + if(is_numeric($user)){ + $user = intval($user); + $extra_query = " AND abook_id = %d "; + } else { + $user = dbesc($user); + $extra_query = " AND xchan_addr like '%s@%%' "; + if (api_user() !== false) + $extra_query .= " AND abook_channel = ".intval(api_user()); + } + } } if (! $user) { @@ -2021,15 +2027,13 @@ require_once('include/items.php'); $ret = Array(); if($r) { foreach($r as $item) { - if ($box == "inbox" || $item['from-url'] != $profile_url){ - $recipient = $user_info; - // fixme to lookup recipient - $sender = api_get_user($a); - } - elseif ($box == "sentbox" || $item['from-url'] != $profile_url){ - // fixme to lookup recipient - $recipient = api_get_user($a); + if ($item['from_xchan'] == $channel['channel_hash']) { $sender = $user_info; + $recipient = api_get_user($a, null, $item['to_xchan']); + } + else { + $sender = api_get_user($a, null, $item['from_xchan']); + $recipient = $user_info; } $ret[]=api_format_message($item, $recipient, $sender); |