]> git.mxchange.org Git - friendica.git/blobdiff - include/acl_selectors.php
Merge pull request #3343 from annando/1704-mastodon
[friendica.git] / include / acl_selectors.php
index fccdb80665974f98df95047592697052c5ecd222..f2d2999ba6175341ef254b4754e29f0f4b9c0083 100644 (file)
@@ -495,12 +495,14 @@ function acl_lookup(App $a, $out_type = 'json') {
 
        if ($type=='' || $type=='g'){
 
+               /// @todo We should cache this query.
+               // This can be done when we can delete cache entries via wildcard
                $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') AS uids
                                FROM `group`
                                INNER JOIN `group_member` ON `group_member`.`gid`=`group`.`id` AND `group_member`.`uid` = `group`.`uid`
                                WHERE NOT `group`.`deleted` AND `group`.`uid` = %d
                                        $sql_extra
-                               GROUP BY `group`.`name`
+                               GROUP BY `group`.`name`, `group`.`id`
                                ORDER BY `group`.`name`
                                LIMIT %d,%d",
                        intval(local_user()),
@@ -608,46 +610,50 @@ function acl_lookup(App $a, $out_type = 'json') {
        $items = array_merge($groups, $contacts);
 
        if ($conv_id) {
-               /* if $conv_id is set, get unknow contacts in thread */
-               /* but first get know contacts url to filter them out */
-               function _contact_link($i){ return dbesc($i['link']); }
-               $known_contacts = array_map(_contact_link, $contacts);
-               $unknow_contacts=array();
-               $r = q("SELECT `author-avatar`,`author-name`,`author-link`
+               /*
+                * if $conv_id is set, get unknown contacts in thread
+                * but first get known contacts url to filter them out
+                */
+               $known_contacts = array_map(
+                       function ($i) {
+                               return dbesc($i['link']);
+                       }
+               , $contacts);
+
+               $unknown_contacts = array();
+               $r = q("SELECT `author-link`
                                FROM `item` WHERE `parent` = %d
                                        AND (`author-name` LIKE '%%%s%%' OR `author-link` LIKE '%%%s%%')
                                        AND `author-link` NOT IN ('%s')
-                               GROUP BY `author-link`
+                               GROUP BY `author-link`, `author-avatar`, `author-name`
                                ORDER BY `author-name` ASC
                                ",
                                intval($conv_id),
                                dbesc($search),
                                dbesc($search),
-                               implode("','", $known_contacts)
+                               implode("', '", $known_contacts)
                );
-               if (dbm::is_result($r)){
+               if (dbm::is_result($r)) {
                        foreach ($r as $row) {
-                               // nickname..
-                               $up = parse_url($row['author-link']);
-                               $nick = explode("/",$up['path']);
-                               $nick = $nick[count($nick)-1];
-                               $nick .= "@".$up['host'];
-                               // /nickname
-                               $unknow_contacts[] = array(
-                                       'type'    => 'c',
-                                       'photo'   => proxy_url($row['author-avatar'], false, PROXY_SIZE_MICRO),
-                                       'name'    => htmlentities($row['author-name']),
-                                       'id'      => '',
-                                       'network' => 'unknown',
-                                       'link'    => $row['author-link'],
-                                       'nick'    => htmlentities($nick),
-                                       'forum'   => false
-                               );
+                               $contact = get_contact_details_by_url($row['author-link']);
+
+                               if (count($contact) > 0) {
+                                       $unknown_contacts[] = array(
+                                               'type'    => 'c',
+                                               'photo'   => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
+                                               'name'    => htmlentities($contact['name']),
+                                               'id'      => intval($contact['cid']),
+                                               'network' => $contact['network'],
+                                               'link'    => $contact['url'],
+                                               'nick'    => htmlentities($contact['nick'] ? : $contact['addr']),
+                                               'forum'   => $contact['forum']
+                                       );
+                               }
                        }
                }
 
-               $items = array_merge($items, $unknow_contacts);
-               $tot += count($unknow_contacts);
+               $items = array_merge($items, $unknown_contacts);
+               $tot += count($unknown_contacts);
        }
 
        $results = array(