]> git.mxchange.org Git - friendica.git/commitdiff
api: allow filter of direct messages sender by `user_id` or `screen_name`
authorFabrixxm <fabrix.xm@gmail.com>
Thu, 23 Oct 2014 06:59:48 +0000 (08:59 +0200)
committerFabrixxm <fabrix.xm@gmail.com>
Thu, 23 Oct 2014 06:59:48 +0000 (08:59 +0200)
include/api.php

index e22fb9d74ad9fac4e4cebd87e122f5c895108a3c..69095aec10a05b52a7a4f2a7ed8607daf3c2bea4 100644 (file)
        function api_direct_messages_box(&$a, $type, $box) {
                if (api_user()===false) return false;
 
-               unset($_REQUEST["user_id"]);
-               unset($_GET["user_id"]);
-
-               unset($_REQUEST["screen_name"]);
-               unset($_GET["screen_name"]);
-
-               $user_info = api_get_user($a);
 
                // params
                $count = (x($_GET,'count')?$_GET['count']:20);
                $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
                $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
 
-               $start = $page*$count;
+               $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 = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
                $profile_url = $user_info["url"];
 
+
+               // pagination
+               $start = $page*$count;
+
+               // filters
                if ($box=="sentbox") {
                        $sql_extra = "`mail`.`from-url`='".dbesc( $profile_url )."'";
                }
                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)
                );
+       
 
                $ret = Array();
                foreach($r as $item) {
                        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);
                }