remove api_friendica_direct_messages_all

instead included 'friendica_verbose' parameter into standard function
api_direct_messages_box()
This commit is contained in:
gerhard6380 2016-08-12 15:40:22 +02:00
parent fb087ce89e
commit 41c1f71d4d

View File

@ -2808,7 +2808,7 @@
} }
api_register_func('api/direct_messages/new','api_direct_messages_new',true, API_METHOD_POST); api_register_func('api/direct_messages/new','api_direct_messages_new',true, API_METHOD_POST);
function api_direct_messages_box($type, $box) { function api_direct_messages_box($type, $box, $verbose) {
$a = get_app(); $a = get_app();
@ -2868,7 +2868,13 @@
intval($since_id), intval($since_id),
intval($start), intval($count) intval($start), intval($count)
); );
if ($verbose == "true") {
// stop execution and return error message if no mails available
if($r == null) {
$answer = array('result' => 'error', 'message' => 'no mails available');
return api_format_data("direct_messages_all", $type, array('$result' => $answer));
}
}
$ret = Array(); $ret = Array();
foreach($r as $item) { foreach($r as $item) {
@ -2897,16 +2903,20 @@
} }
function api_direct_messages_sentbox($type){ function api_direct_messages_sentbox($type){
return api_direct_messages_box($type, "sentbox"); $verbose = (x($_GET,'friendica_verbose')?strtolower($_GET['friendica_verbose']):"false");
return api_direct_messages_box($type, "sentbox", $verbose);
} }
function api_direct_messages_inbox($type){ function api_direct_messages_inbox($type){
return api_direct_messages_box($type, "inbox"); $verbose = (x($_GET,'friendica_verbose')?strtolower($_GET['friendica_verbose']):"false");
return api_direct_messages_box($type, "inbox", $verbose);
} }
function api_direct_messages_all($type){ function api_direct_messages_all($type){
return api_direct_messages_box($type, "all"); $verbose = (x($_GET,'friendica_verbose')?strtolower($_GET['friendica_verbose']):"false");
return api_direct_messages_box($type, "all", $verbose);
} }
function api_direct_messages_conversation($type){ function api_direct_messages_conversation($type){
return api_direct_messages_box($type, "conversation"); $verbose = (x($_GET,'friendica_verbose')?strtolower($_GET['friendica_verbose']):"false");
return api_direct_messages_box($type, "conversation", $verbose);
} }
api_register_func('api/direct_messages/conversation','api_direct_messages_conversation',true); api_register_func('api/direct_messages/conversation','api_direct_messages_conversation',true);
api_register_func('api/direct_messages/all','api_direct_messages_all',true); api_register_func('api/direct_messages/all','api_direct_messages_all',true);
@ -3667,95 +3677,6 @@
api_register_func('api/friendica/notification', 'api_friendica_notification', true, API_METHOD_GET); api_register_func('api/friendica/notification', 'api_friendica_notification', true, API_METHOD_GET);
/**
* @brief return direct_messages (similar to direct_messages/all, but additional
* error string returned if no mails available to react in client with notification)
*
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
* @return string (error -> No Mails available, success -> return messages)
*/
function api_friendica_direct_messages_all($type){
$a = get_app();
if (api_user()===false) throw new ForbiddenException();
// params
$count = (x($_GET,'count')?$_GET['count']:20);
$page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
if ($page<0) $page=0;
$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
$max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
$user_id = (x($_REQUEST,'user_id')?$_REQUEST['user_id']:"");
$screen_name = (x($_REQUEST,'screen_name')?$_REQUEST['screen_name']:"");
// caller user info
unset($_REQUEST["user_id"]);
unset($_GET["user_id"]);
unset($_REQUEST["screen_name"]);
unset($_GET["screen_name"]);
$user_info = api_get_user($a);
$profile_url = $user_info["url"];
// pagination
$start = $page*$count;
// filters
$sql_extra = "true";
if ($max_id > 0)
$sql_extra .= ' AND `mail`.`id` <= '.intval($max_id);
if ($user_id !="") {
$sql_extra .= ' AND `mail`.`contact-id` = ' . intval($user_id);
}
elseif($screen_name !=""){
$sql_extra .= " AND `contact`.`nick` = '" . dbesc($screen_name). "'";
}
$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`.`id` DESC LIMIT %d,%d",
intval(api_user()),
intval($since_id),
intval($start), intval($count)
);
// stop execution and return error message if no mails available
if($r == null) {
$answer = array('result' => 'error', 'message' => 'no mails available');
return api_format_data("direct_messages_all", $type, array('$result' => $answer));
}
$ret = Array();
foreach($r as $item) {
if ($box == "inbox" || $item['from-url'] != $profile_url){
$recipient = $user_info;
$sender = api_get_user($a,normalise_link($item['contact-url']));
}
elseif ($box == "sentbox" || $item['from-url'] == $profile_url){
$recipient = api_get_user($a,normalise_link($item['contact-url']));
$sender = $user_info;
}
$ret[]=api_format_messages($item, $recipient, $sender);
}
$data = array('direct-messages' => $ret);
switch($type){
case "atom":
case "rss":
$data = api_rss_extra($a, $data, $user_info);
}
return api_format_data("direct-messages", $type, $data);
}
api_register_func('api/friendica/direct_messages_all', 'api_friendica_direct_messages_all', true);
/** /**
* @brief update a direct_message to seen state * @brief update a direct_message to seen state
* *