profile

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTipCardColorHex = "#000000"

DefaultTipCardColorHex is the Tip Card colour a user gets before they pick one of their own.

Variables

View Source
var ErrExistingSocialLink = errors.New("existing social link")
View Source
var ErrInvalidDisplayName = errors.New("invalid display name")
View Source
var ErrNotFound = errors.New("not found")

Functions

func DefaultTipCardCustomization added in v1.25.0

func DefaultTipCardCustomization() *profilepb.TipCardCustomization

DefaultTipCardCustomization returns the Tip Card customization for a user who has customized nothing. UserProfile.tip_card_customization is a required field, so every profile the store hands out carries one, resolved from the user's choices where they exist and from this default where they do not.

func NewChatProfileReader added in v1.16.0

func NewChatProfileReader(store Store, media Media) chat.ProfileReader

NewChatProfileReader returns a chat.ProfileReader backed by the given profile store and blob storage, for wiring the Chat service. The media dependency is what lets member avatars come back with resolved blob metadata, so chat itself never touches blob storage.

func NormalizeColorHex added in v1.25.0

func NormalizeColorHex(hex string) string

NormalizeColorHex puts a colour into the canonical upper-case form it is stored and handed back in, so a colour round-trips as the same string regardless of the casing the client sent it in.

func TipCardCustomizationFromStored added in v1.25.0

func TipCardCustomizationFromStored(storedColorHex *string) *profilepb.TipCardCustomization

TipCardCustomizationFromStored resolves a user's stored Tip Card choices into the customization their profile carries, filling in the default for anything they have not picked. storedColorHex is nil for a user who never chose a colour. Every store resolves through here, so the "always set" contract on UserProfile.tip_card_customization holds no matter which one served the read.

Types

type Media added in v1.22.0

type Media interface {
	// SetAsProfilePicture validates that ownerID owns the blob and that it can back
	// a picture, then grants ownerID's public profile read access to it. It returns
	// one of blob.ErrBlobNotFound, blob.ErrBlobNotReady, blob.ErrBlobRejected, or
	// blob.ErrBlobInvalid when the blob cannot be used.
	SetAsProfilePicture(ctx context.Context, ownerID *commonpb.UserId, blobID *blobpb.BlobId) error

	// ResolveRenditions returns each original's full rendition set — the ORIGINAL
	// plus every derived rendition, each with a freshly minted, short-lived download
	// URL — keyed by string(BlobId.Value). It performs no authorization.
	ResolveRenditions(ctx context.Context, ids []*blobpb.BlobId) (map[string][]*blobpb.Rendition, error)
}

Media is the blob storage surface the profile service depends on, satisfied by blob.Integration. It is declared here, rather than depending on the blob server directly, so the dependency runs one way: profile states what it needs of blob storage and the wiring supplies it.

type PhoneForPayment added in v1.14.0

type PhoneForPayment struct {
	PhoneNumber *commonpb.PhoneNumber
	UserID      *commonpb.UserId
	JoinedAt    time.Time
}

PhoneForPayment is a payment-enabled phone number together with the user that owns it.

type Server

type Server struct {
	profilepb.UnimplementedProfileServer
	// contains filtered or unexported fields
}

func NewServer

func NewServer(log *zap.Logger, authz auth.Authorizer, accounts account.Store, profiles Store, media Media, moderator moderation.Client, xClient *x.Client) *Server

func (*Server) GetProfile

func (*Server) SetProfilePicture added in v1.22.0

func (*Server) UpdateTipCard added in v1.25.0

type Store

type Store interface {
	// GetProfile returns the user profile for a user, or ErrNotFound when the store
	// does not know the user.
	GetProfile(ctx context.Context, id *commonpb.UserId, includePrivateProfile bool) (*profilepb.UserProfile, error)

	// SetDisplayName sets the display name for a user, provided they exist.
	//
	// ErrInvalidDisplayName is returned if there is an issue with the display name.
	SetDisplayName(ctx context.Context, id *commonpb.UserId, displayName string) error

	// GetPublicProfiles returns, for each of the given users the store knows, the
	// public part of that user's profile keyed by string(userID.Value): the
	// fields any viewer may see, carrying no private ones. Unknown users are
	// absent from the map. It resolves the whole set in a single lookup.
	//
	// Display name is empty and profile picture nil for a user who has set
	// neither, while the join timestamp and Tip Card customization are always set
	// — so a present entry means "this user exists", not "this user filled in a
	// profile".
	//
	// The returned picture carries only the blob holding its ORIGINAL rendition;
	// resolving that blob's metadata is left to the caller.
	GetPublicProfiles(ctx context.Context, userIDs []*commonpb.UserId) (map[string]*profilepb.UserProfile, error)

	// SetProfilePicture sets the user's profile picture to the blob holding its
	// ORIGINAL rendition, replacing any picture already set.
	SetProfilePicture(ctx context.Context, id *commonpb.UserId, blobID *blobpb.BlobId) error

	// SetTipCardColor sets the colour of the user's Tip Card, provided they exist,
	// replacing any colour already picked. colorHex is stored as given, so callers
	// normalize it first.
	SetTipCardColor(ctx context.Context, id *commonpb.UserId, colorHex string) error

	// LinkPhoneNumber links the phone number and its precomputed hash to a user, provided
	// they exist. Any other user previously holding the same phone number has both fields
	// cleared.
	LinkPhoneNumber(ctx context.Context, id *commonpb.UserId, phoneNumber string, phoneNumberHash *commonpb.Hash) error

	// UnlinkPhoneNumber removes the link for the phone number
	UnlinkPhoneNumber(ctx context.Context, userID *commonpb.UserId, phoneNumber string) error

	// LinkPhoneNumberForPayment marks the user's linked phone number as enabled for
	// payment, provided the given phone number is currently linked to the user. It
	// reports whether the flag transitioned from false to true (false if it was
	// already enabled).
	//
	// ErrNotFound is returned when the phone number is not associated with the user.
	LinkPhoneNumberForPayment(ctx context.Context, userID *commonpb.UserId, phoneNumber string) (bool, error)

	// IsPhoneNumberLinkedForPayment reports whether the given phone number is
	// currently linked to the user and enabled for payment.
	IsPhoneNumberLinkedForPayment(ctx context.Context, userID *commonpb.UserId, phoneNumber string) (bool, error)

	// GetPhonesByHashes returns the phone numbers for users whose stored
	// phoneNumberHash matches any of the provided hashes. Order is unspecified.
	GetPhonesByHashes(ctx context.Context, hashes []*commonpb.Hash) ([]*commonpb.PhoneNumber, error)

	// GetPhonesByHashesForPayment returns the payment-enabled phone numbers,
	// each paired with the user that owns it, for users whose stored
	// phoneNumberHash matches any of the provided hashes and who have enabled
	// their phone number for payment. Order is unspecified.
	GetPhonesByHashesForPayment(ctx context.Context, hashes []*commonpb.Hash) ([]*PhoneForPayment, error)

	// GetPhoneNumbersForPayment returns, for each of the given users that has a
	// phone number enabled for payment, that phone number keyed by
	// string(userID.Value). Users without a payment-enabled phone number are
	// absent from the map. It resolves the whole set in a single lookup.
	GetPhoneNumbersForPayment(ctx context.Context, userIDs []*commonpb.UserId) (map[string]*commonpb.PhoneNumber, error)

	// GetUserIdByPhoneNumber returns the UserId currently linked to the given
	// phone number. Returns ErrNotFound when no user holds the number.
	GetUserIdByPhoneNumber(ctx context.Context, phoneNumber string) (*commonpb.UserId, error)

	// GetUserIdByPhoneNumberForPayment returns the UserId currently linked to the
	// given phone number, but only when that user has enabled the phone number for
	// payment. Returns ErrNotFound when no user holds the number or the number is
	// not enabled for payment.
	GetUserIdByPhoneNumberForPayment(ctx context.Context, phoneNumber string) (*commonpb.UserId, error)

	// LinkEmailAddress links the email address to a user, provided they exist. Any other
	// user previously holding the same email address has it cleared.
	LinkEmailAddress(ctx context.Context, id *commonpb.UserId, emailAddress string) error

	// UnlinkPhoneNumber removes the link for the email address
	UnlinkEmailAddress(ctx context.Context, userID *commonpb.UserId, emailAddress string) error

	// LinkXAccount links a X account to a user ID
	LinkXAccount(ctx context.Context, userID *commonpb.UserId, xProfile *profilepb.XProfile, accessToken string) error

	// UnlinkXAccount removes the link to the X account
	UnlinkXAccount(ctx context.Context, userID *commonpb.UserId, xUserID string) error

	// GetXProfile gets a user's X profile if it has been linked
	GetXProfile(ctx context.Context, userID *commonpb.UserId) (*profilepb.XProfile, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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