Skip to content

Commit

Permalink
sync preferred name;
Browse files Browse the repository at this point in the history
remove settings.usernames
  • Loading branch information
qfrank committed Sep 13, 2023
1 parent 7a9845c commit 2b6f320
Show file tree
Hide file tree
Showing 23 changed files with 396 additions and 440 deletions.
24 changes: 22 additions & 2 deletions api/geth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"context"
"database/sql"
"encoding/json"
"errors"
"fmt"
"math/big"
Expand All @@ -12,6 +13,8 @@ import (
"sync"
"time"

"github.com/status-im/status-go/services/ens"

"github.com/imdario/mergo"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -763,6 +766,12 @@ func (b *GethStatusBackend) GetSettings() (*settings.Settings, error) {
return &settings, nil
}

func (b *GethStatusBackend) GetEnsUsernames() ([]*ens.UsernameDetail, error) {
db := ens.NewEnsDatabase(b.appDB)
removed := false
return db.GetEnsUsernames(&removed)
}

func (b *GethStatusBackend) MigrateKeyStoreDir(acc multiaccounts.Account, password, oldDir, newDir string) error {
err := b.ensureDBsOpened(acc, password)
if err != nil {
Expand Down Expand Up @@ -812,7 +821,7 @@ func (b *GethStatusBackend) StartNodeWithAccount(acc multiaccounts.Account, pass

func (b *GethStatusBackend) LoggedIn(keyUID string, err error) error {
if err != nil {
signal.SendLoggedIn(nil, nil, err)
signal.SendLoggedIn(nil, nil, nil, err)
return err
}
settings, err := b.GetSettings()
Expand All @@ -824,7 +833,18 @@ func (b *GethStatusBackend) LoggedIn(keyUID string, err error) error {
return err
}

signal.SendLoggedIn(account, settings, nil)
ensUsernames, err := b.GetEnsUsernames()
if err != nil {
return err
}
var ensUsernamesJSON json.RawMessage
if ensUsernames != nil {
ensUsernamesJSON, err = json.Marshal(ensUsernames)
if err != nil {
return err
}
}
signal.SendLoggedIn(account, settings, ensUsernamesJSON, nil)
return nil
}

Expand Down
178 changes: 89 additions & 89 deletions appdatabase/migrations/bindata.go

Large diffs are not rendered by default.

108 changes: 54 additions & 54 deletions appdatabase/migrationsprevnodecfg/bindata.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions mailserver/migrations/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions multiaccounts/migrations/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions multiaccounts/settings/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ var (
PreferredName = SettingField{
reactFieldName: "preferred-name",
dBColumnName: "preferred_name",
// TODO resolve issue 9 https://github.com/status-im/status-mobile/pull/13053#issuecomment-1075336559
syncProtobufFactory: &SyncProtobufFactory{
inactive: true, // Remove after issue is resolved
fromInterface: preferredNameProtobufFactory,
fromStruct: preferredNameProtobufFactoryStruct,
valueFromProtobuf: StringFromSyncProtobuf,
Expand Down Expand Up @@ -399,17 +397,6 @@ var (
dBColumnName: "use_mailservers",
valueHandler: BoolHandler,
}
Usernames = SettingField{
reactFieldName: "usernames",
dBColumnName: "usernames",
valueHandler: JSONBlobHandler,
syncProtobufFactory: &SyncProtobufFactory{
fromInterface: usernamesProtobufFactory,
fromStruct: usernamesProtobufFactoryStruct,
valueFromProtobuf: BytesFromSyncProtobuf,
protobufType: protobuf.SyncSetting_ENS_USERNAMES,
},
}
WakuBloomFilterMode = SettingField{
reactFieldName: "waku-bloom-filter-mode",
dBColumnName: "waku_bloom_filter_mode",
Expand Down Expand Up @@ -519,7 +506,6 @@ var (
TelemetryServerURL,
TestNetworksEnabled,
UseMailservers,
Usernames,
WakuBloomFilterMode,
WalletRootAddress,
WalletSetUpPassed,
Expand Down
5 changes: 0 additions & 5 deletions multiaccounts/settings/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,6 @@ func (db *Database) GetInstalledStickerPacks() (rst *json.RawMessage, err error)
return
}

func (db *Database) Usernames() (rst *json.RawMessage, err error) {
err = db.makeSelectRow(Usernames).Scan(&rst)
return
}

func (db *Database) GetPendingStickerPacks() (rst *json.RawMessage, err error) {
err = db.makeSelectRow(StickersPacksPending).Scan(&rst)
return
Expand Down
26 changes: 0 additions & 26 deletions multiaccounts/settings/sync_protobuf_factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,32 +515,6 @@ func mnemonicRemovedProtobufFactoryStruct(s Settings, clock uint64, chatID strin
return buildRawMnemonicRemovedSyncMessage(s.MnemonicRemoved, clock, chatID)
}

// Usernames

func buildRawUsernamesSyncMessage(v []byte, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) {
pb := &protobuf.SyncSetting{
Type: protobuf.SyncSetting_ENS_USERNAMES,
Value: &protobuf.SyncSetting_ValueBytes{ValueBytes: v},
Clock: clock,
}
rm, err := buildRawSyncSettingMessage(pb, chatID)
return rm, pb, err
}

func usernamesProtobufFactory(value interface{}, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) {
v, err := assertBytes(value)
if err != nil {
return nil, nil, err
}

return buildRawUsernamesSyncMessage(v, clock, chatID)
}

func usernamesProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) {
us := extractJSONRawMessage(s.Usernames)
return buildRawUsernamesSyncMessage(us, clock, chatID)
}

// IncludeWatchOnlyAccount

func buildRawIncludeWatchOnlyAccountSyncMessage(v bool, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) {
Expand Down
6 changes: 3 additions & 3 deletions protocol/anonmetrics/migrations/migrations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2b6f320

Please sign in to comment.