mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 12:08:26 +00:00
SES-1251 - App crash on non alphanumeric first char search (#1393)
* Investigation in progress * Working fix push before cleanup * Fixes #1346 * Removed unused logging imports * Put back some whitespace * Minor cleanup
This commit is contained in:
parent
d3c8635748
commit
7a7ea8909d
@ -1,6 +1,5 @@
|
||||
package org.thoughtcrime.securesms.components;
|
||||
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
@ -68,9 +67,7 @@ public class SearchToolbar extends LinearLayout {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
return onQueryTextSubmit(newText);
|
||||
}
|
||||
public boolean onQueryTextChange(String newText) { return onQueryTextSubmit(newText); }
|
||||
});
|
||||
|
||||
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
||||
|
@ -10,6 +10,7 @@ import com.annimon.stream.Stream;
|
||||
import net.zetetic.database.sqlcipher.SQLiteDatabase;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
|
||||
import java.util.List;
|
||||
@ -115,9 +116,7 @@ public class SearchDatabase extends Database {
|
||||
public Cursor queryMessages(@NonNull String query) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String prefixQuery = adjustQuery(query);
|
||||
|
||||
int queryLimit = Math.min(query.length()*50,500);
|
||||
|
||||
Cursor cursor = db.rawQuery(MESSAGES_QUERY, new String[] { prefixQuery, prefixQuery, String.valueOf(queryLimit) });
|
||||
setNotifyConversationListListeners(cursor);
|
||||
return cursor;
|
||||
|
@ -293,7 +293,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
||||
}
|
||||
|
||||
val newData = contactResults + messageResults
|
||||
|
||||
globalSearchAdapter.setNewData(result.query, newData)
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
@ -119,10 +129,11 @@ public class SearchRepository {
|
||||
}
|
||||
|
||||
executor.execute(() -> {
|
||||
long startTime = System.currentTimeMillis();
|
||||
CursorList<MessageResult> messages = queryMessages(sanitizeQuery(query), threadId);
|
||||
Log.d(TAG, "[ConversationQuery] " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
|
||||
// If the sanitized search query is empty then abort the search to prevent SQLite errors.
|
||||
String cleanQuery = sanitizeQuery(query).trim();
|
||||
if (cleanQuery.isEmpty()) { return; }
|
||||
|
||||
CursorList<MessageResult> messages = queryMessages(cleanQuery, threadId);
|
||||
callback.onResult(messages);
|
||||
});
|
||||
}
|
||||
@ -215,7 +226,7 @@ public class SearchRepository {
|
||||
out.append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user