Extract check if chat is a channel to the method

This commit is contained in:
Alex Sytnyk 2018-06-22 19:22:22 +03:00
parent f2069eef9c
commit aa33de7fbb

View file

@ -138,6 +138,10 @@ class TelegramHelper private constructor() {
} }
} }
private fun isChannel(chat: TdApi.Chat): Boolean {
return chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel
}
enum class TelegramAuthenticationParameterType { enum class TelegramAuthenticationParameterType {
PHONE_NUMBER, PHONE_NUMBER,
CODE, CODE,
@ -353,7 +357,7 @@ class TelegramHelper private constructor() {
val chatId = this.chatTitles[chatTitle] val chatId = this.chatTitles[chatTitle]
if (chatId != null) { if (chatId != null) {
val chat = chats[chatId] val chat = chats[chatId]
if (chat == null || (chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel)) { if (chat == null || isChannel(chat)) {
return return
} }
client?.send(TdApi.SearchChatRecentLocationMessages(chatId, CHAT_LIVE_USERS_LIMIT)) { obj -> client?.send(TdApi.SearchChatRecentLocationMessages(chatId, CHAT_LIVE_USERS_LIMIT)) { obj ->
@ -491,8 +495,7 @@ class TelegramHelper private constructor() {
private fun setChatOrder(chat: TdApi.Chat, order: Long) { private fun setChatOrder(chat: TdApi.Chat, order: Long) {
synchronized(chatList) { synchronized(chatList) {
val type = chat.type val isChannel = isChannel(chat)
val isChannel = type is TdApi.ChatTypeSupergroup && type.isChannel
if (chat.order != 0L) { if (chat.order != 0L) {
chatList.remove(OrderedChat(chat.order, chat.id, isChannel)) chatList.remove(OrderedChat(chat.order, chat.id, isChannel))