forked from mirror/monocles_chat_clean
search individual conversations. fixes #3243
(cherry picked from commit 35af8894d2dedfda8a4b66e8e3fb6a2d5a8346a0)
This commit is contained in:
parent
3319383b14
commit
84fdf9ff1c
12 changed files with 83 additions and 16 deletions
|
@ -812,11 +812,20 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
return list;
|
||||
}
|
||||
|
||||
public Cursor getMessageSearchCursor(List<String> term) {
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
String SQL = "SELECT " + Message.TABLENAME + ".*," + Conversation.TABLENAME + '.' + Conversation.CONTACTJID + ',' + Conversation.TABLENAME + '.' + Conversation.ACCOUNT + ',' + Conversation.TABLENAME + '.' + Conversation.MODE + " FROM " + Message.TABLENAME + " join " + Conversation.TABLENAME + " on " + Message.TABLENAME + '.' + Message.CONVERSATION + '=' + Conversation.TABLENAME + '.' + Conversation.UUID + " join messages_index ON messages_index.uuid=messages.uuid where " + Message.ENCRYPTION + " NOT IN(" + Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE + ',' + Message.ENCRYPTION_PGP + ',' + Message.ENCRYPTION_DECRYPTION_FAILED + ',' + Message.ENCRYPTION_AXOLOTL_FAILED + ") AND " + Message.TYPE + " IN(" + Message.TYPE_TEXT + ',' + Message.TYPE_PRIVATE + ") AND messages_index.body MATCH ? ORDER BY " + Message.TIME_SENT + " DESC limit " + Config.MAX_SEARCH_RESULTS;
|
||||
public Cursor getMessageSearchCursor(final List<String> term, final String uuid) {
|
||||
final SQLiteDatabase db = this.getReadableDatabase();
|
||||
final StringBuilder SQL = new StringBuilder();
|
||||
final String[] selectionArgs;
|
||||
SQL.append("SELECT " + Message.TABLENAME + ".*," + Conversation.TABLENAME + '.' + Conversation.CONTACTJID + ',' + Conversation.TABLENAME + '.' + Conversation.ACCOUNT + ',' + Conversation.TABLENAME + '.' + Conversation.MODE + " FROM " + Message.TABLENAME + " join " + Conversation.TABLENAME + " on " + Message.TABLENAME + '.' + Message.CONVERSATION + '=' + Conversation.TABLENAME + '.' + Conversation.UUID + " join messages_index ON messages_index.uuid=messages.uuid where " + Message.ENCRYPTION + " NOT IN(" + Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE + ',' + Message.ENCRYPTION_PGP + ',' + Message.ENCRYPTION_DECRYPTION_FAILED + ',' + Message.ENCRYPTION_AXOLOTL_FAILED + ") AND " + Message.TYPE + " IN(" + Message.TYPE_TEXT + ',' + Message.TYPE_PRIVATE + ") AND messages_index.body MATCH ?");
|
||||
if (uuid == null) {
|
||||
selectionArgs = new String[]{FtsUtils.toMatchString(term)};
|
||||
} else {
|
||||
selectionArgs = new String[]{FtsUtils.toMatchString(term), uuid};
|
||||
SQL.append(" AND "+Conversation.TABLENAME+'.'+Conversation.UUID+"=?");
|
||||
}
|
||||
SQL.append(" ORDER BY " + Message.TIME_SENT + " DESC limit " + Config.MAX_SEARCH_RESULTS);
|
||||
Log.d(Config.LOGTAG, "search term: " + FtsUtils.toMatchString(term));
|
||||
return db.rawQuery(SQL, new String[]{FtsUtils.toMatchString(term)});
|
||||
return db.rawQuery(SQL.toString(), selectionArgs);
|
||||
}
|
||||
|
||||
public Iterable<Message> getMessagesIterable(final Conversation conversation) {
|
||||
|
|
|
@ -56,18 +56,20 @@ public class MessageSearchTask implements Runnable, Cancellable {
|
|||
|
||||
private final XmppConnectionService xmppConnectionService;
|
||||
private final List<String> term;
|
||||
private final String uuid;
|
||||
private final OnSearchResultsAvailable onSearchResultsAvailable;
|
||||
|
||||
private boolean isCancelled = false;
|
||||
|
||||
private MessageSearchTask(XmppConnectionService xmppConnectionService, List<String> term, OnSearchResultsAvailable onSearchResultsAvailable) {
|
||||
private MessageSearchTask(XmppConnectionService xmppConnectionService, List<String> term, final String uuid, OnSearchResultsAvailable onSearchResultsAvailable) {
|
||||
this.xmppConnectionService = xmppConnectionService;
|
||||
this.term = term;
|
||||
this.uuid = uuid;
|
||||
this.onSearchResultsAvailable = onSearchResultsAvailable;
|
||||
}
|
||||
|
||||
public static void search(XmppConnectionService xmppConnectionService, List<String> term, OnSearchResultsAvailable onSearchResultsAvailable) {
|
||||
new MessageSearchTask(xmppConnectionService, term, onSearchResultsAvailable).executeInBackground();
|
||||
public static void search(XmppConnectionService xmppConnectionService, List<String> term, final String uuid, OnSearchResultsAvailable onSearchResultsAvailable) {
|
||||
new MessageSearchTask(xmppConnectionService, term, uuid, onSearchResultsAvailable).executeInBackground();
|
||||
}
|
||||
|
||||
public static void cancelRunningTasks() {
|
||||
|
@ -86,7 +88,7 @@ public class MessageSearchTask implements Runnable, Cancellable {
|
|||
try {
|
||||
final HashMap<String, Conversational> conversationCache = new HashMap<>();
|
||||
final List<Message> result = new ArrayList<>();
|
||||
cursor = xmppConnectionService.databaseBackend.getMessageSearchCursor(term);
|
||||
cursor = xmppConnectionService.databaseBackend.getMessageSearchCursor(term, uuid);
|
||||
long dbTimer = SystemClock.elapsedRealtime();
|
||||
if (isCancelled) {
|
||||
Log.d(Config.LOGTAG, "canceled search task");
|
||||
|
|
|
@ -630,8 +630,8 @@ public class XmppConnectionService extends Service {
|
|||
return c != null && c.getMode() == Conversational.MODE_MULTI;
|
||||
}
|
||||
|
||||
public void search(List<String> term, OnSearchResultsAvailable onSearchResultsAvailable) {
|
||||
MessageSearchTask.search(this, term, onSearchResultsAvailable);
|
||||
public void search(final List<String> term, final String uuid, final OnSearchResultsAvailable onSearchResultsAvailable) {
|
||||
MessageSearchTask.search(this, term, uuid, onSearchResultsAvailable);
|
||||
}
|
||||
|
||||
@SuppressLint("InvalidWakeLockTag")
|
||||
|
|
|
@ -1465,6 +1465,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
|||
case R.id.attach_location:
|
||||
handleAttachmentSelection(item);
|
||||
break;
|
||||
case R.id.action_search:
|
||||
startSearch();
|
||||
break;
|
||||
case R.id.action_archive_chat:
|
||||
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
||||
activity.xmppConnectionService.archiveConversation(conversation);
|
||||
|
@ -1525,6 +1528,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void startSearch() {
|
||||
final Intent intent = new Intent(getActivity(), SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.EXTRA_CONVERSATION_UUID, conversation.getUuid());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void returnToOngoingCall() {
|
||||
final Optional<OngoingRtpSession> ongoingRtpSession = activity.xmppConnectionService.getJingleConnectionManager().getOngoingRtpConnection(conversation.getContact());
|
||||
if (ongoingRtpSession.isPresent()) {
|
||||
|
@ -3074,7 +3083,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
|||
correctMessage(lastEditableMessage);
|
||||
return true;
|
||||
} else {
|
||||
Toast.makeText(getActivity(),R.string.could_not_correct_message, Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getActivity(), R.string.could_not_correct_message, Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -570,6 +570,18 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
|||
case R.id.action_scan_qr_code:
|
||||
UriHandlerActivity.scan(this);
|
||||
return true;
|
||||
case R.id.action_search_all_conversations:
|
||||
startActivity(new Intent(this, SearchActivity.class));
|
||||
return true;
|
||||
case R.id.action_search_this_conversation:
|
||||
final Conversation conversation = ConversationFragment.getConversation(this);
|
||||
if (conversation == null) {
|
||||
return true;
|
||||
}
|
||||
final Intent intent = new Intent(this, SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.EXTRA_CONVERSATION_UUID, conversation.getUuid());
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.action_check_updates:
|
||||
if (xmppConnectionService.hasInternetConnection()) {
|
||||
openInstallFromUnknownSourcesDialogIfNeeded(true);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
package eu.siacs.conversations.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
|
@ -43,6 +44,8 @@ import android.widget.EditText;
|
|||
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
|
@ -74,16 +77,20 @@ import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.showKeyboard;
|
|||
public class SearchActivity extends XmppActivity implements TextWatcher, OnSearchResultsAvailable, MessageAdapter.OnContactPictureClicked {
|
||||
|
||||
private static final String EXTRA_SEARCH_TERM = "search-term";
|
||||
public static final String EXTRA_CONVERSATION_UUID = "uuid";
|
||||
private ActivitySearchBinding binding;
|
||||
private MessageAdapter messageListAdapter;
|
||||
private final List<Message> messages = new ArrayList<>();
|
||||
private WeakReference<Message> selectedMessageReference = new WeakReference<>(null);
|
||||
private String uuid;
|
||||
private final ChangeWatcher<List<String>> currentSearch = new ChangeWatcher<>();
|
||||
private final PendingItem<String> pendingSearchTerm = new PendingItem<>();
|
||||
private final PendingItem<List<String>> pendingSearch = new PendingItem<>();
|
||||
|
||||
@Override
|
||||
public void onCreate(final Bundle bundle) {
|
||||
final Intent intent = getIntent();
|
||||
this.uuid = intent == null ? null : Strings.emptyToNull(intent.getStringExtra(EXTRA_CONVERSATION_UUID));
|
||||
final String searchTerm = bundle == null ? null : bundle.getString(EXTRA_SEARCH_TERM);
|
||||
if (searchTerm != null) {
|
||||
pendingSearchTerm.push(searchTerm);
|
||||
|
@ -106,10 +113,10 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc
|
|||
final String term = pendingSearchTerm.pop();
|
||||
if (term != null) {
|
||||
searchField.append(term);
|
||||
List<String> searchTerm = FtsUtils.parse(term);
|
||||
final List<String> searchTerm = FtsUtils.parse(term);
|
||||
if (xmppConnectionService != null) {
|
||||
if (currentSearch.watch(searchTerm)) {
|
||||
xmppConnectionService.search(searchTerm, this);
|
||||
xmppConnectionService.search(searchTerm, uuid, this);
|
||||
}
|
||||
} else {
|
||||
pendingSearch.push(searchTerm);
|
||||
|
@ -210,7 +217,7 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc
|
|||
void onBackendConnected() {
|
||||
final List<String> searchTerm = pendingSearch.pop();
|
||||
if (searchTerm != null && currentSearch.watch(searchTerm)) {
|
||||
xmppConnectionService.search(searchTerm, this);
|
||||
xmppConnectionService.search(searchTerm, uuid,this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -243,7 +250,7 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc
|
|||
return;
|
||||
}
|
||||
if (term.size() > 0) {
|
||||
xmppConnectionService.search(term, this);
|
||||
xmppConnectionService.search(term, uuid,this);
|
||||
} else {
|
||||
MessageSearchTask.cancelRunningTasks();
|
||||
this.messages.clear();
|
||||
|
|
|
@ -8,6 +8,21 @@
|
|||
android:title="@string/scan_qr_code"
|
||||
android:visible="@bool/show_qr_code_scan"
|
||||
app:showAsAction="always" />
|
||||
<item
|
||||
android:icon="?attr/icon_search"
|
||||
android:orderInCategory="11"
|
||||
android:title="@string/search_messages"
|
||||
android:visible="@bool/show_combined_search_options"
|
||||
app:showAsAction="always">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/action_search_all_conversations"
|
||||
android:title="@string/search_all_conversations" />
|
||||
<item
|
||||
android:id="@+id/action_search_this_conversation"
|
||||
android:title="@string/search_this_conversation" />
|
||||
</menu>
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/action_accounts"
|
||||
android:orderInCategory="90"
|
||||
|
|
|
@ -98,6 +98,12 @@
|
|||
android:orderInCategory="45"
|
||||
android:title="@string/invite_contact"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_search"
|
||||
android:orderInCategory="48"
|
||||
android:title="@string/search_messages"
|
||||
android:visible="@bool/show_individual_search_options"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_clear_history"
|
||||
android:orderInCategory="50"
|
||||
|
@ -124,5 +130,5 @@
|
|||
android:id="@+id/action_toggle_pinned"
|
||||
android:orderInCategory="72"
|
||||
android:title="@string/add_to_favorites"
|
||||
app:showAsAction="never"/>
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
|
@ -31,6 +31,7 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_search"
|
||||
android:visible="@bool/show_individual_search_options"
|
||||
android:orderInCategory="50"
|
||||
android:title="@string/search_messages"
|
||||
android:icon="@drawable/ic_search_white_24dp"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<bool name="show_qr_code_scan">false</bool>
|
||||
<bool name="show_individual_search_options">false</bool>
|
||||
<bool name="show_combined_search_options">true</bool>
|
||||
</resources>
|
||||
|
||||
|
|
|
@ -44,6 +44,8 @@
|
|||
<bool name="use_bundled_emoji">true</bool>
|
||||
<bool name="enable_multi_accounts">false</bool>
|
||||
<bool name="show_qr_code_scan">true</bool>
|
||||
<bool name="show_individual_search_options">true</bool>
|
||||
<bool name="show_combined_search_options">false</bool>
|
||||
<bool name="scroll_to_bottom">true</bool>
|
||||
<bool name="start_searching">false</bool>
|
||||
<bool name="show_record_voice_btn">true</bool>
|
||||
|
|
|
@ -1045,4 +1045,6 @@
|
|||
<string name="improperly_formatted_provisioning">Improperly formatted provisioning code</string>
|
||||
<string name="gpx_track">GPX track</string>
|
||||
<string name="could_not_correct_message">Could not correct message</string>
|
||||
<string name="search_all_conversations">All conversations</string>
|
||||
<string name="search_this_conversation">This conversation</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Reference in a new issue