intent

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TaskTypeSendContactDmPaymentMessage is the task that injects the cash
	// message into the sender and recipient's DM after a contact DM payment.
	TaskTypeSendContactDmPaymentMessage uint32 = 1

	// TaskTypeSendDmPaymentMessage is the task that injects the cash message
	// into the sender and recipient's DM after a DM payment.
	TaskTypeSendDmPaymentMessage uint32 = 2

	// TaskTypeSendGroupPaymentMessage is the task that injects the cash
	// message into the group after a group payment.
	TaskTypeSendGroupPaymentMessage uint32 = 3

	// TaskTypeRecordReactionBoost is the task that records a reaction boost
	// against the payer's reaction once its payment is made (see
	// messaging.Sender.RecordBoost).
	TaskTypeRecordReactionBoost uint32 = 4
)

The OCP task system treats the type as an opaque app-owned namespace, so values must be globally unique across the app and stable forever — pending tasks in the DB reference them. Type 0 is reserved as invalid by the base system.

Variables

View Source
var ErrNotBoostPayment = errors.New("intent is not a boost payment")

ErrNotBoostPayment is returned by GetBoostPayment for an intent that cannot carry a boost's payment.

Functions

func GetChatMetadata added in v1.15.0

func GetChatMetadata(appMetadata []byte) *intentpb.ChatMetadata

GetChatMetadata extracts the chat metadata from an intent's additional app metadata, if present. It returns nil when there is no app metadata, the metadata fails to decode, or it is not chat metadata.

This and the accessors below take the blob rather than the intent it came from, because the intent is not the only thing that carries it: a transaction history record passes the same bytes through unmodified, and decodes to the same metadata the intent was submitted with.

func GetChatPaymentVerb added in v1.35.0

func GetChatPaymentVerb(appMetadata []byte, createdAt time.Time) messagingpb.CashContent_Verb

GetChatPaymentVerb reports how a chat payment created at createdAt should be rendered. A DM payment is a tip only when its action is TIP; SEND and the unset DEFAULT are plain sends, from either location, except for payments created before sendByDefaultCutoff. Everything else, contact DM and group payments included, is a plain send: a group payment's TIP is denied at validation (see validateGroupAppMetadata).

Both the cash message injected into the chat and the sender's activity feed entry render off this, so they cannot disagree about what a payment was. createdAt is the intent's creation time, which OCP sets before validation and copies onto the intent's history records, so every caller passes the same time for the same payment.

func GetContactDmPayment added in v1.15.0

func GetContactDmPayment(appMetadata []byte) *intentpb.ChatMetadata_ContactDmPayment

GetContactDmPayment extracts the contact DM payment from app metadata, if present. It returns nil when there is no app metadata, the metadata fails to decode, or it is not a contact DM payment.

func GetDmPayment added in v1.33.0

func GetDmPayment(appMetadata []byte) *intentpb.ChatMetadata_DmPayment

GetDmPayment extracts the DM payment from app metadata, if present. It returns nil when there is no app metadata, the metadata fails to decode, or it is not a DM payment.

func GetGroupPayment added in v1.35.0

func GetGroupPayment(appMetadata []byte) *intentpb.ChatMetadata_GroupPayment

GetGroupPayment extracts the group payment from app metadata, if present. It returns nil when there is no app metadata, the metadata fails to decode, or it is not a group payment.

func GetReactionBoost added in v1.35.0

func GetReactionBoost(appMetadata []byte) *intentpb.ChatMetadata_ReactionBoost

GetReactionBoost extracts the reaction boost from app metadata, if present. It returns nil when there is no app metadata, the metadata fails to decode, or it is not a reaction boost.

func IsUserChatPayment added in v1.35.0

func IsUserChatPayment(appMetadata []byte) bool

IsUserChatPayment reports whether app metadata is a chat payment whose parties know each other by user ID: a DM payment, a group payment, whose cash message names both in the group, or a reaction boost, whose payer is shown on the reaction to the group and whose payees are the group's creator and the message's sender. A contact DM payment is not one, since its parties know each other by phone number; nor is a payment carrying no chat metadata, such as one handed off in person, where no identity was exchanged at all.

func NewIntegration

func NewIntegration(
	accounts account.Store,
	chats chat.Store,
	messages messaging.Store,
	profiles profile.Store,
	access *chat.Access,
	mintDataProvider *ocp_currency_util.MintDataProvider,
	teamUserID *commonpb.UserId,
) ocp_integration.SubmitIntent

NewIntegration constructs the intent integration. messages is the messaging store, read to validate reaction boosts. access is the one chat.Access the parent builds and shares with the chat and messaging servers. teamUserID is the Flipcash team account, which the parent resolves once at startup with flipcashteam.GetUserID and passes to the chat store, the chat RuleEvaluator, the chat server and the Sender too; nil names no one.

func NewRecordReactionBoostTask added in v1.35.0

func NewRecordReactionBoostTask(intentRecord *ocp_intent.Record) *ocp_task.Record

NewRecordReactionBoostTask creates the task that records a reaction boost after its payment. Only the intent ID is carried, via the reference ID; the executor reloads the authoritative intent record at execution time.

func NewSendContactDmPaymentMessageTask added in v1.15.0

func NewSendContactDmPaymentMessageTask(intentRecord *ocp_intent.Record) *ocp_task.Record

NewSendContactDmPaymentMessageTask creates the task that injects the cash message into the sender and recipient's DM after a contact DM payment. Only the intent ID is carried, via the reference ID; the executor reloads the authoritative intent record at execution time.

func NewSendDmPaymentMessageTask added in v1.33.0

func NewSendDmPaymentMessageTask(intentRecord *ocp_intent.Record) *ocp_task.Record

NewSendDmPaymentMessageTask creates the task that injects the cash message into the sender and recipient's DM after a DM payment. Only the intent ID is carried, via the reference ID; the executor reloads the authoritative intent record at execution time.

func NewSendGroupPaymentMessageTask added in v1.35.0

func NewSendGroupPaymentMessageTask(intentRecord *ocp_intent.Record) *ocp_task.Record

NewSendGroupPaymentMessageTask creates the task that injects the cash message into the group after a group payment. Only the intent ID is carried, via the reference ID; the executor reloads the authoritative intent record at execution time.

Types

type BoostDestination added in v1.35.0

type BoostDestination struct {
	Owner        *ocp_common.Account
	Quarks       uint64
	NativeAmount float64
}

BoostDestination is one destination of a boost's payment: the owner account paid and how much, in quarks and in the payment's currency.

type BoostPayment added in v1.35.0

type BoostPayment struct {
	// Payer is the owner account that made the payment.
	Payer *ocp_common.Account

	// Destinations are the payment's destinations, one per payee, in the
	// payment's own order.
	Destinations []BoostDestination

	// Amount is the whole payment, every destination's part together.
	Amount *commonpb.CryptoPaymentAmount

	// UsdMarketValue is the whole payment's value in USD, what the boost
	// grows the reaction's totals by.
	UsdMarketValue float64
}

BoostPayment is the payment behind a reaction boost, read off its intent record by GetBoostPayment: who paid, who it pays, and the whole payment. It is what boost validation and the boost task read instead of the intent's own metadata, so that the one place that knows which intents carry a boost, and how each names its destinations, is GetBoostPayment.

func GetBoostPayment added in v1.35.0

func GetBoostPayment(intentRecord *ocp_intent.Record) (*BoostPayment, error)

GetBoostPayment reads the payment behind a reaction boost off its intent record. A boost that pays one person (see messaging.BoostPayees) is a direct SendPublicPayment, with one destination; a boost that pays both the message's sender and the group's creator is a SendPublicMultiPayment, one BoostDestination per destination. Which of the two a boost must be is judged in validateReactionBoostAppMetadata, not here.

It reads nothing but the record and returns ErrNotBoostPayment (wrapped) for an intent that is neither.

type Integration

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

func (*Integration) AllowCreation

func (i *Integration) AllowCreation(ctx context.Context, intentRecord *ocp_intent.Record, metadata *ocp_transactionpb.Metadata, actions []*ocp_transactionpb.Action) error

func (*Integration) GetTasksToSchedule added in v1.15.0

func (i *Integration) GetTasksToSchedule(ctx context.Context, intentRecord *ocp_intent.Record) ([]*ocp_task.Record, error)

GetTasksToSchedule returns the guaranteed work derived from a submitted intent. A DM payment of either type (contact DM or DM) schedules the cash message injected into the DM between the sender and recipient, and a group payment the one injected into the group; a reaction boost, made as either payment intent, schedules the task that records the boost. Execution is handled by task.Executor.

func (*Integration) OnSuccess

func (i *Integration) OnSuccess(ctx context.Context, intentRecord *ocp_intent.Record) error

Jump to

Keyboard shortcuts

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