Use image server for all kind of images and integrate identity rings

This commit is contained in:
frank 2022-08-07 15:35:54 +08:00 committed by Andrea Maria Piana
parent 0217b6a439
commit 6e4ac1c495
19 changed files with 158 additions and 258 deletions

View File

@ -1 +1 @@
0.109.2
0.109.3

2
go.mod
View File

@ -80,7 +80,7 @@ require (
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3
)
require github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90
require github.com/fogleman/gg v1.3.0
require github.com/gorilla/sessions v1.2.1

2
go.sum
View File

@ -769,6 +769,7 @@ github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlK
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
@ -926,6 +927,7 @@ github.com/golang-migrate/migrate/v4 v4.6.2/go.mod h1:JYi6reN3+Z734VZ0akNuyOJNcr
github.com/golang-migrate/migrate/v4 v4.15.2 h1:vU+M05vs6jWHKDdmE1Ecwj0BznygFc4QsdRe2E/L7kc=
github.com/golang-migrate/migrate/v4 v4.15.2/go.mod h1:f2toGLkYqD3JH+Todi4aZ2ZdbeUNx4sIwiOK96rE9Lw=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=

View File

@ -2,9 +2,7 @@ package images
import (
"bytes"
"encoding/base64"
"errors"
"fmt"
"image"
"image/gif"
"image/jpeg"
@ -13,7 +11,6 @@ import (
"io/ioutil"
"net/http"
"os"
"strings"
"time"
"golang.org/x/image/webp"
@ -36,15 +33,6 @@ func Decode(fileName string) (image.Image, error) {
return decodeImageData(fb, file)
}
func DecodeFromB64Uri(b64Uri string) ([]byte, error) {
a := strings.Split(b64Uri, ";")
if len(a) != 2 || len(a[1]) <= 7 {
return nil, errors.New(fmt.Sprintf("b64Uri can not be parsed. b64Uri: %s", b64Uri))
}
imageB64String := strings.Split(b64Uri, ";")[1][7:]
return base64.StdEncoding.DecodeString(imageB64String)
}
func DecodeFromURL(path string) (image.Image, error) {
client := http.Client{
Timeout: 5 * time.Second,

View File

@ -8,9 +8,6 @@ import (
"os"
"unsafe"
"github.com/status-im/status-go/extkeys"
"github.com/status-im/status-go/protocol/identity/ring"
validator "gopkg.in/go-playground/validator.v9"
"github.com/ethereum/go-ethereum/log"
@ -24,6 +21,7 @@ import (
"github.com/status-im/status-go/api/multiformat"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/exportlogs"
"github.com/status-im/status-go/extkeys"
"github.com/status-im/status-go/images"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/multiaccounts/accounts"
@ -60,31 +58,6 @@ func OpenAccounts(datadir string) string {
return string(data)
}
func DrawIdentityImageRing(drawRingParamsJson string) string {
var drawRingParams []ring.DrawRingParam
if err := json.Unmarshal([]byte(drawRingParamsJson), &drawRingParams); err != nil {
return makeJSONResponse(err)
}
var ringImageUris []string
for _, param := range drawRingParams {
ringImageBytes, err := ring.DrawRing(&param)
if err != nil {
return makeJSONResponse(err)
}
ringImageUri, err := images.GetPayloadDataURI(ringImageBytes)
if err != nil {
return makeJSONResponse(err)
}
ringImageUris = append(ringImageUris, ringImageUri)
}
data, err := json.Marshal(ringImageUris)
if err != nil {
return makeJSONResponse(err)
}
return string(data)
}
// ExtractGroupMembershipSignatures extract public keys from tuples of content/signature.
func ExtractGroupMembershipSignatures(signaturePairsStr string) string {
var signaturePairs [][2]string

View File

@ -363,15 +363,14 @@ func (db *Database) StoreIdentityImages(keyUID string, iis []images.IdentityImag
err = valueOr(err, errRollback)
}()
for _, ii := range iis {
for i, ii := range iis {
if ii.IsEmpty() {
continue
}
ii.KeyUID = keyUID
iis[i].KeyUID = keyUID
_, err := tx.Exec(
"INSERT INTO identity_images (key_uid, name, image_payload, width, height, file_size, resize_target, clock) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
ii.KeyUID,
keyUID,
ii.Name,
ii.Payload,
ii.Width,

View File

@ -2,15 +2,12 @@ package ring
import (
"bytes"
"errors"
"fmt"
"image"
"image/png"
"math"
"github.com/fogleman/gg"
"github.com/status-im/status-go/images"
)
type Theme int
@ -29,7 +26,6 @@ type DrawRingParam struct {
Theme Theme `json:"theme"`
ColorHash [][]int `json:"colorHash"`
ImageBytes []byte `json:"imageBytes"`
ImageUri string `json:"uri"`
Height int `json:"height"`
Width int `json:"width"`
}
@ -42,17 +38,10 @@ func DrawRing(param *DrawRingParam) ([]byte, error) {
case DarkTheme:
colors = darkThemeIdenticonRingColors
default:
return nil, errors.New(fmt.Sprintf("unknown theme"))
return nil, fmt.Errorf("unknown theme")
}
dc := gg.NewContext(param.Width, param.Height)
if param.ImageUri != "" {
imageBytes, err := images.DecodeFromB64Uri(param.ImageUri)
if err != nil {
return nil, err
}
param.ImageBytes = imageBytes
}
img, _, err := image.Decode(bytes.NewReader(param.ImageBytes))
if err != nil {
return nil, err

View File

@ -1500,7 +1500,6 @@ func (m *Messenger) Init() error {
if err != nil {
return err
}
m.SetRingUrlForContactImages(contacts)
for idx, contact := range contacts {
m.allContacts.Store(contact.ID, contacts[idx])
// We only need filters for contacts added by us and not blocked.
@ -1528,20 +1527,6 @@ func (m *Messenger) Init() error {
return err
}
func (m *Messenger) SetRingUrlForContactImages(contacts []*Contact) {
for i, _ := range contacts {
m.SetRingUrlForContactImage(contacts[i])
}
}
func (m *Messenger) SetRingUrlForContactImage(contact *Contact) {
for key, _ := range contact.Images {
image := contact.Images[key]
image.RingUrl = m.httpServer.MakeDrawRingURL(contact.ID, server.DrawRingTypeContact, image.Name)
contact.Images[key] = image
}
}
// Shutdown takes care of ensuring a clean shutdown of Messenger
func (m *Messenger) Shutdown() (err error) {
close(m.quit)
@ -4149,8 +4134,6 @@ func (m *Messenger) prepareMessages(messages map[string]*common.Message) {
}
func (m *Messenger) prepareMessage(msg *common.Message, s *server.MediaServer) {
msg.Identicon = s.MakeIdenticonURL(msg.From)
if msg.QuotedMessage != nil && msg.QuotedMessage.ContentType == int64(protobuf.ChatMessage_IMAGE) {
msg.QuotedMessage.ImageLocalURL = s.MakeImageURL(msg.QuotedMessage.ID)
}

View File

@ -1906,7 +1906,7 @@ func (m *Messenger) HandleChatIdentity(state *ReceivedMessageState, ci protobuf.
if contact.Images == nil {
contact.Images = make(map[string]images.IdentityImage)
}
contact.Images[imageType] = images.IdentityImage{Name: imageType, Payload: image.Payload}
contact.Images[imageType] = images.IdentityImage{Name: imageType, Payload: image.Payload, Clock: ci.Clock}
}
contactModified = true

View File

@ -599,7 +599,7 @@ func (db sqlitePersistence) Contacts() ([]*Contact, error) {
&contactRequestClock,
&imageType,
&imagePayload,
&identityImageClock,
&identityImageClock,
&contact.VerificationStatus,
&contact.TrustStatus,
)
@ -654,13 +654,13 @@ func (db sqlitePersistence) Contacts() ([]*Contact, error) {
previousContact, ok := allContacts[contact.ID]
if !ok {
if imageType.Valid {
contact.Images[imageType.String] = images.IdentityImage{Name: imageType.String, Payload: imagePayload, Clock: uint64(identityImageClock.Int64)}
contact.Images[imageType.String] = images.IdentityImage{Name: imageType.String, Payload: imagePayload, Clock: uint64(identityImageClock.Int64)}
}
allContacts[contact.ID] = &contact
} else if imageType.Valid {
previousContact.Images[imageType.String] = images.IdentityImage{Name: imageType.String, Payload: imagePayload, Clock: uint64(identityImageClock.Int64)}
previousContact.Images[imageType.String] = images.IdentityImage{Name: imageType.String, Payload: imagePayload, Clock: uint64(identityImageClock.Int64)}
allContacts[contact.ID] = previousContact
}

View File

@ -29,7 +29,7 @@ func (s *ConnectionParamsSuite) SetupSuite() {
cert, _, err := GenerateCertFromKey(s.PK, s.NotBefore, defaultIP.String())
s.Require().NoError(err)
bs := NewServer(&cert, defaultIP.String())
bs := NewServer(&cert, defaultIP.String(), func(int) {})
bs.port = 1337
s.server = &PairingServer{

View File

@ -11,17 +11,15 @@ import (
"strconv"
"time"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/protocol/identity/colorhash"
"github.com/status-im/status-go/protocol/identity/ring"
"github.com/btcsuite/btcutil/base58"
"go.uber.org/zap"
"github.com/status-im/status-go/ipfs"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/protocol/common"
identityImages "github.com/status-im/status-go/images"
"github.com/status-im/status-go/protocol/identity/colorhash"
"github.com/status-im/status-go/protocol/identity/identicon"
"github.com/status-im/status-go/protocol/identity/ring"
"github.com/status-im/status-go/protocol/images"
"github.com/status-im/status-go/signal"
)
@ -31,7 +29,6 @@ const (
identiconsPath = basePath + "/identicons"
imagesPath = basePath + "/images"
audioPath = basePath + "/audio"
identityImagesPath = "/identityImages"
ipfsPath = "/ipfs"
// Handler routes for pairing
@ -44,39 +41,79 @@ const (
sessionChallenge = "challenge"
sessionBlocked = "blocked"
drawRingPath = basePath + "/drawRing"
DrawRingTypeAccount = "account"
DrawRingTypeContact = "contact"
accountImagesPath = "/accountImages"
contactImagesPath = "/contactImages"
)
type HandlerPatternMap map[string]http.HandlerFunc
func drawRingForAccountIdentity(multiaccountsDB *multiaccounts.Database, publicKey string, imageName string, theme ring.Theme, colorHash [][]int) ([]byte, error) {
image, err := multiaccountsDB.GetIdentityImage(publicKey, imageName)
if err != nil {
return nil, err
func handleAccountImages(multiaccountsDB *multiaccounts.Database, logger *zap.Logger) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
params := r.URL.Query()
keyUids, ok := params["keyUid"]
if !ok || len(keyUids) == 0 {
logger.Error("no keyUid")
return
}
imageNames, ok := params["imageName"]
if !ok || len(imageNames) == 0 {
logger.Error("no imageName")
return
}
identityImage, err := multiaccountsDB.GetIdentityImage(keyUids[0], imageNames[0])
if err != nil {
logger.Error("handleAccountImages: failed to load image.", zap.String("keyUid", keyUids[0]), zap.String("imageName", imageNames[0]), zap.Error(err))
return
}
var payload = identityImage.Payload
if ringEnabled(params) {
pks, ok := params["publicKey"]
if !ok || len(pks) == 0 {
logger.Error("no publicKey")
return
}
colorHash, err := colorhash.GenerateFor(pks[0])
if err != nil {
logger.Error("could not generate color hash")
return
}
var theme = getTheme(params, logger)
payload, err = ring.DrawRing(&ring.DrawRingParam{
Theme: theme, ColorHash: colorHash, ImageBytes: identityImage.Payload, Height: identityImage.Height, Width: identityImage.Width,
})
if err != nil {
logger.Error("failed to draw ring for account identity", zap.Error(err))
return
}
}
if len(payload) == 0 {
logger.Error("empty image")
return
}
mime, err := images.ImageMime(payload)
if err != nil {
logger.Error("failed to get mime", zap.Error(err))
}
w.Header().Set("Content-Type", mime)
w.Header().Set("Cache-Control", "no-store")
_, err = w.Write(payload)
if err != nil {
logger.Error("failed to write image", zap.Error(err))
}
}
return ring.DrawRing(&ring.DrawRingParam{
Theme: theme, ColorHash: colorHash, ImageBytes: image.Payload, Height: image.Height, Width: image.Width,
})
}
func drawRingForContactIdentity(db *sql.DB, publicKey string, imageName string, theme ring.Theme, colorHash [][]int) ([]byte, error) {
var payload []byte
err := db.QueryRow(`SELECT payload FROM chat_identity_contacts WHERE contact_id = ? and image_type = ?`, publicKey, imageName).Scan(&payload)
if err != nil {
return nil, err
}
config, _, err := image.DecodeConfig(bytes.NewReader(payload))
if err != nil {
return nil, err
}
return ring.DrawRing(&ring.DrawRingParam{
Theme: theme, ColorHash: colorHash, ImageBytes: payload, Height: config.Height, Width: config.Width,
})
}
func handleDrawRing(db *sql.DB, multiaccountsDB *multiaccounts.Database, logger *zap.Logger) func(w http.ResponseWriter, r *http.Request) {
func handleContactImages(db *sql.DB, logger *zap.Logger) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
params := r.URL.Query()
pks, ok := params["publicKey"]
@ -84,11 +121,6 @@ func handleDrawRing(db *sql.DB, multiaccountsDB *multiaccounts.Database, logger
logger.Error("no publicKey")
return
}
types, ok := params["type"] // account or contact
if !ok || len(types) == 0 {
logger.Error("no type")
return
}
imageNames, ok := params["imageName"]
if !ok || len(imageNames) == 0 {
logger.Error("no imageName")
@ -100,30 +132,36 @@ func handleDrawRing(db *sql.DB, multiaccountsDB *multiaccounts.Database, logger
return
}
var image []byte
var theme = getTheme(params, logger)
if types[0] == DrawRingTypeAccount {
image, err = drawRingForAccountIdentity(multiaccountsDB, pks[0], imageNames[0], theme, colorHash)
if err != nil {
logger.Error("failed to draw ring for account identity", zap.Error(err))
return
}
} else if types[0] == DrawRingTypeContact {
image, err = drawRingForContactIdentity(db, pks[0], imageNames[0], theme, colorHash)
if err != nil {
logger.Error("failed to draw ring for contact identity", zap.Error(err))
return
}
} else {
logger.Error("unknown type:", zap.String("type", types[0]))
var payload []byte
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 len(image) == 0 {
if ringEnabled(params) {
var theme = getTheme(params, logger)
config, _, err := image.DecodeConfig(bytes.NewReader(payload))
if err != nil {
logger.Error("failed to decode config.", zap.String("contact id", pks[0]), zap.String("image type", imageNames[0]), zap.Error(err))
return
}
payload, err = ring.DrawRing(&ring.DrawRingParam{
Theme: theme, ColorHash: colorHash, ImageBytes: payload, Height: config.Height, Width: config.Width,
})
if err != nil {
logger.Error("failed to draw ring for contact image.", zap.Error(err))
return
}
}
if len(payload) == 0 {
logger.Error("empty image")
return
}
mime, err := images.ImageMime(image)
mime, err := images.ImageMime(payload)
if err != nil {
logger.Error("failed to get mime", zap.Error(err))
}
@ -131,13 +169,18 @@ func handleDrawRing(db *sql.DB, multiaccountsDB *multiaccounts.Database, logger
w.Header().Set("Content-Type", mime)
w.Header().Set("Cache-Control", "no-store")
_, err = w.Write(image)
_, err = w.Write(payload)
if err != nil {
logger.Error("failed to write image", zap.Error(err))
}
}
}
func ringEnabled(params url.Values) bool {
addRings, ok := params["addRing"]
return ok && len(addRings) == 1 && addRings[0] == "1"
}
func getTheme(params url.Values, logger *zap.Logger) ring.Theme {
theme := ring.LightTheme // default
themes, ok := params["theme"]
@ -166,7 +209,7 @@ func handleIdenticon(logger *zap.Logger) http.HandlerFunc {
logger.Error("could not generate identicon")
}
if image != nil {
if image != nil && ringEnabled(params) {
colorHash, err := colorhash.GenerateFor(pk)
if err != nil {
logger.Error("could not generate color hash")
@ -193,81 +236,6 @@ func handleIdenticon(logger *zap.Logger) http.HandlerFunc {
}
}
// TODO: return error
func handleIdentityImage(db *sql.DB, logger *zap.Logger) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
pks, ok := r.URL.Query()["publicKey"]
if !ok || len(pks) == 0 {
logger.Error("no publicKey")
return
}
pk := pks[0]
rows, err := db.Query(`SELECT image_type, payload FROM chat_identity_contacts WHERE contact_id = ?`, pk)
if err != nil {
logger.Error("could not fetch identity images")
return
}
defer rows.Close()
var identityImage identityImages.IdentityImage
for rows.Next() {
var imageType sql.NullString
var imagePayload []byte
err := rows.Scan(
&imageType,
&imagePayload,
)
if err != nil {
logger.Error("could not scan image row")
return
}
identityImage = identityImages.IdentityImage{Name: imageType.String, Payload: imagePayload}
}
imageType := "image/png"
var image []byte
if identityImage.Payload != nil {
t, err := identityImage.GetType()
if err != nil {
logger.Error("could not get image type")
return
}
switch t {
case identityImages.JPEG:
imageType = "image/jpeg"
case identityImages.PNG:
imageType = "image/png"
case identityImages.GIF:
imageType = "image/gif"
case identityImages.WEBP:
imageType = "image/webp"
}
image = identityImage.Payload
} else {
image, err = identicon.Generate(pk)
if err != nil {
logger.Error("could not generate identicon")
return
}
}
w.Header().Set("Content-Type", imageType)
w.Header().Set("Cache-Control", "max-age:290304000, public")
w.Header().Set("Expires", time.Now().AddDate(60, 0, 0).Format(http.TimeFormat))
_, err = w.Write(image)
if err != nil {
logger.Error("failed to write image", zap.Error(err))
}
}
}
func handleImage(db *sql.DB, logger *zap.Logger) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
messageIDs, ok := r.URL.Query()["messageId"]

View File

@ -11,21 +11,21 @@ import (
"go.uber.org/zap"
"github.com/status-im/status-go/logutils"
"github.com/status-im/status-go/signal"
)
type Server struct {
run bool
server *http.Server
logger *zap.Logger
cert *tls.Certificate
hostname string
port int
handlers HandlerPatternMap
run bool
server *http.Server
logger *zap.Logger
cert *tls.Certificate
hostname string
port int
handlers HandlerPatternMap
afterPortChanged func(port int)
}
func NewServer(cert *tls.Certificate, hostname string) Server {
return Server{logger: logutils.ZapLogger(), cert: cert, hostname: hostname}
func NewServer(cert *tls.Certificate, hostname string, afterPortChanged func(int)) Server {
return Server{logger: logutils.ZapLogger(), cert: cert, hostname: hostname, afterPortChanged: afterPortChanged}
}
func (s *Server) getHost() string {
@ -49,7 +49,9 @@ func (s *Server) listenAndServe() {
}
s.port = listener.Addr().(*net.TCPAddr).Port
signal.SendMediaServerStarted(s.port)
if s.afterPortChanged != nil {
s.afterPortChanged(s.port)
}
s.run = true
err = s.server.Serve(listener)
@ -83,7 +85,6 @@ func (s *Server) applyHandlers() {
func (s *Server) Start() error {
// Once Shutdown has been called on a server, it may not be reused;
s.logger.Info("media server starting...")
s.resetServer()
s.applyHandlers()
go s.listenAndServe()

View File

@ -4,6 +4,8 @@ import (
"database/sql"
"net/url"
"github.com/status-im/status-go/signal"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/ipfs"
@ -25,18 +27,18 @@ func NewMediaServer(db *sql.DB, downloader *ipfs.Downloader, multiaccountsDB *mu
}
s := &MediaServer{
Server: NewServer(globalCertificate, localhost),
Server: NewServer(globalCertificate, localhost, signal.SendMediaServerStarted),
db: db,
downloader: downloader,
multiaccountsDB: multiaccountsDB,
}
s.SetHandlers(HandlerPatternMap{
imagesPath: handleImage(s.db, s.logger),
audioPath: handleAudio(s.db, s.logger),
identityImagesPath: handleIdentityImage(s.db, s.logger),
identiconsPath: handleIdenticon(s.logger),
ipfsPath: handleIPFS(s.downloader, s.logger),
drawRingPath: handleDrawRing(s.db, s.multiaccountsDB, s.logger),
imagesPath: handleImage(s.db, s.logger),
audioPath: handleAudio(s.db, s.logger),
identiconsPath: handleIdenticon(s.logger),
ipfsPath: handleIPFS(s.downloader, s.logger),
accountImagesPath: handleAccountImages(s.multiaccountsDB, s.logger),
contactImagesPath: handleContactImages(s.db, s.logger),
})
return s, nil
@ -79,11 +81,3 @@ func (s *MediaServer) MakeStickerURL(stickerHash string) string {
return u.String()
}
func (s *MediaServer) MakeDrawRingURL(publicKey string, drawRingType string, imageName string) string {
u := s.MakeBaseURL()
u.Path = drawRingPath
u.RawQuery = url.Values{"publicKey": {publicKey}, "type": {drawRingType}, "imageName": {imageName}}.Encode()
return u.String()
}

View File

@ -69,6 +69,7 @@ func NewPairingServer(config *Config) (*PairingServer, error) {
return &PairingServer{Server: NewServer(
config.Cert,
config.Hostname,
nil,
),
pk: config.PK,
ek: config.EK,

View File

@ -34,20 +34,12 @@ func (api *MultiAccountsAPI) UpdateAccount(account multiaccounts.Account) error
// GetIdentityImages returns an array of json marshalled IdentityImages assigned to the user's identity
func (api *MultiAccountsAPI) GetIdentityImages(keyUID string) ([]*images.IdentityImage, error) {
images, err := api.db.GetIdentityImages(keyUID)
for i, _ := range images {
images[i].RingUrl = api.mediaServer.MakeDrawRingURL(keyUID, server.DrawRingTypeAccount, images[i].Name)
}
return images, err
return api.db.GetIdentityImages(keyUID)
}
// GetIdentityImage returns a json object representing the image with the given name
func (api *MultiAccountsAPI) GetIdentityImage(keyUID, name string) (*images.IdentityImage, error) {
image, err := api.db.GetIdentityImage(keyUID, name)
if image != nil {
image.RingUrl = api.mediaServer.MakeDrawRingURL(keyUID, server.DrawRingTypeAccount, image.Name)
}
return image, err
return api.db.GetIdentityImage(keyUID, name)
}
// StoreIdentityImage takes the filepath of an image, crops it as per the rect coords and finally resizes the image.

View File

@ -20,12 +20,12 @@ func NewService(db *accounts.Database, mdb *multiaccounts.Database, manager *acc
// Service is a browsers service.
type Service struct {
db *accounts.Database
mdb *multiaccounts.Database
manager *account.GethManager
config *params.NodeConfig
feed *event.Feed
messenger *protocol.Messenger
db *accounts.Database
mdb *multiaccounts.Database
manager *account.GethManager
config *params.NodeConfig
feed *event.Feed
messenger *protocol.Messenger
mediaServer *server.MediaServer
}

View File

@ -4,7 +4,6 @@ const (
// EventMediaServerStarted triggers when the media server successfully binds a new port
EventMediaServerStarted = "mediaserver.started"
// EventMesssageDelivered triggered when we got acknowledge from datasync level, that means peer got message
EventMesssageDelivered = "message.delivered"
@ -24,7 +23,7 @@ type MessageDeliveredSignal struct {
// MediaServerStarted specifies chat and message that was delivered
type MediaServerStarted struct {
Port int `json:"port"`
Port int `json:"port"`
}
// MessageDeliveredSignal specifies chat and message that was delivered
@ -45,7 +44,6 @@ func SendMediaServerStarted(port int) {
send(EventMediaServerStarted, MediaServerStarted{Port: port})
}
// SendMessageDelivered notifies about delivered message
func SendCommunityInfoFound(community interface{}) {
send(EventCommunityInfoFound, community)

12
vendor/modules.txt vendored
View File

@ -275,6 +275,9 @@ github.com/fjl/memsize/memsizeui
# github.com/flynn/noise v1.0.0 => github.com/status-im/noise v1.0.1-handshakeMessages
## explicit; go 1.16
github.com/flynn/noise
# github.com/fogleman/gg v1.3.0
## explicit
github.com/fogleman/gg
# github.com/forPelevin/gomoji v1.1.2 => github.com/status-im/gomoji v1.1.3-0.20220213022530-e5ac4a8732d4
## explicit; go 1.13
github.com/forPelevin/gomoji
@ -321,6 +324,10 @@ github.com/golang-migrate/migrate/v4/database/sqlite3
github.com/golang-migrate/migrate/v4/internal/url
github.com/golang-migrate/migrate/v4/source
github.com/golang-migrate/migrate/v4/source/go_bindata
# github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
## explicit
github.com/golang/freetype/raster
github.com/golang/freetype/truetype
# github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
## explicit
github.com/golang/groupcache
@ -1118,6 +1125,11 @@ golang.org/x/crypto/ssh/terminal
# golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb
## explicit; go 1.12
golang.org/x/image/bmp
golang.org/x/image/draw
golang.org/x/image/font
golang.org/x/image/font/basicfont
golang.org/x/image/math/f64
golang.org/x/image/math/fixed
golang.org/x/image/riff
golang.org/x/image/vp8
golang.org/x/image/vp8l