models

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModuleName               = common.ModuleName
	RouterKey                = common.RouterKey
	StoreKey                 = common.StoreKey
	ActionCreatePost         = common.ActionCreatePost
	ActionEditPost           = common.ActionEditPost
	ActionAnswerPoll         = common.ActionAnswerPoll
	ActionAddPostReaction    = common.ActionAddPostReaction
	ActionRemovePostReaction = common.ActionRemovePostReaction
	ActionRegisterReaction   = common.ActionRegisterReaction
	QuerierRoute             = common.QuerierRoute
	QueryPost                = common.QueryPost
	QueryPosts               = common.QueryPosts
	QueryPollAnswers         = common.QueryPollAnswers
	QueryRegisteredReactions = common.QueryRegisteredReactions
	QueryParams              = common.QueryParams
	PostSortByCreationDate   = common.PostSortByCreationDate
	PostSortByID             = common.PostSortByID
	PostSortOrderAscending   = common.PostSortOrderAscending
	PostSortOrderDescending  = common.PostSortOrderDescending
)

Variables

View Source
var (
	// functions aliases
	NewPostMedia               = common.NewPostMedia
	ValidateURI                = common.ValidateURI
	NewPostMedias              = common.NewPostMedias
	GetEmojiByShortCodeOrValue = common.GetEmojiByShortCodeOrValue
	ParseAnswerID              = polls.ParseAnswerID
	NewPollAnswer              = polls.NewPollAnswer
	NewPollAnswers             = polls.NewPollAnswers
	NewPollData                = polls.NewPollData
	ArePollDataEquals          = polls.ArePollDataEquals
	NewUserAnswer              = polls.NewUserAnswer
	NewUserAnswers             = polls.NewUserAnswers
	NewPostReaction            = reactions.NewPostReaction
	NewPostReactions           = reactions.NewPostReactions
	NewReaction                = reactions.NewReaction
	IsEmoji                    = reactions.IsEmoji
	NewReactions               = reactions.NewReactions

	// variable aliases
	Sha256RegEx              = common.Sha256RegEx
	HashtagRegEx             = common.HashtagRegEx
	ShortCodeRegEx           = common.ShortCodeRegEx
	URIRegEx                 = common.URIRegEx
	ModuleAddress            = common.ModuleAddress
	PostStorePrefix          = common.PostStorePrefix
	PostCommentsStorePrefix  = common.PostCommentsStorePrefix
	PostReactionsStorePrefix = common.PostReactionsStorePrefix
	ReactionsStorePrefix     = common.ReactionsStorePrefix
	PollAnswersStorePrefix   = common.PollAnswersStorePrefix
)
View Source
var ModelsCdc = codec.New()

ModelsCdc is the codec

Functions

func PollAnswersStoreKey

func PollAnswersStoreKey(id PostID) []byte

PollAnswersStoreKey turns an id to a key used to store a post's poll answers into the posts store nolint: interfacer

func PostCommentsStoreKey

func PostCommentsStoreKey(id PostID) []byte

PostCommentsStoreKey turns an id to a key used to store a post's comments into the posts store nolint: interfacer

func PostReactionsStoreKey

func PostReactionsStoreKey(id PostID) []byte

PostCommentsStoreKey turns an id to a key used to store a post's reactions into the posts store nolint: interfacer

func PostStoreKey

func PostStoreKey(id PostID) []byte

PostStoreKey turns an id to a key used to store a post into the posts store nolint: interfacer

func ReactionsStoreKey

func ReactionsStoreKey(shortCode, subspace string) []byte

ReactionsStoreKey turns the combination of shortCode and subspace to a key used to store a reaction into the reaction's store nolint: interfacer

func RegisterModelsCodec

func RegisterModelsCodec(cdc *codec.Codec)

RegisterModelsCodec registers concrete types on the Amino codec

Types

type AnswerID

type AnswerID = polls.AnswerID

type KeyValue

type KeyValue = common.KeyValue

type OptionalData

type OptionalData = common.OptionalData

type PollAnswer

type PollAnswer = polls.PollAnswer

type PollAnswers

type PollAnswers = polls.PollAnswers

type PollAnswersQueryResponse

type PollAnswersQueryResponse struct {
	PostID         PostID      `json:"post_id" yaml:"post_id"`
	AnswersDetails UserAnswers `json:"answers_details" yaml:"answers_details"`
}

PollAnswersQueryResponse represents the answers made to a post's poll that is returned to user upon a query

func (PollAnswersQueryResponse) String

func (response PollAnswersQueryResponse) String() string

String implements fmt.Stringer

type PollData

type PollData = polls.PollData

type Post

type Post struct {
	PostID         PostID         `json:"id" yaml:"id" `                                          // Unique id
	ParentID       PostID         `json:"parent_id" yaml:"parent_id"`                             // Post of which this one is a comment
	Message        string         `json:"message" yaml:"message"`                                 // Message contained inside the post
	Created        time.Time      `json:"created" yaml:"created"`                                 // RFC3339 date at which the post has been created
	LastEdited     time.Time      `json:"last_edited" yaml:"last_edited"`                         // RFC3339 date at which the post has been edited the last time
	AllowsComments bool           `json:"allows_comments" yaml:"allows_comments"`                 // Tells if users can reference this PostID as the parent
	Subspace       string         `json:"subspace" yaml:"subspace"`                               // Identifies the application that has posted the message
	OptionalData   OptionalData   `json:"optional_data,omitempty" yaml:"optional_data,omitempty"` // Arbitrary data that can be used from the developers
	Creator        sdk.AccAddress `json:"creator" yaml:"creator"`                                 // Creator of the Post
	Medias         PostMedias     `json:"medias,omitempty" yaml:"medias,omitempty"`               // Contains all the medias that are shared with the post
	PollData       *PollData      `json:"poll_data,omitempty" yaml:"poll_data"`                   // Contains the poll details, if existing
}

Post is a struct of a post

func NewPost

func NewPost(id, parentID PostID, message string, allowsComments bool, subspace string,
	optionalData map[string]string, created time.Time, creator sdk.AccAddress) Post

func (Post) ContentsEquals

func (p Post) ContentsEquals(other Post) bool

ContentsEquals returns true if and only if p and other contain the same data, without considering the ID

func (Post) Equals

func (p Post) Equals(other Post) bool

Equals allows to check whether the contents of p are the same of other

func (Post) GetPostHashtags

func (p Post) GetPostHashtags() []string

GetPostHashtags returns all the post's hashtags without duplicates

func (Post) String

func (p Post) String() string

String implements fmt.Stringer

func (Post) Validate

func (p Post) Validate() error

Validate implements validator

func (Post) WithMedias

func (p Post) WithMedias(medias PostMedias) Post

WithMedias allows to easily set the given medias as the multimedia files associated with the p Post

func (Post) WithPollData

func (p Post) WithPollData(data PollData) Post

WithMedias allows to easily set the given data as the poll data files associated with the p Post

type PostID

type PostID string

PostID represents a unique post id

func ComputeID

func ComputeID(creationDate time.Time, creator sdk.AccAddress, subspace string) PostID

ComputeID returns a sha256 hash of the given data concatenated together nolint: interfacer

func ParsePostID

func ParsePostID(value string) (PostID, error)

ParsePostID takes the given value and returns a PostID from it. If the given value cannot be parse, an error is returned instead.

func (PostID) Equals

func (id PostID) Equals(other PostID) bool

Equals compares two PostID instances

func (PostID) String

func (id PostID) String() string

String implements fmt.Stringer

func (PostID) Valid

func (id PostID) Valid() bool

Valid tells if the id can be used safely

type PostIDs

type PostIDs []PostID

PostIDs represents a slice of PostID objects

func (PostIDs) AppendIfMissing

func (ids PostIDs) AppendIfMissing(id PostID) (PostIDs, bool)

AppendIfMissing appends the given postID to the ids slice if it does not exist inside it yet. It returns a new slice of PostIDs containing such ID and a boolean indicating whether or not the original slice has been modified.

func (PostIDs) Equals

func (ids PostIDs) Equals(other PostIDs) bool

Equals returns true iff the ids slice and the other one contain the same data in the same order

func (PostIDs) String

func (ids PostIDs) String() string

String implements fmt.Stringer

type PostMedia

type PostMedia = common.PostMedia

type PostMedias

type PostMedias = common.PostMedias

type PostQueryResponse

type PostQueryResponse struct {
	Post
	PollAnswers []UserAnswer   `json:"poll_answers,omitempty" yaml:"poll_answers,omitempty"`
	Reactions   []PostReaction `json:"reactions" yaml:"reactions,omitempty"`
	Children    PostIDs        `json:"children" yaml:"children"`
}

PostQueryResponse represents the data of a post that is returned to user upon a query

func NewPostResponse

func NewPostResponse(
	post Post, pollAnswers []UserAnswer, reactions []PostReaction, children PostIDs,
) PostQueryResponse

func (PostQueryResponse) MarshalJSON

func (response PostQueryResponse) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler as Amino does not respect default json composition

func (PostQueryResponse) String

func (response PostQueryResponse) String() string

String implements fmt.Stringer

func (*PostQueryResponse) UnmarshalJSON

func (response *PostQueryResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler as Amino does not respect default json composition

type PostReaction

type PostReaction = reactions.PostReaction

type PostReactions

type PostReactions = reactions.PostReactions

type Posts

type Posts []Post

Posts represents a slice of Post objects

func (Posts) Len

func (p Posts) Len() int

Len implements sort.Interface

func (Posts) Less

func (p Posts) Less(i, j int) bool

Less implements sort.Interface

func (Posts) String

func (p Posts) String() string

String implements stringer interface

func (Posts) Swap

func (p Posts) Swap(i, j int)

Swap implements sort.Interface

type Reaction

type Reaction = reactions.Reaction

type Reactions

type Reactions = reactions.Reactions

type UserAnswer

type UserAnswer = polls.UserAnswer

type UserAnswers

type UserAnswers = polls.UserAnswers

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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