fix for #132225. local addressbook searches return (bogus) duplicate results if you have mailing lists.

r=racham, sr=bienvenu, a=asa
This commit is contained in:
sspitzer%netscape.com 2002-03-21 01:59:47 +00:00
Родитель 1769c7a05e
Коммит 24a8669d1b
2 изменённых файлов: 29 добавлений и 30 удалений

Просмотреть файл

@ -134,7 +134,7 @@ NS_IMETHODIMP nsAbDirectoryQuerySimpleBooleanExpression::AgetExpressions(PRUint3
NS_IMPL_THREADSAFE_ISUPPORTS1(nsAbDirectoryQueryArguments, nsIAbDirectoryQueryArguments) NS_IMPL_THREADSAFE_ISUPPORTS1(nsAbDirectoryQueryArguments, nsIAbDirectoryQueryArguments)
nsAbDirectoryQueryArguments::nsAbDirectoryQueryArguments() : nsAbDirectoryQueryArguments::nsAbDirectoryQueryArguments() :
mQuerySubDirectories (PR_TRUE) mQuerySubDirectories(PR_TRUE)
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
} }
@ -162,18 +162,14 @@ NS_IMETHODIMP nsAbDirectoryQueryArguments::SetExpression(nsISupports* aExpressio
/* attribute boolean querySubDirectories; */ /* attribute boolean querySubDirectories; */
NS_IMETHODIMP nsAbDirectoryQueryArguments::GetQuerySubDirectories(PRBool* aQuerySubDirectories) NS_IMETHODIMP nsAbDirectoryQueryArguments::GetQuerySubDirectories(PRBool* aQuerySubDirectories)
{ {
if (!aQuerySubDirectories) NS_ENSURE_ARG_POINTER(aQuerySubDirectories);
return NS_ERROR_NULL_POINTER;
*aQuerySubDirectories = mQuerySubDirectories; *aQuerySubDirectories = mQuerySubDirectories;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsAbDirectoryQueryArguments::SetQuerySubDirectories(PRBool aQuerySubDirectories) NS_IMETHODIMP nsAbDirectoryQueryArguments::SetQuerySubDirectories(PRBool aQuerySubDirectories)
{ {
mQuerySubDirectories = aQuerySubDirectories; mQuerySubDirectories = aQuerySubDirectories;
return NS_OK; return NS_OK;
} }
@ -183,7 +179,7 @@ NS_IMETHODIMP nsAbDirectoryQueryArguments::SetReturnProperties(PRUint32 returnPr
const char** returnPropertiesArray) const char** returnPropertiesArray)
{ {
nsresult rv; nsresult rv;
rv = CharPtrArrayToCStringArray::Convert (mReturnProperties, rv = CharPtrArrayToCStringArray::Convert(mReturnProperties,
returnPropertiesSize, returnPropertiesSize,
returnPropertiesArray); returnPropertiesArray);
@ -387,9 +383,8 @@ nsresult nsAbDirectoryQuery::query (nsIAbDirectory* directory,
PRBool doSubDirectories; PRBool doSubDirectories;
arguments->GetQuerySubDirectories (&doSubDirectories); arguments->GetQuerySubDirectories (&doSubDirectories);
if (doSubDirectories == PR_TRUE && *resultLimit != 0) if (doSubDirectories && *resultLimit != 0) {
{ rv = queryChildren(directory, arguments, listener, resultLimit);
rv = queryChildren (directory, arguments, listener, resultLimit);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
@ -407,7 +402,7 @@ nsresult nsAbDirectoryQuery::queryChildren (nsIAbDirectory* directory,
rv = directory->GetChildNodes(getter_AddRefs(subDirectories)); rv = directory->GetChildNodes(getter_AddRefs(subDirectories));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = subDirectories->First (); rv = subDirectories->First();
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return NS_OK; return NS_OK;
@ -423,7 +418,7 @@ nsresult nsAbDirectoryQuery::queryChildren (nsIAbDirectory* directory,
rv = query (subDirectory, arguments, listener, resultLimit); rv = query (subDirectory, arguments, listener, resultLimit);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = subDirectories->Next (); rv = subDirectories->Next();
} }
while (rv == NS_OK); while (rv == NS_OK);
@ -450,14 +445,14 @@ nsresult nsAbDirectoryQuery::queryCards (nsIAbDirectory* directory,
if (!cards) if (!cards)
return NS_OK; return NS_OK;
rv = cards->First (); rv = cards->First();
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return NS_OK; return NS_OK;
do do
{ {
nsCOMPtr<nsISupports> item; nsCOMPtr<nsISupports> item;
rv = cards->CurrentItem (getter_AddRefs (item)); rv = cards->CurrentItem(getter_AddRefs(item));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbCard> card(do_QueryInterface(item, &rv)); nsCOMPtr<nsIAbCard> card(do_QueryInterface(item, &rv));

Просмотреть файл

@ -408,7 +408,7 @@ NS_IMETHODIMP nsAbMDBDirectory::GetChildCards(nsIEnumerator* *result)
if (mIsQueryURI) if (mIsQueryURI)
{ {
nsresult rv; nsresult rv;
rv = StartSearch (); rv = StartSearch();
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// TODO // TODO
@ -416,7 +416,7 @@ NS_IMETHODIMP nsAbMDBDirectory::GetChildCards(nsIEnumerator* *result)
// results after search is complete // results after search is complete
nsCOMPtr<nsISupportsArray> array; nsCOMPtr<nsISupportsArray> array;
NS_NewISupportsArray(getter_AddRefs(array)); NS_NewISupportsArray(getter_AddRefs(array));
mSearchCache.Enumerate (enumerateSearchCache, (void* )array); mSearchCache.Enumerate(enumerateSearchCache, (void*)array);
return array->Enumerate(result); return array->Enumerate(result);
} }
@ -912,31 +912,36 @@ NS_IMETHODIMP nsAbMDBDirectory::StartSearch()
nsresult rv; nsresult rv;
mPerformingQuery = PR_TRUE; mPerformingQuery = PR_TRUE;
mSearchCache.Reset (); mSearchCache.Reset();
nsCOMPtr<nsIAbDirectoryQueryArguments> arguments = do_CreateInstance(NS_ABDIRECTORYQUERYARGUMENTS_CONTRACTID,&rv); nsCOMPtr<nsIAbDirectoryQueryArguments> arguments = do_CreateInstance(NS_ABDIRECTORYQUERYARGUMENTS_CONTRACTID,&rv);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbBooleanExpression> expression; nsCOMPtr<nsIAbBooleanExpression> expression;
rv = nsAbQueryStringToExpression::Convert (mQueryString.get (), rv = nsAbQueryStringToExpression::Convert(mQueryString.get(),
getter_AddRefs(expression)); getter_AddRefs(expression));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = arguments->SetExpression (expression); rv = arguments->SetExpression(expression);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Set the return properties to // Set the return properties to
// return nsIAbCard interfaces // return nsIAbCard interfaces
nsCStringArray properties; nsCStringArray properties;
properties.AppendCString (nsCAutoString ("card:nsIAbCard")); properties.AppendCString(nsCAutoString("card:nsIAbCard"));
CharPtrArrayGuard returnProperties (PR_FALSE); CharPtrArrayGuard returnProperties(PR_FALSE);
rv = CStringArrayToCharPtrArray::Convert (properties,returnProperties.GetSizeAddr(), rv = CStringArrayToCharPtrArray::Convert(properties,returnProperties.GetSizeAddr(),
returnProperties.GetArrayAddr(), PR_FALSE); returnProperties.GetArrayAddr(), PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = arguments->SetReturnProperties (returnProperties.GetSize(), returnProperties.GetArray()); rv = arguments->SetReturnProperties(returnProperties.GetSize(), returnProperties.GetArray());
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = arguments->SetQuerySubDirectories (PR_TRUE); // don't search the subdirectories
// if the current directory is a mailing list, it won't have any subdirectories
// if the current directory is a addressbook, searching both it
// and the subdirectories (the mailing lists), will yield duplicate results
// because every entry in a mailing list will be an entry in the parent addressbook
rv = arguments->SetQuerySubDirectories(PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Set the the query listener // Set the the query listener
@ -945,24 +950,23 @@ NS_IMETHODIMP nsAbMDBDirectory::StartSearch()
new nsAbDirSearchListener (this); new nsAbDirSearchListener (this);
queryListener = _queryListener; queryListener = _queryListener;
// Get the directory without the query // Get the directory without the query
nsCOMPtr<nsIRDFResource> resource; nsCOMPtr<nsIRDFResource> resource;
rv = gRDFService->GetResource (mURINoQuery.get (), getter_AddRefs (resource)); rv = gRDFService->GetResource (mURINoQuery.get(), getter_AddRefs(resource));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbDirectory> directory (do_QueryInterface(resource, &rv)); nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(resource, &rv));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Initiate the proxy query with the no query directory // Initiate the proxy query with the no query directory
nsCOMPtr<nsIAbDirectoryQueryProxy> queryProxy = nsCOMPtr<nsIAbDirectoryQueryProxy> queryProxy =
do_CreateInstance (NS_ABDIRECTORYQUERYPROXY_CONTRACTID, &rv); do_CreateInstance(NS_ABDIRECTORYQUERYPROXY_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = queryProxy->Initiate (directory); rv = queryProxy->Initiate(directory);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = queryProxy->DoQuery (arguments, queryListener, -1, 0, &mContext); rv = queryProxy->DoQuery(arguments, queryListener, -1, 0, &mContext);
return NS_OK; return NS_OK;
} }