add check for private chat

This commit is contained in:
Chumva 2018-08-02 14:57:08 +03:00
parent 862fd08e4c
commit 3b1a79c079
2 changed files with 11 additions and 4 deletions

View file

@ -106,8 +106,6 @@ class TelegramHelper private constructor() {
fun getCurrentUser() = currentUser
fun getCurrentUserId() = currentUser?.id
fun getUserMessage(user: TdApi.User) =
usersLocationMessages.values.firstOrNull { it.senderUserId == user.id }
@ -138,6 +136,10 @@ class TelegramHelper private constructor() {
return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup
}
fun isPrivateChat(chat: TdApi.Chat): Boolean {
return chat.type is TdApi.ChatTypePrivate
}
private fun isChannel(chat: TdApi.Chat): Boolean {
return chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel
}

View file

@ -329,10 +329,15 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private fun updateList() {
val chatList = telegramHelper.getChatList()
val chats: MutableList<TdApi.Chat> = mutableListOf()
val currentUserId = telegramHelper.getCurrentUserId()
val currentUser = telegramHelper.getCurrentUser()
for (orderedChat in chatList) {
val chat = telegramHelper.getChat(orderedChat.chatId)
if (chat != null && (chat.id != currentUserId?.toLong())) {
if (chat != null) {
if (telegramHelper.isPrivateChat(chat)) {
if ((chat.type as TdApi.ChatTypePrivate).userId == currentUser?.id) {
continue
}
}
chats.add(chat)
}
}