pushnotificationserver

package
v0.126.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: MPL-2.0, MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCouldNotUnmarshalPushNotificationRegistration = errors.New("could not unmarshal preferences")
View Source
var ErrEmptyPushNotificationRegistrationPayload = errors.New("empty payload")
View Source
var ErrEmptyPushNotificationRegistrationPublicKey = errors.New("no public key")
View Source
var ErrInvalidPushNotificationRegistrationVersion = errors.New("invalid version")
View Source
var ErrMalformedPushNotificationRegistrationAccessToken = errors.New("invalid access token")
View Source
var ErrMalformedPushNotificationRegistrationDeviceToken = errors.New("invalid device token")
View Source
var ErrMalformedPushNotificationRegistrationGrant = errors.New("invalid grant")
View Source
var ErrMalformedPushNotificationRegistrationInstallationID = errors.New("invalid installationID")
View Source
var ErrUnknownPushNotificationRegistrationTokenType = errors.New("invalid token type")

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled bool
	// Identity is our identity key
	Identity *ecdsa.PrivateKey
	// GorushUrl is the url for the gorush service
	GorushURL string

	Logger *zap.Logger
}

type GoRushRequest

type GoRushRequest struct {
	Notifications []*GoRushRequestNotification `json:"notifications"`
}

func PushNotificationRegistrationToGoRushRequest

func PushNotificationRegistrationToGoRushRequest(requestAndRegistrations []*RequestAndRegistration) *GoRushRequest

type GoRushRequestData

type GoRushRequestData struct {
	EncryptedMessage string `json:"encryptedMessage"`
	ChatID           string `json:"chatId"`
	PublicKey        string `json:"publicKey"`
}

type GoRushRequestNotification

type GoRushRequestNotification struct {
	Tokens   []string           `json:"tokens"`
	Platform uint               `json:"platform"`
	Message  string             `json:"message"`
	Topic    string             `json:"topic"`
	Data     *GoRushRequestData `json:"data"`
}

type Persistence

type Persistence interface {
	// GetPushNotificationRegistrationByPublicKeyAndInstallationID retrieve a push notification registration from storage given a public key and installation id
	GetPushNotificationRegistrationByPublicKeyAndInstallationID(publicKey []byte, installationID string) (*protobuf.PushNotificationRegistration, error)
	// GetPushNotificationRegistrationByPublicKey retrieve all the push notification registrations from storage given a public key
	GetPushNotificationRegistrationByPublicKeys(publicKeys [][]byte) ([]*PushNotificationIDAndRegistration, error)
	// GetPushNotificationRegistrationPublicKeys return all the public keys stored
	GetPushNotificationRegistrationPublicKeys() ([][]byte, error)

	//GetPushNotificationRegistrationVersion returns the latest version or 0 for a given pk and installationID
	GetPushNotificationRegistrationVersion(publicKey []byte, installationID string) (uint64, error)
	// UnregisterPushNotificationRegistration unregister a given pk/installationID
	UnregisterPushNotificationRegistration(publicKey []byte, installationID string, version uint64) error

	// DeletePushNotificationRegistration deletes a push notification registration from storage given a public key and installation id
	DeletePushNotificationRegistration(publicKey []byte, installationID string) error
	// SavePushNotificationRegistration saves a push notification option to the db
	SavePushNotificationRegistration(publicKey []byte, registration *protobuf.PushNotificationRegistration) error
	// GetIdentity returns the server identity key
	GetIdentity() (*ecdsa.PrivateKey, error)
	// SaveIdentity saves the server identity key
	SaveIdentity(*ecdsa.PrivateKey) error
	// PushNotificationExists checks whether a push notification exists and inserts it otherwise
	PushNotificationExists([]byte) (bool, error)
}

func NewSQLitePersistence

func NewSQLitePersistence(db *sql.DB) Persistence

type PushNotificationIDAndRegistration

type PushNotificationIDAndRegistration struct {
	ID           []byte
	Registration *protobuf.PushNotificationRegistration
}

type RequestAndRegistration

type RequestAndRegistration struct {
	Request      *protobuf.PushNotification
	Registration *protobuf.PushNotificationRegistration
}

type SQLitePersistence

type SQLitePersistence struct {
	// contains filtered or unexported fields
}

func (*SQLitePersistence) DeletePushNotificationRegistration

func (p *SQLitePersistence) DeletePushNotificationRegistration(publicKey []byte, installationID string) error

func (*SQLitePersistence) GetIdentity

func (p *SQLitePersistence) GetIdentity() (*ecdsa.PrivateKey, error)

func (*SQLitePersistence) GetPushNotificationRegistrationByPublicKeyAndInstallationID

func (p *SQLitePersistence) GetPushNotificationRegistrationByPublicKeyAndInstallationID(publicKey []byte, installationID string) (*protobuf.PushNotificationRegistration, error)

func (*SQLitePersistence) GetPushNotificationRegistrationByPublicKeys

func (p *SQLitePersistence) GetPushNotificationRegistrationByPublicKeys(publicKeys [][]byte) ([]*PushNotificationIDAndRegistration, error)

func (*SQLitePersistence) GetPushNotificationRegistrationPublicKeys

func (p *SQLitePersistence) GetPushNotificationRegistrationPublicKeys() ([][]byte, error)

func (*SQLitePersistence) GetPushNotificationRegistrationVersion added in v0.59.0

func (p *SQLitePersistence) GetPushNotificationRegistrationVersion(publicKey []byte, installationID string) (uint64, error)

func (*SQLitePersistence) PushNotificationExists added in v0.59.0

func (p *SQLitePersistence) PushNotificationExists(messageID []byte) (bool, error)

func (*SQLitePersistence) SaveIdentity

func (p *SQLitePersistence) SaveIdentity(privateKey *ecdsa.PrivateKey) error

func (*SQLitePersistence) SavePushNotificationRegistration

func (p *SQLitePersistence) SavePushNotificationRegistration(publicKey []byte, registration *protobuf.PushNotificationRegistration) error

func (*SQLitePersistence) UnregisterPushNotificationRegistration added in v0.59.0

func (p *SQLitePersistence) UnregisterPushNotificationRegistration(publicKey []byte, installationID string, version uint64) error

type Server

type Server struct {

	// SentRequests keeps track of the requests sent to gorush, for testing only
	SentRequests int64
	// contains filtered or unexported fields
}

func New

func New(config *Config, persistence Persistence, messageSender *common.MessageSender) *Server

func (*Server) HandlePushNotificationQuery

func (s *Server) HandlePushNotificationQuery(publicKey *ecdsa.PublicKey, messageID []byte, query protobuf.PushNotificationQuery) error

HandlePushNotificationQuery builds a response for the query and sends it back to the user

func (*Server) HandlePushNotificationRegistration

func (s *Server) HandlePushNotificationRegistration(publicKey *ecdsa.PublicKey, payload []byte) error

HandlePushNotificationRegistration builds a response for the registration and sends it back to the user

func (*Server) HandlePushNotificationRequest

func (s *Server) HandlePushNotificationRequest(publicKey *ecdsa.PublicKey,
	messageID []byte,
	request protobuf.PushNotificationRequest) error

HandlePushNotificationRequest will send a gorush notification and send a response back to the user

func (*Server) Start

func (s *Server) Start() error

Directories

Path Synopsis
sql

Jump to

Keyboard shortcuts

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