Telegram - fix possible npe

This commit is contained in:
crimean 2018-06-13 20:52:43 +03:00
parent ae2aa88578
commit cfa3861d4d

View file

@ -562,7 +562,7 @@ class TelegramHelper private constructor() {
TdApi.UpdateNewChat.CONSTRUCTOR -> { TdApi.UpdateNewChat.CONSTRUCTOR -> {
val updateNewChat = obj as TdApi.UpdateNewChat val updateNewChat = obj as TdApi.UpdateNewChat
val chat = updateNewChat.chat val chat = updateNewChat.chat
synchronized(chat!!) { synchronized(chat) {
if (chat.type !is TdApi.ChatTypeSupergroup || !(chat.type as TdApi.ChatTypeSupergroup).isChannel) { if (chat.type !is TdApi.ChatTypeSupergroup || !(chat.type as TdApi.ChatTypeSupergroup).isChannel) {
chats[chat.id] = chat chats[chat.id] = chat
val localPhoto = chat.photo?.small?.local val localPhoto = chat.photo?.small?.local
@ -604,75 +604,94 @@ class TelegramHelper private constructor() {
TdApi.UpdateChatTitle.CONSTRUCTOR -> { TdApi.UpdateChatTitle.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatTitle val updateChat = obj as TdApi.UpdateChatTitle
val chat = chats[updateChat.chatId] val chat = chats[updateChat.chatId]
synchronized(chat!!) { if (chat != null) {
synchronized(chat) {
chat.title = updateChat.title chat.title = updateChat.title
} }
updateChatTitles() updateChatTitles()
listener?.onTelegramChatChanged(chat) listener?.onTelegramChatChanged(chat)
} }
}
TdApi.UpdateChatPhoto.CONSTRUCTOR -> { TdApi.UpdateChatPhoto.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatPhoto val updateChat = obj as TdApi.UpdateChatPhoto
val chat = chats[updateChat.chatId] val chat = chats[updateChat.chatId]
synchronized(chat!!) { if (chat != null) {
synchronized(chat) {
chat.photo = updateChat.photo chat.photo = updateChat.photo
} }
listener?.onTelegramChatChanged(chat) listener?.onTelegramChatChanged(chat)
} }
}
TdApi.UpdateChatLastMessage.CONSTRUCTOR -> { TdApi.UpdateChatLastMessage.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatLastMessage val updateChat = obj as TdApi.UpdateChatLastMessage
val chat = chats[updateChat.chatId] val chat = chats[updateChat.chatId]
synchronized(chat!!) { if (chat != null) {
synchronized(chat) {
chat.lastMessage = updateChat.lastMessage chat.lastMessage = updateChat.lastMessage
setChatOrder(chat, updateChat.order) setChatOrder(chat, updateChat.order)
} }
} }
}
TdApi.UpdateChatOrder.CONSTRUCTOR -> { TdApi.UpdateChatOrder.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatOrder val updateChat = obj as TdApi.UpdateChatOrder
val chat = chats[updateChat.chatId] val chat = chats[updateChat.chatId]
synchronized(chat!!) { if (chat != null) {
synchronized(chat) {
setChatOrder(chat, updateChat.order) setChatOrder(chat, updateChat.order)
} }
listener?.onTelegramChatsChanged() listener?.onTelegramChatsChanged()
} }
}
TdApi.UpdateChatIsPinned.CONSTRUCTOR -> { TdApi.UpdateChatIsPinned.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatIsPinned val updateChat = obj as TdApi.UpdateChatIsPinned
val chat = chats[updateChat.chatId] val chat = chats[updateChat.chatId]
synchronized(chat!!) { if (chat != null) {
synchronized(chat) {
chat.isPinned = updateChat.isPinned chat.isPinned = updateChat.isPinned
setChatOrder(chat, updateChat.order) setChatOrder(chat, updateChat.order)
} }
} }
}
TdApi.UpdateChatReadInbox.CONSTRUCTOR -> { TdApi.UpdateChatReadInbox.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatReadInbox val updateChat = obj as TdApi.UpdateChatReadInbox
val chat = chats[updateChat.chatId] val chat = chats[updateChat.chatId]
synchronized(chat!!) { if (chat != null) {
synchronized(chat) {
chat.lastReadInboxMessageId = updateChat.lastReadInboxMessageId chat.lastReadInboxMessageId = updateChat.lastReadInboxMessageId
chat.unreadCount = updateChat.unreadCount chat.unreadCount = updateChat.unreadCount
} }
} }
}
TdApi.UpdateChatReadOutbox.CONSTRUCTOR -> { TdApi.UpdateChatReadOutbox.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatReadOutbox val updateChat = obj as TdApi.UpdateChatReadOutbox
val chat = chats[updateChat.chatId] val chat = chats[updateChat.chatId]
synchronized(chat!!) { if (chat != null) {
synchronized(chat) {
chat.lastReadOutboxMessageId = updateChat.lastReadOutboxMessageId chat.lastReadOutboxMessageId = updateChat.lastReadOutboxMessageId
} }
} }
}
TdApi.UpdateChatUnreadMentionCount.CONSTRUCTOR -> { TdApi.UpdateChatUnreadMentionCount.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatUnreadMentionCount val updateChat = obj as TdApi.UpdateChatUnreadMentionCount
val chat = chats[updateChat.chatId] val chat = chats[updateChat.chatId]
synchronized(chat!!) { if (chat != null) {
synchronized(chat) {
chat.unreadMentionCount = updateChat.unreadMentionCount chat.unreadMentionCount = updateChat.unreadMentionCount
} }
} }
}
TdApi.UpdateMessageContent.CONSTRUCTOR -> { TdApi.UpdateMessageContent.CONSTRUCTOR -> {
val updateMessageContent = obj as TdApi.UpdateMessageContent val updateMessageContent = obj as TdApi.UpdateMessageContent
val message = usersLiveMessages[updateMessageContent.messageId] val message = usersLiveMessages[updateMessageContent.messageId]
if (message != null && !message.isOutgoing) { if (message != null && !message.isOutgoing) {
synchronized(message) {
message.content = updateMessageContent.newContent message.content = updateMessageContent.newContent
}
val chatTitle = chats[message.chatId]?.title val chatTitle = chats[message.chatId]?.title
if (chatTitle != null) { if (chatTitle != null) {
incomingMessagesListener?.onReceiveChatLocationMessages(chatTitle, message) incomingMessagesListener?.onReceiveChatLocationMessages(chatTitle, message)
} }
} }
} }
TdApi.UpdateNewMessage.CONSTRUCTOR -> { TdApi.UpdateNewMessage.CONSTRUCTOR -> {
@ -689,10 +708,12 @@ class TelegramHelper private constructor() {
TdApi.UpdateMessageMentionRead.CONSTRUCTOR -> { TdApi.UpdateMessageMentionRead.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateMessageMentionRead val updateChat = obj as TdApi.UpdateMessageMentionRead
val chat = chats[updateChat.chatId] val chat = chats[updateChat.chatId]
synchronized(chat!!) { if (chat != null) {
synchronized(chat) {
chat.unreadMentionCount = updateChat.unreadMentionCount chat.unreadMentionCount = updateChat.unreadMentionCount
} }
} }
}
TdApi.UpdateMessageSendFailed.CONSTRUCTOR -> { TdApi.UpdateMessageSendFailed.CONSTRUCTOR -> {
needRefreshActiveLiveLocationMessages = true needRefreshActiveLiveLocationMessages = true
} }
@ -716,27 +737,33 @@ class TelegramHelper private constructor() {
TdApi.UpdateChatReplyMarkup.CONSTRUCTOR -> { TdApi.UpdateChatReplyMarkup.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatReplyMarkup val updateChat = obj as TdApi.UpdateChatReplyMarkup
val chat = chats[updateChat.chatId] val chat = chats[updateChat.chatId]
synchronized(chat!!) { if (chat != null) {
synchronized(chat) {
chat.replyMarkupMessageId = updateChat.replyMarkupMessageId chat.replyMarkupMessageId = updateChat.replyMarkupMessageId
} }
} }
}
TdApi.UpdateChatDraftMessage.CONSTRUCTOR -> { TdApi.UpdateChatDraftMessage.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatDraftMessage val updateChat = obj as TdApi.UpdateChatDraftMessage
val chat = chats[updateChat.chatId] val chat = chats[updateChat.chatId]
synchronized(chat!!) { if (chat != null) {
synchronized(chat) {
chat.draftMessage = updateChat.draftMessage chat.draftMessage = updateChat.draftMessage
setChatOrder(chat, updateChat.order) setChatOrder(chat, updateChat.order)
} }
} }
}
TdApi.UpdateNotificationSettings.CONSTRUCTOR -> { TdApi.UpdateNotificationSettings.CONSTRUCTOR -> {
val update = obj as TdApi.UpdateNotificationSettings val update = obj as TdApi.UpdateNotificationSettings
if (update.scope is TdApi.NotificationSettingsScopeChat) { if (update.scope is TdApi.NotificationSettingsScopeChat) {
val chat = chats[(update.scope as TdApi.NotificationSettingsScopeChat).chatId] val chat = chats[(update.scope as TdApi.NotificationSettingsScopeChat).chatId]
synchronized(chat!!) { if (chat != null) {
synchronized(chat) {
chat.notificationSettings = update.notificationSettings chat.notificationSettings = update.notificationSettings
} }
} }
} }
}
TdApi.UpdateFile.CONSTRUCTOR -> { TdApi.UpdateFile.CONSTRUCTOR -> {
val updateFile = obj as TdApi.UpdateFile val updateFile = obj as TdApi.UpdateFile
@ -744,11 +771,13 @@ class TelegramHelper private constructor() {
val remoteId = updateFile.file.remote.id val remoteId = updateFile.file.remote.id
val chat = downloadChatFilesMap.remove(remoteId) val chat = downloadChatFilesMap.remove(remoteId)
if (chat != null) { if (chat != null) {
synchronized(chat) {
chat.photo?.small = updateFile.file chat.photo?.small = updateFile.file
listener?.onTelegramChatChanged(chat) listener?.onTelegramChatChanged(chat)
} }
} }
} }
}
TdApi.UpdateUserFullInfo.CONSTRUCTOR -> { TdApi.UpdateUserFullInfo.CONSTRUCTOR -> {
val updateUserFullInfo = obj as TdApi.UpdateUserFullInfo val updateUserFullInfo = obj as TdApi.UpdateUserFullInfo