Republish image on change of visibility settings

This commit is contained in:
Andrea Maria Piana 2021-10-07 16:02:01 +01:00
parent 4e33e46795
commit 75aebd94ab
4 changed files with 41 additions and 19 deletions

View File

@ -1 +1 @@
0.89.9
0.89.10

View File

@ -1002,13 +1002,9 @@ func (m *Messenger) watchIdentityImageChanges() {
for {
select {
case <-channel:
if m.online() {
if err := m.publishContactCode(); err != nil {
m.logger.Error("failed to publish contact code", zap.Error(err))
}
} else {
m.shouldPublishContactCode = true
err := m.PublishIdentityImage()
if err != nil {
m.logger.Error("failed to publish identity image", zap.Error(err))
}
case <-m.quit:
return
@ -1017,6 +1013,23 @@ func (m *Messenger) watchIdentityImageChanges() {
}()
}
func (m *Messenger) PublishIdentityImage() error {
// Reset last published time for ChatIdentity so new contact can receive data
err := m.resetLastPublishedTimeForChatIdentity()
if err != nil {
m.logger.Error("failed to reset publish time", zap.Error(err))
return err
}
// If not online, we schedule it
if !m.online() {
m.shouldPublishContactCode = true
return nil
}
return m.publishContactCode()
}
// handlePushNotificationClientRegistration handles registration events
func (m *Messenger) handlePushNotificationClientRegistrations(c chan struct{}) {
go func() {

View File

@ -5,7 +5,6 @@ import (
"crypto/ecdsa"
"github.com/golang/protobuf/proto"
"go.uber.org/zap"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/protobuf"
@ -51,11 +50,8 @@ func (m *Messenger) AddContact(ctx context.Context, pubKey string) (*MessengerRe
}
// Reset last published time for ChatIdentity so new contact can receive data
contactCodeTopic := transport.ContactCodeTopic(&m.identity.PublicKey)
m.logger.Debug("contact state changed ResetWhenChatIdentityLastPublished")
err = m.persistence.ResetWhenChatIdentityLastPublished(contactCodeTopic)
err = m.resetLastPublishedTimeForChatIdentity()
if err != nil {
m.logger.Error("ResetWhenChatIdentityLastPublished error", zap.Error(err))
return nil, err
}
@ -96,6 +92,13 @@ func (m *Messenger) AddContact(ctx context.Context, pubKey string) (*MessengerRe
return response, nil
}
func (m *Messenger) resetLastPublishedTimeForChatIdentity() error {
// Reset last published time for ChatIdentity so new contact can receive data
contactCodeTopic := transport.ContactCodeTopic(&m.identity.PublicKey)
m.logger.Debug("contact state changed ResetWhenChatIdentityLastPublished")
return m.persistence.ResetWhenChatIdentityLastPublished(contactCodeTopic)
}
func (m *Messenger) removeContact(ctx context.Context, response *MessengerResponse, pubKey string) error {
contact, ok := m.allContacts.Load(pubKey)
if !ok {
@ -233,16 +236,12 @@ func (m *Messenger) saveContact(contact *Contact) error {
// Reregister only when data has changed
if shouldReregisterForPushNotifications {
// Reset last published time for ChatIdentity so new contact can receive data
contactCodeTopic := transport.ContactCodeTopic(&m.identity.PublicKey)
m.logger.Debug("contact state changed ResetWhenChatIdentityLastPublished")
err = m.persistence.ResetWhenChatIdentityLastPublished(contactCodeTopic)
err := m.resetLastPublishedTimeForChatIdentity()
if err != nil {
m.logger.Error("ResetWhenChatIdentityLastPublished error", zap.Error(err))
return err
}
// Publish contact code
err := m.publishContactCode()
err = m.publishContactCode()
if err != nil {
return err
}

View File

@ -16,6 +16,7 @@ import (
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/mailserver"
"github.com/status-im/status-go/multiaccounts/accounts"
"github.com/status-im/status-go/protocol"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/communities"
@ -928,6 +929,15 @@ func (api *PublicAPI) Peers() map[string][]string {
return api.service.messenger.Peers()
}
func (api *PublicAPI) ChangeIdentityImageShowTo(showTo accounts.ProfilePicturesShowToType) error {
err := api.service.accountsDB.SaveSetting("profile-pictures-show-to", showTo)
if err != nil {
return err
}
return api.service.messenger.PublishIdentityImage()
}
// -----
// HELPER
// -----