From 7c4ee55fcf4ae8b9ebdcd47d0b3a36eef092aa3c Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Wed, 7 Jun 2017 15:00:37 +0200 Subject: [PATCH] Refactor chat cache to get remote GXS from GxsIdentityDelegate.qml instead from ChatView --- retroshare-qml-app/src/ChatCache.qml | 8 ++++---- retroshare-qml-app/src/GxsIdentityDelegate.qml | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/retroshare-qml-app/src/ChatCache.qml b/retroshare-qml-app/src/ChatCache.qml index cebdccbfe..8da30c2b1 100644 --- a/retroshare-qml-app/src/ChatCache.qml +++ b/retroshare-qml-app/src/ChatCache.qml @@ -37,10 +37,6 @@ QtObject { console.log("updateLastMessage (chatId, chatModel)") var lastMessage = findChatLastMessage (chatModel) lastMessageList[chatId].lastMessage = lastMessage - if (!lastMessageList[chatId].remoteGXS) { - var firstMessage = findChatFirstMessage (chatModel) - setRemoteGXS(chatId, firstMessage.author_id) - } lastMessageChanged(chatId, lastMessage) } @@ -55,6 +51,10 @@ QtObject { } function setRemoteGXS (chatId, remoteGXS){ + if (!lastMessageList[chatId]) { + lastMessageList[chatId] = {} + console.log("Last message cache created!") + } if (lastMessageList[chatId] && !lastMessageList[chatId].remoteGXS){ lastMessageList[chatId].remoteGXS = remoteGXS return true diff --git a/retroshare-qml-app/src/GxsIdentityDelegate.qml b/retroshare-qml-app/src/GxsIdentityDelegate.qml index 634bab277..85c1f137d 100644 --- a/retroshare-qml-app/src/GxsIdentityDelegate.qml +++ b/retroshare-qml-app/src/GxsIdentityDelegate.qml @@ -56,7 +56,7 @@ Item "remote_gxs_hex": model.gxs_id } rsApi.request("/chat/initiate_distant_chat", JSON.stringify(jsonData), - contactsView.startChatCallback) + startDistantChatCB) } } @@ -113,7 +113,6 @@ Item Text { -// text: (lastMessageData.recv_time)? Date.fromLocaleDateString(locale, lastMessageData.recv_time, "ddd yyyy-MM-dd hh:mm:ss"): "sad" text: setTime() anchors.right: parent.right color: "darkslategrey" @@ -259,5 +258,10 @@ Item "qrc:/ContactDetails.qml", {md: contactsListView.model.get(index)}) } + function startDistantChatCB (par){ + var chId = JSON.parse(par.response).data.chat_id + ChatCache.lastMessageCache.setRemoteGXS(chId, model.gxs_id) + contactsView.startChatCallback (par) + } }