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