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" color: "transparent"
anchors.margins: 5 anchors.margins: 5
AvatarOrColorHash
ColorHash
{ {
id: colorHash id: colorHash
hash: model.gxs_id gxs_id: model.gxs_id
height: parent.height - 4 height: parent.height - 4
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 2 anchors.leftMargin: 2
MouseArea onlyCached: true
{
anchors.fill: parent
onClicked: delegateRoot.showDetails()
}
} }
Column Column

View File

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