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 -> {
|
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) {
|
||||||
chat.title = updateChat.title
|
synchronized(chat) {
|
||||||
|
chat.title = updateChat.title
|
||||||
|
}
|
||||||
|
updateChatTitles()
|
||||||
|
listener?.onTelegramChatChanged(chat)
|
||||||
}
|
}
|
||||||
updateChatTitles()
|
|
||||||
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) {
|
||||||
chat.photo = updateChat.photo
|
synchronized(chat) {
|
||||||
|
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) {
|
||||||
chat.lastMessage = updateChat.lastMessage
|
synchronized(chat) {
|
||||||
setChatOrder(chat, updateChat.order)
|
chat.lastMessage = updateChat.lastMessage
|
||||||
|
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) {
|
||||||
setChatOrder(chat, updateChat.order)
|
synchronized(chat) {
|
||||||
|
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) {
|
||||||
chat.isPinned = updateChat.isPinned
|
synchronized(chat) {
|
||||||
setChatOrder(chat, updateChat.order)
|
chat.isPinned = updateChat.isPinned
|
||||||
|
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) {
|
||||||
chat.lastReadInboxMessageId = updateChat.lastReadInboxMessageId
|
synchronized(chat) {
|
||||||
chat.unreadCount = updateChat.unreadCount
|
chat.lastReadInboxMessageId = updateChat.lastReadInboxMessageId
|
||||||
|
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) {
|
||||||
chat.lastReadOutboxMessageId = updateChat.lastReadOutboxMessageId
|
synchronized(chat) {
|
||||||
|
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) {
|
||||||
chat.unreadMentionCount = updateChat.unreadMentionCount
|
synchronized(chat) {
|
||||||
|
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) {
|
||||||
message.content = updateMessageContent.newContent
|
synchronized(message) {
|
||||||
|
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,8 +708,10 @@ 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) {
|
||||||
chat.unreadMentionCount = updateChat.unreadMentionCount
|
synchronized(chat) {
|
||||||
|
chat.unreadMentionCount = updateChat.unreadMentionCount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TdApi.UpdateMessageSendFailed.CONSTRUCTOR -> {
|
TdApi.UpdateMessageSendFailed.CONSTRUCTOR -> {
|
||||||
|
@ -716,24 +737,30 @@ 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) {
|
||||||
chat.replyMarkupMessageId = updateChat.replyMarkupMessageId
|
synchronized(chat) {
|
||||||
|
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) {
|
||||||
chat.draftMessage = updateChat.draftMessage
|
synchronized(chat) {
|
||||||
setChatOrder(chat, updateChat.order)
|
chat.draftMessage = updateChat.draftMessage
|
||||||
|
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) {
|
||||||
chat.notificationSettings = update.notificationSettings
|
synchronized(chat) {
|
||||||
|
chat.notificationSettings = update.notificationSettings
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -744,8 +771,10 @@ 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) {
|
||||||
chat.photo?.small = updateFile.file
|
synchronized(chat) {
|
||||||
listener?.onTelegramChatChanged(chat)
|
chat.photo?.small = updateFile.file
|
||||||
|
listener?.onTelegramChatChanged(chat)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue