Load cached avatars on contacts view

This commit is contained in:
Angela Mazzurco 2017-07-09 15:55:04 +02:00
parent 53eadfdc19
commit 1917e673f2
2 changed files with 32 additions and 20 deletions

View File

@ -91,22 +91,18 @@ Item
color: "transparent"
anchors.margins: 5
ColorHash
AvatarOrColorHash
{
id: colorHash
hash: model.gxs_id
gxs_id: model.gxs_id
height: parent.height - 4
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 2
MouseArea
{
anchors.fill: parent
onClicked: delegateRoot.showDetails()
}
onlyCached: true
}
Column

View File

@ -25,6 +25,7 @@ Item
id: compRoot
property string gxs_id
property bool onlyCached: false
signal clicked ()
height: 130
@ -54,15 +55,14 @@ Item
function(par)
{
var jData = JSON.parse(par.response).data
ChatCache.contactsCache.setIdentityDetails(jData)
setDetails(jData)
saveDetails(jData)
if(!compRoot.has_avatar &&
compRoot.avatarAttemptCnt < 3) getDetails()
})
}
else
{
setDetails(ChatCache.contactsCache.getIdentityDetails(gxs_id))
setImage(ChatCache.contactsCache.getIdentityDetails(gxs_id))
}
}
else
@ -72,12 +72,19 @@ Item
contactAvatar.source = noGxsImage
}
}
function setDetails(data)
function saveDetails(data)
{
ChatCache.contactsCache.setIdentityDetails(data)
setImage(data)
}
function setImage (data)
{
compRoot.has_avatar = hasAvatar (data.avatar)
if(compRoot.has_avatar)
{
setImage(data.avatar)
contactAvatar.source =
"data:image/png;base64," + data.avatar
}
}
@ -85,11 +92,6 @@ Item
{
return avatar.length > 0
}
function setImage (source)
{
contactAvatar.source =
"data:image/png;base64," + source
}
function showDetails()
{
@ -100,9 +102,23 @@ Item
{md: ChatCache.contactsCache.getContactFromGxsId(gxs_id)})
}
Component.onCompleted: if(visible && (!has_avatar || default_image ) ) getDetails()
Component.onCompleted: startComponent ()
onVisibleChanged: if(visible && (!has_avatar || default_image ) ) getDetails()
onVisibleChanged: startComponent ()
function startComponent ()
{
if (onlyCached && hasAvatar (ChatCache.contactsCache.getIdentityAvatar(gxs_id) ) )
{
console.log("load cached avatar")
setImage(ChatCache.contactsCache.getIdentityDetails(gxs_id))
}
else if (!onlyCached)
{
if(visible && (!has_avatar || default_image ) ) getDetails()
}
}
Image
{