From 94f5dd20bddbfcc293f8fc4a166025e0d34bc317 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 20 Jan 2020 13:14:48 -0800 Subject: [PATCH] strip all absolute paths from stored profile images --- go.sum | 1 + go/ui/gcd.go | 2 +- go/ui/manager.go | 20 ++++++++++++++------ go/ui/utils.go | 4 ++-- qml/widgets/ContactRow.qml | 2 +- qml/widgets/ProfileList.qml | 4 ++-- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/go.sum b/go.sum index c623810b..ed8885e1 100644 --- a/go.sum +++ b/go.sum @@ -79,6 +79,7 @@ golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190420181800-aa740d480789 h1:FF0rjo15h51+N6642mf5S3QuplmKo2aCrJUYkHTx85s= golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= diff --git a/go/ui/gcd.go b/go/ui/gcd.go index 40d54d1a..3245fd20 100644 --- a/go/ui/gcd.go +++ b/go/ui/gcd.go @@ -602,7 +602,7 @@ func (this *GrandCentralDispatcher) loadProfile(onion string) { pic = RandomProfileImage(the.Peer.GetProfile().Onion) the.Peer.SetAttribute(constants.Picture, pic) } - this.UpdateMyProfile(the.Peer.GetProfile().Name, the.Peer.GetProfile().Onion, pic) + this.UpdateMyProfile(the.Peer.GetProfile().Name, the.Peer.GetProfile().Onion, profilePicRelativize(pic)) contacts := the.Peer.GetContacts() for i := range contacts { diff --git a/go/ui/manager.go b/go/ui/manager.go index 89ebc9ba..ea055d83 100644 --- a/go/ui/manager.go +++ b/go/ui/manager.go @@ -8,6 +8,7 @@ import ( "cwtch.im/ui/go/the" "git.openprivacy.ca/openprivacy/libricochet-go/log" "runtime/debug" + "strings" "time" ) @@ -62,11 +63,18 @@ func initLastReadTime(id string) time.Time { return lastRead } +// a lot of pics were stored full path + uri. remove all this to the relative path in images/ +// fix for storing full paths introduced 2019.12 +func profilePicRelativize(filename string) string { + parts := strings.Split(filename, "qml/images") + return parts[len(parts)-1] +} + func initProfilePicture(id string) string { if isGroup(id) { - return getWithSetDefault(id, constants.Picture, RandomGroupImage(id)) + return profilePicRelativize(getWithSetDefault(id, constants.Picture, RandomGroupImage(id))) } else { - return getWithSetDefault(id, constants.Picture, RandomProfileImage(id)) + return profilePicRelativize(getWithSetDefault(id, constants.Picture, RandomProfileImage(id))) } } @@ -76,11 +84,11 @@ func getProfilePic(id string) string { if pic, exists := the.Peer.GetGroupAttribute(id, constants.Picture); !exists { return RandomGroupImage(id) } else { - return pic + return profilePicRelativize(pic) } } else { if pic, exists := the.Peer.GetContactAttribute(id, constants.Picture); !exists { - return RandomProfileImage(id) + return profilePicRelativize(RandomProfileImage(id)) } else { return pic } @@ -125,8 +133,8 @@ func AddProfile(gcd *GrandCentralDispatcher, handle string) { } tag, _ := peer.GetAttribute(app.AttributeTag) - log.Infof("AddProfile %v %v %v %v\n", handle, nick, pic, tag) - gcd.AddProfile(handle, nick, pic, tag) + log.Infof("AddProfile %v %v %v %v\n", handle, nick, profilePicRelativize(pic), tag) + gcd.AddProfile(handle, nick, profilePicRelativize(pic), tag) } } diff --git a/go/ui/utils.go b/go/ui/utils.go index b0f39e8e..9761eaa8 100644 --- a/go/ui/utils.go +++ b/go/ui/utils.go @@ -13,7 +13,7 @@ func RandomProfileImage(onion string) string { barr, err := base32.StdEncoding.DecodeString(strings.ToUpper(onion)) if err != nil || len(barr) != 35 { log.Errorf("error: %v %v %v\n", onion, err, barr) - return "qrc:/qml/images/extra/openprivacy.png" + return "extra/openprivacy.png" } return "profiles/" + choices[int(barr[33])%len(choices)] + ".png" } @@ -23,7 +23,7 @@ func RandomGroupImage(handle string) string { barr, err := hex.DecodeString(handle) if err != nil || len(barr) == 0 { log.Errorf("error: %v %v %v\n", handle, err, barr) - return "qrc:/qml/images/extra/openprivacy.png" + return "extra/openprivacy.png" } return "servers/" + choices[int(barr[0])%len(choices)] + ".png" } diff --git a/qml/widgets/ContactRow.qml b/qml/widgets/ContactRow.qml index f74d838d..f25f21e8 100644 --- a/qml/widgets/ContactRow.qml +++ b/qml/widgets/ContactRow.qml @@ -118,7 +118,7 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY Image {// Profle Type id: profiletype - source: tag == "v1-userPassword" ? "qrc:/qml/images/fontawesome/solid/lock.svg" : "qrc:/qml/images/fontawesome/solid/lock-open.svg" + source: tag == "v1-userPassword" ? gcd.assetPath + "/fontawesome/solid/lock.svg" : gcd.assetPath + "/fontawesome/solid/lock-open.svg" anchors.right: parent.right diff --git a/qml/widgets/ProfileList.qml b/qml/widgets/ProfileList.qml index b7c1cc57..8c69e28b 100644 --- a/qml/widgets/ProfileList.qml +++ b/qml/widgets/ProfileList.qml @@ -86,7 +86,7 @@ ColumnLayout { profilesModel.append({ _handle: "", _displayName: qsTr("add-new-profile-btn"), - _image: "qrc:/qml/images/fontawesome/solid/user-plus.svg", + _image: "/fontawesome/solid/user-plus.svg", _type: "button", _tag: "," }) @@ -99,7 +99,7 @@ ColumnLayout { ListElement { _handle: "" _displayName: qsTr("add-new-profile-btn") - _image: "qrc:/qml/images/fontawesome/solid/user-plus.svg" + _image: "/fontawesome/solid/user-plus.svg" _type: "button" _tag: "" }