chickenfresh
08/27/2018, 12:55 PMchickenfresh
08/27/2018, 12:57 PMchickenfresh
08/27/2018, 12:58 PMinit {
executor.scheduleAtFixedRate(executorTask, 0, AppPrefs.delay, TimeUnit.SECONDS)
}
private val executorTask = {
if (isActive) {
try {
updateChatsAndMessagesList()
}catch(e: ConnectException){
println(e)
}
}
}
chickenfresh
08/27/2018, 12:58 PMchickenfresh
08/27/2018, 12:59 PMprivate 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 themchickenfresh
08/27/2018, 1:00 PMchickenfresh
08/27/2018, 1:03 PMNewMessaegEvent
, MessageView is on screen and I’m already seeing last item from list, then I’d add new object to the end of the list and scroll to the bottom (as it was before update received)chickenfresh
08/27/2018, 1:05 PMScrollableItemWrapper
that last item from the list is changed to the added one, and prevent it asking server for anotherschickenfresh
08/27/2018, 1:10 PMexecutor
keeps list of messages up-to-date — there’s no need to have endless scroll working. only if on opening (probably, only at first time) I’d continue viewing messages from last saved position, and there are a lot more bellow
and if I’m scrolling to the top for old messageschickenfresh
08/27/2018, 1:12 PMcarlw
08/27/2018, 1:18 PMcarlw
08/27/2018, 1:19 PMchickenfresh
08/27/2018, 1:19 PMchickenfresh
08/27/2018, 1:21 PMchickenfresh
08/27/2018, 1:21 PMcarlw
08/27/2018, 1:22 PMcarlw
08/27/2018, 1:22 PMcarlw
08/27/2018, 1:22 PMchickenfresh
08/27/2018, 1:23 PMcarlw
08/27/2018, 1:24 PMchickenfresh
08/27/2018, 1:26 PMcarlw
08/27/2018, 1:26 PMcarlw
08/27/2018, 1:27 PMcarlw
08/27/2018, 1:28 PMchickenfresh
08/27/2018, 1:31 PMcarlw
08/27/2018, 1:31 PMcarlw
08/27/2018, 1:32 PMchickenfresh
08/27/2018, 1:33 PMchickenfresh
08/27/2018, 1:36 PMchickenfresh
08/27/2018, 1:36 PM