mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Implement chat cache on GXS delegate view
This commit is contained in:
parent
549b76141a
commit
d3e3f14afd
@ -11,8 +11,12 @@ QtObject {
|
||||
|
||||
property QtObject lastMessageCache: QtObject
|
||||
{
|
||||
id: lastMessageCache
|
||||
property var lastMessageList: ({})
|
||||
|
||||
signal lastMessageChanged()
|
||||
|
||||
|
||||
function updateLastMessageCache (chatId, chatModel){
|
||||
console.log("updateLastMessageCache (chatId, chatModel)", chatId)
|
||||
|
||||
@ -27,14 +31,34 @@ QtObject {
|
||||
|
||||
function updateLastMessage (chatId, chatModel){
|
||||
console.log("updateLastMessage (chatId, chatModel)")
|
||||
var lastMessage = getLastMessageFromChat (chatModel)
|
||||
var lastMessage = findChatLastMessage (chatModel)
|
||||
lastMessageList[chatId] = lastMessage
|
||||
|
||||
}
|
||||
|
||||
function getLastMessageFromChat (chatModel){
|
||||
function findChatLastMessage (chatModel){
|
||||
var messagesData = JSON.parse(chatModel).data
|
||||
return messagesData.slice(-1)[0]
|
||||
}
|
||||
|
||||
|
||||
function getChatIdFromGxs (gxs){
|
||||
for (var key in lastMessageList) {
|
||||
if ( lastMessageList[key].author_id === gxs ) {
|
||||
return key
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function getChatLastMessage (chatId){
|
||||
if (lastMessageList[chatId]) {
|
||||
return lastMessageList[chatId]
|
||||
}
|
||||
|
||||
return undefined
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.0
|
||||
import "." //Needed for ChatCache singleton
|
||||
|
||||
Item
|
||||
{
|
||||
@ -25,6 +26,18 @@ Item
|
||||
height: 50
|
||||
width: parent.width
|
||||
|
||||
// property var lastMessageData: getLastMessage()
|
||||
|
||||
property var chatId: undefined
|
||||
property var lastMessageData: ""
|
||||
property var authorName: lastMessageData.author_name
|
||||
|
||||
// JSONListModel
|
||||
// {
|
||||
// id: lastMessageData
|
||||
// query: "$.*"
|
||||
// }
|
||||
|
||||
Rectangle {
|
||||
|
||||
anchors.fill: parent
|
||||
@ -61,7 +74,6 @@ Item
|
||||
anchors.fill: parent
|
||||
color: "transparent"
|
||||
anchors.margins: 5
|
||||
// anchors.leftMargin: 5
|
||||
|
||||
|
||||
ColorHash
|
||||
@ -81,16 +93,32 @@ Item
|
||||
}
|
||||
}
|
||||
|
||||
Text
|
||||
{
|
||||
id: nickText
|
||||
color: model.own ? "blue" : "black"
|
||||
text: model.name
|
||||
Column {
|
||||
|
||||
height: parent.height
|
||||
anchors.left: colorHash.right
|
||||
anchors.leftMargin: 5
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
Text
|
||||
{
|
||||
id: nickText
|
||||
color: model.own ? "blue" : "black"
|
||||
text: model.name
|
||||
font.bold: true
|
||||
}
|
||||
|
||||
Text
|
||||
{
|
||||
id: lastMessage
|
||||
color: model.own ? "blue" : "black"
|
||||
text: (lastMessageData.msg) ? lastMessageData.msg : ""
|
||||
font.italic: true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Row
|
||||
{
|
||||
anchors.right: parent.right
|
||||
@ -133,6 +161,39 @@ Item
|
||||
}
|
||||
}
|
||||
}
|
||||
// signal lastMessageChanged(var chatI, var newLastMessage)
|
||||
// lastMessageChanged(chatId, lastMessage)
|
||||
// Connections {
|
||||
// target: ChatCache.lastMessageCache
|
||||
// onLastMessageChanged: {
|
||||
// if (!chatId) {
|
||||
// getChatIdFromGXS()
|
||||
// }
|
||||
|
||||
// if (chatId && chatId === chatI){
|
||||
// delegateRoot.lastMessageData = newLastMessage
|
||||
// console.log("@@@@@@@@@@@2 Last message changed ",chatI ,newLastMessage.msg, chatId )
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
Component.onCompleted: {
|
||||
if (!chatId){
|
||||
chatId = getChatIdFromGXS()
|
||||
}
|
||||
if (chatId) {
|
||||
lastMessageData = getChatLastMessage(chatId)
|
||||
}
|
||||
}
|
||||
|
||||
function getChatLastMessage (chatId){
|
||||
return ChatCache.lastMessageCache.getChatLastMessage(chatId)
|
||||
}
|
||||
|
||||
function getChatIdFromGXS (){
|
||||
return ChatCache.lastMessageCache.getChatIdFromGxs(model.gxs_id)
|
||||
}
|
||||
|
||||
function showDetails()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user