update account name if necessary (#3072)

This commit is contained in:
frank 2023-01-12 11:00:24 +08:00 committed by GitHub
parent 880a201037
commit a29511b921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 9 deletions

View File

@ -1750,12 +1750,18 @@ func (m *Messenger) handleSyncSetting(messageState *ReceivedMessageState, messag
if err != nil {
return err
}
if message.GetType() == protobuf.SyncSetting_DISPLAY_NAME {
m.account.Name = message.GetValueString()
err = m.multiAccounts.SaveAccount(*m.account)
if message.GetType() == protobuf.SyncSetting_DISPLAY_NAME && settingField != nil {
oldDisplayName, err := m.settings.DisplayName()
if err != nil {
return err
}
if oldDisplayName != message.GetValueString() {
m.account.Name = message.GetValueString()
err = m.multiAccounts.SaveAccount(*m.account)
if err != nil {
return err
}
}
}
messageState.Response.AddSetting(settingField)
return nil

View File

@ -83,6 +83,8 @@ func (s *SyncDeviceSuite) prepareBackendWithAccount(tmpdir string) *api.GethStat
settings, err := defaultSettings(generatedAccountInfo.GeneratedAccountInfo, derivedAddresses, nil)
require.NoError(s.T(), err)
account.Name = settings.Name
nodeConfig, err := defaultNodeConfig(tmpdir, settings.InstallationID, account.KeyUID)
require.NoError(s.T(), err)
@ -146,12 +148,12 @@ func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsSender() {
})
require.NoError(s.T(), err)
activeAccount, err := clientBackend.GetActiveAccount()
clientActiveAccount, err := clientBackend.GetActiveAccount()
require.NoError(s.T(), err)
clientKeystorePath := filepath.Join(clientTmpDir, keystoreDir, activeAccount.KeyUID)
clientKeystorePath := filepath.Join(clientTmpDir, keystoreDir, clientActiveAccount.KeyUID)
var config = PayloadSourceConfig{
KeystorePath: clientKeystorePath,
KeyUID: activeAccount.KeyUID,
KeyUID: clientActiveAccount.KeyUID,
Password: s.password,
}
configBytes, err := json.Marshal(config)
@ -165,6 +167,10 @@ func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsSender() {
require.NoError(s.T(), err)
require.Equal(s.T(), 1, len(bookmarks))
require.Equal(s.T(), "status.im", bookmarks[0].Name)
serverActiveAccount, err := serverBackend.GetActiveAccount()
require.NoError(s.T(), err)
require.Equal(s.T(), serverActiveAccount.Name, clientActiveAccount.Name)
}
func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsReceiver() {
@ -177,12 +183,12 @@ func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsReceiver() {
require.NoError(s.T(), clientBackend.Logout())
}()
activeAccount, err := serverBackend.GetActiveAccount()
serverActiveAccount, err := serverBackend.GetActiveAccount()
require.NoError(s.T(), err)
serverKeystorePath := filepath.Join(serverTmpDir, keystoreDir, activeAccount.KeyUID)
serverKeystorePath := filepath.Join(serverTmpDir, keystoreDir, serverActiveAccount.KeyUID)
var config = PayloadSourceConfig{
KeystorePath: serverKeystorePath,
KeyUID: activeAccount.KeyUID,
KeyUID: serverActiveAccount.KeyUID,
Password: s.password,
}
configBytes, err := json.Marshal(config)
@ -214,6 +220,10 @@ func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsReceiver() {
require.NoError(s.T(), err)
require.Equal(s.T(), 1, len(bookmarks))
require.Equal(s.T(), "status.im", bookmarks[0].Name)
clientActiveAccount, err := clientBackend.GetActiveAccount()
require.NoError(s.T(), err)
require.Equal(s.T(), serverActiveAccount.Name, clientActiveAccount.Name)
}
func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derivedAddresses map[string]generator.AccountInfo, mnemonic *string) (*settings.Settings, error) {