Added getSettings helper and moved IdentityImage attachment to dedicated function
This commit is contained in:
parent
aaf9aeca8a
commit
de14ec9628
|
@ -753,42 +753,9 @@ func (m *Messenger) createChatIdentity(context chatContext) (*protobuf.ChatIdent
|
||||||
Clock: m.transport.GetCurrentTime(),
|
Clock: m.transport.GetCurrentTime(),
|
||||||
EnsName: "", // TODO add ENS name handling to dedicate PR
|
EnsName: "", // TODO add ENS name handling to dedicate PR
|
||||||
}
|
}
|
||||||
|
err := m.attachIdentityImagesToChatIdentity(context, ci)
|
||||||
ciis := make(map[string]*protobuf.IdentityImage)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
switch context {
|
|
||||||
case publicChat:
|
|
||||||
m.logger.Info(fmt.Sprintf("handling %s ChatIdentity", context))
|
|
||||||
|
|
||||||
img, err := m.multiAccounts.GetIdentityImage(m.account.KeyUID, userimage.SmallDimName)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
m.logger.Debug(fmt.Sprintf("%s images.IdentityImage '%s'", context, spew.Sdump(img)))
|
|
||||||
|
|
||||||
ciis[userimage.SmallDimName] = m.adaptIdentityImageToProtobuf(img)
|
|
||||||
m.logger.Debug(fmt.Sprintf("%s protobuf.IdentityImage '%s'", context, spew.Sdump(ciis)))
|
|
||||||
ci.Images = ciis
|
|
||||||
|
|
||||||
case privateChat:
|
|
||||||
m.logger.Info(fmt.Sprintf("handling %s ChatIdentity", context))
|
|
||||||
|
|
||||||
imgs, err := m.multiAccounts.GetIdentityImages(m.account.KeyUID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
m.logger.Debug(fmt.Sprintf("%s images.IdentityImage '%s'", context, spew.Sdump(imgs)))
|
|
||||||
|
|
||||||
for _, img := range imgs {
|
|
||||||
ciis[img.Name] = m.adaptIdentityImageToProtobuf(img)
|
|
||||||
}
|
|
||||||
m.logger.Debug(fmt.Sprintf("%s protobuf.IdentityImage '%s'", context, spew.Sdump(ciis)))
|
|
||||||
ci.Images = ciis
|
|
||||||
|
|
||||||
default:
|
|
||||||
return ci, fmt.Errorf("unknown ChatIdentity context '%s'", context)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ci, nil
|
return ci, nil
|
||||||
|
@ -803,6 +770,60 @@ func (m *Messenger) adaptIdentityImageToProtobuf(img *userimage.IdentityImage) *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Messenger) attachIdentityImagesToChatIdentity(context chatContext, ci *protobuf.ChatIdentity) error {
|
||||||
|
s, err := m.getSettings()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ciis := make(map[string]*protobuf.IdentityImage)
|
||||||
|
|
||||||
|
switch context {
|
||||||
|
case publicChat:
|
||||||
|
m.logger.Info(fmt.Sprintf("handling %s ChatIdentity", context))
|
||||||
|
|
||||||
|
if s.ProfilePicturesVisibility != accounts.ProfilePicturesVisibilityEveryone {
|
||||||
|
m.logger.Info(fmt.Sprintf("settings.ProfilePicturesVisibility is set to '%d', public chat requires '%d'", s.ProfilePicturesVisibility, accounts.ProfilePicturesVisibilityEveryone))
|
||||||
|
}
|
||||||
|
|
||||||
|
img, err := m.multiAccounts.GetIdentityImage(m.account.KeyUID, userimage.SmallDimName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
m.logger.Debug(fmt.Sprintf("%s images.IdentityImage '%s'", context, spew.Sdump(img)))
|
||||||
|
|
||||||
|
ciis[userimage.SmallDimName] = m.adaptIdentityImageToProtobuf(img)
|
||||||
|
m.logger.Debug(fmt.Sprintf("%s protobuf.IdentityImage '%s'", context, spew.Sdump(ciis)))
|
||||||
|
ci.Images = ciis
|
||||||
|
|
||||||
|
case privateChat:
|
||||||
|
m.logger.Info(fmt.Sprintf("handling %s ChatIdentity", context))
|
||||||
|
|
||||||
|
if s.ProfilePicturesVisibility == accounts.ProfilePicturesVisibilityEveryone {
|
||||||
|
m.logger.Info(fmt.Sprintf("settings.ProfilePicturesVisibility is set to '%d', public chat requires '%d'", s.ProfilePicturesVisibility, accounts.ProfilePicturesVisibilityEveryone))
|
||||||
|
}
|
||||||
|
|
||||||
|
imgs, err := m.multiAccounts.GetIdentityImages(m.account.KeyUID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
m.logger.Debug(fmt.Sprintf("%s images.IdentityImage '%s'", context, spew.Sdump(imgs)))
|
||||||
|
|
||||||
|
for _, img := range imgs {
|
||||||
|
ciis[img.Name] = m.adaptIdentityImageToProtobuf(img)
|
||||||
|
}
|
||||||
|
m.logger.Debug(fmt.Sprintf("%s protobuf.IdentityImage '%s'", context, spew.Sdump(ciis)))
|
||||||
|
ci.Images = ciis
|
||||||
|
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown ChatIdentity context '%s'", context)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// handleSharedSecrets process the negotiated secrets received from the encryption layer
|
// handleSharedSecrets process the negotiated secrets received from the encryption layer
|
||||||
func (m *Messenger) handleSharedSecrets(secrets []*sharedsecret.Secret) error {
|
func (m *Messenger) handleSharedSecrets(secrets []*sharedsecret.Secret) error {
|
||||||
for _, secret := range secrets {
|
for _, secret := range secrets {
|
||||||
|
@ -4545,3 +4566,8 @@ func (m *Messenger) getOrBuildContactFromMessage(msg *common.Message) (*Contact,
|
||||||
func (m *Messenger) BloomFilter() []byte {
|
func (m *Messenger) BloomFilter() []byte {
|
||||||
return m.transport.BloomFilter()
|
return m.transport.BloomFilter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Messenger) getSettings() (accounts.Settings, error) {
|
||||||
|
sDB := accounts.NewDB(m.database)
|
||||||
|
return sDB.GetSettings()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue