moved api direct message formating to own function.

added same formating to direct reply message, when posting a new message.
This commit is contained in:
Sebastian Egbers 2012-06-26 08:54:01 +02:00
parent 0f0fb2e2f3
commit 587b081a38

View file

@ -1238,6 +1238,40 @@
return($as); return($as);
} }
function api_format_messages($item, $recipient, $sender) {
// standard meta information
$ret=Array(
'id' => $item['id'],
'created_at' => api_date($item['created']),
'sender_id' => $sender['id'] ,
'sender_screen_name' => $sender['screen_name'],
'sender' => $sender,
'recipient_id' => $recipient['id'],
'recipient_screen_name' => $recipient['screen_name'],
'recipient' => $recipient,
);
//don't send title to regular StatusNET requests to avoid confusing these apps
if (x($_GET, 'getText')) {
$ret['title'] = $item['title'] ;
if ($_GET["getText"] == "html") {
$ret['text'] = bbcode($item['body']);
}
elseif ($_GET["getText"] == "plain") {
$ret['text'] = html2plain(bbcode($item['body']), 0);
}
}
else {
$ret['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0);
}
if (isset($_GET["getUserObjects"]) && $_GET["getUserObjects"] == "false") {
unset($ret['sender']);
unset($ret['recipient']);
}
return $ret;
}
function api_format_items($r,$user_info) { function api_format_items($r,$user_info) {
//logger('api_format_items: ' . print_r($r,true)); //logger('api_format_items: ' . print_r($r,true));
@ -1546,20 +1580,7 @@
if ($id>-1) { if ($id>-1) {
$r = q("SELECT * FROM `mail` WHERE id=%d", intval($id)); $r = q("SELECT * FROM `mail` WHERE id=%d", intval($id));
$item = $r[0]; $ret = api_format_messages($r[0], $recipient, $sender);
$ret=Array(
'id' => $item['id'],
'created_at'=> api_date($item['created']),
'sender_id'=> $sender['id'] ,
'sender_screen_name'=> $sender['screen_name'],
'sender'=> $sender,
'recipient_id'=> $recipient['id'],
'recipient_screen_name'=> $recipient['screen_name'],
'recipient'=> $recipient,
'text'=> $item['title']."\n".html2plain(bbcode($item['body']), 0) ,
);
} else { } else {
$ret = array("error"=>$id); $ret = array("error"=>$id);
@ -1578,7 +1599,7 @@
} }
api_register_func('api/direct_messages/new','api_direct_messages_new',true); api_register_func('api/direct_messages/new','api_direct_messages_new',true);
function api_direct_messages_box(&$a, $type, $box) { function api_direct_messages_box(&$a, $type, $box) {
if (local_user()===false) return false; if (local_user()===false) return false;
$user_info = api_get_user($a); $user_info = api_get_user($a);
@ -1590,14 +1611,17 @@
$start = $page*$count; $start = $page*$count;
$profile_url = $a->get_baseurl() . '/profile/' . $a->user['nickname']; $profile_url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
if ($box=="sentbox") { if ($box=="sentbox") {
$sql_extra = "`from-url`='".dbesc( $profile_url )."'"; $sql_extra = "`from-url`='".dbesc( $profile_url )."'";
} elseif ($box=="conversation") { }
$sql_extra = "`parent-uri`='".dbesc( $_GET["uri"] ) ."'"; elseif ($box=="conversation") {
} elseif ($box=="all") { $sql_extra = "`parent-uri`='".dbesc( $_GET["uri"] ) ."'";
$sql_extra = "true"; }
} elseif ($box=="inbox") { elseif ($box=="all") {
$sql_extra = "true";
}
elseif ($box=="inbox") {
$sql_extra = "`from-url`!='".dbesc( $profile_url )."'"; $sql_extra = "`from-url`!='".dbesc( $profile_url )."'";
} }
@ -1607,41 +1631,17 @@
); );
$ret = Array(); $ret = Array();
foreach($r as $item){ foreach($r as $item) {
if ($box == "inbox" || $item['from-url'] != $profile_url){ if ($box == "inbox" || $item['from-url'] != $profile_url){
$recipient = $user_info; $recipient = $user_info;
$sender = api_get_user($a,$item['contact-id']); $sender = api_get_user($a,$item['contact-id']);
} elseif ($box == "sentbox" || $item['from-url'] != $profile_url){ }
$recipient = api_get_user($a,$item['contact-id']); elseif ($box == "sentbox" || $item['from-url'] != $profile_url){
$sender = $user_info; $recipient = api_get_user($a,$item['contact-id']);
$sender = $user_info;
} }
$d=Array( $ret[]=api_format_messages($item, $recipient, $sender);
'id' => $item['id'],
'created_at'=> api_date($item['created']),
'sender_id'=> $sender['id'] ,
'sender_screen_name'=> $sender['screen_name'],
'sender_profile_img'=> $item['from-photo'],
'sender'=> $sender,
'recipient_id'=> $recipient['id'],
'recipient_screen_name'=> $recipient['screen_name'],
'recipient'=> $recipient,
);
//don't send title to regular StatusNET requests to avoid confusing these apps
if (isset($_GET["getText"])) {
$d['title'] = $item['title'] ;
if ($_GET["getText"] == "html") {
$d['text'] = bbcode($item['body']);
} elseif ($_GET["getText"] == "plain") {
$d['text'] = html2plain(bbcode($item['body']), 0);
}
} else {
$d['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0);
}
if (isset($_GET["getUserObjects"]) && $_GET["getUserObjects"] == "false") {
unset($d['sender']); unset($d['recipient']);
}
$ret[]=$d;
} }