```private fun updateChatsAndMessagesList() { ...
# tornadofx
c
Copy code
private fun updateChatsAndMessagesList() {
        try {
//            val chats = chatAPI.getChats()
            val updates = chatAPI.getUpdates(oldTimestamp)
//            oldTimestamp = Instant.now().toEpochMilli()
            updates.lastOrNull()?.apply {
                oldTimestamp = this.ts + 1
            }
            Platform.runLater {
                //                chatsList.setAll(chats)
//                view.showMsg(curSelectedChatId)
                removeUnsendMessages()
                for (update in updates) {
                    when (update) {
is Update.NewMessageUpdate -> {
                            val msg = MessageModel(update.msg)
                            chatsList2.find { it is ChatViewInstance.Chat && it.chat.id == msg.chat }?.run {
                                if (this is ChatViewInstance.Chat){
                                this.chat.lastSendMsg = msg
                                if (msg.user_id != getMyUserInfo().id) {
                                    this.chat.unreadCount += 1
                                }}
                            }
                            if (update.msg.chat == curSelectedChatId) {
                                chatMessagesList.add(ChatEvent.NewMessageEvent(msg))

                            }
                        }
so it automatically adds new messages when server sends them