diff --git a/multiaccounts/database.go b/multiaccounts/database.go index 9ca2bc8ec..9822262f3 100644 --- a/multiaccounts/database.go +++ b/multiaccounts/database.go @@ -31,6 +31,10 @@ type Account struct { CustomizationColorClock uint64 `json:"-"` } +func (a *Account) RefersToKeycard() bool { + return a.KeycardPairing != "" +} + func (a *Account) ToProtobuf() *protobuf.MultiAccount { var colorHashes []*protobuf.MultiAccount_ColorHash for _, index := range a.ColorHash { diff --git a/protocol/messenger_backup.go b/protocol/messenger_backup.go index 9040ddc63..003d5f7f7 100644 --- a/protocol/messenger_backup.go +++ b/protocol/messenger_backup.go @@ -497,7 +497,7 @@ func (m *Messenger) backupProfile(ctx context.Context, clock uint64) ([]*protobu } func (m *Messenger) backupKeypairs() ([]*protobuf.Backup, error) { - keypairs, err := m.settings.GetActiveKeypairs() + keypairs, err := m.settings.GetAllKeypairs() if err != nil { return nil, err } diff --git a/protocol/messenger_backup_handler.go b/protocol/messenger_backup_handler.go index d3eb1d680..f7b3db1b8 100644 --- a/protocol/messenger_backup_handler.go +++ b/protocol/messenger_backup_handler.go @@ -250,7 +250,7 @@ func (m *Messenger) handleKeypair(message *protobuf.SyncKeypair) error { } // If user is recovering his account via seed phrase, but the backed up messages indicate that the profile keypair // is a keycard related profile, then we need to remove related profile keycards (only profile, other keycards should remain). - if multiAcc != nil && multiAcc.KeyUID == message.KeyUid && multiAcc.KeycardPairing == "" && len(message.Keycards) > 0 { + if multiAcc != nil && multiAcc.KeyUID == message.KeyUid && !multiAcc.RefersToKeycard() && len(message.Keycards) > 0 { message.Keycards = []*protobuf.SyncKeycard{} } diff --git a/protocol/messenger_handler.go b/protocol/messenger_handler.go index f86fd20c3..04a8f4868 100644 --- a/protocol/messenger_handler.go +++ b/protocol/messenger_handler.go @@ -3247,13 +3247,13 @@ func mapSyncAccountToAccount(message *protobuf.SyncAccount, accountOperability a } } -func (m *Messenger) resolveAccountOperability(syncAcc *protobuf.SyncAccount, syncKpMigratedToKeycard bool, - dbKpMigratedToKeycard bool, accountReceivedFromLocalPairing bool) (accounts.AccountOperable, error) { +func (m *Messenger) resolveAccountOperability(syncAcc *protobuf.SyncAccount, recoverinrecoveringFromWakuInitiatedByKeycard bool, + syncKpMigratedToKeycard bool, dbKpMigratedToKeycard bool, accountReceivedFromLocalPairing bool) (accounts.AccountOperable, error) { if accountReceivedFromLocalPairing { return accounts.AccountOperable(syncAcc.Operable), nil } - if syncKpMigratedToKeycard || m.account.KeyUID == syncAcc.KeyUid { + if syncKpMigratedToKeycard || recoverinrecoveringFromWakuInitiatedByKeycard && m.account.KeyUID == syncAcc.KeyUid { return accounts.AccountFullyOperable, nil } @@ -3534,18 +3534,19 @@ func (m *Messenger) handleSyncKeypair(message *protobuf.SyncKeypair, fromLocalPa } syncKpMigratedToKeycard := len(message.Keycards) > 0 + recoveringFromWaku := message.SyncedFrom == accounts.SyncedFromBackup + + multiAcc, err := m.multiAccounts.GetAccount(kp.KeyUID) + if err != nil { + return nil, err + } + recoverinrecoveringFromWakuInitiatedByKeycard := recoveringFromWaku && multiAcc != nil && multiAcc.RefersToKeycard() for _, sAcc := range message.Accounts { - if message.SyncedFrom == accounts.SyncedFromBackup && kp.Type == accounts.KeypairTypeProfile { - // if a profile keypair is coming from backup, we're handling within this block the case when a recovering - // was inititiated via keycard, while backed up profile keypair data refers to a regular profile - multiAcc, err := m.multiAccounts.GetAccount(kp.KeyUID) - if err != nil { - return nil, err - } - syncKpMigratedToKeycard = multiAcc != nil && multiAcc.KeycardPairing != "" - } - accountOperability, err := m.resolveAccountOperability(sAcc, syncKpMigratedToKeycard, - dbKeypair != nil && dbKeypair.MigratedToKeycard(), fromLocalPairing) + accountOperability, err := m.resolveAccountOperability(sAcc, + recoverinrecoveringFromWakuInitiatedByKeycard, + syncKpMigratedToKeycard, + dbKeypair != nil && dbKeypair.MigratedToKeycard(), + fromLocalPairing) if err != nil { return nil, err } @@ -3554,7 +3555,7 @@ func (m *Messenger) handleSyncKeypair(message *protobuf.SyncKeypair, fromLocalPa kp.Accounts = append(kp.Accounts, acc) } - if !fromLocalPairing { + if !fromLocalPairing && !recoverinrecoveringFromWakuInitiatedByKeycard { if kp.Removed || dbKeypair != nil && !dbKeypair.MigratedToKeycard() && syncKpMigratedToKeycard { // delete all keystore files diff --git a/protocol/messenger_identity.go b/protocol/messenger_identity.go index 5f45ec3b0..1fe14851d 100644 --- a/protocol/messenger_identity.go +++ b/protocol/messenger_identity.go @@ -95,16 +95,9 @@ func (m *Messenger) SaveSyncDisplayName(displayName string, clock uint64) error if err != nil { return err } - preferredNameClock, err := m.settings.GetSettingLastSynced(settings.PreferredName) - if err != nil { - return err - } - // check clock of preferred name to avoid override account name - if preferredNameClock < clock { - m.account.Name = displayName - return m.multiAccounts.SaveAccount(*m.account) - } - return nil + + m.account.Name = displayName + return m.multiAccounts.SaveAccount(*m.account) } func ValidateBio(bio *string) error {