Searching for "Note to self" should show note to self in search results (#1070)

pull/1713/head
ThomasSession 1 month ago committed by GitHub
parent b4a9b22529
commit 6aa0024aa9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -269,7 +269,12 @@ class HomeActivity : ScreenLockActionBarActivity(),
addAll(result.groupedContacts) addAll(result.groupedContacts)
} }
else -> buildList { else -> buildList {
result.contactAndGroupList.takeUnless { it.isEmpty() }?.let { val conversations = result.contactAndGroupList.toMutableList()
if(result.showNoteToSelf){
conversations.add(GlobalSearchAdapter.Model.SavedMessages(publicKey))
}
conversations.takeUnless { it.isEmpty() }?.let {
add(GlobalSearchAdapter.Model.Header(R.string.sessionConversations)) add(GlobalSearchAdapter.Model.Header(R.string.sessionConversations))
addAll(it) addAll(it)
} }

@ -9,7 +9,8 @@ data class GlobalSearchResult(
val query: String, val query: String,
val contacts: List<Contact> = emptyList(), val contacts: List<Contact> = emptyList(),
val threads: List<GroupRecord> = emptyList(), val threads: List<GroupRecord> = emptyList(),
val messages: List<MessageResult> = emptyList() val messages: List<MessageResult> = emptyList(),
val showNoteToSelf: Boolean = false
) { ) {
val isEmpty: Boolean val isEmpty: Boolean
get() = contacts.isEmpty() && threads.isEmpty() && messages.isEmpty() get() = contacts.isEmpty() && threads.isEmpty() && messages.isEmpty()

@ -28,6 +28,7 @@ import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.plus import kotlinx.coroutines.plus
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import network.loki.messenger.R
import org.session.libsignal.utilities.Log import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.database.DatabaseContentProviders import org.thoughtcrime.securesms.database.DatabaseContentProviders
import org.thoughtcrime.securesms.dependencies.ConfigFactory import org.thoughtcrime.securesms.dependencies.ConfigFactory
@ -56,6 +57,8 @@ class GlobalSearchViewModel @Inject constructor(
configFactory.configUpdateNotifications configFactory.configUpdateNotifications
) )
val noteToSelfString by lazy { application.getString(R.string.noteToSelf).lowercase() }
val result = combine( val result = combine(
_queryText, _queryText,
observeChangesAffectingSearch().onStart { emit(Unit) } observeChangesAffectingSearch().onStart { emit(Unit) }
@ -73,7 +76,14 @@ class GlobalSearchViewModel @Inject constructor(
) )
} }
} else { } else {
searchRepository.suspendQuery(query).toGlobalSearchResult() val results = searchRepository.suspendQuery(query).toGlobalSearchResult()
// show "Note to Self" is the user searches for parts of"Note to Self"
if(noteToSelfString.contains(query.lowercase())){
results.copy(showNoteToSelf = true)
} else {
results
}
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.e("GlobalSearchViewModel", "Error searching len = ${query.length}", e) Log.e("GlobalSearchViewModel", "Error searching len = ${query.length}", e)

Loading…
Cancel
Save