Add version to notification info

This commit is contained in:
Andrea Maria Piana 2020-07-17 13:41:49 +02:00
parent 026e16533f
commit 12a3c5a31a
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
18 changed files with 492 additions and 126 deletions

View File

@ -3,3 +3,4 @@ Specs changes:
- Encrypt of payload instead of signature + public key of server
- Removed preferencs + each device registers individually
- Add grant
- Add version in PushNotificationInfo

View File

@ -12,7 +12,7 @@
// 0005_waku_mode.up.sql (146B)
// 0006_appearance.up.sql (67B)
// 0007_enable_waku_default.up.sql (38B)
// 0008_add_push_notifications.up.sql (214B)
// 0008_add_push_notifications.up.sql (294B)
// doc.go (74B)
package migrations
@ -322,7 +322,7 @@ func _0007_enable_waku_defaultUpSql() (*asset, error) {
return a, nil
}
var __0008_add_push_notificationsUpSql = []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\x4a\xcd\xcd\x2f\x49\x8d\x2f\x28\x2d\xce\x88\xcf\xcb\x2f\xc9\x4c\xcb\x4c\x4e\x2c\xc9\xcc\xcf\x2b\x8e\x4f\xcd\x4b\x4c\xca\x49\x4d\x51\x70\xf2\xf7\xf7\x71\x75\xf4\xb3\xe6\x22\x64\x54\x71\x6a\x5e\x0a\x16\x83\x88\x37\x00\x43\x6f\x7c\x71\x6a\x51\x59\x6a\x11\xa6\x53\x00\x01\x00\x00\xff\xff\xfc\xde\xba\xf0\xd6\x00\x00\x00")
var __0008_add_push_notificationsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\xce\xc1\x0a\xc2\x30\x0c\x00\xd0\xbb\x5f\x91\xff\xf0\xd4\xb9\xde\xea\x0a\x32\xcf\xa1\x76\x99\x16\xd6\x44\x9a\x28\xf8\xf7\x1e\xbd\x14\xd4\x1f\x78\x3c\x17\x66\x7f\x82\xd9\x0d\xc1\x83\x92\x59\xe1\xab\x82\x1b\x47\x38\xc4\x70\x3e\x4e\xd0\xa8\x8a\x11\xde\x1f\x7a\x43\x16\x2b\x6b\xc9\xc9\x8a\xb0\x22\x71\xba\x6c\xb4\xc0\x10\x63\xf0\x6e\xda\xef\xbe\x51\x4a\xbc\x74\xa0\xdf\x81\x4e\x42\xa9\x3d\xa9\xfd\x7f\xe9\x50\x6b\x93\x8a\x59\xd8\x52\x36\x45\xe1\xed\xf5\xe1\xde\x01\x00\x00\xff\xff\x16\x96\xb2\xb5\x26\x01\x00\x00")
func _0008_add_push_notificationsUpSqlBytes() ([]byte, error) {
return bindataRead(
@ -337,8 +337,8 @@ func _0008_add_push_notificationsUpSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "0008_add_push_notifications.up.sql", size: 214, mode: os.FileMode(0644), modTime: time.Unix(1594815858, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x34, 0x77, 0x87, 0xd3, 0xd7, 0x50, 0x58, 0x80, 0x8f, 0x56, 0x4c, 0x2f, 0x1b, 0x58, 0x4d, 0x98, 0xdd, 0x3, 0xc5, 0x91, 0xad, 0x5e, 0xfe, 0xb, 0x54, 0xb3, 0x7e, 0xd8, 0xf7, 0x25, 0xa0, 0xda}}
info := bindataFileInfo{name: "0008_add_push_notifications.up.sql", size: 294, mode: os.FileMode(0644), modTime: time.Unix(1594974529, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xde, 0x81, 0x4a, 0x9, 0x4d, 0xd9, 0xa1, 0x3d, 0xc5, 0xc3, 0xd7, 0x62, 0x8f, 0xc5, 0xfd, 0xb8, 0xa2, 0x71, 0x1d, 0xbc, 0xa6, 0x0, 0x3, 0x83, 0x7a, 0x12, 0x7b, 0x1f, 0xa9, 0x2, 0x29, 0x1a}}
return a, nil
}

View File

@ -1,3 +1,4 @@
ALTER TABLE settings ADD COLUMN remote_push_notifications_enabled BOOLEAN;
ALTER TABLE settings ADD COLUMN send_push_notifications BOOLEAN;
ALTER TABLE settings ADD COLUMN push_notification_server_enabled BOOLEAN;
ALTER TABLE settings ADD COLUMN push_notifications_server_enabled BOOLEAN;
ALTER TABLE settings ADD COLUMN push_notifications_from_contacts_only BOOLEAN;

View File

@ -38,49 +38,50 @@ type Account struct {
type Settings struct {
// required
Address types.Address `json:"address"`
ChaosMode bool `json:"chaos-mode?,omitempty"`
Currency string `json:"currency,omitempty"`
CurrentNetwork string `json:"networks/current-network"`
CustomBootnodes *json.RawMessage `json:"custom-bootnodes,omitempty"`
CustomBootnodesEnabled *json.RawMessage `json:"custom-bootnodes-enabled?,omitempty"`
DappsAddress types.Address `json:"dapps-address"`
EIP1581Address types.Address `json:"eip1581-address"`
Fleet *string `json:"fleet,omitempty"`
HideHomeTooltip bool `json:"hide-home-tooltip?,omitempty"`
InstallationID string `json:"installation-id"`
KeyUID string `json:"key-uid"`
KeycardInstanceUID string `json:"keycard-instance-uid,omitempty"`
KeycardPAiredOn int64 `json:"keycard-paired-on,omitempty"`
KeycardPairing string `json:"keycard-pairing,omitempty"`
LastUpdated *int64 `json:"last-updated,omitempty"`
LatestDerivedPath uint `json:"latest-derived-path"`
LogLevel *string `json:"log-level,omitempty"`
Mnemonic *string `json:"mnemonic,omitempty"`
Name string `json:"name,omitempty"`
Networks *json.RawMessage `json:"networks/networks"`
NotificationsEnabled bool `json:"notifications-enabled?,omitempty"`
PhotoPath string `json:"photo-path"`
PinnedMailserver *json.RawMessage `json:"pinned-mailservers,omitempty"`
PreferredName *string `json:"preferred-name,omitempty"`
PreviewPrivacy bool `json:"preview-privacy?"`
PublicKey string `json:"public-key"`
PushNotificationServerEnabled bool `json:"push-notification-server-enabled,omitempty"`
RememberSyncingChoice bool `json:"remember-syncing-choice?,omitempty"`
RemotePushNotificationsEnabled bool `json:"remote-push-notifications-enabled,omitempty"`
SigningPhrase string `json:"signing-phrase"`
StickerPacksInstalled *json.RawMessage `json:"stickers/packs-installed,omitempty"`
StickerPacksPending *json.RawMessage `json:"stickers/packs-pending,omitempty"`
StickersRecentStickers *json.RawMessage `json:"stickers/recent-stickers,omitempty"`
SyncingOnMobileNetwork bool `json:"syncing-on-mobile-network?,omitempty"`
SendPushNotifications bool `json:"send-push-notifications,omitempty"`
Appearance uint `json:"appearance"`
Usernames *json.RawMessage `json:"usernames,omitempty"`
WalletRootAddress types.Address `json:"wallet-root-address,omitempty"`
WalletSetUpPassed bool `json:"wallet-set-up-passed?,omitempty"`
WalletVisibleTokens *json.RawMessage `json:"wallet/visible-tokens,omitempty"`
WakuEnabled bool `json:"waku-enabled,omitempty"`
WakuBloomFilterMode bool `json:"waku-bloom-filter-mode,omitempty"`
Address types.Address `json:"address"`
ChaosMode bool `json:"chaos-mode?,omitempty"`
Currency string `json:"currency,omitempty"`
CurrentNetwork string `json:"networks/current-network"`
CustomBootnodes *json.RawMessage `json:"custom-bootnodes,omitempty"`
CustomBootnodesEnabled *json.RawMessage `json:"custom-bootnodes-enabled?,omitempty"`
DappsAddress types.Address `json:"dapps-address"`
EIP1581Address types.Address `json:"eip1581-address"`
Fleet *string `json:"fleet,omitempty"`
HideHomeTooltip bool `json:"hide-home-tooltip?,omitempty"`
InstallationID string `json:"installation-id"`
KeyUID string `json:"key-uid"`
KeycardInstanceUID string `json:"keycard-instance-uid,omitempty"`
KeycardPAiredOn int64 `json:"keycard-paired-on,omitempty"`
KeycardPairing string `json:"keycard-pairing,omitempty"`
LastUpdated *int64 `json:"last-updated,omitempty"`
LatestDerivedPath uint `json:"latest-derived-path"`
LogLevel *string `json:"log-level,omitempty"`
Mnemonic *string `json:"mnemonic,omitempty"`
Name string `json:"name,omitempty"`
Networks *json.RawMessage `json:"networks/networks"`
NotificationsEnabled bool `json:"notifications-enabled?,omitempty"`
PhotoPath string `json:"photo-path"`
PinnedMailserver *json.RawMessage `json:"pinned-mailservers,omitempty"`
PreferredName *string `json:"preferred-name,omitempty"`
PreviewPrivacy bool `json:"preview-privacy?"`
PublicKey string `json:"public-key"`
PushNotificationsServerEnabled bool `json:"push-notifications-server-enabled,omitempty"`
PushNotificationsFromContactsOnly bool `json:"push-notifications-from-contacts-only,omitempty"`
RememberSyncingChoice bool `json:"remember-syncing-choice?,omitempty"`
RemotePushNotificationsEnabled bool `json:"remote-push-notifications-enabled,omitempty"`
SigningPhrase string `json:"signing-phrase"`
StickerPacksInstalled *json.RawMessage `json:"stickers/packs-installed,omitempty"`
StickerPacksPending *json.RawMessage `json:"stickers/packs-pending,omitempty"`
StickersRecentStickers *json.RawMessage `json:"stickers/recent-stickers,omitempty"`
SyncingOnMobileNetwork bool `json:"syncing-on-mobile-network?,omitempty"`
SendPushNotifications bool `json:"send-push-notifications,omitempty"`
Appearance uint `json:"appearance"`
Usernames *json.RawMessage `json:"usernames,omitempty"`
WalletRootAddress types.Address `json:"wallet-root-address,omitempty"`
WalletSetUpPassed bool `json:"wallet-set-up-passed?,omitempty"`
WalletVisibleTokens *json.RawMessage `json:"wallet/visible-tokens,omitempty"`
WakuEnabled bool `json:"waku-enabled,omitempty"`
WakuBloomFilterMode bool `json:"waku-bloom-filter-mode,omitempty"`
}
func NewDB(db *sql.DB) *Database {
@ -260,8 +261,13 @@ func (db *Database) SaveSetting(setting string, value interface{}) error {
if !ok {
return ErrInvalidConfig
}
update, err = db.db.Prepare("UPDATE settings SET push_notification_server_enabled = ? WHERE synthetic_id = 'id'")
update, err = db.db.Prepare("UPDATE settings SET push_notifications_server_enabled = ? WHERE synthetic_id = 'id'")
case "push-notifications-from-contacts-only":
_, ok := value.(bool)
if !ok {
return ErrInvalidConfig
}
update, err = db.db.Prepare("UPDATE settings SET push_notifications_from_contacts_only = ? WHERE synthetic_id = 'id'")
case "send-push-notifications":
_, ok := value.(bool)
if !ok {

View File

@ -3043,6 +3043,14 @@ func (m *Messenger) AddPushNotificationServer(ctx context.Context, publicKey *ec
return m.pushNotificationClient.AddPushNotificationServer(publicKey)
}
// RemovePushNotificationServer removes a push notification server
func (m *Messenger) RemovePushNotificationServer(ctx context.Context, publicKey *ecdsa.PublicKey) error {
if m.pushNotificationClient == nil {
return errors.New("push notification client not enabled")
}
return m.pushNotificationClient.RemovePushNotificationServer(publicKey)
}
func (m *Messenger) UnregisterFromPushNotifications(ctx context.Context) error {
return m.pushNotificationClient.Unregister()
}
@ -3102,6 +3110,22 @@ func (m *Messenger) RegisteredForPushNotifications() (bool, error) {
return m.pushNotificationClient.Registered()
}
func (m *Messenger) EnablePushNotificationsFromContactsOnly() error {
if m.pushNotificationClient == nil {
return errors.New("no push notification client")
}
return m.pushNotificationClient.EnablePushNotificationsFromContactsOnly()
}
func (m *Messenger) DisablePushNotificationsFromContactsOnly() error {
if m.pushNotificationClient == nil {
return errors.New("no push notification client")
}
return m.pushNotificationClient.DisablePushNotificationsFromContactsOnly()
}
func (m *Messenger) GetPushNotificationServers() ([]*push_notification_client.PushNotificationServer, error) {
if m.pushNotificationClient == nil {
return nil, errors.New("no push notification client")

View File

@ -338,7 +338,7 @@ func _1593087212_add_mute_chatDownSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1593087212_add_mute_chat.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1594393604, 0)}
info := bindataFileInfo{name: "1593087212_add_mute_chat.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1594896559, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}}
return a, nil
}
@ -358,7 +358,7 @@ func _1593087212_add_mute_chatUpSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1593087212_add_mute_chat.up.sql", size: 58, mode: os.FileMode(0644), modTime: time.Unix(1594393604, 0)}
info := bindataFileInfo{name: "1593087212_add_mute_chat.up.sql", size: 58, mode: os.FileMode(0644), modTime: time.Unix(1594896559, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe, 0x9, 0xa0, 0x4a, 0x8e, 0x23, 0xe4, 0xce, 0xbc, 0xd4, 0x9, 0xeb, 0xf9, 0x67, 0x90, 0xc0, 0x4b, 0x67, 0x84, 0xe4, 0x42, 0x8d, 0x0, 0x17, 0x29, 0x7f, 0x12, 0xbf, 0x7d, 0x4e, 0x78, 0xec}}
return a, nil
}

View File

@ -418,6 +418,7 @@ type PushNotificationQueryInfo struct {
PublicKey []byte `protobuf:"bytes,3,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"`
AllowedUserList [][]byte `protobuf:"bytes,4,rep,name=allowed_user_list,json=allowedUserList,proto3" json:"allowed_user_list,omitempty"`
Grant []byte `protobuf:"bytes,5,opt,name=grant,proto3" json:"grant,omitempty"`
Version uint64 `protobuf:"varint,6,opt,name=version,proto3" json:"version,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -483,6 +484,13 @@ func (m *PushNotificationQueryInfo) GetGrant() []byte {
return nil
}
func (m *PushNotificationQueryInfo) GetVersion() uint64 {
if m != nil {
return m.Version
}
return 0
}
type PushNotificationQueryResponse struct {
Info []*PushNotificationQueryInfo `protobuf:"bytes,1,rep,name=info,proto3" json:"info,omitempty"`
MessageId []byte `protobuf:"bytes,2,opt,name=message_id,json=messageId,proto3" json:"message_id,omitempty"`
@ -786,59 +794,59 @@ func init() {
func init() { proto.RegisterFile("push_notifications.proto", fileDescriptor_200acd86044eaa5d) }
var fileDescriptor_200acd86044eaa5d = []byte{
// 856 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0xe1, 0x6e, 0xe3, 0x44,
0x10, 0xc7, 0x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 0x11, 0x13, 0x5b, 0x44, 0xef, 0xeb, 0x75, 0xd1, 0x7b, 0xb1,
0x4d, 0xf4, 0xd2, 0xad, 0x6a, 0x65, 0xee, 0xff, 0x40, 0xa9, 0xff, 0xb8, 0x8b, 0x1c, 0x1e, 0xc1,
0xc1, 0x2b, 0x62, 0x5b, 0x97, 0xe5, 0xff, 0x82, 0x8a, 0xac, 0x29, 0xa9, 0xcf, 0xb2, 0x1d, 0x97,
0x18, 0x97, 0xe6, 0xc4, 0x31, 0x88, 0x71, 0xde, 0x6d, 0xe8, 0x09, 0x68, 0x9b, 0x05, 0xe5, 0xef,
0x79, 0x9d, 0x2b, 0xaa, 0x3e, 0xcb, 0xaf, 0xa0, 0xc5, 0x64, 0xed, 0x5c, 0x53, 0x64, 0xb7, 0x7a,
0x0f, 0x41, 0x22, 0x45, 0xc2, 0x74, 0x5f, 0x46, 0x7e, 0xfe, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff,
0xcc, 0x3e, 0xe7, 0x96, 0xa1, 0x08, 0x00, 0x00,
// 858 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x51, 0x6f, 0xe3, 0x44,
0x10, 0x66, 0x9d, 0xb4, 0x89, 0xa7, 0xa1, 0xcd, 0xad, 0x7a, 0x3d, 0x73, 0xe2, 0x20, 0x67, 0x90,
0x88, 0x0e, 0x29, 0x42, 0x45, 0x82, 0x13, 0x4f, 0x84, 0xd6, 0x2d, 0x56, 0x1b, 0x3b, 0x6c, 0x5c,
0x4e, 0x48, 0x48, 0x96, 0x13, 0x6f, 0x5b, 0xab, 0x39, 0xdb, 0xec, 0xae, 0x8b, 0xf2, 0x80, 0xc4,
0x2f, 0x40, 0xe2, 0x95, 0x5f, 0x81, 0xf8, 0x3b, 0xbc, 0xf1, 0x4b, 0x90, 0xd7, 0x76, 0x70, 0x1c,
0x37, 0xcd, 0x03, 0x4f, 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2a, 0xae, 0xa8, 0x3a, 0x96, 0x5f, 0x41, 0x8b, 0xc9, 0xde, 0xb9, 0xa6, 0x48,
0xb6, 0x7a, 0x8f, 0x81, 0x44, 0x8a, 0x84, 0xe9, 0xae, 0x8c, 0xfc, 0xfc, 0xdf, 0x00, 0x00, 0x00,
0xff, 0xff, 0x04, 0xbd, 0xc3, 0x50, 0xbb, 0x08, 0x00, 0x00,
}

View File

@ -54,6 +54,7 @@ message PushNotificationQueryInfo {
bytes public_key = 3;
repeated bytes allowed_user_list = 4;
bytes grant = 5;
uint64 version = 6;
}
message PushNotificationQueryResponse {

View File

@ -64,6 +64,7 @@ type PushNotificationInfo struct {
PublicKey *ecdsa.PublicKey
ServerPublicKey *ecdsa.PublicKey
RetrievedAt int64
Version uint64
}
type Config struct {
@ -74,9 +75,9 @@ type Config struct {
// RemoteNotificationsEnabled is whether we should register with a remote server for push notifications
RemoteNotificationsEnabled bool
// AllowOnlyFromContacts indicates whether we should be receiving push notifications
// AllowyFromContactsOnly indicates whether we should be receiving push notifications
// only from contacts
AllowOnlyFromContacts bool
AllowFromContactsOnly bool
// InstallationID is the installation-id for this device
InstallationID string
@ -786,6 +787,7 @@ func (c *Client) HandlePushNotificationQueryResponse(serverPublicKey *ecdsa.Publ
ServerPublicKey: serverPublicKey,
AccessToken: info.AccessToken,
InstallationID: info.InstallationId,
Version: info.Version,
RetrievedAt: time.Now().Unix(),
})
@ -804,6 +806,13 @@ func (p *Client) HandlePushNotificationResponse(ack *protobuf.PushNotificationRe
return nil
}
func (c *Client) RemovePushNotificationServer(publicKey *ecdsa.PublicKey) error {
c.config.Logger.Info("removing push notification server", zap.Any("public-key", publicKey))
//TODO: this needs implementing. It requires unregistering from the server and
// likely invalidate the device token of the user
return errors.New("not implemented")
}
func (c *Client) AddPushNotificationServer(publicKey *ecdsa.PublicKey) error {
c.config.Logger.Info("adding push notification server", zap.Any("public-key", publicKey))
currentServers, err := c.persistence.GetServers()
@ -872,6 +881,16 @@ func (c *Client) DisableSending() {
c.config.SendEnabled = false
}
func (c *Client) EnablePushNotificationsFromContactsOnly() error {
c.config.AllowFromContactsOnly = true
return nil
}
func (c *Client) DisablePushNotificationsFromContactsOnly() error {
c.config.AllowFromContactsOnly = false
return nil
}
func (c *Client) listenToPublicKeyQueryTopic(hashedPublicKey []byte) error {
encodedPublicKey := hex.EncodeToString(hashedPublicKey)
return c.messageProcessor.JoinPublic(encodedPublicKey)

View File

@ -1,7 +1,7 @@
// Code generated by go-bindata. DO NOT EDIT.
// sources:
// 1593601729_initial_schema.down.sql (144B)
// 1593601729_initial_schema.up.sql (1.576kB)
// 1593601729_initial_schema.up.sql (1.6kB)
// doc.go (382B)
package migrations
@ -86,12 +86,12 @@ func _1593601729_initial_schemaDownSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1593601729_initial_schema.down.sql", size: 144, mode: os.FileMode(0644), modTime: time.Unix(1594393629, 0)}
info := bindataFileInfo{name: "1593601729_initial_schema.down.sql", size: 144, mode: os.FileMode(0644), modTime: time.Unix(1594896579, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xa, 0x95, 0x55, 0x64, 0x38, 0x40, 0x16, 0xbf, 0x8b, 0x1c, 0x18, 0xb4, 0xc5, 0x7f, 0xd0, 0xb8, 0xf0, 0x3c, 0xa2, 0x82, 0xf8, 0x8d, 0x5a, 0xd3, 0xb6, 0x6e, 0xa3, 0xb4, 0xc, 0x9, 0x33, 0x0}}
return a, nil
}
var __1593601729_initial_schemaUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x94\xc1\x8e\x9b\x30\x10\x86\xef\x3c\xc5\x1c\x17\x89\x43\xef\x7b\x02\xd6\x54\x48\x96\xdd\x26\x46\xca\xcd\x72\x8d\x77\x63\x85\x9a\xad\x6d\x56\xe5\xed\x2b\x60\xc9\x92\x90\x40\x95\xe4\x82\x84\xfd\x7b\xec\x6f\xfe\x99\x49\x37\x28\x66\x08\x58\x9c\x60\x04\x79\x06\x84\x32\x40\xbb\x7c\xcb\xb6\xf0\xde\xb8\x3d\x37\xb5\xd7\xaf\x5a\x0a\xaf\x6b\xc3\x65\xa5\x95\xf1\xdc\x29\xfb\xa1\xac\x83\xa7\x00\xe0\xbd\xf9\x55\x69\xc9\x0f\xaa\x85\x04\xd3\xa4\x3f\x4f\x0a\x8c\xa3\x00\xc0\xaa\x37\xed\xbc\xb2\xaa\x84\x84\x52\x8c\x62\x02\x2f\x28\x8b\x0b\xcc\x20\x8b\xf1\x16\x9d\x6a\xb8\xf0\x90\x13\x76\x8c\x70\xd4\x7e\xeb\x74\x95\x70\x9e\x5b\xe5\xad\x5e\x53\x76\xa2\x96\xcb\xba\x31\x4b\x2a\x21\xa5\x72\x8e\xfb\xfa\xa0\x0c\x30\xb4\x63\xdd\x62\x41\xf2\x9f\x05\x7a\xfa\x62\x0a\x81\x12\x48\x29\xc9\x70\x9e\x32\xd8\xa0\x1f\x38\x4e\x51\x10\x3e\x07\xc1\x2d\x79\xfb\xd3\x28\xab\xd5\x7a\xde\x06\xdd\x0c\x73\xdc\x6a\xb9\x2e\xe7\x87\x66\x6f\x8f\x46\xed\x63\x21\xb4\x79\xad\x57\x09\x86\x0a\xe1\x4b\x12\x6d\x9c\x17\x55\x35\xc4\xd6\x65\xef\xc1\x89\x60\xe6\xd0\x59\x6d\x75\xa5\xf0\x71\x39\x4b\xf3\x5c\x9c\x5f\x17\xcd\x9f\xf8\xd8\x34\x79\x2b\xe4\x41\x95\xfc\xb7\x72\x4e\xbc\x7d\x9a\xfe\xf9\x73\xd1\x3f\xb9\x17\xfe\x62\x1e\xc6\x48\xd7\x39\xbf\xc2\x9e\x32\xe4\xdf\x09\xdd\xa0\x00\xe0\x56\x08\xd7\x7d\xa6\x1b\xeb\x18\x77\x59\xde\xdf\xf7\x3f\x9c\x11\x2c\x78\x1b\xde\x41\x3c\x8c\x23\x3b\x81\x1d\x47\xd4\xb0\x36\x87\x02\x90\xb5\xf1\x42\x76\xe6\xb9\x7e\x7b\x58\x75\xad\xf1\x7b\xe5\xb5\xec\x48\xaf\xcf\xa1\x23\xdc\x54\xbf\x5a\x8a\x39\x79\x41\x3b\xd0\xe5\x5f\xbe\xd8\xa7\xd3\x06\xa4\x64\xb9\xa7\x97\xba\x25\x7c\x0e\xfe\x05\x00\x00\xff\xff\x58\xe5\xb5\x4b\x28\x06\x00\x00")
var __1593601729_initial_schemaUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x94\xc1\x6e\xa3\x30\x10\x86\xef\x3c\xc5\x1c\x1b\x29\x87\xbd\xf7\x44\xa8\x59\x21\x59\xf6\x6e\x62\xa4\xdc\x2c\xaf\x71\x1b\x2b\xac\xe9\xda\xa6\x5a\xde\x7e\x65\x08\x29\xa9\x59\xa8\xda\x5e\x22\x65\xfc\x7b\xf0\x37\xf3\xcf\x64\x7b\x94\x32\x04\x2c\xdd\x61\x04\x45\x0e\x84\x32\x40\xc7\xe2\xc0\x0e\xf0\xdc\xba\x13\x37\x8d\xd7\x8f\x5a\x0a\xaf\x1b\xc3\x65\xad\x95\xf1\xdc\x29\xfb\xa2\xac\x83\xbb\x04\xe0\xb9\xfd\x55\x6b\xc9\xcf\xaa\x83\x1d\xa6\xbb\xfe\x3e\x29\x31\xde\x26\x00\x56\x3d\x69\xe7\x95\x55\x15\xec\x28\xc5\x28\x25\xf0\x80\xf2\xb4\xc4\x0c\xf2\x14\x1f\xd0\xad\x86\x0b\x0f\x05\x61\xd7\x0c\x57\xed\xb7\xa0\xab\x85\xf3\xdc\x2a\x6f\xf5\x9a\x32\x88\x3a\x2e\x9b\xd6\x2c\xa9\x84\x94\xca\x39\xee\x9b\xb3\x32\xc0\xd0\x91\x85\x60\x49\x8a\x9f\x25\xba\x7b\x65\xda\x00\x25\x90\x51\x92\xe3\x22\x63\xb0\x47\x3f\x70\x9a\xa1\x64\x73\x9f\x24\x1f\xa9\xdb\x9f\x56\x59\xad\xd6\xeb\x36\xe8\x22\xcc\xf1\xa8\xe3\xba\x8a\x2f\x45\x6f\xdf\x8e\xda\xaf\x85\xd0\xe6\xb1\x59\x25\x18\x1c\xc2\x97\x24\xda\x38\x2f\xea\x7a\xc8\xad\xab\xbe\x07\x37\x82\xa8\x43\x6f\xbc\x15\xac\xf0\x32\x5f\xa5\xe0\x4e\xdd\x98\x28\x1e\xd7\xe8\xed\x33\xb6\xf1\xd3\xbf\xb6\x7c\xde\x0a\x79\x56\x15\xff\xad\x9c\x13\x4f\x17\x33\x5c\xfe\xcc\xf6\x55\x9e\x84\x9f\xad\xcf\x98\x69\x86\xff\xc2\xf9\x9a\xf6\x96\xa1\xf8\x4e\xe8\x1e\x25\x00\x1f\x85\x70\xe1\x67\x7a\xb0\x8e\xf1\x29\x2b\xf4\xdf\x7b\x0f\xe7\x16\x16\x7a\xbb\xf9\x04\xf1\xb0\xa6\xec\x04\x76\x5c\x5d\x43\x2c\x86\x02\x90\x8d\xf1\x42\x86\xe6\xb9\xfe\x78\x88\xba\xce\xf8\x93\xf2\x5a\x06\xd2\xff\xef\xa7\x2b\xdc\x54\xbf\x6a\xc5\x82\x3c\xa0\x23\xe8\xea\x2f\x5f\x9c\xdf\xe9\x60\x52\xb2\x3c\xeb\x4b\xd3\xb2\xb9\x4f\xfe\x05\x00\x00\xff\xff\x2b\xa6\x15\x32\x40\x06\x00\x00")
func _1593601729_initial_schemaUpSqlBytes() ([]byte, error) {
return bindataRead(
@ -106,8 +106,8 @@ func _1593601729_initial_schemaUpSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1593601729_initial_schema.up.sql", size: 1576, mode: os.FileMode(0644), modTime: time.Unix(1594803635, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xf4, 0xe, 0xc, 0xdf, 0xb6, 0xdb, 0x22, 0x1, 0x1f, 0xe0, 0x18, 0x96, 0x1b, 0x13, 0x5f, 0x60, 0x2c, 0x41, 0xd5, 0x4, 0x77, 0x99, 0x8a, 0x4d, 0xa1, 0xd6, 0x41, 0xb5, 0x1, 0x86, 0x29, 0x1e}}
info := bindataFileInfo{name: "1593601729_initial_schema.up.sql", size: 1600, mode: os.FileMode(0644), modTime: time.Unix(1594978360, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd, 0x57, 0x6b, 0xc6, 0x63, 0x1c, 0x3a, 0x78, 0xa0, 0xc3, 0x12, 0x63, 0xbf, 0x34, 0x6c, 0x86, 0xd2, 0xce, 0x6c, 0xfb, 0xdd, 0xa8, 0x44, 0x5c, 0x0, 0x4e, 0x1a, 0x99, 0xa1, 0xfc, 0xf5, 0x3b}}
return a, nil
}
@ -126,7 +126,7 @@ func docGo() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "doc.go", size: 382, mode: os.FileMode(0644), modTime: time.Unix(1594393629, 0)}
info := bindataFileInfo{name: "doc.go", size: 382, mode: os.FileMode(0644), modTime: time.Unix(1594896579, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc0, 0x2f, 0x1e, 0x64, 0x9, 0x93, 0xe4, 0x8b, 0xf2, 0x98, 0x5a, 0x45, 0xe2, 0x80, 0x88, 0x67, 0x7a, 0x2d, 0xd7, 0x4b, 0xd1, 0x73, 0xb6, 0x6d, 0x15, 0xc2, 0x0, 0x34, 0xcd, 0xa0, 0xdb, 0x20}}
return a, nil
}

View File

@ -21,6 +21,7 @@ CREATE TABLE IF NOT EXISTS push_notification_client_info (
installation_id TEXT NOT NULL,
access_token TEXT NOT NULL,
retrieved_at INT NOT NULL,
version INT NOT NULL,
UNIQUE(public_key, installation_id, server_public_key) ON CONFLICT REPLACE
);

View File

@ -145,7 +145,24 @@ func (p *Persistence) SavePushNotificationInfo(infos []*PushNotificationInfo) er
_ = tx.Rollback()
}()
for _, info := range infos {
_, err := tx.Exec(`INSERT INTO push_notification_client_info (public_key, server_public_key, installation_id, access_token, retrieved_at) VALUES (?, ?, ?, ?, ?)`, crypto.CompressPubkey(info.PublicKey), crypto.CompressPubkey(info.ServerPublicKey), info.InstallationID, info.AccessToken, info.RetrievedAt)
var latestVersion uint64
clientCompressedKey := crypto.CompressPubkey(info.PublicKey)
err := tx.QueryRow(`SELECT IFNULL(MAX(version),0) FROM push_notification_client_info WHERE public_key = ? AND installation_id = ? LIMIT 1`, clientCompressedKey, info.InstallationID).Scan(&latestVersion)
if err != sql.ErrNoRows && err != nil {
return err
}
if latestVersion > info.Version {
// Nothing to do
continue
}
// Remove anything that as a lower version
_, err = tx.Exec(`DELETE FROM push_notification_client_info WHERE public_key = ? AND installation_id = ? AND version < ?`, clientCompressedKey, info.InstallationID, info.Version)
if err != nil {
return err
}
// Insert
_, err = tx.Exec(`INSERT INTO push_notification_client_info (public_key, server_public_key, installation_id, access_token, retrieved_at, version) VALUES (?, ?, ?, ?, ?,?)`, clientCompressedKey, crypto.CompressPubkey(info.ServerPublicKey), info.InstallationID, info.AccessToken, info.RetrievedAt, info.Version)
if err != nil {
return err
}
@ -163,7 +180,7 @@ func (p *Persistence) GetPushNotificationInfo(publicKey *ecdsa.PublicKey, instal
inVector := strings.Repeat("?, ", len(installationIDs)-1) + "?"
rows, err := p.db.Query(`SELECT server_public_key, installation_id, access_token, retrieved_at FROM push_notification_client_info WHERE public_key = ? AND installation_id IN (`+inVector+`)`, queryArgs...)
rows, err := p.db.Query(`SELECT server_public_key, installation_id, version, access_token, retrieved_at FROM push_notification_client_info WHERE public_key = ? AND installation_id IN (`+inVector+`)`, queryArgs...)
if err != nil {
return nil, err
}
@ -171,7 +188,7 @@ func (p *Persistence) GetPushNotificationInfo(publicKey *ecdsa.PublicKey, instal
for rows.Next() {
var serverPublicKeyBytes []byte
info := &PushNotificationInfo{PublicKey: publicKey}
err := rows.Scan(&serverPublicKeyBytes, &info.InstallationID, &info.AccessToken, &info.RetrievedAt)
err := rows.Scan(&serverPublicKeyBytes, &info.InstallationID, &info.Version, &info.AccessToken, &info.RetrievedAt)
if err != nil {
return nil, err
}

View File

@ -94,6 +94,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
PublicKey: &key1.PublicKey,
ServerPublicKey: &serverKey.PublicKey,
RetrievedAt: 1,
Version: 1,
AccessToken: accessToken,
InstallationID: installationID1,
},
@ -101,6 +102,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
PublicKey: &key1.PublicKey,
ServerPublicKey: &serverKey.PublicKey,
RetrievedAt: 1,
Version: 1,
AccessToken: accessToken,
InstallationID: installationID2,
},
@ -108,6 +110,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
PublicKey: &key1.PublicKey,
ServerPublicKey: &serverKey.PublicKey,
RetrievedAt: 1,
Version: 1,
AccessToken: accessToken,
InstallationID: installationID3,
},
@ -115,6 +118,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
PublicKey: &key2.PublicKey,
ServerPublicKey: &serverKey.PublicKey,
RetrievedAt: 1,
Version: 1,
AccessToken: accessToken,
InstallationID: installationID1,
},
@ -122,6 +126,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
PublicKey: &key2.PublicKey,
ServerPublicKey: &serverKey.PublicKey,
RetrievedAt: 1,
Version: 1,
AccessToken: accessToken,
InstallationID: installationID2,
},
@ -129,6 +134,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
PublicKey: &key2.PublicKey,
ServerPublicKey: &serverKey.PublicKey,
RetrievedAt: 1,
Version: 1,
AccessToken: accessToken,
InstallationID: installationID3,
},
@ -142,6 +148,69 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
s.Require().Len(retrievedInfos, 2)
}
func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfoWithVersion() {
installationID := "installation-id-1"
key, err := crypto.GenerateKey()
s.Require().NoError(err)
serverKey1, err := crypto.GenerateKey()
s.Require().NoError(err)
serverKey2, err := crypto.GenerateKey()
s.Require().NoError(err)
accessToken := "token"
infos := []*PushNotificationInfo{
{
PublicKey: &key.PublicKey,
ServerPublicKey: &serverKey1.PublicKey,
RetrievedAt: 1,
Version: 1,
AccessToken: accessToken,
InstallationID: installationID,
},
{
PublicKey: &key.PublicKey,
ServerPublicKey: &serverKey2.PublicKey,
RetrievedAt: 1,
Version: 1,
AccessToken: accessToken,
InstallationID: installationID,
},
}
s.Require().NoError(s.persistence.SavePushNotificationInfo(infos))
retrievedInfos, err := s.persistence.GetPushNotificationInfo(&key.PublicKey, []string{installationID})
s.Require().NoError(err)
// We should retrieve both
s.Require().Len(retrievedInfos, 2)
s.Require().Equal(uint64(1), retrievedInfos[0].Version)
// Bump version
infos[0].Version = 2
s.Require().NoError(s.persistence.SavePushNotificationInfo(infos))
retrievedInfos, err = s.persistence.GetPushNotificationInfo(&key.PublicKey, []string{installationID})
s.Require().NoError(err)
// Only one should be retrieved now
s.Require().Len(retrievedInfos, 1)
s.Require().Equal(uint64(2), retrievedInfos[0].Version)
// Lower version
infos[0].Version = 1
s.Require().NoError(s.persistence.SavePushNotificationInfo(infos))
retrievedInfos, err = s.persistence.GetPushNotificationInfo(&key.PublicKey, []string{installationID})
s.Require().NoError(err)
s.Require().Len(retrievedInfos, 1)
s.Require().Equal(uint64(2), retrievedInfos[0].Version)
}
func (s *SQLitePersistenceSuite) TestSaveAndRetrieveRegistration() {
// Try with nil first
retrievedRegistration, retrievedContactIDs, err := s.persistence.GetLastPushNotificationRegistration()

View File

@ -86,7 +86,7 @@ func _1593601728_initial_schemaDownSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1593601728_initial_schema.down.sql", size: 200, mode: os.FileMode(0644), modTime: time.Unix(1594393629, 0)}
info := bindataFileInfo{name: "1593601728_initial_schema.down.sql", size: 200, mode: os.FileMode(0644), modTime: time.Unix(1594896579, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x88, 0x8a, 0x61, 0x81, 0x57, 0x45, 0x9b, 0x97, 0x9b, 0x1f, 0xf6, 0x94, 0x8a, 0x20, 0xb3, 0x2b, 0xff, 0x69, 0x49, 0xf4, 0x58, 0xcc, 0xd0, 0x55, 0xcc, 0x9a, 0x8b, 0xb6, 0x7f, 0x29, 0x53, 0xc1}}
return a, nil
}
@ -106,7 +106,7 @@ func _1593601728_initial_schemaUpSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1593601728_initial_schema.up.sql", size: 675, mode: os.FileMode(0644), modTime: time.Unix(1594636412, 0)}
info := bindataFileInfo{name: "1593601728_initial_schema.up.sql", size: 675, mode: os.FileMode(0644), modTime: time.Unix(1594896582, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xfd, 0x61, 0x90, 0x79, 0xd9, 0x14, 0x65, 0xe9, 0x96, 0x53, 0x17, 0x33, 0x54, 0xeb, 0x8b, 0x5d, 0x95, 0x99, 0x10, 0x36, 0x58, 0xdd, 0xb2, 0xbf, 0x45, 0xd9, 0xbb, 0xc4, 0x92, 0xe, 0xce, 0x2}}
return a, nil
}
@ -126,7 +126,7 @@ func docGo() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "doc.go", size: 382, mode: os.FileMode(0644), modTime: time.Unix(1594393629, 0)}
info := bindataFileInfo{name: "doc.go", size: 382, mode: os.FileMode(0644), modTime: time.Unix(1594896579, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc0, 0x2f, 0x1e, 0x64, 0x9, 0x93, 0xe4, 0x8b, 0xf2, 0x98, 0x5a, 0x45, 0xe2, 0x80, 0x88, 0x67, 0x7a, 0x2d, 0xd7, 0x4b, 0xd1, 0x73, 0xb6, 0x6d, 0x15, 0xc2, 0x0, 0x34, 0xcd, 0xa0, 0xdb, 0x20}}
return a, nil
}

View File

@ -157,6 +157,7 @@ func (s *Server) HandlePushNotificationQuery(query *protobuf.PushNotificationQue
info := &protobuf.PushNotificationQueryInfo{
PublicKey: idAndResponse.ID,
Grant: registration.Grant,
Version: registration.Version,
InstallationId: registration.InstallationId,
}

View File

@ -26,8 +26,6 @@ func TestMessengerPushNotificationSuite(t *testing.T) {
suite.Run(t, new(MessengerPushNotificationSuite))
}
// TODO: to test. Register -> stop server -> re-start -> is it loading the topics?
type MessengerPushNotificationSuite struct {
suite.Suite
m *Messenger // main instance of Messenger
@ -290,3 +288,180 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
s.Require().NotNil(retrievedNotificationInfo)
s.Require().Len(retrievedNotificationInfo, 2)
}
func (s *MessengerPushNotificationSuite) TestReceivePushNotificationFromContactOnly() {
bob1DeviceToken := "token-1"
bob2DeviceToken := "token-2"
bob1 := s.m
bob2 := s.newMessengerWithKey(s.shh, s.m.identity)
server := s.newPushNotificationServer(s.shh)
alice := s.newMessenger(s.shh)
bobInstallationIDs := []string{bob1.installationID, bob2.installationID}
// Register bob1
err := bob1.AddPushNotificationServer(context.Background(), &server.identity.PublicKey)
s.Require().NoError(err)
err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken)
// Receive message, reply
// TODO: find a better way to handle this waiting
time.Sleep(500 * time.Millisecond)
_, err = server.RetrieveAll()
s.Require().NoError(err)
time.Sleep(500 * time.Millisecond)
_, err = server.RetrieveAll()
s.Require().NoError(err)
time.Sleep(500 * time.Millisecond)
_, err = server.RetrieveAll()
s.Require().NoError(err)
// Check reply
// TODO: find a better way to handle this waiting
time.Sleep(500 * time.Millisecond)
_, err = bob1.RetrieveAll()
s.Require().NoError(err)
time.Sleep(500 * time.Millisecond)
_, err = bob1.RetrieveAll()
s.Require().NoError(err)
time.Sleep(500 * time.Millisecond)
_, err = bob1.RetrieveAll()
s.Require().NoError(err)
// Pull servers and check we registered
err = tt.RetryWithBackOff(func() error {
registered, err := bob1.RegisteredForPushNotifications()
if err != nil {
return err
}
if !registered {
return errors.New("not registered")
}
return nil
})
// Make sure we receive it
s.Require().NoError(err)
bob1Servers, err := bob1.GetPushNotificationServers()
s.Require().NoError(err)
// Register bob2
err = bob2.AddPushNotificationServer(context.Background(), &server.identity.PublicKey)
s.Require().NoError(err)
err = bob2.RegisterForPushNotifications(context.Background(), bob2DeviceToken)
s.Require().NoError(err)
// Receive message, reply
// TODO: find a better way to handle this waiting
time.Sleep(500 * time.Millisecond)
_, err = server.RetrieveAll()
s.Require().NoError(err)
time.Sleep(500 * time.Millisecond)
_, err = server.RetrieveAll()
s.Require().NoError(err)
time.Sleep(500 * time.Millisecond)
_, err = server.RetrieveAll()
s.Require().NoError(err)
// Check reply
// TODO: find a better way to handle this waiting
time.Sleep(500 * time.Millisecond)
_, err = bob2.RetrieveAll()
s.Require().NoError(err)
time.Sleep(500 * time.Millisecond)
_, err = bob2.RetrieveAll()
s.Require().NoError(err)
time.Sleep(500 * time.Millisecond)
_, err = bob2.RetrieveAll()
s.Require().NoError(err)
err = tt.RetryWithBackOff(func() error {
registered, err := bob2.RegisteredForPushNotifications()
if err != nil {
return err
}
if !registered {
return errors.New("not registered")
}
return nil
})
// Make sure we receive it
s.Require().NoError(err)
bob2Servers, err := bob2.GetPushNotificationServers()
s.Require().NoError(err)
err = alice.pushNotificationClient.QueryPushNotificationInfo(&bob2.identity.PublicKey)
s.Require().NoError(err)
// Receive push notification query
// TODO: find a better way to handle this waiting
time.Sleep(500 * time.Millisecond)
_, err = server.RetrieveAll()
s.Require().NoError(err)
time.Sleep(500 * time.Millisecond)
_, err = server.RetrieveAll()
s.Require().NoError(err)
time.Sleep(500 * time.Millisecond)
_, err = server.RetrieveAll()
s.Require().NoError(err)
// Receive push notification query response
// TODO: find a better way to handle this waiting
time.Sleep(500 * time.Millisecond)
_, err = alice.RetrieveAll()
s.Require().NoError(err)
time.Sleep(500 * time.Millisecond)
_, err = alice.RetrieveAll()
s.Require().NoError(err)
time.Sleep(500 * time.Millisecond)
_, err = alice.RetrieveAll()
s.Require().NoError(err)
// Here we should poll, as we don't know whether they are already there
info, err := alice.pushNotificationClient.GetPushNotificationInfo(&bob1.identity.PublicKey, bobInstallationIDs)
s.Require().NoError(err)
// Check we have replies for both bob1 and bob2
s.Require().NotNil(info)
s.Require().Len(info, 2)
var bob1Info, bob2Info *push_notification_client.PushNotificationInfo
if info[0].AccessToken == bob1Servers[0].AccessToken {
bob1Info = info[0]
bob2Info = info[1]
} else {
bob2Info = info[0]
bob1Info = info[1]
}
s.Require().NotNil(bob1Info)
s.Require().Equal(bob1.installationID, bob1Info.InstallationID)
s.Require().Equal(bob1Info.AccessToken, bob1Servers[0].AccessToken, bob1Info.AccessToken)
s.Require().Equal(&bob1.identity.PublicKey, bob1Info.PublicKey)
s.Require().NotNil(bob2Info)
s.Require().Equal(bob2.installationID, bob2Info.InstallationID)
s.Require().Equal(bob2Servers[0].AccessToken, bob2Info.AccessToken)
s.Require().Equal(&bob2.identity.PublicKey, bob2Info.PublicKey)
retrievedNotificationInfo, err := alice.pushNotificationClient.GetPushNotificationInfo(&bob1.identity.PublicKey, bobInstallationIDs)
alice.logger.Info("BOB KEY", zap.Any("key", bob1.identity.PublicKey))
s.Require().NoError(err)
s.Require().NotNil(retrievedNotificationInfo)
s.Require().Len(retrievedNotificationInfo, 2)
}

View File

@ -406,12 +406,20 @@ func (api *PublicAPI) UpdateMailservers(enodes []string) error {
// PushNotifications server
func (api *PublicAPI) StartPushNotificationServer() error {
// update settings
err := api.service.accountsDB.SaveSetting("push-notifications-server-enabled", true)
if err != nil {
return err
}
return api.service.messenger.StartPushNotificationServer()
}
func (api *PublicAPI) StopPushNotificationServer() error {
// update settings
err := api.service.accountsDB.SaveSetting("push-notifications-server-enabled", false)
if err != nil {
return err
}
return api.service.messenger.StopPushNotificationServer()
}
@ -422,6 +430,11 @@ func (api *PublicAPI) RegisterForPushNotifications(ctx context.Context, deviceTo
if err != nil {
return err
}
err = api.service.accountsDB.SaveSetting("notifications-enabled?", true)
if err != nil {
return err
}
return api.service.messenger.RegisterForPushNotifications(ctx, deviceToken)
}
@ -430,6 +443,11 @@ func (api *PublicAPI) UnregisterForPushNotifications(ctx context.Context) error
if err != nil {
return err
}
err = api.service.accountsDB.SaveSetting("notifications-enabled?", false)
if err != nil {
return err
}
return api.service.messenger.UnregisterFromPushNotifications(ctx)
}
@ -450,6 +468,22 @@ func (api *PublicAPI) EnableSendingNotifications(ctx context.Context) error {
return api.service.messenger.EnableSendingPushNotifications()
}
func (api *PublicAPI) EnablePushNotificationsFromContactsOnly(ctx context.Context) error {
err := api.service.accountsDB.SaveSetting("push-notifications-from-contacts-only", true)
if err != nil {
return err
}
return api.service.messenger.EnablePushNotificationsFromContactsOnly()
}
func (api *PublicAPI) DisablePushNotificationsFromContactsOnly(ctx context.Context) error {
err := api.service.accountsDB.SaveSetting("push-notifications-from-contacts-only", false)
if err != nil {
return err
}
return api.service.messenger.DisablePushNotificationsFromContactsOnly()
}
func (api *PublicAPI) AddPushNotificationServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
publicKey, err := crypto.UnmarshalPubkey(publicKeyBytes)
if err != nil {
@ -459,6 +493,15 @@ func (api *PublicAPI) AddPushNotificationServer(ctx context.Context, publicKeyBy
return api.service.messenger.AddPushNotificationServer(ctx, publicKey)
}
func (api *PublicAPI) RemovePushNotificationServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
publicKey, err := crypto.UnmarshalPubkey(publicKeyBytes)
if err != nil {
return err
}
return api.service.messenger.RemovePushNotificationServer(ctx, publicKey)
}
func (api *PublicAPI) GetPushNotificationServers() ([]*push_notification_client.PushNotificationServer, error) {
return api.service.messenger.GetPushNotificationServers()
}

View File

@ -469,7 +469,7 @@ func buildMessengerOptions(
return nil, err
}
if settings.PushNotificationServerEnabled {
if settings.PushNotificationsServerEnabled {
config := &push_notification_server.Config{
Logger: logger,
}