pushnotificationclient

package
v0.64.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2020 License: MPL-2.0, MPL-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerTypeDefault = iota + 1
	ServerTypeCustom
)
View Source
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) Enabled added in v0.59.0

func (c *Client) Enabled() bool

func (*Client) GetPushNotificationInfo

func (c *Client) GetPushNotificationInfo(publicKey *ecdsa.PublicKey, installationIDs []string) ([]*PushNotificationInfo, error)

func (*Client) GetSentNotification

func (c *Client) GetSentNotification(hashedPublicKey []byte, installationID string, messageID []byte) (*SentNotification, error)

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) Offline added in v0.59.0

func (c *Client) Offline()

func (*Client) Online added in v0.59.0

func (c *Client) Online()

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

func (c *Client) Registered() (bool, error)

Registered returns true if we registered with all the servers

func (*Client) RemovePushNotificationServer

func (c *Client) RemovePushNotificationServer(publicKey *ecdsa.PublicKey) error

func (*Client) Reregister

func (c *Client) Reregister(options *RegistrationOptions) error

func (*Client) Start

func (c *Client) Start() error

func (*Client) Stop

func (c *Client) Stop() error

func (*Client) SubscribeToRegistrations added in v0.59.0

func (c *Client) SubscribeToRegistrations() chan struct{}

func (*Client) Unregister

func (c *Client) Unregister() error

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 MessagePersistence interface {
	MessageByID(string) (*common.Message, error)
}

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 (p *Persistence) ShouldSendNotificationFor(publicKey *ecdsa.PublicKey, installationID string, messageID []byte) (bool, error)

func (*Persistence) ShouldSendNotificationToAllInstallationIDs

func (p *Persistence) ShouldSendNotificationToAllInstallationIDs(publicKey *ecdsa.PublicKey, messageID []byte) (bool, error)

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 PushNotificationInfo struct {
	AccessToken     string
	InstallationID  string
	PublicKey       *ecdsa.PublicKey
	ServerPublicKey *ecdsa.PublicKey
	RetrievedAt     int64
	Version         uint64
}

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 RegistrationOptions struct {
	PublicChatIDs []string
	MutedChatIDs  []string
	ContactIDs    []*ecdsa.PublicKey
}

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

Directories

Path Synopsis
sql

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL