push

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCurrencyStateNotFound = errors.New("currency state not found")

ErrCurrencyStateNotFound is returned when no push state exists for a mint.

Functions

func SendContactDmPush added in v1.14.0

func SendContactDmPush(ctx context.Context, pusher Pusher, badges badge.Store, ocpData ocp_data.Provider, chatId *commonpb.ChatId, message *messagingpb.Message, senderContact *phonepb.PhoneNumber, recipients ...*commonpb.UserId) error

func SendContactJoinedFlipcashPush added in v1.11.0

func SendContactJoinedFlipcashPush(ctx context.Context, pusher Pusher, joinedPhone *phonepb.PhoneNumber, users ...*commonpb.UserId) error

func SendFlipcashCurrencyBoughtPush added in v0.4.0

func SendFlipcashCurrencyBoughtPush(ctx context.Context, pusher Pusher, user *commonpb.UserId, mint *commonpb.PublicKey, currencyName string, region ocp_currency.Code, nativeAmount float64) error

func SendFlipcashCurrencyDepositedPush added in v0.4.0

func SendFlipcashCurrencyDepositedPush(ctx context.Context, pusher Pusher, user *commonpb.UserId, mint *commonpb.PublicKey, currencyName string, usdMarketValue float64) error

func SendFlipcashCurrencyGainPush added in v1.1.0

func SendFlipcashCurrencyGainPush(ctx context.Context, pusher Pusher, user *commonpb.UserId, mint *commonpb.PublicKey, currencyName string, gainRegion ocp_currency.Code, gainAmount float64) error

func SendFlipcashCurrencySoldPush added in v0.4.0

func SendFlipcashCurrencySoldPush(ctx context.Context, pusher Pusher, user *commonpb.UserId, mint *commonpb.PublicKey, currencyName string, region ocp_currency.Code, nativeAmount float64) error

func SendUsdfDepositProcessingPush added in v1.9.0

func SendUsdfDepositProcessingPush(ctx context.Context, pusher Pusher, user *commonpb.UserId) error

func SendUsdfDepositedPush added in v0.4.0

func SendUsdfDepositedPush(ctx context.Context, pusher Pusher, user *commonpb.UserId) error

Types

type CurrencyState added in v1.19.0

type CurrencyState struct {
	Mint              *commonpb.PublicKey
	AllTimeHighSupply uint64
	AllTimeHighSlot   uint64
	LastGainPushAt    *time.Time // nil if a gain push has never been granted for the mint
}

CurrencyState captures per-currency state used to gate push notifications.

AllTimeHighSupply tracks the circulating supply (in quarks) observed at the last granted gain push, NOT a true high-water mark: it only advances when a gain push is actually granted (see CurrencyStateStore.ClaimGainPush).

type CurrencyStateStore added in v1.19.0

type CurrencyStateStore interface {
	// ClaimGainPush atomically gates a "currency gain" push wave for a mint.
	//
	// granted is true only when both conditions hold against the currently stored
	// state: (1) supply is strictly greater than the stored all-time high, and
	// (2) at least cooldown has elapsed since the last granted gain push (or none
	// has ever been granted). When granted, the stored all-time high (supply,
	// slot) and last-gain-push timestamp are advanced to the provided values / now.
	// When not granted, the stored state is left unchanged — in particular a new
	// high observed during cooldown is NOT recorded.
	//
	// Whenever err is nil, the returned CurrencyState reflects the resulting stored
	// state — the freshly written values when granted, or the existing values when
	// not — so callers can populate a local cache regardless of the outcome.
	ClaimGainPush(ctx context.Context, mint *commonpb.PublicKey, supply, slot uint64, cooldown time.Duration) (granted bool, state *CurrencyState, err error)

	// GetCurrencyState returns the stored push state for a mint, or
	// ErrCurrencyStateNotFound if none has been recorded yet.
	GetCurrencyState(ctx context.Context, mint *commonpb.PublicKey) (*CurrencyState, error)
}

type FCMClient

type FCMClient interface {
	SendEachForMulticast(ctx context.Context, message *messaging.MulticastMessage) (*messaging.BatchResponse, error)
}

type FCMPusher

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

func NewFCMPusher

func NewFCMPusher(log *zap.Logger, tokens TokenStore, client FCMClient) *FCMPusher

func (*FCMPusher) SendBadgeCountPush added in v1.16.0

func (p *FCMPusher) SendBadgeCountPush(ctx context.Context, user *commonpb.UserId, count uint64) error

SendBadgeCountPush updates the app-icon badge to count on a user's iOS devices only. It sends a badge-only APNs notification — no alert, sound, or payload — so the icon updates without showing a banner.

It targets iOS exclusively: APNs is the only platform with a server-settable numeric badge, so FCM_ANDROID tokens are skipped. Android badges are driven by notification state, not a pushed number.

func (*FCMPusher) SendPushes added in v0.7.0

func (p *FCMPusher) SendPushes(ctx context.Context, title, body string, customPayload *pushpb.Payload, users ...*commonpb.UserId) error

type NoOpPusher

type NoOpPusher struct{}

func (*NoOpPusher) SendBadgeCountPush added in v1.16.0

func (n *NoOpPusher) SendBadgeCountPush(_ context.Context, _ *commonpb.UserId, _ uint64) error

func (*NoOpPusher) SendPushes added in v0.7.0

func (n *NoOpPusher) SendPushes(_ context.Context, _, _ string, _ *pushpb.Payload, _ ...*commonpb.UserId) error

type Pusher

type Pusher interface {
	SendPushes(ctx context.Context, title, body string, customPayload *pushpb.Payload, users ...*commonpb.UserId) error

	SendBadgeCountPush(ctx context.Context, user *commonpb.UserId, count uint64) error
}

func NewNoOpPusher

func NewNoOpPusher() Pusher

type Server

type Server struct {
	pushpb.UnimplementedPushServer
	// contains filtered or unexported fields
}

func NewServer

func NewServer(log *zap.Logger, authz auth.Authorizer, tokens TokenStore) *Server

func (*Server) AddToken

func (*Server) DeleteTokens

type Store added in v1.19.0

type Store interface {
	TokenStore
	CurrencyStateStore
}

Store is the combined push persistence surface, implemented by each backend.

type Token

type Token struct {
	Type         pushpb.TokenType
	Token        string
	AppInstallID string
}

Token represents a push notification token.

Tokens are bound to a (user, device) pair, identified by the AppInstallID.

type TokenStore

type TokenStore interface {
	// GetTokens returns all tokens for a user.
	GetTokens(ctx context.Context, userID *commonpb.UserId) ([]Token, error)

	// GetTokensBatch returns all tokens for a batch of users.
	GetTokensBatch(ctx context.Context, userIDs ...*commonpb.UserId) ([]Token, error)

	// AddToken adds a token for a user.
	//
	// If the token already exists for the same user and device, it will be updated.
	AddToken(ctx context.Context, userID *commonpb.UserId, appInstallID *commonpb.AppInstallId, tokenType pushpb.TokenType, token string) error

	// DeleteToken deletes a token for a user.
	DeleteToken(ctx context.Context, tokenType pushpb.TokenType, token string) error

	// FilterUsersWithTokens returns the subset of user IDs that have at least one push token.
	FilterUsersWithTokens(ctx context.Context, userIDs ...*commonpb.UserId) ([]*commonpb.UserId, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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