From b0a1f4e1b9eca0b5a25bbfa6f2ea8aa1a6e6bdff Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 27 Dec 2013 14:11:13 +0100 Subject: [PATCH] API: Bugfix: Wrong contact ids with direct messages --- include/api.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/include/api.php b/include/api.php index 72c65f35d0..8ae1f9faac 100644 --- a/include/api.php +++ b/include/api.php @@ -218,7 +218,7 @@ /** - * Unique contact to to contact url. + * Unique contact to contact url. */ function api_unique_id_to_url($id){ $r = q("SELECT url FROM unique_contacts WHERE id=%d LIMIT 1", @@ -1760,11 +1760,11 @@ require_once("include/message.php"); - $r = q("SELECT `id` FROM `contact` WHERE `uid`=%d AND `nick`='%s'", + $r = q("SELECT `id`, `nurl` FROM `contact` WHERE `uid`=%d AND `nick`='%s'", intval(api_user()), dbesc($_POST['screen_name'])); - $recipient = api_get_user($a, $r[0]['id']); + $recipient = api_get_user($a, $r[0]['nurl']); $replyto = ''; $sub = ''; if (x($_REQUEST,'replyto')) { @@ -1824,19 +1824,19 @@ $profile_url = $user_info["url"]; if ($box=="sentbox") { - $sql_extra = "`from-url`='".dbesc( $profile_url )."'"; + $sql_extra = "`mail`.`from-url`='".dbesc( $profile_url )."'"; } elseif ($box=="conversation") { - $sql_extra = "`parent-uri`='".dbesc( $_GET["uri"] ) ."'"; + $sql_extra = "`mail`.`parent-uri`='".dbesc( $_GET["uri"] ) ."'"; } elseif ($box=="all") { $sql_extra = "true"; } elseif ($box=="inbox") { - $sql_extra = "`from-url`!='".dbesc( $profile_url )."'"; + $sql_extra = "`mail`.`from-url`!='".dbesc( $profile_url )."'"; } - $r = q("SELECT * FROM `mail` WHERE uid=%d AND $sql_extra AND id > %d ORDER BY created DESC LIMIT %d,%d", + $r = q("SELECT `mail`.*, `contact`.`nurl` AS `contact-url` FROM `mail`,`contact` WHERE `mail`.`contact-id` = `contact`.`id` AND `mail`.`uid`=%d AND $sql_extra AND `mail`.`id` > %d ORDER BY `mail`.`created` DESC LIMIT %d,%d", intval(api_user()), intval($since_id), intval($start), intval($count) @@ -1846,11 +1846,12 @@ foreach($r as $item) { if ($box == "inbox" || $item['from-url'] != $profile_url){ $recipient = $user_info; - $sender = api_get_user($a,$item['contact-id']); + $sender = api_get_user($a,normalise_link($item['contact-url'])); } elseif ($box == "sentbox" || $item['from-url'] != $profile_url){ - $recipient = api_get_user($a,$item['contact-id']); + $recipient = api_get_user($a,normalise_link($item['contact-url'])); $sender = $user_info; + } $ret[]=api_format_messages($item, $recipient, $sender); -- 2.39.5