mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Implement last message cache from chats
This commit is contained in:
parent
fa9578fca6
commit
36a0e1fbb8
40
retroshare-qml-app/src/ChatCache.qml
Normal file
40
retroshare-qml-app/src/ChatCache.qml
Normal file
@ -0,0 +1,40 @@
|
||||
pragma Singleton
|
||||
|
||||
import QtQml 2.7
|
||||
import QtQuick.Controls 2.0
|
||||
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
||||
import Qt.labs.settings 1.0
|
||||
|
||||
QtObject {
|
||||
|
||||
id: chatCache
|
||||
|
||||
property QtObject lastMessageCache: QtObject
|
||||
{
|
||||
property var lastMessageList: ({})
|
||||
|
||||
function updateLastMessageCache (chatId, chatModel){
|
||||
console.log("updateLastMessageCache (chatId, chatModel)", chatId)
|
||||
|
||||
if (!chatModel) {
|
||||
rsApi.request( "/chat/messages/"+chatId, "", function (par){
|
||||
updateLastMessage(chatId, par.response)
|
||||
})
|
||||
} else {
|
||||
updateLastMessage (chatId, chatModel)
|
||||
}
|
||||
}
|
||||
|
||||
function updateLastMessage (chatId, chatModel){
|
||||
var lastMessage = getLastMessage (chatModel)
|
||||
lastMessageList[chatId] = lastMessage
|
||||
}
|
||||
|
||||
function getLastMessageFromChat (chatModel){
|
||||
console.log("getLastMessage (chatMessages)")
|
||||
var messagesData = JSON.parse(chatMessages).data
|
||||
return messagesData.slice(-1)[0]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user