- * @brief same as api_format_messages, but output extended by seen and parent-uri as needed
- * in Windows 10 client
- *
- * @param array $item
- * @param array $recipient
- * @param array $sender
- * @return array $ret
- */
- function api_format_messages_win($item, $recipient, $sender) {
- // standard meta information
- $ret=Array(
- 'id' => $item['id'],
- 'sender_id' => $sender['id'] ,
- 'text' => "",
- 'recipient_id' => $recipient['id'],
- 'created_at' => api_date($item['created']),
- 'sender_screen_name' => $sender['screen_name'],
- 'recipient_screen_name' => $recipient['screen_name'],
- 'sender' => $sender,
- 'recipient' => $recipient,
- 'title' => "",
- 'seen' => $item['seen'],
- 'parent_uri' => $item['parent-uri'],
- );
-
- // "uid" and "self" are only needed for some internal stuff, so remove it from here
- unset($ret["sender"]["uid"]);
- unset($ret["sender"]["self"]);
- unset($ret["recipient"]["uid"]);
- unset($ret["recipient"]["self"]);
-
- //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'], false, false);
- }
- elseif ($_GET["getText"] == "plain") {
- $ret['text'] = trim(html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 2, true), 0));
- }
- }
- else {
- $ret['text'] = $item['title']."\n".html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 2, true), 0);
- }
- if (isset($_GET["getUserObjects"]) && $_GET["getUserObjects"] == "false") {
- unset($ret['sender']);
- unset($ret['recipient']);
- }
-
- return $ret;
- }
-
- /**
- * @brief return direct_messages for Windows 10 App (similar to direct_messages/all, but seen
- * and parent-uri added to output
- *
- * @param App $a
- * @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
- * @return string
- */
- 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_win($item, $recipient, $sender);
- }
-
-
- $data = array('$messages' => $ret);
- switch($type){
- case "atom":
- case "rss":
- $data = api_rss_extra($a, $data, $user_info);
- }
-
- return api_format_data("direct_messages_all", $type, $data);
-
- }
- api_register_func('api/friendica/direct_messages_all', 'api_friendica_direct_messages_all', true);
-
-
- /**
- * @brief update a direct_message to seen state for Windows 10 App