diff options
author | Aleksander Machniak <alec@alec.pl> | 2015-02-25 09:45:57 -0500 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2015-02-25 09:45:57 -0500 |
commit | e1c8fe5c4a0f30cd36069e3460ac937282fb8e1a (patch) | |
tree | b0aace4d057b7dd0686134db6c8a08f28fa736b1 /program/steps | |
parent | 83f1f6b12fb5405ca598322e09b3ccd0842ccc85 (diff) |
Fix duplicate entries supression in autocomplete result (#1490290)
Diffstat (limited to 'program/steps')
-rw-r--r-- | program/steps/mail/autocomplete.inc | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/program/steps/mail/autocomplete.inc b/program/steps/mail/autocomplete.inc index 30b8f2299..38501eb9d 100644 --- a/program/steps/mail/autocomplete.inc +++ b/program/steps/mail/autocomplete.inc @@ -88,16 +88,18 @@ if (!empty($book_types) && strlen($search)) { continue; } + $index = $contact; + // skip duplicates - if (!in_array($contact, $contacts)) { + if (empty($contacts[$index])) { $contact = array('name' => $contact, 'type' => $sql_arr['_type']); if (($display = rcube_addressbook::compose_search_name($sql_arr, $email, $name)) && $display != $contact['name']) { $contact['display'] = $display; } - $contacts[] = $contact; - $sort_keys[] = sprintf('%s %03d', $contact['display'] ?: $name, $idx++); + $contacts[$index] = $contact; + $sort_keys[$index] = sprintf('%s %03d', $contact['display'] ?: $name, $idx++); if (count($contacts) >= $MAXNUM) { break 2; @@ -124,34 +126,40 @@ if (!empty($book_types) && strlen($search)) { if ($group_prop['email']) { $idx = 0; foreach ((array)$group_prop['email'] as $email) { - $contacts[] = array( - 'name' => format_email_recipient($email, $group['name']), - 'email' => $email, + $index = format_email_recipient($email, $group['name']); + + if (empty($contacts[$index])) { + $sort_keys[$index] = sprintf('%s %03d', $group['name'] , $idx++); + $contacts[$index] = array( + 'name' => $index, + 'email' => $email, + 'type' => 'group', + 'id' => $group['ID'], + 'source' => $id, + ); + + if (count($contacts) >= $MAXNUM) { + break 2; + } + } + } + } + // show group with count + else if (($result = $abook->count()) && $result->count) { + if (empty($contacts[$group['name']])) { + $sort_keys[$group['name']] = $group['name']; + $contacts[$group['name']] = array( + 'name' => $group['name'] . ' (' . intval($result->count) . ')', 'type' => 'group', 'id' => $group['ID'], - 'source' => $id, + 'source' => $id ); - $sort_keys[] = sprintf('%s %03d', $group['name'] , $idx++); if (count($contacts) >= $MAXNUM) { - break 2; + break; } } } - // show group with count - else if (($result = $abook->count()) && $result->count) { - $sort_keys[] = $group['name']; - $contacts[] = array( - 'name' => $group['name'] . ' (' . intval($result->count) . ')', - 'type' => 'group', - 'id' => $group['ID'], - 'source' => $id - ); - - if (count($contacts) >= $MAXNUM) { - break; - } - } } } } |