diff --git a/protocol/messenger.go b/protocol/messenger.go index 14634a841..27faf34fb 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -753,42 +753,9 @@ func (m *Messenger) createChatIdentity(context chatContext) (*protobuf.ChatIdent Clock: m.transport.GetCurrentTime(), EnsName: "", // TODO add ENS name handling to dedicate PR } - - ciis := make(map[string]*protobuf.IdentityImage) - - 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) + err := m.attachIdentityImagesToChatIdentity(context, ci) + if err != nil { + return nil, err } 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 func (m *Messenger) handleSharedSecrets(secrets []*sharedsecret.Secret) error { for _, secret := range secrets { @@ -4545,3 +4566,8 @@ func (m *Messenger) getOrBuildContactFromMessage(msg *common.Message) (*Contact, func (m *Messenger) BloomFilter() []byte { return m.transport.BloomFilter() } + +func (m *Messenger) getSettings() (accounts.Settings, error) { + sDB := accounts.NewDB(m.database) + return sDB.GetSettings() +}