feat: add and populate IdentityImage::LocalURL
part of: status-im/status-desktop#10886
This commit is contained in:
parent
d73c886d3b
commit
46768e624a
|
@ -17,6 +17,7 @@ type IdentityImage struct {
|
|||
FileSize int `json:"fileSize"`
|
||||
ResizeTarget int `json:"resizeTarget"`
|
||||
Clock uint64 `json:"clock"`
|
||||
LocalURL string `json:"localUrl,omitempty"`
|
||||
}
|
||||
|
||||
func (i IdentityImage) GetType() (ImageType, error) {
|
||||
|
@ -51,6 +52,7 @@ func (i IdentityImage) MarshalJSON() ([]byte, error) {
|
|||
FileSize int `json:"fileSize"`
|
||||
ResizeTarget int `json:"resizeTarget"`
|
||||
Clock uint64 `json:"clock"`
|
||||
LocalURL string `json:"localUrl,omitempty"`
|
||||
}{
|
||||
KeyUID: i.KeyUID,
|
||||
Name: i.Name,
|
||||
|
@ -60,6 +62,7 @@ func (i IdentityImage) MarshalJSON() ([]byte, error) {
|
|||
FileSize: i.FileSize,
|
||||
ResizeTarget: i.ResizeTarget,
|
||||
Clock: i.Clock,
|
||||
LocalURL: i.LocalURL,
|
||||
}
|
||||
|
||||
return json.Marshal(temp)
|
||||
|
|
|
@ -1642,6 +1642,9 @@ func (m *Messenger) Init() error {
|
|||
return err
|
||||
}
|
||||
for idx, contact := range contacts {
|
||||
if err = m.updateContactImagesURL(contact); err != nil {
|
||||
return err
|
||||
}
|
||||
m.allContacts.Store(contact.ID, contacts[idx])
|
||||
// We only need filters for contacts added by us and not blocked.
|
||||
if !contact.added() || contact.Blocked {
|
||||
|
|
|
@ -554,6 +554,20 @@ func (m *Messenger) RemoveContact(ctx context.Context, pubKey string) (*Messenge
|
|||
return response, nil
|
||||
}
|
||||
|
||||
func (m *Messenger) updateContactImagesURL(contact *Contact) error {
|
||||
if m.httpServer != nil {
|
||||
for k, v := range contact.Images {
|
||||
publicKey, err := contact.PublicKey()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.LocalURL = m.httpServer.MakeContactImageURL(common.PubkeyToHex(publicKey), k)
|
||||
contact.Images[k] = v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Messenger) Contacts() []*Contact {
|
||||
var contacts []*Contact
|
||||
m.allContacts.Range(func(contactID string, contact *Contact) (shouldContinue bool) {
|
||||
|
|
|
@ -2671,6 +2671,10 @@ func (m *Messenger) HandleChatIdentity(state *ReceivedMessageState, ci protobuf.
|
|||
contact.Images[imageType] = images.IdentityImage{Name: imageType, Payload: image.Payload, Clock: ci.Clock}
|
||||
|
||||
}
|
||||
if err = m.updateContactImagesURL(contact); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
contactModified = true
|
||||
}
|
||||
|
||||
|
|
|
@ -147,20 +147,21 @@ func handleContactImages(db *sql.DB, logger *zap.Logger) http.HandlerFunc {
|
|||
logger.Error("no imageName")
|
||||
return
|
||||
}
|
||||
colorHash, err := colorhash.GenerateFor(pks[0])
|
||||
if err != nil {
|
||||
logger.Error("could not generate color hash")
|
||||
return
|
||||
}
|
||||
|
||||
var payload []byte
|
||||
err = db.QueryRow(`SELECT payload FROM chat_identity_contacts WHERE contact_id = ? and image_type = ?`, pks[0], imageNames[0]).Scan(&payload)
|
||||
err := db.QueryRow(`SELECT payload FROM chat_identity_contacts WHERE contact_id = ? and image_type = ?`, pks[0], imageNames[0]).Scan(&payload)
|
||||
if err != nil {
|
||||
logger.Error("failed to load image.", zap.String("contact id", pks[0]), zap.String("image type", imageNames[0]), zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
if ringEnabled(params) {
|
||||
colorHash, err := colorhash.GenerateFor(pks[0])
|
||||
if err != nil {
|
||||
logger.Error("could not generate color hash")
|
||||
return
|
||||
}
|
||||
|
||||
var theme = getTheme(params, logger)
|
||||
config, _, err := image.DecodeConfig(bytes.NewReader(payload))
|
||||
if err != nil {
|
||||
|
|
|
@ -130,3 +130,11 @@ func (s *MediaServer) MakeQRURL(qurul string,
|
|||
|
||||
return u.String()
|
||||
}
|
||||
|
||||
func (s *MediaServer) MakeContactImageURL(publicKey string, imageType string) string {
|
||||
u := s.MakeBaseURL()
|
||||
u.Path = contactImagesPath
|
||||
u.RawQuery = url.Values{"publicKey": {publicKey}, "imageName": {imageType}}.Encode()
|
||||
|
||||
return u.String()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue