Autocomplete now matches remote profiles as well.

This commit is contained in:
Mikael Nordfeldth 2014-02-23 20:12:01 +01:00
parent 862a2dab3f
commit 834ecd0f80

View File

@ -2,7 +2,7 @@
/** /**
* StatusNet, the distributed open-source microblogging tool * StatusNet, the distributed open-source microblogging tool
* *
* List users for autocompletion * List profiles and groups for autocompletion
* *
* PHP version 5 * PHP version 5
* *
@ -29,7 +29,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { if (!defined('GNUSOCIAL') && !defined('STATUSNET')) {
exit(1); exit(1);
} }
@ -62,8 +62,8 @@ class AutocompleteAction extends Action
function lastModified() function lastModified()
{ {
$max=0; $max=0;
foreach($this->users as $user){ foreach($this->profiles as $profile){
$max = max($max,strtotime($user->modified),strtotime($user->getProfile()->modified)); $max = max($max,strtotime($user->modified),strtotime($profile->modified));
} }
foreach($this->groups as $group){ foreach($this->groups as $group){
$max = max($max,strtotime($group->modified)); $max = max($max,strtotime($group->modified));
@ -103,19 +103,22 @@ class AutocompleteAction extends Action
} }
$this->groups=array(); $this->groups=array();
$this->users=array(); $this->profiles=array();
$term = $this->arg('term'); $term = $this->arg('term');
$limit = $this->arg('limit'); $limit = $this->arg('limit');
if($limit > 200) $limit=200; //prevent DOS attacks if($limit > 200) $limit=200; //prevent DOS attacks
if(substr($term,0,1)=='@'){ if(substr($term,0,1)=='@'){
//user search //profile search
$term=substr($term,1); $term=substr($term,1);
$user = new User(); $profile = new Profile();
$user->limit($limit); $profile->limit($limit);
$user->whereAdd('nickname like \'' . trim($user->escape($term), '\'') . '%\''); $profile->whereAdd('nickname like \'' . trim($profile->escape($term), '\'') . '%\'');
if($user->find()){ $profile->whereAdd(sprintf('id in (SELECT id FROM user) OR '
while($user->fetch()) { . 'id in (SELECT subscribed from subscription'
$this->users[]=clone($user); . ' where subscriber = %d)', $cur->id));
if ($profile->find()) {
while($profile->fetch()) {
$this->profiles[]=clone($profile);
} }
} }
} }
@ -139,8 +142,7 @@ class AutocompleteAction extends Action
parent::handle(); parent::handle();
$results = array(); $results = array();
foreach($this->users as $user){ foreach($this->profiles as $profile){
$profile = $user->getProfile();
$avatarUrl = $profile->avatarUrl(AVATAR_MINI_SIZE); $avatarUrl = $profile->avatarUrl(AVATAR_MINI_SIZE);
$results[] = array( $results[] = array(
'value' => '@'.$profile->nickname, 'value' => '@'.$profile->nickname,