mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-10 06:28:34 +00:00
Fixes #1346
This commit is contained in:
parent
cfe2dbca7b
commit
09e48fdc5c
@ -69,12 +69,7 @@ public class SearchToolbar extends LinearLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String newText) {
|
public boolean onQueryTextChange(String newText) { return onQueryTextSubmit(newText); }
|
||||||
|
|
||||||
Log.d("[ACL]", "IT'S NOT THIS ONE - Search text changed to: " + newText);
|
|
||||||
|
|
||||||
return onQueryTextSubmit(newText);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
||||||
|
@ -2066,11 +2066,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onSearchQueryUpdated(query: String) {
|
fun onSearchQueryUpdated(query: String) {
|
||||||
Log.d("[ACL]", "1")
|
|
||||||
searchViewModel.onQueryUpdated(query, viewModel.threadId)
|
searchViewModel.onQueryUpdated(query, viewModel.threadId)
|
||||||
Log.d("[ACL]", "2")
|
|
||||||
binding?.searchBottomBar?.showLoading()
|
binding?.searchBottomBar?.showLoading()
|
||||||
Log.d("[ACL]", "3")
|
|
||||||
adapter.onSearchQueryUpdated(query)
|
adapter.onSearchQueryUpdated(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,9 +269,7 @@ class ConversationAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onSearchQueryUpdated(query: String?) {
|
fun onSearchQueryUpdated(query: String?) {
|
||||||
Log.d("[ACL]", "4")
|
|
||||||
this.searchQuery = query
|
this.searchQuery = query
|
||||||
Log.d("[ACL]", "5")
|
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,10 +125,6 @@ object ConversationMenuHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onQueryTextChange(query: String): Boolean {
|
override fun onQueryTextChange(query: String): Boolean {
|
||||||
|
|
||||||
// *** Crashes when searching for non-alphanumeric first char ***
|
|
||||||
Log.d("[ACL]", "[ConversationMenuHelper] Query text changed to: $query")
|
|
||||||
|
|
||||||
context.onSearchQueryUpdated(query)
|
context.onSearchQueryUpdated(query)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -116,11 +116,7 @@ public class SearchDatabase extends Database {
|
|||||||
public Cursor queryMessages(@NonNull String query) {
|
public Cursor queryMessages(@NonNull String query) {
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
String prefixQuery = adjustQuery(query);
|
String prefixQuery = adjustQuery(query);
|
||||||
|
|
||||||
int queryLimit = Math.min(query.length()*50,500);
|
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) });
|
Cursor cursor = db.rawQuery(MESSAGES_QUERY, new String[] { prefixQuery, prefixQuery, String.valueOf(queryLimit) });
|
||||||
setNotifyConverationListListeners(cursor);
|
setNotifyConverationListListeners(cursor);
|
||||||
return cursor;
|
return cursor;
|
||||||
|
@ -293,10 +293,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
val newData = contactResults + messageResults
|
val newData = contactResults + messageResults
|
||||||
|
|
||||||
|
|
||||||
Log.d("[ACL]", "THIS IS THE GLOBAL SEARCH - Result query is: ${result.query}")
|
|
||||||
|
|
||||||
globalSearchAdapter.setNewData(result.query, newData)
|
globalSearchAdapter.setNewData(result.query, newData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,28 +124,15 @@ public class SearchRepository {
|
|||||||
|
|
||||||
public void query(@NonNull String query, long threadId, @NonNull Callback<CursorList<MessageResult>> callback) {
|
public void query(@NonNull String query, long threadId, @NonNull Callback<CursorList<MessageResult>> callback) {
|
||||||
if (TextUtils.isEmpty(query)) {
|
if (TextUtils.isEmpty(query)) {
|
||||||
Log.d("[ACL]", "Recognised empty query!");
|
|
||||||
|
|
||||||
callback.onResult(CursorList.emptyList());
|
callback.onResult(CursorList.emptyList());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
Log.d("[ACL]", "Non-empty query is: " + query);
|
|
||||||
}
|
|
||||||
|
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
|
// If the sanitized search query is empty or just contains a single space (" ") then abort
|
||||||
Log.d("[ACL]", "Hit query.execute!");
|
// the search to prevent SQLite errors.
|
||||||
|
|
||||||
// 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);
|
String cleanQuery = sanitizeQuery(query);
|
||||||
Log.d("[ACL]", "clean query is: \"" + cleanQuery + "\"");
|
if (cleanQuery.equalsIgnoreCase(" ") || cleanQuery.isEmpty()) { return; }
|
||||||
if (cleanQuery.isEmpty() || cleanQuery.equalsIgnoreCase(" "))
|
|
||||||
{
|
|
||||||
Log.d("[ACL]", "Aborting empty search query.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CursorList<MessageResult> messages = queryMessages(cleanQuery, threadId);
|
CursorList<MessageResult> messages = queryMessages(cleanQuery, threadId);
|
||||||
callback.onResult(messages);
|
callback.onResult(messages);
|
||||||
@ -211,19 +198,12 @@ public class SearchRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private CursorList<MessageResult> queryMessages(@NonNull String query) {
|
private CursorList<MessageResult> queryMessages(@NonNull String query) {
|
||||||
|
|
||||||
Log.d("[ACL]", "[SearchRepository] Query is:\n" + query);
|
|
||||||
|
|
||||||
|
|
||||||
Cursor messages = searchDatabase.queryMessages(query);
|
Cursor messages = searchDatabase.queryMessages(query);
|
||||||
return messages != null ? new CursorList<>(messages, new MessageModelBuilder(context))
|
return messages != null ? new CursorList<>(messages, new MessageModelBuilder(context))
|
||||||
: CursorList.emptyList();
|
: CursorList.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CursorList<MessageResult> queryMessages(@NonNull String query, long threadId) {
|
private CursorList<MessageResult> queryMessages(@NonNull String query, long threadId) {
|
||||||
|
|
||||||
Log.d("[ACL]", "[SearchRepository] 6 - query is: " + query);
|
|
||||||
|
|
||||||
Cursor messages = searchDatabase.queryMessages(query, threadId);
|
Cursor messages = searchDatabase.queryMessages(query, threadId);
|
||||||
return messages != null ? new CursorList<>(messages, new MessageModelBuilder(context))
|
return messages != null ? new CursorList<>(messages, new MessageModelBuilder(context))
|
||||||
: CursorList.emptyList();
|
: CursorList.emptyList();
|
||||||
@ -237,11 +217,7 @@ public class SearchRepository {
|
|||||||
* However, if we replace the apostrophe with a space, then the query will find the match.
|
* However, if we replace the apostrophe with a space, then the query will find the match.
|
||||||
*/
|
*/
|
||||||
private String sanitizeQuery(@NonNull String query) {
|
private String sanitizeQuery(@NonNull String query) {
|
||||||
|
|
||||||
Log.d("[ACL]", "[SearchRepository] Hit sanitizeQuery - initial query is: " + query);
|
|
||||||
|
|
||||||
StringBuilder out = new StringBuilder();
|
StringBuilder out = new StringBuilder();
|
||||||
|
|
||||||
for (int i = 0; i < query.length(); i++) {
|
for (int i = 0; i < query.length(); i++) {
|
||||||
char c = query.charAt(i);
|
char c = query.charAt(i);
|
||||||
if (!BANNED_CHARACTERS.contains(c)) {
|
if (!BANNED_CHARACTERS.contains(c)) {
|
||||||
@ -250,11 +226,7 @@ public class SearchRepository {
|
|||||||
out.append(' ');
|
out.append(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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> {
|
private static class ContactModelBuilder implements CursorList.ModelBuilder<Contact> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user