Set block mentions
This commit is contained in:
parent
4e18d21129
commit
2d525f9503
|
@ -15,6 +15,8 @@
|
|||
// 0008_add_push_notifications.up.sql (349B)
|
||||
// 0009_enable_sending_push_notifications.down.sql (49B)
|
||||
// 0009_enable_sending_push_notifications.up.sql (49B)
|
||||
// 0010_add_block_mentions.down.sql (83B)
|
||||
// 0010_add_block_mentions.up.sql (89B)
|
||||
// doc.go (74B)
|
||||
|
||||
package migrations
|
||||
|
@ -359,7 +361,7 @@ func _0009_enable_sending_push_notificationsDownSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0009_enable_sending_push_notifications.down.sql", size: 49, mode: os.FileMode(0644), modTime: time.Unix(1597918101, 0)}
|
||||
info := bindataFileInfo{name: "0009_enable_sending_push_notifications.down.sql", size: 49, mode: os.FileMode(0644), modTime: time.Unix(1598949727, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe9, 0xae, 0x1b, 0x41, 0xcb, 0x9c, 0x2c, 0x93, 0xc6, 0x2a, 0x77, 0x3, 0xb9, 0x51, 0xe0, 0x68, 0x68, 0x0, 0xf7, 0x5b, 0xb3, 0x1e, 0x94, 0x44, 0xba, 0x9c, 0xd0, 0x3b, 0x80, 0x21, 0x6f, 0xb5}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -379,11 +381,51 @@ func _0009_enable_sending_push_notificationsUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0009_enable_sending_push_notifications.up.sql", size: 49, mode: os.FileMode(0644), modTime: time.Unix(1597918090, 0)}
|
||||
info := bindataFileInfo{name: "0009_enable_sending_push_notifications.up.sql", size: 49, mode: os.FileMode(0644), modTime: time.Unix(1598949727, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x1b, 0x80, 0xe4, 0x9c, 0xc8, 0xb8, 0xd5, 0xef, 0xce, 0x74, 0x9b, 0x7b, 0xdd, 0xa, 0x99, 0x1e, 0xef, 0x7f, 0xb8, 0x99, 0x84, 0x4, 0x0, 0x6b, 0x1d, 0x2c, 0xa, 0xf8, 0x2c, 0x4f, 0xb5, 0x44}}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var __0010_add_block_mentionsDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\xf4\x09\x71\x0d\x52\x28\x4e\x2d\x29\xc9\xcc\x4b\x2f\x56\x70\x74\x71\x51\x70\xf6\xf7\x09\xf5\xf5\x53\x28\x28\x2d\xce\x88\xcf\xcb\x2f\xc9\x4c\xcb\x4c\x4e\x2c\xc9\xcc\xcf\x2b\x8e\x4f\xca\xc9\x4f\xce\x8e\xcf\x4d\xcd\x03\x73\x15\x9c\xfc\xfd\x7d\x5c\x1d\xfd\x14\x5c\x5c\xdd\x1c\x43\x7d\x42\x14\xdc\x1c\x7d\x82\x5d\xad\xb9\x00\x01\x00\x00\xff\xff\xa8\x45\x75\x3b\x53\x00\x00\x00")
|
||||
|
||||
func _0010_add_block_mentionsDownSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__0010_add_block_mentionsDownSql,
|
||||
"0010_add_block_mentions.down.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _0010_add_block_mentionsDownSql() (*asset, error) {
|
||||
bytes, err := _0010_add_block_mentionsDownSqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0010_add_block_mentions.down.sql", size: 83, mode: os.FileMode(0644), modTime: time.Unix(1599117686, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x6d, 0x9e, 0x27, 0x1e, 0xba, 0x9f, 0xca, 0xae, 0x98, 0x2e, 0x6e, 0xe3, 0xdd, 0xac, 0x73, 0x34, 0x4e, 0x69, 0x92, 0xb5, 0xf6, 0x9, 0xab, 0x50, 0x35, 0xd, 0xee, 0xeb, 0x3e, 0xcc, 0x7e, 0xce}}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var __0010_add_block_mentionsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x1c\xc7\x31\x0a\x42\x31\x0c\x06\xe0\xdd\x53\xfc\xf7\x70\xca\xb3\x79\x53\x7c\x05\x6d\xe7\xa2\xa5\x6a\x50\x53\x21\xf1\xfe\x82\xe3\x47\x52\xf8\x84\x42\x8b\x30\x7c\x44\xa8\xdd\x1d\x94\x12\x0e\x59\xea\x71\xc3\xe7\xeb\x8f\x66\x33\xf4\xa6\xfd\x12\x3a\xcd\xdb\xf5\x35\xfb\xb3\xbd\x87\xfd\x89\x25\x67\x61\xda\x90\x78\xa5\x2a\x05\x2b\xc9\x99\xf7\xbb\x5f\x00\x00\x00\xff\xff\x2b\x4e\x3f\xc5\x59\x00\x00\x00")
|
||||
|
||||
func _0010_add_block_mentionsUpSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__0010_add_block_mentionsUpSql,
|
||||
"0010_add_block_mentions.up.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _0010_add_block_mentionsUpSql() (*asset, error) {
|
||||
bytes, err := _0010_add_block_mentionsUpSqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0010_add_block_mentions.up.sql", size: 89, mode: os.FileMode(0644), modTime: time.Unix(1599118789, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd7, 0x23, 0x85, 0xa2, 0xb5, 0xb6, 0xb4, 0x3f, 0xdc, 0x4e, 0xff, 0xe2, 0x6b, 0x66, 0x68, 0x5e, 0xb2, 0xb4, 0x14, 0xb2, 0x1b, 0x4d, 0xb1, 0xce, 0xf7, 0x6, 0x58, 0xa7, 0xaf, 0x93, 0x3f, 0x25}}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _docGo = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x2c\xc9\xb1\x0d\xc4\x20\x0c\x05\xd0\x9e\x29\xfe\x02\xd8\xfd\x6d\xe3\x4b\xac\x2f\x44\x82\x09\x78\x7f\xa5\x49\xfd\xa6\x1d\xdd\xe8\xd8\xcf\x55\x8a\x2a\xe3\x47\x1f\xbe\x2c\x1d\x8c\xfa\x6f\xe3\xb4\x34\xd4\xd9\x89\xbb\x71\x59\xb6\x18\x1b\x35\x20\xa2\x9f\x0a\x03\xa2\xe5\x0d\x00\x00\xff\xff\x60\xcd\x06\xbe\x4a\x00\x00\x00")
|
||||
|
||||
func docGoBytes() ([]byte, error) {
|
||||
|
@ -525,6 +567,10 @@ var _bindata = map[string]func() (*asset, error){
|
|||
|
||||
"0009_enable_sending_push_notifications.up.sql": _0009_enable_sending_push_notificationsUpSql,
|
||||
|
||||
"0010_add_block_mentions.down.sql": _0010_add_block_mentionsDownSql,
|
||||
|
||||
"0010_add_block_mentions.up.sql": _0010_add_block_mentionsUpSql,
|
||||
|
||||
"doc.go": docGo,
|
||||
}
|
||||
|
||||
|
@ -584,7 +630,9 @@ var _bintree = &bintree{nil, map[string]*bintree{
|
|||
"0008_add_push_notifications.up.sql": &bintree{_0008_add_push_notificationsUpSql, map[string]*bintree{}},
|
||||
"0009_enable_sending_push_notifications.down.sql": &bintree{_0009_enable_sending_push_notificationsDownSql, map[string]*bintree{}},
|
||||
"0009_enable_sending_push_notifications.up.sql": &bintree{_0009_enable_sending_push_notificationsUpSql, map[string]*bintree{}},
|
||||
"doc.go": &bintree{docGo, map[string]*bintree{}},
|
||||
"0010_add_block_mentions.down.sql": &bintree{_0010_add_block_mentionsDownSql, map[string]*bintree{}},
|
||||
"0010_add_block_mentions.up.sql": &bintree{_0010_add_block_mentionsUpSql, map[string]*bintree{}},
|
||||
"doc.go": &bintree{docGo, map[string]*bintree{}},
|
||||
}}
|
||||
|
||||
// RestoreAsset restores an asset under the given directory.
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
ALTER settings ADD COLUMN push_notifications_block_mentions BOOLEAN DEFAULT FALSE;
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE settings ADD COLUMN push_notifications_block_mentions BOOLEAN DEFAULT FALSE;
|
|
@ -70,7 +70,9 @@ type Settings struct {
|
|||
PushNotificationsServerEnabled bool `json:"push-notifications-server-enabled?,omitempty"`
|
||||
// PushNotificationsFromContactsOnly indicates whether we should only receive push notifications from contacts
|
||||
PushNotificationsFromContactsOnly bool `json:"push-notifications-from-contacts-only?,omitempty"`
|
||||
RememberSyncingChoice bool `json:"remember-syncing-choice?,omitempty"`
|
||||
// PushNotificationsBlockMentions indicates whether we should receive notifications for mentions
|
||||
PushNotificationsBlockMentions bool `json:"push-notifications-block-mentions?,omitempty"`
|
||||
RememberSyncingChoice bool `json:"remember-syncing-choice?,omitempty"`
|
||||
// RemotePushNotificationsEnabled indicates whether we should be using remote notifications (ios only for now)
|
||||
RemotePushNotificationsEnabled bool `json:"remote-push-notifications-enabled?,omitempty"`
|
||||
SigningPhrase string `json:"signing-phrase"`
|
||||
|
@ -273,6 +275,12 @@ func (db *Database) SaveSetting(setting string, value interface{}) error {
|
|||
return ErrInvalidConfig
|
||||
}
|
||||
update, err = db.db.Prepare("UPDATE settings SET push_notifications_from_contacts_only = ? WHERE synthetic_id = 'id'")
|
||||
case "push-notifications-block-mentions?":
|
||||
_, ok := value.(bool)
|
||||
if !ok {
|
||||
return ErrInvalidConfig
|
||||
}
|
||||
update, err = db.db.Prepare("UPDATE settings SET push_notifications_block_mentions = ? WHERE synthetic_id = 'id'")
|
||||
case "send-push-notifications?":
|
||||
_, ok := value.(bool)
|
||||
if !ok {
|
||||
|
@ -337,7 +345,7 @@ func (db *Database) GetNodeConfig(nodecfg interface{}) error {
|
|||
|
||||
func (db *Database) GetSettings() (Settings, error) {
|
||||
var s Settings
|
||||
err := db.db.QueryRow("SELECT address, chaos_mode, currency, current_network, custom_bootnodes, custom_bootnodes_enabled, dapps_address, eip1581_address, fleet, hide_home_tooltip, installation_id, key_uid, keycard_instance_uid, keycard_paired_on, keycard_pairing, last_updated, latest_derived_path, log_level, mnemonic, name, networks, notifications_enabled, push_notifications_server_enabled, push_notifications_from_contacts_only, remote_push_notifications_enabled, send_push_notifications, photo_path, pinned_mailservers, preferred_name, preview_privacy, public_key, remember_syncing_choice, signing_phrase, stickers_packs_installed, stickers_packs_pending, stickers_recent_stickers, syncing_on_mobile_network, usernames, appearance, wallet_root_address, wallet_set_up_passed, wallet_visible_tokens, waku_enabled, waku_bloom_filter_mode FROM settings WHERE synthetic_id = 'id'").Scan(
|
||||
err := db.db.QueryRow("SELECT address, chaos_mode, currency, current_network, custom_bootnodes, custom_bootnodes_enabled, dapps_address, eip1581_address, fleet, hide_home_tooltip, installation_id, key_uid, keycard_instance_uid, keycard_paired_on, keycard_pairing, last_updated, latest_derived_path, log_level, mnemonic, name, networks, notifications_enabled, push_notifications_server_enabled, push_notifications_from_contacts_only, remote_push_notifications_enabled, send_push_notifications, push_notifications_block_mentions, photo_path, pinned_mailservers, preferred_name, preview_privacy, public_key, remember_syncing_choice, signing_phrase, stickers_packs_installed, stickers_packs_pending, stickers_recent_stickers, syncing_on_mobile_network, usernames, appearance, wallet_root_address, wallet_set_up_passed, wallet_visible_tokens, waku_enabled, waku_bloom_filter_mode FROM settings WHERE synthetic_id = 'id'").Scan(
|
||||
&s.Address,
|
||||
&s.ChaosMode,
|
||||
&s.Currency,
|
||||
|
@ -364,6 +372,7 @@ func (db *Database) GetSettings() (Settings, error) {
|
|||
&s.PushNotificationsFromContactsOnly,
|
||||
&s.RemotePushNotificationsEnabled,
|
||||
&s.SendPushNotifications,
|
||||
&s.PushNotificationsBlockMentions,
|
||||
&s.PhotoPath,
|
||||
&s.PinnedMailserver,
|
||||
&s.PreferredName,
|
||||
|
|
|
@ -30,50 +30,21 @@ import (
|
|||
"github.com/status-im/status-go/whisper/v6"
|
||||
)
|
||||
|
||||
// GetFreePort asks the kernel for a free open port that is ready to use.
|
||||
func getFreePort() (int, error) {
|
||||
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
l, err := net.ListenTCP("tcp", addr)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer l.Close()
|
||||
return l.Addr().(*net.TCPAddr).Port, nil
|
||||
}
|
||||
|
||||
type PeerPoolSimulationSuite struct {
|
||||
suite.Suite
|
||||
|
||||
bootnode *p2p.Server
|
||||
peers []*p2p.Server
|
||||
discovery []discovery.Discovery
|
||||
port uint16
|
||||
rendezvousServer *server.Server
|
||||
}
|
||||
|
||||
func TestPeerPoolSimulationSuite(t *testing.T) {
|
||||
s := &PeerPoolSimulationSuite{}
|
||||
port, err := getFreePort()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s.port = uint16(port)
|
||||
|
||||
suite.Run(t, s)
|
||||
}
|
||||
|
||||
func (s *PeerPoolSimulationSuite) nextPort() uint16 {
|
||||
port, err := getFreePort()
|
||||
s.Require().NoError(err)
|
||||
return uint16(port)
|
||||
}
|
||||
|
||||
func (s *PeerPoolSimulationSuite) SetupTest() {
|
||||
bootnodePort := s.nextPort()
|
||||
key, _ := crypto.GenerateKey()
|
||||
name := common.MakeName("bootnode", "1.0")
|
||||
// 127.0.0.1 is invalidated by discovery v5
|
||||
|
@ -81,13 +52,14 @@ func (s *PeerPoolSimulationSuite) SetupTest() {
|
|||
Config: p2p.Config{
|
||||
MaxPeers: 10,
|
||||
Name: name,
|
||||
ListenAddr: fmt.Sprintf("0.0.0.0:%d", bootnodePort),
|
||||
ListenAddr: ":0",
|
||||
PrivateKey: key,
|
||||
DiscoveryV5: true,
|
||||
NoDiscovery: true,
|
||||
},
|
||||
}
|
||||
s.Require().NoError(s.bootnode.Start())
|
||||
bootnodePort := uint16(s.bootnode.NodeInfo().Ports.Listener)
|
||||
bootnodeV5 := discv5.NewNode(s.bootnode.DiscV5.Self().ID, net.ParseIP("127.0.0.1"), bootnodePort, bootnodePort)
|
||||
|
||||
// 1 peer to initiate connection, 1 peer as a first candidate, 1 peer - for failover
|
||||
|
@ -100,7 +72,7 @@ func (s *PeerPoolSimulationSuite) SetupTest() {
|
|||
Config: p2p.Config{
|
||||
MaxPeers: 10,
|
||||
Name: common.MakeName("peer-"+strconv.Itoa(i), "1.0"),
|
||||
ListenAddr: fmt.Sprintf("0.0.0.0:%d", s.nextPort()),
|
||||
ListenAddr: ":0",
|
||||
PrivateKey: key,
|
||||
NoDiscovery: true,
|
||||
BootstrapNodesV5: []*discv5.Node{bootnodeV5},
|
||||
|
|
|
@ -3592,6 +3592,28 @@ func (m *Messenger) DisablePushNotificationsFromContactsOnly() error {
|
|||
return m.pushNotificationClient.DisablePushNotificationsFromContactsOnly(m.pushNotificationOptions())
|
||||
}
|
||||
|
||||
// EnablePushNotificationsBlockMentions is used to indicate that we dont want to received push notifications for mentions
|
||||
func (m *Messenger) EnablePushNotificationsBlockMentions() error {
|
||||
if m.pushNotificationClient == nil {
|
||||
return errors.New("no push notification client")
|
||||
}
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
||||
return m.pushNotificationClient.EnablePushNotificationsBlockMentions(m.pushNotificationOptions())
|
||||
}
|
||||
|
||||
// DisablePushNotificationsBlockMentions is used to indicate that we want to received push notifications for mentions
|
||||
func (m *Messenger) DisablePushNotificationsBlockMentions() error {
|
||||
if m.pushNotificationClient == nil {
|
||||
return errors.New("no push notification client")
|
||||
}
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
||||
return m.pushNotificationClient.DisablePushNotificationsBlockMentions(m.pushNotificationOptions())
|
||||
}
|
||||
|
||||
// GetPushNotificationsServers returns the servers used for push notifications
|
||||
func (m *Messenger) GetPushNotificationsServers() ([]*pushnotificationclient.PushNotificationServer, error) {
|
||||
if m.pushNotificationClient == nil {
|
||||
|
|
|
@ -627,6 +627,26 @@ func (c *Client) DisablePushNotificationsFromContactsOnly(options *RegistrationO
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) EnablePushNotificationsBlockMentions(options *RegistrationOptions) error {
|
||||
c.config.Logger.Debug("disabling push notifications for mentions")
|
||||
c.config.BlockMentions = true
|
||||
if c.lastPushNotificationRegistration != nil && c.config.RemoteNotificationsEnabled {
|
||||
c.config.Logger.Debug("re-registering after disabling push notifications for mentions")
|
||||
return c.Register(c.deviceToken, c.apnTopic, c.tokenType, options)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) DisablePushNotificationsBlockMentions(options *RegistrationOptions) error {
|
||||
c.config.Logger.Debug("enabling push notifications for mentions")
|
||||
c.config.BlockMentions = false
|
||||
if c.lastPushNotificationRegistration != nil && c.config.RemoteNotificationsEnabled {
|
||||
c.config.Logger.Debug("re-registering after enabling push notifications for mentions")
|
||||
return c.Register(c.deviceToken, c.apnTopic, c.tokenType, options)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func encryptAccessToken(plaintext []byte, key []byte, reader io.Reader) ([]byte, error) {
|
||||
c, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
|
|
|
@ -506,6 +506,22 @@ func (api *PublicAPI) DisablePushNotificationsFromContactsOnly(ctx context.Conte
|
|||
return api.service.messenger.DisablePushNotificationsFromContactsOnly()
|
||||
}
|
||||
|
||||
func (api *PublicAPI) EnablePushNotificationsBlockMentions(ctx context.Context) error {
|
||||
err := api.service.accountsDB.SaveSetting("push-notifications-block-mentions?", true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return api.service.messenger.EnablePushNotificationsBlockMentions()
|
||||
}
|
||||
|
||||
func (api *PublicAPI) DisablePushNotificationsBlockMentions(ctx context.Context) error {
|
||||
err := api.service.accountsDB.SaveSetting("push-notifications-block-mentions?", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return api.service.messenger.DisablePushNotificationsBlockMentions()
|
||||
}
|
||||
|
||||
func (api *PublicAPI) AddPushNotificationsServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
|
||||
publicKey, err := crypto.UnmarshalPubkey(publicKeyBytes)
|
||||
if err != nil {
|
||||
|
|
|
@ -484,6 +484,7 @@ func buildMessengerOptions(
|
|||
|
||||
options = append(options, protocol.WithPushNotificationClientConfig(&pushnotificationclient.Config{
|
||||
DefaultServers: config.DefaultPushNotificationsServers,
|
||||
BlockMentions: settings.PushNotificationsBlockMentions,
|
||||
SendEnabled: settings.SendPushNotifications,
|
||||
AllowFromContactsOnly: settings.PushNotificationsFromContactsOnly,
|
||||
RemoteNotificationsEnabled: settings.RemotePushNotificationsEnabled,
|
||||
|
|
Loading…
Reference in New Issue