Version: v0.0.0-...-6789dc4 Latest Latest

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

Go to latest
Published: Jul 30, 2021 License: GPL-3.0, GPL-3.0 Imports: 9 Imported by: 6



Package store takes care of storing pending notifications.



View Source
const SystemInternalChannelId = InternalChannelId("0")


View Source
var ErrExpected128BitsHexRepr = errors.New("expected 128 bits hex repr")
View Source
var ErrFull = errors.New("channel is full")
View Source
var ErrUnauthorized = errors.New("unauthorized")
View Source
var ErrUnknownChannel = errors.New("unknown channel name")
View Source
var ErrUnknownToken = errors.New("unknown token")


func FilterOutByMsgId

func FilterOutByMsgId(orig, targets []protocol.Notification) []protocol.Notification

FilterOutByMsgId returns the notifications from orig whose msg id is not mentioned in targets.

func FilterOutObsolete

func FilterOutObsolete(notifications []protocol.Notification, meta []Metadata) []protocol.Notification

FilterOutObsolete filters out expired notifications and superseded notifications sharing a replace tag based on paired meta information.

func InternalChannelIdToHex

func InternalChannelIdToHex(chanId InternalChannelId) string


type InMemoryPendingStore

type InMemoryPendingStore struct {
	// contains filtered or unexported fields

InMemoryPendingStore is a basic in-memory pending notification store.

func NewInMemoryPendingStore

func NewInMemoryPendingStore() *InMemoryPendingStore

NewInMemoryPendingStore returns a new InMemoryStore.

func (*InMemoryPendingStore) AppendToChannel

func (sto *InMemoryPendingStore) AppendToChannel(chanId InternalChannelId, notificationPayload json.RawMessage, expiration time.Time) error

func (*InMemoryPendingStore) AppendToUnicastChannel

func (sto *InMemoryPendingStore) AppendToUnicastChannel(chanId InternalChannelId, appId string, notificationPayload json.RawMessage, msgId string, meta Metadata) error

func (*InMemoryPendingStore) Close

func (sto *InMemoryPendingStore) Close()

func (*InMemoryPendingStore) DropByMsgId

func (sto *InMemoryPendingStore) DropByMsgId(chanId InternalChannelId, targets []protocol.Notification) error

func (*InMemoryPendingStore) GetChannelSnapshot

func (sto *InMemoryPendingStore) GetChannelSnapshot(chanId InternalChannelId) (int64, []protocol.Notification, error)

func (*InMemoryPendingStore) GetChannelUnfiltered

func (sto *InMemoryPendingStore) GetChannelUnfiltered(chanId InternalChannelId) (int64, []protocol.Notification, []Metadata, error)

func (*InMemoryPendingStore) GetInternalChannelId

func (sto *InMemoryPendingStore) GetInternalChannelId(name string) (InternalChannelId, error)

func (*InMemoryPendingStore) GetInternalChannelIdFromToken

func (sto *InMemoryPendingStore) GetInternalChannelIdFromToken(token, appId, userId, deviceId string) (InternalChannelId, error)

func (*InMemoryPendingStore) Register

func (sto *InMemoryPendingStore) Register(deviceId, appId string) (string, error)

func (*InMemoryPendingStore) Scrub

func (sto *InMemoryPendingStore) Scrub(chanId InternalChannelId, criteria ...string) error

func (*InMemoryPendingStore) Unregister

func (sto *InMemoryPendingStore) Unregister(deviceId, appId string) error

type InternalChannelId

type InternalChannelId string

func HexToInternalChannelId

func HexToInternalChannelId(hexRepr string) (InternalChannelId, error)

func UnicastInternalChannelId

func UnicastInternalChannelId(userId, deviceId string) InternalChannelId

UnicastInternalChannelId builds a channel id for the userId, deviceId pair.

func (InternalChannelId) BroadcastChannel

func (icid InternalChannelId) BroadcastChannel() bool

BroadcastChannel returns whether the id represents a broadcast channel.

func (InternalChannelId) UnicastChannel

func (icid InternalChannelId) UnicastChannel() bool

UnicastChannel returns whether the id represents a unicast channel.

func (InternalChannelId) UnicastUserAndDevice

func (icid InternalChannelId) UnicastUserAndDevice() (userId, deviceId string)

UnicastUserAndDevice returns the user and device ids of a unicast channel.

type Metadata

type Metadata struct {
	Expiration time.Time
	ReplaceTag string
	Obsolete   bool

Metadata holds the metadata stored for a notification.

func (*Metadata) Before

func (m *Metadata) Before(ref time.Time) bool

Before checks whether the expiration date in the metadata is before ref.

type PendingStore

type PendingStore interface {
	// Register returns a token for a device id, application id pair.
	Register(deviceId, appId string) (token string, err error)
	// Unregister forgets the token for a device id, application id pair.
	Unregister(deviceId, appId string) error
	// GetInternalChannelId returns the internal store id for a channel
	// given the name.
	GetInternalChannelId(name string) (InternalChannelId, error)
	// AppendToChannel appends a notification to the channel.
	AppendToChannel(chanId InternalChannelId, notification json.RawMessage, expiration time.Time) error
	// GetInternalChannelIdFromToken returns the matching internal store
	// id for a channel given a registered token and application id or
	// directly a device id, user id pair.
	GetInternalChannelIdFromToken(token, appId, userId, deviceId string) (InternalChannelId, error)
	// AppendToUnicastChannel appends a notification to the unicast channel.
	AppendToUnicastChannel(chanId InternalChannelId, appId string, notification json.RawMessage, msgId string, meta Metadata) error
	// GetChannelSnapshot gets all the current notifications and
	// current top level in the channel.
	GetChannelSnapshot(chanId InternalChannelId) (topLevel int64, notifications []protocol.Notification, err error)
	// GetChannelUnfiltered gets all the stored notifications with
	// metadata and current top level in the channel.
	GetChannelUnfiltered(chanId InternalChannelId) (topLevel int64, notifications []protocol.Notification, metadata []Metadata, err error)
	// Scrub removes notifications from the channel based on criteria.
	// Usages:
	// Scrub(chanId) removes all expired notifications.
	// Scrub(chanId, appId) removes all expired notifications and
	// all notifications for appId.
	// Scrub(chanId, appId, replaceTag) removes all expired notifications
	// and all notifications matching both appId and replaceTag.
	Scrub(chanId InternalChannelId, criteria ...string) error
	// DropByMsgId drops notifications from a unicast channel
	// based on message ids.
	DropByMsgId(chanId InternalChannelId, targets []protocol.Notification) error
	// Close is to be called when done with the store.

PendingStore let store notifications into channels.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL