Include group titles in search

When searching for messages only simple threads matching the
contact names are returned as search results. With this commit
also group converstations where the group title matches the search
term are displayed in the result. This makes search results more
consistent with the conversation list as now all conversation
titles (i.e. contact names and group titles) are searched through.

Fixes #1954
Closes #2216
This commit is contained in:
Oliver Gasser 2014-12-14 14:53:56 +01:00 committed by Moxie Marlinspike
parent e8b947dfde
commit 33d466a5cc
3 changed files with 36 additions and 6 deletions

View File

@ -32,6 +32,8 @@ import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.telephony.PhoneNumberUtils;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.GroupDatabase;
import org.thoughtcrime.securesms.database.TextSecureDirectory;
import java.util.ArrayList;
@ -39,6 +41,8 @@ import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import static org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
/**
* This class was originally a layer of indirection between
* ContactAccessorNewApi and ContactAccesorOldApi, which corresponded
@ -215,14 +219,14 @@ public class ContactAccessor {
return contacts;
}
public List<String> getNumbersForThreadSearchFilter(String constraint, ContentResolver contentResolver) {
LinkedList<String> numberList = new LinkedList<String>();
public List<String> getNumbersForThreadSearchFilter(Context context, String constraint) {
LinkedList<String> numberList = new LinkedList<>();
Cursor cursor = null;
try {
cursor = contentResolver.query(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI,
Uri.encode(constraint)),
null, null, null, null);
cursor = context.getContentResolver().query(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI,
Uri.encode(constraint)),
null, null, null, null);
while (cursor != null && cursor.moveToNext()) {
numberList.add(cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER)));
@ -233,6 +237,20 @@ public class ContactAccessor {
cursor.close();
}
GroupDatabase.Reader reader = null;
GroupRecord record;
try {
reader = DatabaseFactory.getGroupDatabase(context).getGroupsFilteredByTitle(constraint);
while ((record = reader.getNext()) != null) {
numberList.add(record.getEncodedId());
}
} finally {
if (reader != null)
reader.close();
}
return numberList;
}

View File

@ -79,6 +79,14 @@ public class GroupDatabase extends Database {
return record;
}
public Reader getGroupsFilteredByTitle(String constraint) {
Cursor cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, null, TITLE + " LIKE ?",
new String[]{"%" + constraint + "%"},
null, null, null);
return new Reader(cursor);
}
public Recipients getGroupMembers(byte[] groupId, boolean includeSelf) {
String localNumber = TextSecurePreferences.getLocalNumber(context);
List<String> members = getCurrentMembers(groupId);
@ -296,6 +304,10 @@ public class GroupDatabase extends Database {
}
}
public String getEncodedId() {
return id;
}
public String getTitle() {
return title;
}

View File

@ -22,7 +22,7 @@ public class ConversationListLoader extends AbstractCursorLoader {
public Cursor getCursor() {
if (filter != null && filter.trim().length() != 0) {
List<String> numbers = ContactAccessor.getInstance()
.getNumbersForThreadSearchFilter(filter, context.getContentResolver());
.getNumbersForThreadSearchFilter(filter, context);
return DatabaseFactory.getThreadDatabase(context).getFilteredConversationList(numbers);
} else {