mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-21 13:58:26 +00:00
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:
parent
e8b947dfde
commit
33d466a5cc
@ -32,6 +32,8 @@ import android.support.v4.content.CursorLoader;
|
|||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
import android.telephony.PhoneNumberUtils;
|
import android.telephony.PhoneNumberUtils;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||||
import org.thoughtcrime.securesms.database.TextSecureDirectory;
|
import org.thoughtcrime.securesms.database.TextSecureDirectory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -39,6 +41,8 @@ import java.util.Collection;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class was originally a layer of indirection between
|
* This class was originally a layer of indirection between
|
||||||
* ContactAccessorNewApi and ContactAccesorOldApi, which corresponded
|
* ContactAccessorNewApi and ContactAccesorOldApi, which corresponded
|
||||||
@ -215,12 +219,12 @@ public class ContactAccessor {
|
|||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getNumbersForThreadSearchFilter(String constraint, ContentResolver contentResolver) {
|
public List<String> getNumbersForThreadSearchFilter(Context context, String constraint) {
|
||||||
LinkedList<String> numberList = new LinkedList<String>();
|
LinkedList<String> numberList = new LinkedList<>();
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = contentResolver.query(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI,
|
cursor = context.getContentResolver().query(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI,
|
||||||
Uri.encode(constraint)),
|
Uri.encode(constraint)),
|
||||||
null, null, null, null);
|
null, null, null, null);
|
||||||
|
|
||||||
@ -233,6 +237,20 @@ public class ContactAccessor {
|
|||||||
cursor.close();
|
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;
|
return numberList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +79,14 @@ public class GroupDatabase extends Database {
|
|||||||
return record;
|
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) {
|
public Recipients getGroupMembers(byte[] groupId, boolean includeSelf) {
|
||||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||||
List<String> members = getCurrentMembers(groupId);
|
List<String> members = getCurrentMembers(groupId);
|
||||||
@ -296,6 +304,10 @@ public class GroupDatabase extends Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEncodedId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class ConversationListLoader extends AbstractCursorLoader {
|
|||||||
public Cursor getCursor() {
|
public Cursor getCursor() {
|
||||||
if (filter != null && filter.trim().length() != 0) {
|
if (filter != null && filter.trim().length() != 0) {
|
||||||
List<String> numbers = ContactAccessor.getInstance()
|
List<String> numbers = ContactAccessor.getInstance()
|
||||||
.getNumbersForThreadSearchFilter(filter, context.getContentResolver());
|
.getNumbersForThreadSearchFilter(filter, context);
|
||||||
|
|
||||||
return DatabaseFactory.getThreadDatabase(context).getFilteredConversationList(numbers);
|
return DatabaseFactory.getThreadDatabase(context).getFilteredConversationList(numbers);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user