Merge pull request #873 from annando/master
API: Bugfix: Wrong contact ids with direct messages
This commit is contained in:
commit
0c0419bc95
|
@ -1,4 +1,9 @@
|
|||
<?php
|
||||
/* To-Do:
|
||||
- Detecting shared items and transfer them as retweeted items
|
||||
- Automatically detect if incoming data is HTML or BBCode
|
||||
- search for usernames should first search friendica, then the other open networks, then the closed ones
|
||||
*/
|
||||
require_once("include/bbcode.php");
|
||||
require_once("include/datetime.php");
|
||||
require_once("include/conversation.php");
|
||||
|
@ -218,7 +223,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",
|
||||
|
@ -276,7 +281,7 @@
|
|||
if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
|
||||
}
|
||||
|
||||
if (is_null($user) && $a->argc > (count($called_api)-1)){
|
||||
if (is_null($user) AND ($a->argc > (count($called_api)-1)) AND (count($called_api) > 0)){
|
||||
$argid = count($called_api);
|
||||
list($user, $null) = explode(".",$a->argv[$argid]);
|
||||
if(is_numeric($user)){
|
||||
|
@ -533,6 +538,10 @@
|
|||
*/
|
||||
function api_account_verify_credentials(&$a, $type){
|
||||
if (api_user()===false) return false;
|
||||
|
||||
unset($_REQUEST["user_id"]);
|
||||
unset($_GET["user_id"]);
|
||||
|
||||
$user_info = api_get_user($a);
|
||||
|
||||
// "verified" isn't used here in the standard
|
||||
|
@ -540,7 +549,10 @@
|
|||
|
||||
// - Adding last status
|
||||
$user_info["status"] = api_status_show($a,"raw");
|
||||
unset($user_info["status"]["user"]);
|
||||
if (!count($user_info["status"]))
|
||||
unset($user_info["status"]);
|
||||
else
|
||||
unset($user_info["status"]["user"]);
|
||||
|
||||
// "cid", "uid" and "self" are only needed for some internal stuff, so remove it from here
|
||||
unset($user_info["cid"]);
|
||||
|
@ -839,6 +851,9 @@
|
|||
function api_statuses_home_timeline(&$a, $type){
|
||||
if (api_user()===false) return false;
|
||||
|
||||
unset($_REQUEST["user_id"]);
|
||||
unset($_GET["user_id"]);
|
||||
|
||||
$user_info = api_get_user($a);
|
||||
// get last newtork messages
|
||||
|
||||
|
@ -1138,6 +1153,9 @@
|
|||
function api_statuses_mentions(&$a, $type){
|
||||
if (api_user()===false) return false;
|
||||
|
||||
unset($_REQUEST["user_id"]);
|
||||
unset($_GET["user_id"]);
|
||||
|
||||
$user_info = api_get_user($a);
|
||||
// get last newtork messages
|
||||
|
||||
|
@ -1233,7 +1251,8 @@
|
|||
$start = $page*$count;
|
||||
|
||||
$sql_extra = '';
|
||||
if ($user_info['self']==1) $sql_extra .= " AND `item`.`wall` = 1 ";
|
||||
if ($user_info['self']==1)
|
||||
$sql_extra .= " AND `item`.`wall` = 1 ";
|
||||
|
||||
if ($exclude_replies > 0)
|
||||
$sql_extra .= ' AND `item`.`parent` = `item`.`id`';
|
||||
|
@ -1275,9 +1294,14 @@
|
|||
|
||||
|
||||
function api_favorites(&$a, $type){
|
||||
global $called_api;
|
||||
|
||||
if (api_user()===false) return false;
|
||||
|
||||
$called_api= array();
|
||||
|
||||
$user_info = api_get_user($a);
|
||||
|
||||
// in friendica starred item are private
|
||||
// return favorites only for self
|
||||
logger('api_favorites: self:' . $user_info['self']);
|
||||
|
@ -1286,7 +1310,6 @@
|
|||
$ret = array();
|
||||
} else {
|
||||
|
||||
|
||||
// params
|
||||
$count = (x($_GET,'count')?$_GET['count']:20);
|
||||
$page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
|
||||
|
@ -1754,17 +1777,21 @@
|
|||
function api_direct_messages_new(&$a, $type) {
|
||||
if (api_user()===false) return false;
|
||||
|
||||
if (!x($_POST, "text") || !x($_POST,"screen_name")) return;
|
||||
if (!x($_POST, "text") OR (!x($_POST,"screen_name") AND !x($_POST,"user_id"))) return;
|
||||
|
||||
$sender = api_get_user($a);
|
||||
|
||||
require_once("include/message.php");
|
||||
|
||||
$r = q("SELECT `id` FROM `contact` WHERE `uid`=%d AND `nick`='%s'",
|
||||
intval(api_user()),
|
||||
dbesc($_POST['screen_name']));
|
||||
if ($_POST['screen_name']) {
|
||||
$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]['nurl']);
|
||||
} else
|
||||
$recipient = api_get_user($a, $_POST['user_id']);
|
||||
|
||||
$recipient = api_get_user($a, $r[0]['id']);
|
||||
$replyto = '';
|
||||
$sub = '';
|
||||
if (x($_REQUEST,'replyto')) {
|
||||
|
@ -1783,7 +1810,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
$id = send_message($recipient['id'], $_POST['text'], $sub, $replyto);
|
||||
$id = send_message($recipient['cid'], $_POST['text'], $sub, $replyto);
|
||||
|
||||
if ($id>-1) {
|
||||
$r = q("SELECT * FROM `mail` WHERE id=%d", intval($id));
|
||||
|
@ -1809,6 +1836,9 @@
|
|||
function api_direct_messages_box(&$a, $type, $box) {
|
||||
if (api_user()===false) return false;
|
||||
|
||||
unset($_REQUEST["user_id"]);
|
||||
unset($_GET["user_id"]);
|
||||
|
||||
$user_info = api_get_user($a);
|
||||
|
||||
// params
|
||||
|
@ -1824,19 +1854,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 +1876,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);
|
||||
|
|
Loading…
Reference in a new issue