diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SearchDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SearchDialogFragment.kt index 88ac770e78..8a9be5a417 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SearchDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SearchDialogFragment.kt @@ -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 }