From 53eadfdc1985cb25fc7d2c7c0829f0bf8f788c36 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Sun, 9 Jul 2017 15:40:37 +0200 Subject: [PATCH] Create avatar cache and identity details cache --- retroshare-qml-app/src/ChatCache.qml | 27 +++++++++-- .../src/components/AvatarOrColorHash.qml | 45 +++++++++++++------ 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/retroshare-qml-app/src/ChatCache.qml b/retroshare-qml-app/src/ChatCache.qml index cc0a9e85a..6e7b55c72 100644 --- a/retroshare-qml-app/src/ChatCache.qml +++ b/retroshare-qml-app/src/ChatCache.qml @@ -101,6 +101,8 @@ QtObject id: contactsCache property var contactsList property var own + property var identityDetails: ({}) + function getContactFromGxsId (gxsId) { @@ -109,10 +111,29 @@ QtObject { if (contactsList[i].gxs_id == gxsId) return contactsList[i] } - - - } + + function getIdentityDetails (gxsId) + { + if (identityDetails[gxsId]) return identityDetails[gxsId] + return "" + } + + function setIdentityDetails (jData) + { + identityDetails[jData.gxs_id] = jData + } + + function getIdentityAvatar (gxsId) + { + + if (identityDetails[gxsId] && identityDetails[gxsId].avatar !== undefined) + { + return identityDetails[gxsId].avatar + } + return "" + } + } } diff --git a/retroshare-qml-app/src/components/AvatarOrColorHash.qml b/retroshare-qml-app/src/components/AvatarOrColorHash.qml index fe0597356..b50002687 100644 --- a/retroshare-qml-app/src/components/AvatarOrColorHash.qml +++ b/retroshare-qml-app/src/components/AvatarOrColorHash.qml @@ -45,16 +45,25 @@ Item if (gxs_id) { default_image = false - rsApi.request( - "/identity/get_identity_details", - JSON.stringify({ gxs_id: compRoot.gxs_id }), - function(par) - { - var jData = JSON.parse(par.response).data - setDetails(jData) - if(!compRoot.has_avatar && - compRoot.avatarAttemptCnt < 3) getDetails() - }) + var hasAvatarCached = hasAvatar (ChatCache.contactsCache.getIdentityAvatar(gxs_id)) + if ( !hasAvatarCached ) + { + rsApi.request( + "/identity/get_identity_details", + JSON.stringify({ gxs_id: compRoot.gxs_id }), + function(par) + { + var jData = JSON.parse(par.response).data + ChatCache.contactsCache.setIdentityDetails(jData) + setDetails(jData) + if(!compRoot.has_avatar && + compRoot.avatarAttemptCnt < 3) getDetails() + }) + } + else + { + setDetails(ChatCache.contactsCache.getIdentityDetails(gxs_id)) + } } else { @@ -65,14 +74,23 @@ Item } function setDetails(data) { - compRoot.has_avatar = data.avatar.length > 0 + compRoot.has_avatar = hasAvatar (data.avatar) if(compRoot.has_avatar) { - contactAvatar.source = - "data:image/png;base64," + data.avatar + setImage(data.avatar) } } + function hasAvatar (avatar) + { + return avatar.length > 0 + } + function setImage (source) + { + contactAvatar.source = + "data:image/png;base64," + source + } + function showDetails() { console.log("showDetails() ", gxs_id) @@ -80,7 +98,6 @@ Item stackView.push( "qrc:/ContactDetails.qml", {md: ChatCache.contactsCache.getContactFromGxsId(gxs_id)}) - } Component.onCompleted: if(visible && (!has_avatar || default_image ) ) getDetails()