feat: url unfurling settings (#4128)

This commit is contained in:
Igor Sirotin 2023-10-13 15:31:56 +01:00 committed by GitHub
parent aded258ccb
commit 176bdd297d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 298 additions and 124 deletions

View File

@ -1 +1 @@
0.170.0
0.171.0

View File

@ -53,6 +53,7 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive
s.KeyUID = generatedAccountInfo.KeyUID
s.Address = types.HexToAddress(generatedAccountInfo.Address)
s.WalletRootAddress = types.HexToAddress(derivedAddresses[pathWalletRoot].Address)
s.URLUnfurlingMode = settings.URLUnfurlingAlwaysAsk
// Set chat key & name
name, err := alias.GenerateFromPublicKeyString(chatKeyString)

View File

@ -90,6 +90,7 @@
// 1693900971_add_profile_migration_needed_column_to_settings_table.up.sql (88B)
// 1694764094_add_original_to_networks.up.sql (120B)
// 1695974515_add_is_sepolia_enabled_to_settings.up.sql (82B)
// 1696259336_settings_add_url_unfurling_mode.up.sql (160B)
// 1697123140_drop_include_watch_only_accounts.up.sql (61B)
// 1697123233_drop_include_watch_only_account_to_settings_sync_clock.up.sql (72B)
// doc.go (74B)
@ -1961,6 +1962,26 @@ func _1695974515_add_is_sepolia_enabled_to_settingsUpSql() (*asset, error) {
return a, nil
}
var __1696259336_settings_add_url_unfurling_modeUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\xf4\x09\x71\x0d\x52\x08\x71\x74\xf2\x71\x55\x28\x4e\x2d\x29\xc9\xcc\x4b\x2f\x56\x70\x74\x71\x51\x70\xf6\xf7\x09\xf5\xf5\x53\x28\x2d\xca\x89\x2f\xcd\x4b\x2b\x2d\xca\xc9\xcc\x4b\x8f\xcf\xcd\x4f\x49\x55\xf0\xf4\x0b\x51\xf0\xf3\x0f\x51\xf0\x0b\xf5\xf1\x51\x70\x71\x75\x73\x0c\xf5\x09\x51\x30\xb4\xe6\xc2\x66\x54\x7c\x71\x65\x5e\x72\x7c\x72\x4e\x7e\x72\x36\x39\xa6\x1a\x58\x03\x02\x00\x00\xff\xff\xad\xc8\x55\x02\xa0\x00\x00\x00")
func _1696259336_settings_add_url_unfurling_modeUpSqlBytes() ([]byte, error) {
return bindataRead(
__1696259336_settings_add_url_unfurling_modeUpSql,
"1696259336_settings_add_url_unfurling_mode.up.sql",
)
}
func _1696259336_settings_add_url_unfurling_modeUpSql() (*asset, error) {
bytes, err := _1696259336_settings_add_url_unfurling_modeUpSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "1696259336_settings_add_url_unfurling_mode.up.sql", size: 160, mode: os.FileMode(0644), modTime: time.Unix(1697201656, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xde, 0x62, 0xf4, 0x5, 0x31, 0x4e, 0x35, 0xb5, 0xcd, 0x1a, 0xad, 0xdc, 0xcb, 0x4, 0x94, 0x16, 0x67, 0xc4, 0x8d, 0x6f, 0x63, 0xa6, 0x8f, 0xbf, 0xa5, 0x6, 0xfd, 0xbe, 0xb1, 0x7c, 0xe8, 0xa7}}
return a, nil
}
var __1697123140_drop_include_watch_only_accountsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\xf4\x09\x71\x0d\x52\x08\x71\x74\xf2\x71\x55\x28\x4e\x2d\x29\xc9\xcc\x4b\x2f\x56\x70\x09\xf2\x0f\x50\x70\xf6\xf7\x09\xf5\xf5\x53\xc8\xcc\x4b\xce\x29\x4d\x49\x8d\x2f\x4f\x2c\x49\xce\x88\xcf\xcf\xcb\xa9\x8c\x4f\x4c\x4e\xce\x2f\xcd\x2b\xb1\xe6\x02\x04\x00\x00\xff\xff\xb4\xff\x34\xe0\x3d\x00\x00\x00")
func _1697123140_drop_include_watch_only_accountsUpSqlBytes() ([]byte, error) {
@ -1976,7 +1997,7 @@ func _1697123140_drop_include_watch_only_accountsUpSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1697123140_drop_include_watch_only_accounts.up.sql", size: 61, mode: os.FileMode(0644), modTime: time.Unix(1697196255, 0)}
info := bindataFileInfo{name: "1697123140_drop_include_watch_only_accounts.up.sql", size: 61, mode: os.FileMode(0644), modTime: time.Unix(1697200175, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x77, 0xc9, 0xc7, 0xaf, 0x7b, 0xe4, 0x83, 0x5, 0xe1, 0xde, 0x83, 0xd9, 0xdd, 0xbe, 0xb6, 0x1d, 0x24, 0x5c, 0x19, 0x88, 0xad, 0xc1, 0x5c, 0xd1, 0x26, 0x84, 0x61, 0xce, 0x3a, 0x74, 0x3c, 0x8c}}
return a, nil
}
@ -1996,7 +2017,7 @@ func _1697123233_drop_include_watch_only_account_to_settings_sync_clockUpSql() (
return nil, err
}
info := bindataFileInfo{name: "1697123233_drop_include_watch_only_account_to_settings_sync_clock.up.sql", size: 72, mode: os.FileMode(0644), modTime: time.Unix(1697196255, 0)}
info := bindataFileInfo{name: "1697123233_drop_include_watch_only_account_to_settings_sync_clock.up.sql", size: 72, mode: os.FileMode(0644), modTime: time.Unix(1697200175, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xcd, 0xe9, 0x5b, 0xc9, 0xd2, 0x96, 0x18, 0x8e, 0x97, 0x13, 0x3b, 0x72, 0x2d, 0x8a, 0xa9, 0xa3, 0x32, 0x6, 0x17, 0xb, 0xd1, 0xd8, 0x44, 0x13, 0xde, 0xb6, 0xa3, 0xbf, 0xef, 0xf4, 0xf9, 0xff}}
return a, nil
}
@ -2292,6 +2313,8 @@ var _bindata = map[string]func() (*asset, error){
"1695974515_add_is_sepolia_enabled_to_settings.up.sql": _1695974515_add_is_sepolia_enabled_to_settingsUpSql,
"1696259336_settings_add_url_unfurling_mode.up.sql": _1696259336_settings_add_url_unfurling_modeUpSql,
"1697123140_drop_include_watch_only_accounts.up.sql": _1697123140_drop_include_watch_only_accountsUpSql,
"1697123233_drop_include_watch_only_account_to_settings_sync_clock.up.sql": _1697123233_drop_include_watch_only_account_to_settings_sync_clockUpSql,
@ -2430,6 +2453,7 @@ var _bintree = &bintree{nil, map[string]*bintree{
"1693900971_add_profile_migration_needed_column_to_settings_table.up.sql": &bintree{_1693900971_add_profile_migration_needed_column_to_settings_tableUpSql, map[string]*bintree{}},
"1694764094_add_original_to_networks.up.sql": &bintree{_1694764094_add_original_to_networksUpSql, map[string]*bintree{}},
"1695974515_add_is_sepolia_enabled_to_settings.up.sql": &bintree{_1695974515_add_is_sepolia_enabled_to_settingsUpSql, map[string]*bintree{}},
"1696259336_settings_add_url_unfurling_mode.up.sql": &bintree{_1696259336_settings_add_url_unfurling_modeUpSql, map[string]*bintree{}},
"1697123140_drop_include_watch_only_accounts.up.sql": &bintree{_1697123140_drop_include_watch_only_accountsUpSql, map[string]*bintree{}},
"1697123233_drop_include_watch_only_account_to_settings_sync_clock.up.sql": &bintree{_1697123233_drop_include_watch_only_account_to_settings_sync_clockUpSql, map[string]*bintree{}},
"doc.go": &bintree{docGo, map[string]*bintree{}},

View File

@ -0,0 +1,2 @@
ALTER TABLE settings ADD COLUMN url_unfurling_mode INT NOT NULL DEFAULT 1;
ALTER TABLE settings_sync_clock ADD COLUMN url_unfurling_mode INT NOT NULL DEFAULT 0;

View File

@ -437,6 +437,16 @@ var (
dBColumnName: "profile_migration_needed",
valueHandler: BoolHandler,
}
URLUnfurlingMode = SettingField{
reactFieldName: "url-unfurling-mode",
dBColumnName: "url_unfurling_mode",
syncProtobufFactory: &SyncProtobufFactory{
fromInterface: urlUnfurlingModeProtobufFactory,
fromStruct: urlUnfurlingModeProtobufFactoryStruct,
valueFromProtobuf: Int64FromSyncProtobuf,
protobufType: protobuf.SyncSetting_URL_UNFURLING_MODE,
},
}
SettingFieldRegister = []SettingField{
AnonMetricsShouldSend,
@ -507,6 +517,7 @@ var (
WebviewAllowPermissionRequests,
ProfileMigrationNeeded,
IsSepoliaEnabled,
URLUnfurlingMode,
}
)

View File

@ -64,8 +64,6 @@ func TestGetFieldFromProtobufType(t *testing.T) {
require.Error(t, err, "do not have a SettingField for the unknown type")
continue
}
if err != nil {
require.NoError(t, err)
}
require.NoError(t, err)
}
}

View File

@ -121,10 +121,11 @@ INSERT INTO settings (
synthetic_id,
current_user_status,
profile_pictures_show_to,
profile_pictures_visibility
profile_pictures_visibility,
url_unfurling_mode
) VALUES (
?,?,?,?,?,?,?,?,?,?,?,?,?,
?,?,?,?,?,?,?,?,?,'id',?,?,?)`,
?,?,?,?,?,?,?,?,?,'id',?,?,?,?)`,
s.Address,
s.Currency,
s.CurrentNetwork,
@ -150,6 +151,7 @@ INSERT INTO settings (
s.CurrentUserStatus,
s.ProfilePicturesShowTo,
s.ProfilePicturesVisibility,
s.URLUnfurlingMode,
)
if err != nil {
return err
@ -334,7 +336,7 @@ func (db *Database) GetSettings() (Settings, error) {
profile_pictures_show_to, profile_pictures_visibility, wallet_root_address, wallet_set_up_passed, wallet_visible_tokens,
waku_bloom_filter_mode, webview_allow_permission_requests, current_user_status, send_status_updates, gif_recents,
gif_favorites, opensea_enabled, last_backup, backup_enabled, telemetry_server_url, auto_message_enabled, gif_api_key,
test_networks_enabled, mutual_contact_enabled, profile_migration_needed, is_sepolia_enabled
test_networks_enabled, mutual_contact_enabled, profile_migration_needed, is_sepolia_enabled, url_unfurling_mode
FROM
settings
WHERE
@ -409,6 +411,7 @@ func (db *Database) GetSettings() (Settings, error) {
&s.MutualContactEnabled,
&s.ProfileMigrationNeeded,
&s.IsSepoliaEnabled,
&s.URLUnfurlingMode,
)
return s, err
@ -697,3 +700,11 @@ func (db *Database) ProfileMigrationNeeded() (result bool, err error) {
err = db.makeSelectRow(ProfileMigrationNeeded).Scan(&result)
return result, err
}
func (db *Database) URLUnfurlingMode() (result int64, err error) {
err = db.makeSelectRow(URLUnfurlingMode).Scan(&result)
if err == sql.ErrNoRows {
return result, nil
}
return result, err
}

View File

@ -22,3 +22,11 @@ const (
ProfilePicturesShowToEveryone
ProfilePicturesShowToNone
)
type URLUnfurlingModeType int
const (
URLUnfurlingAlwaysAsk URLUnfurlingModeType = iota + 1
URLUnfurlingEnableAll
URLUnfurlingDisableAll
)

View File

@ -196,6 +196,7 @@ type Settings struct {
TestNetworksEnabled bool `json:"test-networks-enabled?,omitempty"`
ProfileMigrationNeeded bool `json:"profile-migration-needed,omitempty"`
IsSepoliaEnabled bool `json:"is-sepolia-enabled?,omitempty"`
URLUnfurlingMode URLUnfurlingModeType `json:"url-unfurling-mode,omitempty"`
}
func (s Settings) MarshalJSON() ([]byte, error) {

View File

@ -410,6 +410,8 @@ func parseNumberToInt64(value interface{}) (int64, error) {
return int64(v), nil
case ProfilePicturesVisibilityType:
return int64(v), nil
case URLUnfurlingModeType:
return int64(v), nil
default:
return 0, errors.Wrapf(ErrTypeAssertionFailed, "expected a numeric type, received %T", value)
}
@ -514,3 +516,28 @@ func mnemonicRemovedProtobufFactory(value interface{}, clock uint64, chatID stri
func mnemonicRemovedProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) {
return buildRawMnemonicRemovedSyncMessage(s.MnemonicRemoved, clock, chatID)
}
// UrlUnfurlingMode
func buildRawURLUnfurlingModeSyncMessage(v int64, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) {
pb := &protobuf.SyncSetting{
Type: protobuf.SyncSetting_URL_UNFURLING_MODE,
Value: &protobuf.SyncSetting_ValueInt64{ValueInt64: v},
Clock: clock,
}
rm, err := buildRawSyncSettingMessage(pb, chatID)
return rm, pb, err
}
func urlUnfurlingModeProtobufFactory(value any, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) {
v, err := parseNumberToInt64(value)
if err != nil {
return nil, nil, err
}
return buildRawURLUnfurlingModeSyncMessage(v, clock, chatID)
}
func urlUnfurlingModeProtobufFactoryStruct(s Settings, clock uint64, chatID string) (*common.RawMessage, *protobuf.SyncSetting, error) {
return buildRawURLUnfurlingModeSyncMessage(int64(s.URLUnfurlingMode), clock, chatID)
}

View File

@ -281,6 +281,7 @@ func (s *MessengerBackupSuite) TestBackupSettings() {
bob1Mnemonic = ""
bob1MnemonicRemoved = true
bob1PreferredName = "talent"
bob1UrlUnfUnfurlingMode = settings.URLUnfurlingEnableAll
)
// Create bob1 and set fields which are supposed to be backed up to/fetched from waku
@ -301,6 +302,8 @@ func (s *MessengerBackupSuite) TestBackupSettings() {
s.Require().NoError(err)
err = bob1.settings.SaveSettingField(settings.PreferredName, bob1PreferredName)
s.Require().NoError(err)
err = bob1.settings.SaveSettingField(settings.URLUnfurlingMode, bob1UrlUnfUnfurlingMode)
s.Require().NoError(err)
// Create bob2
bob2, err := newMessengerWithKey(s.shh, bob1.identity, s.logger, nil)
@ -336,7 +339,10 @@ func (s *MessengerBackupSuite) TestBackupSettings() {
s.Require().Equal(bob1MnemonicRemoved, storedMnemonicRemoved)
storedPreferredName, err := bob1.settings.GetPreferredUsername()
s.NoError(err)
s.Equal(bob1PreferredName, storedPreferredName)
s.Require().Equal(bob1PreferredName, storedPreferredName)
storedBob1UrlUnfurlingMode, err := bob1.settings.URLUnfurlingMode()
s.NoError(err)
s.Require().Equal(int64(bob1UrlUnfUnfurlingMode), storedBob1UrlUnfurlingMode)
// Check bob2
storedBob2DisplayName, err := bob2.settings.DisplayName()
@ -362,7 +368,10 @@ func (s *MessengerBackupSuite) TestBackupSettings() {
s.Require().Equal(false, storedBob2MnemonicRemoved)
storedBob2PreferredName, err := bob2.settings.GetPreferredUsername()
s.NoError(err)
s.Equal("", storedBob2PreferredName)
s.Require().Equal("", storedBob2PreferredName)
storedBob2UrlUnfurlingMode, err := bob2.settings.URLUnfurlingMode()
s.NoError(err)
s.Require().Equal(int64(settings.URLUnfurlingAlwaysAsk), storedBob2UrlUnfurlingMode)
// Backup
clock, err := bob1.BackupData(context.Background())
@ -402,8 +411,11 @@ func (s *MessengerBackupSuite) TestBackupSettings() {
s.Require().Equal(bob1MnemonicRemoved, storedBob2MnemonicRemoved)
storedBob2PreferredName, err = bob2.settings.GetPreferredUsername()
s.NoError(err)
s.Equal(bob1PreferredName, storedBob2PreferredName)
s.Equal(bob1PreferredName, bob2.account.Name)
s.Require().Equal(bob1PreferredName, storedBob2PreferredName)
s.Require().Equal(bob1PreferredName, bob2.account.Name)
storedBob2UrlUnfurlingMode, err = bob2.settings.URLUnfurlingMode()
s.NoError(err)
s.Require().Equal(storedBob1UrlUnfurlingMode, storedBob2UrlUnfurlingMode)
lastBackup, err := bob1.lastBackup()
s.Require().NoError(err)

View File

@ -103,6 +103,7 @@ func newMessengerWithKey(shh types.Waku, privateKey *ecdsa.PrivateKey, logger *z
DisplayName: DefaultProfileDisplayName,
ProfilePicturesShowTo: 1,
ProfilePicturesVisibility: 1,
URLUnfurlingMode: settings.URLUnfurlingAlwaysAsk,
}, params.NodeConfig{}),
WithBrowserDatabase(nil),
}

View File

@ -8,11 +8,11 @@ import (
"regexp"
"strings"
"github.com/status-im/markdown"
"go.uber.org/zap"
"golang.org/x/net/publicsuffix"
"github.com/status-im/markdown"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/protocol/common"
)
@ -134,13 +134,34 @@ func NewDefaultHTTPClient() *http.Client {
// UnfurlURLs assumes clients pass URLs verbatim that were validated and
// processed by GetURLs.
func (m *Messenger) UnfurlURLs(httpClient *http.Client, urls []string) (UnfurlURLsResponse, error) {
if httpClient == nil {
httpClient = NewDefaultHTTPClient()
response := UnfurlURLsResponse{}
s, err := m.getSettings()
if err != nil {
return response, fmt.Errorf("failed to get settigs: %w", err)
}
r := UnfurlURLsResponse{
LinkPreviews: make([]*common.LinkPreview, 0, len(urls)),
StatusLinkPreviews: make([]*common.StatusLinkPreview, 0, len(urls)),
// We use switch case, though there's most cases are empty for code clarity.
switch s.URLUnfurlingMode {
case settings.URLUnfurlingDisableAll:
return response, fmt.Errorf("url unfurling is disabled")
case settings.URLUnfurlingEnableAll:
break
case settings.URLUnfurlingAlwaysAsk:
// This mode should be handled on the app side
// and is considered as equal to URLUnfurlingEnableAll in status-go.
break
default:
return response, fmt.Errorf("invalid url unfurling mode setting: %d", s.URLUnfurlingMode)
}
// Unfurl in a loop
response.LinkPreviews = make([]*common.LinkPreview, 0, len(urls))
response.StatusLinkPreviews = make([]*common.StatusLinkPreview, 0, len(urls))
if httpClient == nil {
httpClient = NewDefaultHTTPClient()
}
for _, url := range urls {
@ -153,7 +174,7 @@ func (m *Messenger) UnfurlURLs(httpClient *http.Client, urls []string) (UnfurlUR
m.logger.Warn("failed to unfurl status link", zap.String("url", url), zap.Error(err))
continue
}
r.StatusLinkPreviews = append(r.StatusLinkPreviews, preview)
response.StatusLinkPreviews = append(response.StatusLinkPreviews, preview)
continue
}
@ -162,8 +183,8 @@ func (m *Messenger) UnfurlURLs(httpClient *http.Client, urls []string) (UnfurlUR
m.logger.Warn("failed to unfurl", zap.String("url", url), zap.Error(err))
continue
}
r.LinkPreviews = append(r.LinkPreviews, p)
response.LinkPreviews = append(response.LinkPreviews, p)
}
return r, nil
return response, nil
}

View File

@ -15,6 +15,7 @@ import (
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/images"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/requests"
@ -69,36 +70,42 @@ func (t *StubTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return nil, fmt.Errorf("no HTTP matcher found")
}
// Add a matcher based on a URL regexp. If a given request URL matches the
// regexp, then responseBody will be returned with a hardcoded 200 status code.
// If headers is non-nil, use it as the value of http.Response.Header.
func (t *StubTransport) AddURLMatcher(urlRegexp string, responseBody []byte, headers map[string]string) {
func (t *StubTransport) AddURLMatcherRoundTrip(urlRegexp string, roundTrip func(r *http.Request) *http.Response) {
matcher := func(req *http.Request) *http.Response {
rx, err := regexp.Compile(regexp.QuoteMeta(urlRegexp))
if err != nil {
return nil
}
if rx.MatchString(req.URL.String()) {
res := &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBuffer(responseBody)),
}
if headers != nil {
res.Header = http.Header{}
for k, v := range headers {
res.Header.Set(k, v)
}
}
return res
if !rx.MatchString(req.URL.String()) {
return nil
}
return nil
return roundTrip(req)
}
t.matchers = append(t.matchers, matcher)
}
// Add a matcher based on a URL regexp. If a given request URL matches the
// regexp, then responseBody will be returned with a hardcoded 200 status code.
// If headers is non-nil, use it as the value of http.Response.Header.
func (t *StubTransport) AddURLMatcher(urlRegexp string, responseBody []byte, headers map[string]string) {
matcher := func(req *http.Request) *http.Response {
res := &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBuffer(responseBody)),
}
if headers != nil {
res.Header = http.Header{}
for k, v := range headers {
res.Header.Set(k, v)
}
}
return res
}
t.AddURLMatcherRoundTrip(urlRegexp, matcher)
}
// assertContainsLongString verifies if actual contains a slice of expected and
// correctly prints the cause of the failure. The default behavior of
// require.Contains with long strings is to not print the formatted message
@ -507,3 +514,55 @@ func (s *MessengerLinkPreviewsTestSuite) Test_UnfurlURLs_StatusCommunityJoined()
s.Require().Equal(bannerHeight, preview.Community.Banner.Height)
s.Require().Equal(bannerDataURI, preview.Community.Banner.DataURI)
}
func (s *MessengerLinkPreviewsTestSuite) Test_UnfurlURLs_Settings() {
u := "https://github.com"
requestsCount := 0
transport := StubTransport{}
transport.AddURLMatcherRoundTrip(
u,
func(req *http.Request) *http.Response {
requestsCount++
responseBody := []byte(`<html><head><meta property="og:title" content="TestTitle"></head></html>`)
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBuffer(responseBody)),
}
},
)
stubbedClient := http.Client{Transport: &transport}
// Test `AlwaysAsk`
// NOTE: on status-go side `AlwaysAsk` == `EnableAll`, "asking" should be processed by the app
requestsCount = 0
err := s.m.settings.SaveSettingField(settings.URLUnfurlingMode, settings.URLUnfurlingAlwaysAsk)
s.Require().NoError(err)
linkPreviews, err := s.m.UnfurlURLs(&stubbedClient, []string{u})
s.Require().NoError(err)
s.Require().Len(linkPreviews.LinkPreviews, 1)
s.Require().Equal(requestsCount, 1)
// Test `EnableAll`
requestsCount = 0
err = s.m.settings.SaveSettingField(settings.URLUnfurlingMode, settings.URLUnfurlingEnableAll)
s.Require().NoError(err)
linkPreviews, err = s.m.UnfurlURLs(&stubbedClient, []string{u})
s.Require().NoError(err)
s.Require().Len(linkPreviews.LinkPreviews, 1)
s.Require().Equal(requestsCount, 1)
// Test `DisableAll`
requestsCount = 0
err = s.m.settings.SaveSettingField(settings.URLUnfurlingMode, settings.URLUnfurlingDisableAll)
s.Require().NoError(err)
linkPreviews, err = s.m.UnfurlURLs(&stubbedClient, []string{u})
s.Require().Error(err)
s.Require().Len(linkPreviews.LinkPreviews, 0)
s.Require().Equal(requestsCount, 0)
}

View File

@ -148,7 +148,9 @@ func (s *MessengerSyncSettingsSuite) newMessengerWithOptions(shh types.Waku, pri
UseMailservers: true,
LinkPreviewRequestEnabled: true,
SendStatusUpdates: true,
WalletRootAddress: types.HexToAddress("0x1122334455667788990011223344556677889900")}
WalletRootAddress: types.HexToAddress("0x1122334455667788990011223344556677889900"),
URLUnfurlingMode: settings.URLUnfurlingAlwaysAsk,
}
err = m.settings.CreateSettings(setting, config)
s.Require().NoError(err)
@ -203,6 +205,29 @@ func prepAliceMessengersForPairing(s *suite.Suite, alice1, alice2 *Messenger) {
s.Require().NoError(err)
}
func (s *MessengerSyncSettingsSuite) syncSettingAndCheck(m1 *Messenger, m2 *Messenger, settingField settings.SettingField, settingValue interface{}) settings.Settings {
err := m1.settings.SaveSettingField(settingField, settingValue)
s.Require().NoError(err)
// Wait for the message to reach its destination
err = tt.RetryWithBackOff(func() error {
mr, err := m2.RetrieveAll()
if err != nil {
return err
}
if len(mr.Settings) == 0 {
return errors.New("sync settings not in MessengerResponse")
}
return nil
})
s.Require().NoError(err)
// Check settings values
m2s, err := m2.settings.GetSettings()
s.Require().NoError(err)
return m2s
}
func (s *MessengerSyncSettingsSuite) TestSyncSettings() {
// Pair alice's two devices
PairDevices(&s.Suite, s.alice2, s.alice)
@ -213,60 +238,23 @@ func (s *MessengerSyncSettingsSuite) TestSyncSettings() {
s.Require().NoError(err)
s.Require().Exactly(settings.ProfilePicturesShowToContactsOnly, as.ProfilePicturesShowTo)
s.Require().Exactly(settings.ProfilePicturesVisibilityContactsOnly, as.ProfilePicturesVisibility)
s.Require().Exactly(settings.URLUnfurlingAlwaysAsk, as.URLUnfurlingMode)
// Check alice 2 settings values
aos, err := s.alice2.settings.GetSettings()
s.Require().NoError(err)
s.Require().Exactly(settings.ProfilePicturesShowToContactsOnly, aos.ProfilePicturesShowTo)
s.Require().Exactly(settings.ProfilePicturesVisibilityContactsOnly, aos.ProfilePicturesVisibility)
s.Require().Exactly(settings.URLUnfurlingAlwaysAsk, as.URLUnfurlingMode)
// Update alice ProfilePicturesVisibility setting
err = s.alice.settings.SaveSettingField(settings.ProfilePicturesVisibility, settings.ProfilePicturesVisibilityEveryone)
s.Require().NoError(err)
// Wait for the message to reach its destination
err = tt.RetryWithBackOff(func() error {
mr, err := s.alice2.RetrieveAll()
if err != nil {
return err
}
if len(mr.Settings) == 0 {
return errors.New("sync settings not in MessengerResponse")
}
return nil
})
s.Require().NoError(err)
// Check alice 2 settings values
aos, err = s.alice2.settings.GetSettings()
s.Require().NoError(err)
aos = s.syncSettingAndCheck(s.alice, s.alice2, settings.ProfilePicturesVisibility, settings.ProfilePicturesVisibilityEveryone)
s.Require().Equal(settings.ProfilePicturesVisibilityEveryone, aos.ProfilePicturesVisibility)
// Alice 2 updated a setting which triggers the sync functionality
err = s.alice2.settings.SaveSettingField(settings.ProfilePicturesShowTo, settings.ProfilePicturesShowToEveryone)
s.Require().NoError(err)
// Wait for the message to reach its destination
err = tt.RetryWithBackOff(func() error {
mr, err := s.alice.RetrieveAll()
if err != nil {
return err
}
if len(mr.Settings) == 0 {
return errors.New("sync settings not in MessengerResponse")
}
return nil
})
s.Require().NoError(err)
// Check alice 1 settings values
as, err = s.alice.settings.GetSettings()
s.Require().NoError(err)
as = s.syncSettingAndCheck(s.alice2, s.alice, settings.ProfilePicturesShowTo, settings.ProfilePicturesShowToEveryone)
s.Require().Exactly(settings.ProfilePicturesShowToEveryone, as.ProfilePicturesShowTo)
aos = s.syncSettingAndCheck(s.alice, s.alice2, settings.URLUnfurlingMode, settings.URLUnfurlingDisableAll)
s.Require().Exactly(settings.URLUnfurlingDisableAll, aos.URLUnfurlingMode)
}
func (s *MessengerSyncSettingsSuite) TestSyncSettings_StickerPacks() {

View File

@ -2208,7 +2208,7 @@ func _1693311981_community_shardUpSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1693311981_community_shard.up.sql", size: 156, mode: os.FileMode(0644), modTime: time.Unix(1697196255, 0)}
info := bindataFileInfo{name: "1693311981_community_shard.up.sql", size: 156, mode: os.FileMode(0644), modTime: time.Unix(1697200175, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc9, 0x12, 0xf9, 0xde, 0x49, 0x9f, 0x95, 0xaa, 0x22, 0x5e, 0x54, 0x5a, 0x1, 0xd, 0xc6, 0x1f, 0x42, 0x93, 0xe8, 0x69, 0x30, 0x11, 0x69, 0x41, 0x7f, 0x87, 0x57, 0x56, 0x2a, 0x32, 0xb9, 0x3e}}
return a, nil
}
@ -2228,7 +2228,7 @@ func _1695331492_add_status_link_previewsUpSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1695331492_add_status_link_previews.up.sql", size: 136, mode: os.FileMode(0644), modTime: time.Unix(1697196265, 0)}
info := bindataFileInfo{name: "1695331492_add_status_link_previews.up.sql", size: 136, mode: os.FileMode(0644), modTime: time.Unix(1697200175, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xb6, 0x7d, 0x6e, 0x86, 0xf0, 0xf8, 0x23, 0x4b, 0x16, 0x3d, 0xca, 0x8f, 0xfc, 0x8, 0x22, 0xd5, 0x70, 0x14, 0xbb, 0xdd, 0xa9, 0xb8, 0x3e, 0xc6, 0x20, 0xfb, 0x0, 0x26, 0x73, 0xcb, 0x92, 0xb2}}
return a, nil
}

View File

@ -39,6 +39,7 @@ const (
SyncSetting_DISPLAY_NAME SyncSetting_Type = 13
SyncSetting_BIO SyncSetting_Type = 14
SyncSetting_MNEMONIC_REMOVED SyncSetting_Type = 15
SyncSetting_URL_UNFURLING_MODE SyncSetting_Type = 18
)
var SyncSetting_Type_name = map[int32]string{
@ -58,6 +59,7 @@ var SyncSetting_Type_name = map[int32]string{
13: "DISPLAY_NAME",
14: "BIO",
15: "MNEMONIC_REMOVED",
18: "URL_UNFURLING_MODE",
}
var SyncSetting_Type_value = map[string]int32{
@ -77,6 +79,7 @@ var SyncSetting_Type_value = map[string]int32{
"DISPLAY_NAME": 13,
"BIO": 14,
"MNEMONIC_REMOVED": 15,
"URL_UNFURLING_MODE": 18,
}
func (x SyncSetting_Type) String() string {
@ -224,36 +227,39 @@ func init() {
}
var fileDescriptor_e2f7a0bce2873c78 = []byte{
// 484 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x92, 0x4d, 0x8f, 0xda, 0x3c,
0x10, 0x80, 0x09, 0x84, 0xaf, 0x09, 0x0b, 0x96, 0x59, 0xbd, 0x6f, 0xb4, 0xad, 0xb4, 0x29, 0xbd,
0xe4, 0x94, 0x4a, 0x6d, 0xd5, 0x4b, 0x4f, 0x21, 0x31, 0x60, 0x91, 0xd8, 0x91, 0xed, 0x80, 0xe8,
0xc5, 0x2a, 0x88, 0xae, 0x50, 0x11, 0x41, 0x4b, 0xb6, 0x52, 0xfe, 0x6e, 0xff, 0x44, 0xaf, 0x55,
0x92, 0xd2, 0xcf, 0x53, 0x32, 0xcf, 0x3c, 0x33, 0x1e, 0x7f, 0xc0, 0xf8, 0x52, 0x9c, 0x76, 0xfa,
0xb2, 0xcf, 0xf3, 0xc3, 0xe9, 0xe1, 0xe2, 0x9d, 0x1f, 0xb3, 0x3c, 0xc3, 0xbd, 0x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xfb, 0xbb, 0xdd, 0x9b, 0xef, 0x01, 0x00,
0x00, 0xff, 0xff, 0xb8, 0x4c, 0x65, 0xd1, 0xe3, 0x02, 0x00, 0x00,
}

View File

@ -31,7 +31,11 @@ message SyncSetting {
DISPLAY_NAME = 13;
BIO = 14;
MNEMONIC_REMOVED = 15;
reserved 16; //do not use this value anymore as it was removed
reserved 16;
reserved "ENS_USERNAMES";
reserved 17;
reserved "INCLUDE_WATCHONLY_ACCOUNT";
URL_UNFURLING_MODE = 18;
}
}

View File

@ -224,7 +224,7 @@ func ConfigCliFleetShardsTestJson() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "../config/cli/fleet-shards.test.json", size: 1954, mode: os.FileMode(0644), modTime: time.Unix(1697196255, 0)}
info := bindataFileInfo{name: "../config/cli/fleet-shards.test.json", size: 1954, mode: os.FileMode(0644), modTime: time.Unix(1697200175, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xcf, 0xeb, 0x33, 0xd4, 0x3, 0x54, 0xff, 0xda, 0x1f, 0xc4, 0xc, 0x91, 0x88, 0x1e, 0x53, 0xbf, 0x49, 0xa, 0x6c, 0x45, 0xf9, 0x19, 0x91, 0xec, 0xe, 0x1a, 0xfc, 0x14, 0x86, 0x8d, 0xa3, 0x5a}}
return a, nil
}