mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Working fix push before cleanup
This commit is contained in:
parent
88ceffeee2
commit
cfe2dbca7b
@ -2066,8 +2066,11 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
}
|
||||
|
||||
fun onSearchQueryUpdated(query: String) {
|
||||
Log.d("[ACL]", "1")
|
||||
searchViewModel.onQueryUpdated(query, viewModel.threadId)
|
||||
Log.d("[ACL]", "2")
|
||||
binding?.searchBottomBar?.showLoading()
|
||||
Log.d("[ACL]", "3")
|
||||
adapter.onSearchQueryUpdated(query)
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ import kotlinx.coroutines.launch
|
||||
import network.loki.messenger.R
|
||||
import network.loki.messenger.databinding.ViewVisibleMessageBinding
|
||||
import org.session.libsession.messaging.contacts.Contact
|
||||
import org.session.libsignal.utilities.Log
|
||||
import org.thoughtcrime.securesms.conversation.v2.messages.ControlMessageView
|
||||
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageView
|
||||
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageViewDelegate
|
||||
@ -268,7 +269,9 @@ class ConversationAdapter(
|
||||
}
|
||||
|
||||
fun onSearchQueryUpdated(query: String?) {
|
||||
Log.d("[ACL]", "4")
|
||||
this.searchQuery = query
|
||||
Log.d("[ACL]", "5")
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
|
@ -127,8 +127,7 @@ object ConversationMenuHelper {
|
||||
override fun onQueryTextChange(query: String): Boolean {
|
||||
|
||||
// *** Crashes when searching for non-alphanumeric first char ***
|
||||
Log.d("[ACL]", "THIS ONE - CMH search query changed to: $query")
|
||||
|
||||
Log.d("[ACL]", "[ConversationMenuHelper] Query text changed to: $query")
|
||||
|
||||
context.onSearchQueryUpdated(query)
|
||||
return true
|
||||
|
@ -10,6 +10,7 @@ import com.annimon.stream.Stream;
|
||||
import net.zetetic.database.sqlcipher.SQLiteDatabase;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsignal.utilities.Log;
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
|
||||
import java.util.List;
|
||||
@ -118,6 +119,8 @@ public class SearchDatabase extends Database {
|
||||
|
||||
int queryLimit = Math.min(query.length()*50,500);
|
||||
|
||||
Log.d("[ACL]", "[SearchDatabase] Query is:\n" + MESSAGES_QUERY);
|
||||
|
||||
Cursor cursor = db.rawQuery(MESSAGES_QUERY, new String[] { prefixQuery, prefixQuery, String.valueOf(queryLimit) });
|
||||
setNotifyConverationListListeners(cursor);
|
||||
return cursor;
|
||||
|
@ -95,6 +95,16 @@ public class SearchRepository {
|
||||
Stopwatch timer = new Stopwatch("FtsQuery");
|
||||
|
||||
String cleanQuery = sanitizeQuery(query);
|
||||
|
||||
// If the search is for a single character and it was stripped by `sanitizeQuery` then abort
|
||||
// the search for an empty string to avoid SQLite error.
|
||||
if (cleanQuery.length() == 0)
|
||||
{
|
||||
Log.d(TAG, "Aborting empty search query.");
|
||||
timer.stop(TAG);
|
||||
return;
|
||||
}
|
||||
|
||||
timer.split("clean");
|
||||
|
||||
Pair<CursorList<Contact>, List<String>> contacts = queryContacts(cleanQuery);
|
||||
@ -114,15 +124,30 @@ public class SearchRepository {
|
||||
|
||||
public void query(@NonNull String query, long threadId, @NonNull Callback<CursorList<MessageResult>> callback) {
|
||||
if (TextUtils.isEmpty(query)) {
|
||||
Log.d("[ACL]", "Recognised empty query!");
|
||||
|
||||
callback.onResult(CursorList.emptyList());
|
||||
return;
|
||||
}
|
||||
else {
|
||||
Log.d("[ACL]", "Non-empty query is: " + query);
|
||||
}
|
||||
|
||||
executor.execute(() -> {
|
||||
long startTime = System.currentTimeMillis();
|
||||
CursorList<MessageResult> messages = queryMessages(sanitizeQuery(query), threadId);
|
||||
Log.d(TAG, "[ConversationQuery] " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
|
||||
Log.d("[ACL]", "Hit query.execute!");
|
||||
|
||||
// If the search is for a single character and it was stripped by `sanitizeQuery` then abort
|
||||
// the search for an empty string to avoid SQLite error.
|
||||
String cleanQuery = sanitizeQuery(query);
|
||||
Log.d("[ACL]", "clean query is: \"" + cleanQuery + "\"");
|
||||
if (cleanQuery.isEmpty() || cleanQuery.equalsIgnoreCase(" "))
|
||||
{
|
||||
Log.d("[ACL]", "Aborting empty search query.");
|
||||
return;
|
||||
}
|
||||
|
||||
CursorList<MessageResult> messages = queryMessages(cleanQuery, threadId);
|
||||
callback.onResult(messages);
|
||||
});
|
||||
}
|
||||
@ -186,12 +211,19 @@ public class SearchRepository {
|
||||
}
|
||||
|
||||
private CursorList<MessageResult> queryMessages(@NonNull String query) {
|
||||
|
||||
Log.d("[ACL]", "[SearchRepository] Query is:\n" + query);
|
||||
|
||||
|
||||
Cursor messages = searchDatabase.queryMessages(query);
|
||||
return messages != null ? new CursorList<>(messages, new MessageModelBuilder(context))
|
||||
: CursorList.emptyList();
|
||||
}
|
||||
|
||||
private CursorList<MessageResult> queryMessages(@NonNull String query, long threadId) {
|
||||
|
||||
Log.d("[ACL]", "[SearchRepository] 6 - query is: " + query);
|
||||
|
||||
Cursor messages = searchDatabase.queryMessages(query, threadId);
|
||||
return messages != null ? new CursorList<>(messages, new MessageModelBuilder(context))
|
||||
: CursorList.emptyList();
|
||||
@ -205,6 +237,9 @@ public class SearchRepository {
|
||||
* However, if we replace the apostrophe with a space, then the query will find the match.
|
||||
*/
|
||||
private String sanitizeQuery(@NonNull String query) {
|
||||
|
||||
Log.d("[ACL]", "[SearchRepository] Hit sanitizeQuery - initial query is: " + query);
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < query.length(); i++) {
|
||||
@ -216,7 +251,10 @@ public class SearchRepository {
|
||||
}
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
Log.d("[ACL]", "[SearchRepository] Hit sanitizeQuery - sanitized query is: " + out.toString());
|
||||
|
||||
// Querying for an empty string causes a crash so we'll que
|
||||
if (out.toString().length() > 0) { return out.toString(); } else { return " "; }
|
||||
}
|
||||
|
||||
private static class ContactModelBuilder implements CursorList.ModelBuilder<Contact> {
|
||||
|
Loading…
Reference in New Issue
Block a user