Improve the ordering of conversation search results.

fork-5.53.8
Greyson Parrelli 2022-08-25 12:15:02 -04:00
rodzic cdad45096b
commit 497b38ddbf
2 zmienionych plików z 26 dodań i 9 usunięć

Wyświetl plik

@ -602,7 +602,7 @@ public class ThreadDatabase extends Database {
selectionArgs[i++] = recipientId.serialize(); selectionArgs[i++] = recipientId.serialize();
} }
String query = createQuery(selection, 0); String query = createQuery(selection, DATE + " DESC", 0, 0);
cursors.add(db.rawQuery(query, selectionArgs)); cursors.add(db.rawQuery(query, selectionArgs));
} }

Wyświetl plik

@ -35,8 +35,12 @@ import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.concurrent.SerialExecutor; import org.thoughtcrime.securesms.util.concurrent.SerialExecutor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -159,33 +163,46 @@ public class SearchRepository {
return Collections.emptyList(); return Collections.emptyList();
} }
Set<RecipientId> recipientIds = new LinkedHashSet<>();
Set<RecipientId> filteredContacts = new LinkedHashSet<>(); Set<RecipientId> filteredContacts = new LinkedHashSet<>();
try (Cursor cursor = SignalDatabase.recipients().queryAllContacts(query)) { try (Cursor cursor = SignalDatabase.recipients().queryAllContacts(query)) {
while (cursor != null && cursor.moveToNext()) { while (cursor != null && cursor.moveToNext()) {
filteredContacts.add(RecipientId.from(CursorUtil.requireString(cursor, RecipientDatabase.ID))); filteredContacts.add(RecipientId.from(CursorUtil.requireString(cursor, RecipientDatabase.ID)));
} }
} }
recipientIds.addAll(filteredContacts);
Set<RecipientId> contactIds = new LinkedHashSet<>(filteredContacts);
if (noteToSelfTitle.toLowerCase().contains(query.toLowerCase())) {
contactIds.add(Recipient.self().getId());
}
Set<RecipientId> groupsByTitleIds = new LinkedHashSet<>();
GroupDatabase.GroupRecord record; GroupDatabase.GroupRecord record;
try (GroupDatabase.Reader reader = SignalDatabase.groups().queryGroupsByTitle(query, true, false, false)) { try (GroupDatabase.Reader reader = SignalDatabase.groups().queryGroupsByTitle(query, true, false, false)) {
while ((record = reader.getNext()) != null) { while ((record = reader.getNext()) != null) {
recipientIds.add(record.getRecipientId()); groupsByTitleIds.add(record.getRecipientId());
} }
} }
Set<RecipientId> groupsByMemberIds = new LinkedHashSet<>();
try (GroupDatabase.Reader reader = SignalDatabase.groups().queryGroupsByMembership(filteredContacts, true, false, false)) { try (GroupDatabase.Reader reader = SignalDatabase.groups().queryGroupsByMembership(filteredContacts, true, false, false)) {
while ((record = reader.getNext()) != null) { while ((record = reader.getNext()) != null) {
recipientIds.add(record.getRecipientId()); groupsByMemberIds.add(record.getRecipientId());
} }
} }
if (noteToSelfTitle.toLowerCase().contains(query.toLowerCase())) { List<ThreadRecord> output = new ArrayList<>(contactIds.size() + groupsByTitleIds.size() + groupsByMemberIds.size());
recipientIds.add(Recipient.self().getId());
}
output.addAll(getMatchingThreads(contactIds));
output.addAll(getMatchingThreads(groupsByTitleIds));
output.addAll(getMatchingThreads(groupsByMemberIds));
return output;
}
private List<ThreadRecord> getMatchingThreads(@NonNull Collection<RecipientId> recipientIds) {
try (Cursor cursor = threadDatabase.getFilteredConversationList(new ArrayList<>(recipientIds))) { try (Cursor cursor = threadDatabase.getFilteredConversationList(new ArrayList<>(recipientIds))) {
return readToList(cursor, new ThreadModelBuilder(threadDatabase)); return readToList(cursor, new ThreadModelBuilder(threadDatabase));
} }