v030

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModuleName = "posts"
)

Variables

View Source
var (
	SubspaceRegEx = regexp.MustCompile("^[a-fA-F0-9]{64}$")
)

Functions

func ArePollDataEquals added in v0.4.0

func ArePollDataEquals(first, second *PollData) bool

ArePollDataEquals check whether the first and second pointers to a PollData object represents the same poll or not.

func RemoveDoublePosts

func RemoveDoublePosts(posts []v020posts.Post, reactions map[string][]v020posts.Reaction) ([]v020posts.Post, map[string][]v020posts.Reaction)

RemoveDoublePosts removes all the duplicated posts that have the same contents from the given posts slice. All the reactions associated with the removed posts are moved to the post with the lower id.

func SquashPostIDs

func SquashPostIDs(posts []v020posts.Post, reactions map[string][]v020posts.Reaction) ([]v020posts.Post, map[string][]v020posts.Reaction)

SquashPostIDs iterates over all the given posts and reactions and squashes the post IDs to be all subsequent to each other so that no IDs are skipped

Types

type AnswerID added in v0.4.0

type AnswerID uint64

AnswerID represents a unique answer id

func ParseAnswerID added in v0.4.0

func ParseAnswerID(value string) (AnswerID, error)

ParseAnswerID returns the AnswerID represented inside the provided value, or an error if no id could be parsed properly

func (AnswerID) MarshalJSON added in v0.4.0

func (id AnswerID) MarshalJSON() ([]byte, error)

MarshalJSON implements Marshaler

func (AnswerID) String added in v0.4.0

func (id AnswerID) String() string

String implements fmt.Stringer

func (*AnswerID) UnmarshalJSON added in v0.4.0

func (id *AnswerID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements Unmarshaler

type GenesisState

type GenesisState struct {
	Posts       []Post                  `json:"posts"`
	PollAnswers map[string][]UserAnswer `json:"poll_answers_details"`
	Reactions   map[string][]Reaction   `json:"reactions"`
}

GenesisState contains the data of a v0.3.0 genesis state for the posts module

func Migrate

func Migrate(oldGenState v020posts.GenesisState) GenesisState

Migrate accepts exported genesis state from v0.2.0 and migrates it to v0.3.0 genesis state. This migration changes the way subspaces are specified from a simple string to a sha-256 hash

type OptionalData

type OptionalData map[string]string

type PollAnswer added in v0.4.0

type PollAnswer struct {
	ID   AnswerID `json:"id"`   // Unique id inside the post, serialized as a string for Javascript compatibility
	Text string   `json:"text"` // Text of the answer
}

PollAnswer contains the data of a single poll answer inserted by the creator

func (PollAnswer) Equals added in v0.4.0

func (pa PollAnswer) Equals(other PollAnswer) bool

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

type PollAnswers added in v0.4.0

type PollAnswers []PollAnswer

func (PollAnswers) Equals added in v0.4.0

func (answers PollAnswers) Equals(other PollAnswers) bool

Equals returns true iff the answers slice contains the same data in the same order of the other slice

type PollData added in v0.4.0

type PollData struct {
	Question              string      `json:"question"`                // Describes what poll is about
	ProvidedAnswers       PollAnswers `json:"provided_answers"`        // Lists of answers provided by the creator
	EndDate               time.Time   `json:"end_date"`                // RFC3339 date at which the poll will no longer accept new answers
	Open                  bool        `json:"is_open"`                 // Tells if the poll is still accepting answers
	AllowsMultipleAnswers bool        `json:"allows_multiple_answers"` // Tells if the poll is a single or multiple answers one
	AllowsAnswerEdits     bool        `json:"allows_answer_edits"`     // Tells if the poll allows answer edits
}

PollData contains the information of a poll that is associated to a post

func (PollData) Equals added in v0.4.0

func (pd PollData) Equals(other PollData) bool

Equals returns true if this poll data object has the same contents of the other given. It assumes neither pd or other are null. To check the equality between possibly null values use ArePollDataEquals instead.

type Post

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

Post is a struct of a post

func (Post) ConflictsWith added in v0.4.0

func (p Post) ConflictsWith(other Post) bool

func (Post) ContentsEquals added in v0.4.0

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

type PostID

type PostID uint64

PostID represents a unique post id

func ParsePostID added in v0.4.0

func ParsePostID(value string) (PostID, error)

ParsePostID returns the PostID represented inside the provided value, or an error if no id could be parsed properly

func (PostID) MarshalJSON added in v0.4.0

func (id PostID) MarshalJSON() ([]byte, error)

MarshalJSON implements Marshaler

func (PostID) String added in v0.4.0

func (id PostID) String() string

String implements fmt.Stringer

func (*PostID) UnmarshalJSON added in v0.4.0

func (id *PostID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements Unmarshaler

type PostMedia added in v0.4.0

type PostMedia struct {
	URI      string `json:"uri"`
	MimeType string `json:"mime_type"`
}

PostMedia is a struct of a post media

func (PostMedia) Equals added in v0.4.0

func (pm PostMedia) Equals(other PostMedia) bool

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

type PostMedias added in v0.4.0

type PostMedias []PostMedia

func (PostMedias) Equals added in v0.4.0

func (pms PostMedias) Equals(other PostMedias) bool

Equals returns true iff the pms slice contains the same data in the same order of the other slice

type Reaction

type Reaction struct {
	Owner sdk.AccAddress `json:"owner"` // User that has created the reaction
	Value string         `json:"value"` // Value of the reaction
}

Reaction is a struct of a user reaction to a post

type UserAnswer added in v0.4.0

type UserAnswer struct {
	Answers []AnswerID     `json:"answers"`
	User    sdk.AccAddress `json:"user"`
}

UserAnswer contains the data of a user's answer submission to a post's poll

Jump to

Keyboard shortcuts

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