Documentation ¶
Index ¶
- Constants
- type Client
- func (c *Client) AddPushNotificationsServer(publicKey *ecdsa.PublicKey, serverType ServerType) error
- func (c *Client) DisablePushNotificationsBlockMentions(options *RegistrationOptions) error
- func (c *Client) DisablePushNotificationsFromContactsOnly(options *RegistrationOptions) error
- func (c *Client) DisableSending()
- func (c *Client) EnablePushNotificationsBlockMentions(options *RegistrationOptions) error
- func (c *Client) EnablePushNotificationsFromContactsOnly(options *RegistrationOptions) error
- func (c *Client) EnableSending()
- func (c *Client) Enabled() bool
- func (c *Client) GetPushNotificationInfo(publicKey *ecdsa.PublicKey, installationIDs []string) ([]*PushNotificationInfo, error)
- func (c *Client) GetSentNotification(hashedPublicKey []byte, installationID string, messageID []byte) (*SentNotification, error)
- func (c *Client) GetServers() ([]*PushNotificationServer, error)
- func (c *Client) HandleContactCodeAdvertisement(clientPublicKey *ecdsa.PublicKey, message protobuf.ContactCodeAdvertisement) error
- func (c *Client) HandlePushNotificationQueryResponse(serverPublicKey *ecdsa.PublicKey, ...) error
- func (c *Client) HandlePushNotificationRegistrationResponse(publicKey *ecdsa.PublicKey, ...) error
- func (c *Client) HandlePushNotificationResponse(serverKey *ecdsa.PublicKey, response protobuf.PushNotificationResponse) error
- func (c *Client) MyPushNotificationQueryInfo() ([]*protobuf.PushNotificationQueryInfo, error)
- func (c *Client) Offline()
- func (c *Client) Online()
- func (c *Client) Register(deviceToken, apnTopic string, ...) error
- func (c *Client) Registered() (bool, error)
- func (c *Client) RemovePushNotificationServer(publicKey *ecdsa.PublicKey) error
- func (c *Client) Reregister(options *RegistrationOptions) error
- func (c *Client) SendNotification(publicKey *ecdsa.PublicKey, installationIDs []string, messageID []byte, ...) ([]*PushNotificationInfo, error)
- func (c *Client) Start() error
- func (c *Client) Stop() error
- func (c *Client) SubscribeToRegistrations() chan struct{}
- func (c *Client) Unregister() error
- type Config
- type MessagePersistence
- type Persistence
- func (p *Persistence) GetLastPushNotificationRegistration() (*protobuf.PushNotificationRegistration, []*ecdsa.PublicKey, error)
- func (p *Persistence) GetPushNotificationInfo(publicKey *ecdsa.PublicKey, installationIDs []string) ([]*PushNotificationInfo, error)
- func (p *Persistence) GetPushNotificationInfoByPublicKey(publicKey *ecdsa.PublicKey) ([]*PushNotificationInfo, error)
- func (p *Persistence) GetQueriedAt(publicKey *ecdsa.PublicKey) (int64, error)
- func (p *Persistence) GetQueryPublicKey(queryID []byte) (*ecdsa.PublicKey, error)
- func (p *Persistence) GetRetriablePushNotifications() ([]*SentNotification, error)
- func (p *Persistence) GetSentNotification(hashedPublicKey []byte, installationID string, messageID []byte) (*SentNotification, error)
- func (p *Persistence) GetServers() ([]*PushNotificationServer, error)
- func (p *Persistence) GetServersByPublicKey(keys []*ecdsa.PublicKey) ([]*PushNotificationServer, error)
- func (p *Persistence) SaveLastPushNotificationRegistration(registration *protobuf.PushNotificationRegistration, ...) error
- func (p *Persistence) SavePushNotificationInfo(infos []*PushNotificationInfo) error
- func (p *Persistence) SavePushNotificationQuery(publicKey *ecdsa.PublicKey, queryID []byte) error
- func (p *Persistence) ShouldSendNotificationFor(publicKey *ecdsa.PublicKey, installationID string, messageID []byte) (bool, error)
- func (p *Persistence) ShouldSendNotificationToAllInstallationIDs(publicKey *ecdsa.PublicKey, messageID []byte) (bool, error)
- func (p *Persistence) TrackPushNotification(chatID string, messageID []byte) error
- func (p *Persistence) TrackedMessage(messageID []byte) (bool, error)
- func (p *Persistence) UpdateNotificationResponse(messageID []byte, response *protobuf.PushNotificationReport) error
- func (p *Persistence) UpsertSentNotification(n *SentNotification) error
- func (p *Persistence) UpsertServer(server *PushNotificationServer) error
- type PushNotificationInfo
- type PushNotificationServer
- type RegistrationOptions
- type SentNotification
- type ServerType
Constants ¶
const ( ServerTypeDefault = iota + 1 ServerTypeCustom )
const RegistrationBackoffTime int64 = 15
RegistrationBackoffTime is the step of the exponential backoff
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // AccessToken is the access token that is currently being used AccessToken string // contains filtered or unexported fields }
func New ¶
func New(persistence *Persistence, config *Config, processor *common.MessageProcessor, messagePersistence MessagePersistence) *Client
func (*Client) AddPushNotificationsServer ¶
func (c *Client) AddPushNotificationsServer(publicKey *ecdsa.PublicKey, serverType ServerType) error
func (*Client) DisablePushNotificationsBlockMentions ¶ added in v0.61.0
func (c *Client) DisablePushNotificationsBlockMentions(options *RegistrationOptions) error
func (*Client) DisablePushNotificationsFromContactsOnly ¶
func (c *Client) DisablePushNotificationsFromContactsOnly(options *RegistrationOptions) error
func (*Client) DisableSending ¶
func (c *Client) DisableSending()
func (*Client) EnablePushNotificationsBlockMentions ¶ added in v0.61.0
func (c *Client) EnablePushNotificationsBlockMentions(options *RegistrationOptions) error
func (*Client) EnablePushNotificationsFromContactsOnly ¶
func (c *Client) EnablePushNotificationsFromContactsOnly(options *RegistrationOptions) error
func (*Client) EnableSending ¶
func (c *Client) EnableSending()
func (*Client) GetPushNotificationInfo ¶
func (*Client) GetSentNotification ¶
func (*Client) GetServers ¶
func (c *Client) GetServers() ([]*PushNotificationServer, error)
func (*Client) HandleContactCodeAdvertisement ¶ added in v0.59.0
func (c *Client) HandleContactCodeAdvertisement(clientPublicKey *ecdsa.PublicKey, message protobuf.ContactCodeAdvertisement) error
HandleContactCodeAdvertisement checks if there are any info and process them
func (*Client) HandlePushNotificationQueryResponse ¶
func (c *Client) HandlePushNotificationQueryResponse(serverPublicKey *ecdsa.PublicKey, response protobuf.PushNotificationQueryResponse) error
HandlePushNotificationQueryResponse should update the data in the database for a given user
func (*Client) HandlePushNotificationRegistrationResponse ¶
func (c *Client) HandlePushNotificationRegistrationResponse(publicKey *ecdsa.PublicKey, response protobuf.PushNotificationRegistrationResponse) error
HandlePushNotificationRegistrationResponse should check whether the response was successful or not, retry if necessary otherwise store the result in the database
func (*Client) HandlePushNotificationResponse ¶
func (c *Client) HandlePushNotificationResponse(serverKey *ecdsa.PublicKey, response protobuf.PushNotificationResponse) error
HandlePushNotificationResponse should set the request as processed
func (*Client) MyPushNotificationQueryInfo ¶ added in v0.59.0
func (c *Client) MyPushNotificationQueryInfo() ([]*protobuf.PushNotificationQueryInfo, error)
func (*Client) Register ¶
func (c *Client) Register(deviceToken, apnTopic string, tokenType protobuf.PushNotificationRegistration_TokenType, options *RegistrationOptions) error
Register registers with all the servers
func (*Client) Registered ¶
Registered returns true if we registered with all the servers
func (*Client) RemovePushNotificationServer ¶
func (*Client) Reregister ¶
func (c *Client) Reregister(options *RegistrationOptions) error
func (*Client) SendNotification ¶ added in v0.74.2
func (c *Client) SendNotification(publicKey *ecdsa.PublicKey, installationIDs []string, messageID []byte, chatID string, notificationType protobuf.PushNotification_PushNotificationType) ([]*PushNotificationInfo, error)
SendNotification sends an actual notification to the push notification server. the notification is sent using an ephemeral key to shield the real identity of the sender
func (*Client) SubscribeToRegistrations ¶ added in v0.59.0
func (c *Client) SubscribeToRegistrations() chan struct{}
func (*Client) Unregister ¶
Unregister unregisters from all the servers
type Config ¶
type Config struct { // Identity is our identity key Identity *ecdsa.PrivateKey // SendEnabled indicates whether we should be sending push notifications SendEnabled bool // RemoteNotificationsEnabled is whether we should register with a remote server for push notifications RemoteNotificationsEnabled bool // AllowyFromContactsOnly indicates whether we should be receiving push notifications // only from contacts AllowFromContactsOnly bool // BlockMentions indicates whether we should not receive notification for mentions BlockMentions bool // InstallationID is the installation-id for this device InstallationID string Logger *zap.Logger // DefaultServers holds the push notification servers used by // default if none is selected DefaultServers []*ecdsa.PublicKey }
type MessagePersistence ¶ added in v0.61.0
type Persistence ¶
type Persistence struct {
// contains filtered or unexported fields
}
func NewPersistence ¶
func NewPersistence(db *sql.DB) *Persistence
func (*Persistence) GetLastPushNotificationRegistration ¶
func (p *Persistence) GetLastPushNotificationRegistration() (*protobuf.PushNotificationRegistration, []*ecdsa.PublicKey, error)
func (*Persistence) GetPushNotificationInfo ¶
func (p *Persistence) GetPushNotificationInfo(publicKey *ecdsa.PublicKey, installationIDs []string) ([]*PushNotificationInfo, error)
func (*Persistence) GetPushNotificationInfoByPublicKey ¶
func (p *Persistence) GetPushNotificationInfoByPublicKey(publicKey *ecdsa.PublicKey) ([]*PushNotificationInfo, error)
func (*Persistence) GetQueriedAt ¶
func (p *Persistence) GetQueriedAt(publicKey *ecdsa.PublicKey) (int64, error)
func (*Persistence) GetQueryPublicKey ¶
func (p *Persistence) GetQueryPublicKey(queryID []byte) (*ecdsa.PublicKey, error)
func (*Persistence) GetRetriablePushNotifications ¶
func (p *Persistence) GetRetriablePushNotifications() ([]*SentNotification, error)
func (*Persistence) GetSentNotification ¶
func (p *Persistence) GetSentNotification(hashedPublicKey []byte, installationID string, messageID []byte) (*SentNotification, error)
func (*Persistence) GetServers ¶
func (p *Persistence) GetServers() ([]*PushNotificationServer, error)
func (*Persistence) GetServersByPublicKey ¶
func (p *Persistence) GetServersByPublicKey(keys []*ecdsa.PublicKey) ([]*PushNotificationServer, error)
func (*Persistence) SaveLastPushNotificationRegistration ¶
func (p *Persistence) SaveLastPushNotificationRegistration(registration *protobuf.PushNotificationRegistration, contactIDs []*ecdsa.PublicKey) error
func (*Persistence) SavePushNotificationInfo ¶
func (p *Persistence) SavePushNotificationInfo(infos []*PushNotificationInfo) error
func (*Persistence) SavePushNotificationQuery ¶
func (p *Persistence) SavePushNotificationQuery(publicKey *ecdsa.PublicKey, queryID []byte) error
func (*Persistence) ShouldSendNotificationFor ¶
func (*Persistence) ShouldSendNotificationToAllInstallationIDs ¶
func (*Persistence) TrackPushNotification ¶
func (p *Persistence) TrackPushNotification(chatID string, messageID []byte) error
func (*Persistence) TrackedMessage ¶
func (p *Persistence) TrackedMessage(messageID []byte) (bool, error)
func (*Persistence) UpdateNotificationResponse ¶
func (p *Persistence) UpdateNotificationResponse(messageID []byte, response *protobuf.PushNotificationReport) error
func (*Persistence) UpsertSentNotification ¶
func (p *Persistence) UpsertSentNotification(n *SentNotification) error
func (*Persistence) UpsertServer ¶
func (p *Persistence) UpsertServer(server *PushNotificationServer) error
type PushNotificationInfo ¶
type PushNotificationServer ¶
type PushNotificationServer struct { PublicKey *ecdsa.PublicKey `json:"-"` Registered bool `json:"registered,omitempty"` RegisteredAt int64 `json:"registeredAt,omitempty"` LastRetriedAt int64 `json:"lastRetriedAt,omitempty"` RetryCount int64 `json:"retryCount,omitempty"` AccessToken string `json:"accessToken,omitempty"` Type ServerType `json:"type,omitempty"` }
func (*PushNotificationServer) MarshalJSON ¶
func (s *PushNotificationServer) MarshalJSON() ([]byte, error)
type RegistrationOptions ¶ added in v0.61.0
type SentNotification ¶
type SentNotification struct { PublicKey *ecdsa.PublicKey InstallationID string LastTriedAt int64 RetryCount int64 MessageID []byte ChatID string NotificationType protobuf.PushNotification_PushNotificationType Success bool Error protobuf.PushNotificationReport_ErrorType }
func (*SentNotification) HashedPublicKey ¶
func (s *SentNotification) HashedPublicKey() []byte
type ServerType ¶ added in v0.59.0
type ServerType int