From f985cbedc6ae5518fa490612e36ea18a19b4604e Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 25 Feb 2015 09:46:51 -0500
Subject: [PATCH] Fix duplicate entries supression in autocomplete result (#1490290)
---
CHANGELOG | 1 +
program/steps/mail/autocomplete.inc | 52 ++++++++++++++++++++++++++++++----------------------
2 files changed, 31 insertions(+), 22 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index e6f287d..5e8a651 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -15,6 +15,7 @@
- Fix fatal errors on systems without mbstring extension or mb_regex_encoding() function (#1490280)
- Fix cursor position on reply below the quote in HTML mode (#1490263)
- Fix so "over quota" errors are displayed also in message compose page
+- Fix duplicate entries supression in autocomplete result (#1490290)
RELEASE 1.1.0
-------------
diff --git a/program/steps/mail/autocomplete.inc b/program/steps/mail/autocomplete.inc
index 30b8f22..38501eb 100644
--- a/program/steps/mail/autocomplete.inc
+++ b/program/steps/mail/autocomplete.inc
@@ -88,16 +88,18 @@
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,32 +126,38 @@
if ($group_prop['email']) {
$idx = 0;
foreach ((array)$group_prop['email'] as $email) {
- $contacts[] = array(
- 'name' => format_email_recipient($email, $group['name']),
- 'email' => $email,
- 'type' => 'group',
- 'id' => $group['ID'],
- 'source' => $id,
- );
- $sort_keys[] = sprintf('%s %03d', $group['name'] , $idx++);
+ $index = format_email_recipient($email, $group['name']);
- if (count($contacts) >= $MAXNUM) {
- break 2;
+ 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) {
- $sort_keys[] = $group['name'];
- $contacts[] = array(
- 'name' => $group['name'] . ' (' . intval($result->count) . ')',
- 'type' => 'group',
- 'id' => $group['ID'],
- 'source' => $id
- );
+ 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
+ );
- if (count($contacts) >= $MAXNUM) {
- break;
+ if (count($contacts) >= $MAXNUM) {
+ break;
+ }
}
}
}
--
Gitblit v1.9.1