Create avatar cache and identity details cache

This commit is contained in:
Angela Mazzurco 2017-07-09 15:40:37 +02:00
parent 36708efa8c
commit 53eadfdc19
2 changed files with 55 additions and 17 deletions

View File

@ -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 ""
}
}
}

View File

@ -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()