Documentation ¶
Index ¶
- Constants
- Variables
- func GetReactionShortCodeFromValue(originalValue string) (string, error)
- func MigratePostReactions(postReactions map[string][]v030posts.Reaction, posts []v030posts.Post) (map[string][]PostReaction, error)
- func MigrateUsersAnswers(usersAnswersMap map[string][]v030posts.UserAnswer, posts []v030posts.Post) (map[string][]UserAnswer, error)
- type AnswerID
- type GenesisState
- type OptionalData
- type PollAnswer
- type PollData
- type Post
- type PostID
- type PostMedia
- type PostReaction
- type Reaction
- type UserAnswer
Constants ¶
const (
ModuleName = "posts"
)
Variables ¶
var (
Sha256RegEx = regexp.MustCompile(`^[a-fA-F0-9]{64}$`)
)
Functions ¶
func GetReactionShortCodeFromValue ¶
GetReactionShortCodeFromValue retrieves the shortcode that should be associated to the reaction having the given value
func MigratePostReactions ¶
func MigratePostReactions( postReactions map[string][]v030posts.Reaction, posts []v030posts.Post, ) (map[string][]PostReaction, error)
MigratePostReactions takes a map of v0.3.0 Reaction objects and migrates them to a v0.4.0 map of Reaction objects.
func MigrateUsersAnswers ¶
func MigrateUsersAnswers( usersAnswersMap map[string][]v030posts.UserAnswer, posts []v030posts.Post, ) (map[string][]UserAnswer, error)
MigrateUsersAnswers takes a slice of v0.3.0 UsersAnswers object and migrates them to v0.4.0 UserAnswers
Types ¶
type GenesisState ¶
type GenesisState struct { Posts []Post `json:"posts"` UsersPollAnswers map[string][]UserAnswer `json:"users_poll_answers"` PostReactions map[string][]PostReaction `json:"post_reactions"` RegisteredReactions []Reaction `json:"registered_reactions"` }
GenesisState contains the data of a v0.4.0 genesis state for the posts module
func Migrate ¶
func Migrate(oldGenState v030posts.GenesisState) GenesisState
Migrate accepts exported genesis state from v0.3.0 and migrates it to v0.4.0 genesis state. This migration changes the way posts IDs are specified from a simple uint64 to a sha-256 hashed string
type OptionalData ¶
OptionalData represents a Posts' optional data and allows for custom Amino and JSON serialization and deserialization.
type PollAnswer ¶
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
type PollData ¶
type PollData struct { Question string `json:"question"` // Describes what poll is about ProvidedAnswers []PollAnswer `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 MigratePollData ¶ added in v0.5.0
MigrateMedias takes the given v030 poll data and converts it into a v040 poll data
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 []PostMedia `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 MigratePosts ¶
MigratePosts takes a slice of v0.3.0 Post object and migrates them to v0.4.0 Post. For each post, its id is converted from an uint64 representation to a SHA-256 string representation.
type PostID ¶
type PostID string
PostID represents a unique post id
func ComputeID ¶
ComputeID returns a sha256 hash of the given data concatenated together nolint: interfacer
func ComputeParentID ¶
ComputeParentID get the post related to the given parentID if exists and returns it computed ID. Returns "" otherwise
type PostMedia ¶
PostMedia is a struct of a post media
func MigrateMedias ¶ added in v0.5.0
MigrateMedias takes the given v030 medias and converts them into a v040 medias array
type PostReaction ¶
type PostReaction struct { Owner sdk.AccAddress `json:"owner"` // Creator that has created the reaction Value string `json:"value"` // PostReaction of the reaction }
PostReaction is a struct of a user reaction to a post
func RemoveDuplicatedReactions ¶
func RemoveDuplicatedReactions(reactions []PostReaction) (reacts []PostReaction)
RemoveDuplicatedReactions removes all the duplicated reactions present inside the given slice, returning a new one without such duplicates
type Reaction ¶
type Reaction struct { ShortCode string `json:"shortcode" yaml:"shortcode"` Value string `json:"value" yaml:"value"` Subspace string `json:"subspace" yaml:"subspace"` Creator sdk.AccAddress `json:"creator" yaml:"creator"` }
Reaction represents a registered reaction that can be referenced by its shortCode inside post reactions
func GetReactionsToRegister ¶
func GetReactionsToRegister( posts []Post, postReactions map[string][]PostReaction, ) (reactionsToRegister []Reaction, error error)
GetReactionsToRegister takes the list of posts that exist and the map of all the added reactions and returns a list of reactions that should be registered.
type UserAnswer ¶
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