schemas

package
v0.0.0-...-14aab60 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PostTypeAll specifies a request for all post types in a PostFilterset
	PostTypeAll = iota
	// PostTypePosts specifies a request for only top-level posts in a PostFilterset
	PostTypePosts
	// PostTypeComments specifies a request for only comments in a PostFilterset
	PostTypeComments
)

Variables

This section is empty.

Functions

func InitConfig

func InitConfig(a *AppConfig)

InitConfig inits the config variable

Types

type AppConfig

type AppConfig struct {
	Environment          string   `json:"environment"`             // environment
	SiteName             string   `json:"site_name"`               // website's name
	SiteIcon             string   `json:"site_icon"`               // website's icon displayed in the header
	Tagline              string   `json:"tagline"`                 // website's tagline
	SiteURL              string   `json:"site_url"`                // webiste's base URL including protocol. no trailing slash
	ListenPort           int      `json:"listen_port"`             // port to listen on
	Relays               []string `json:"relays"`                  // nostr relay endpoints
	RelayPublic          string   `json:"relay_public"`            // publicly accessable relay endpoint
	RepoLink             string   `json:"repo_link"`               // public repo for the project
	TelegramLink         string   `json:"telegram_link"`           // public telegram group link
	PubkeyVerifyURL      string   `json:"pubkey_verify_url"`       // URL for verifying a user's pubkey with the nostr relay
	VerifyBaseURL        string   `json:"verify_base_url"`         // base URL for a user to submit verification for account
	CheckVerifiedBaseURL string   `json:"check_verified_base_url"` // base URL for checking if a user is registered with the nostr relay
	PostsPerPage         int      `json:"posts_per_page"`          // maximum number of posts to display per-page
	TitleMaxCharacters   int      `json:"title_max_characters"`    // maximum allowed characters in a post title
	BodyMaxCharacters    int      `json:"body_max_characters"`     // maximum allowed characters in a post/comment body
	ChannelMaxCharacters int      `json:"channel_max_characters"`  // maximum allowed characters in a channel name
	NameMaxCharacters    int      `json:"name_max_characters"`     // maximum allowed characters in a user's username
	BioMaxCharacters     int      `json:"bio_max_characters"`      // maximum allowed characters in a user's bio
}

AppConfig defines the schema for global app config

type Login

type Login struct {
	Password string `json:"password" form:"password"` // allows user to login with a password
	PrivKey  string `json:"privkey" form:"privkey"`   // allows user to login with a private key
	Seed     string `json:"seed" form:"seed"`         // allows user to login with a bip39 mnemonic
}

Login defines a login

func (Login) GeneratePrivateKey

func (login Login) GeneratePrivateKey() (string, error)

GeneratePrivateKey generates a private key for a given login

type Metadata

type Metadata struct {
	Name      string `json:"name" form:"name"`                       // user's username
	About     string `json:"about" form:"about"`                     // user's bio
	PubKey    string `json:"pubkey,omitempty" form:"pubkey"`         // user's public key
	UserScore int    `json:"user_score,omitempty" form:"user_score"` // user's global post/comment score
	CreatedAt uint32 `json:"created_at,omitempty" form:"created_at"` // creation timestamp
}

Metadata defines a user's metadata

func MetadataFromEvent

func MetadataFromEvent(event *nostr.Event) (*Metadata, error)

MetadataFromEvent returns a *Metadatas for a supplied nostr event

func (*Metadata) IsValid

func (metadata *Metadata) IsValid() bool

IsValid ensures that user metadata looks valid for submission

func (*Metadata) PrepareForPublish

func (metadata *Metadata) PrepareForPublish()

PrepareForPublish strips superflous parameters to prepare for publishing (omitempty) this is mainly to reduce nostr event content size clients shouldn't assume all post events received from relays have superflous parameters stripped

func (*Metadata) Sanitize

func (metadata *Metadata) Sanitize()

Sanitize sanitizes the metadata's name to prepare for publishing and DB insertion

type Post

type Post struct {
	ID        string `json:"id,omitempty" form:"id"`                 // nostr event's ID
	Score     int32  `json:"score,omitempty" form:"score"`           // post's score
	Children  int32  `json:"children,omitempty" form:"children"`     // number of children
	PubKey    string `json:"pubkey,omitempty" form:"pubkey"`         // poster's public key
	CreatedAt uint32 `json:"created_at,omitempty" form:"created_at"` // creation timestamp
	Title     string `json:"title,omitempty" form:"title"`           // post's title
	Body      string `json:"body,omitempty" form:"body"`             // post's body
	Channel   string `json:"channel,omitempty" form:"channel"`       // post's channel
	Parent    string `json:"parent,omitempty" form:"parent"`         // parent post's nostr event ID
}

Post defines a post structure

func PostFromEvent

func PostFromEvent(event *nostr.Event) (*Post, error)

PostFromEvent returns a *Post for a supplied nostr event

func (*Post) IsValidComment

func (post *Post) IsValidComment() bool

IsValidComment ensures that a reply looks valid for submission

func (*Post) IsValidPost

func (post *Post) IsValidPost() bool

IsValidPost ensures that a post looks valid for submission

func (*Post) PrepareForPublish

func (post *Post) PrepareForPublish()

PrepareForPublish strips superflous parameters to prepare for publishing (omitempty) this is mainly to reduce nostr event content size clients shouldn't assume all post events received from relays have superflous parameters stripped

func (*Post) Sanitize

func (post *Post) Sanitize()

Sanitize sanitizes the posts fields to prepare for publishing and DB insertion

type PostFilterset

type PostFilterset struct {
	Channel       string // filter by channel
	PubKey        string // filter by submitter's pubkey
	PostContains  string // search within post body/title
	PostType      int    // filter by post/comment/all (see iota above)
	HideBadUsers  bool   // hide users with low up/down ratios
	Page          int    // show only posts after specified offset
	OrderByColumn string // which column to use for sorting
	Limit         int    // limit # of rows returned

}

PostFilterset defines a set of filters for querying posts

type User

type User struct {
	PrivKey       string `json:"privkey,omitempty" form:"privkey"`               // user private key
	PubKey        string `json:"pubkey,omitempty" form:"pubkey"`                 // user public key
	Name          string `json:"name,omitempty" form:"name"`                     // username
	About         string `json:"about,omitempty" form:"about"`                   // user bio
	HideDownvoted bool   `json:"hide_downvoted,omitempty" form:"hide_downvoted"` // hide downvoted comments
	HideBadUsers  bool   `json:"hide_bad_users,omitempty" form:"hide_bad_users"` // hide users with low up/down ratios
	HideImages    bool   `json:"hide_images,omitempty" form:"hide_images"`       // don't auto-load images in posts
	DarkMode      bool   `json:"dark_mode,omitempty" form:"dark_mode"`           // enable dark mode styling
}

User defines a user

func LoggedOutUser

func LoggedOutUser() *User

LoggedOutUser creates a new user object with default values

type Vote

type Vote struct {
	PubKey    string `json:"pubkey,omitempty" form:"pubkey"`        // vote owner's public key
	Target    string `json:"target,omitempty" form:"target"`        // the post being voted on
	Channel   string `json:"channel,omitempty" form:"channel"`      // the target vote's channel
	CreatedAt uint32 `json:"create_at,omitempty" form:"created_at"` // vote timestamp
	Direction bool   `json:"direction,omitempty" form:"direction"`  // false=down, true=up
}

Vote defines an upvote/downvote

func VoteFromEvent

func VoteFromEvent(event *nostr.Event) (*Vote, error)

VoteFromEvent returns a *Vote for a supplied nostr event

func (*Vote) IsValid

func (vote *Vote) IsValid() bool

IsValid ensures that a vote looks valid for submission

func (*Vote) PrepareForPublish

func (vote *Vote) PrepareForPublish()

PrepareForPublish strips superflous parameters to prepare for publishing (omitempty) this is mainly to reduce nostr event content size clients shouldn't assume all post events received from relays have superflous parameters stripped

type VoteFilterset

type VoteFilterset struct {
	PubKey        string // filter by submitter's pubkey
	Channel       string // filter by vote target's channel
	OrderByColumn string // which column to use for sorting
	Limit         int    // limit # of rows returnd

}

VoteFilterset defines a set of filters for querying votes

Jump to

Keyboard shortcuts

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