Merge pull request #8193 from osmandapp/saved_msgs_in_search

saved messages in search
This commit is contained in:
max-klaus 2020-01-08 18:20:43 +03:00 committed by GitHub
commit 24c8048d81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -155,14 +155,22 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
}
private fun runSearch(text: String) {
if (getSavedMessagesChatTitle().startsWith(text, true)) {
val savedMessages = telegramHelper.getChat(telegramHelper.getCurrentUserId().toLong())
if (savedMessages != null) {
telegramHelper.searchChats(savedMessages.title)
}
}
telegramHelper.searchChats(text)
telegramHelper.searchChatsOnServer(text)
telegramHelper.searchContacts(text)
if (text.length > 4) {
if (text.length > 4 && !getSavedMessagesChatTitle().startsWith(text, true)) {
telegramHelper.searchPublicChats(text)
}
}
private fun getSavedMessagesChatTitle() = getString(R.string.saved_messages)
override fun onResume() {
super.onResume()
telegramHelper.addSearchListener(this)
@ -231,7 +239,7 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
selectedChats.forEach {
val chat = telegramHelper.getChat(it)
if (chat != null) {
if (!telegramHelper.isChannel(chat) && telegramHelper.getUserIdFromChatType(chat.type) != currentUserId) {
if (!telegramHelper.isChannel(chat)) {
items.add(chat)
}
} else {
@ -250,7 +258,7 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
searchedChatsIds.forEach {
val chat = telegramHelper.getChat(it)
if (chat != null && !selectedChats.contains(it)) {
if (!telegramHelper.isChannel(chat) && telegramHelper.getUserIdFromChatType(chat.type) != currentUserId) {
if (!telegramHelper.isChannel(chat)) {
chats.add(chat)
}
} else {
@ -382,9 +390,18 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
TelegramUiHelper.setupPhoto(app, holder.icon, photoPath, placeholderId, false)
val currentUserId = telegramHelper.getCurrentUserId()
val title = when (item) {
is TdApi.Chat -> item.title
is TdApi.User -> TelegramUiHelper.getUserName(item)
is TdApi.Chat -> {
if (telegramHelper.isPrivateChat(item) && (item.type as TdApi.ChatTypePrivate).userId == currentUserId) {
getSavedMessagesChatTitle()
} else {
item.title
}
}
is TdApi.User -> {
if (item.id == currentUserId) getSavedMessagesChatTitle() else TelegramUiHelper.getUserName(item)
}
else -> null
}