poll

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SettingKeyAnonymous       = "anonymous"
	SettingKeyProgress        = "progress"
	SettingKeyPublicAddOption = "public-add-option"
)
View Source
const (
	// MatterpollAdminButtonType is action_type of buttons that are used for managing a poll.
	MatterpollAdminButtonType = "custom_matterpoll_admin_button"
)

Variables

This section is empty.

Functions

func NewPoll

func NewPoll(creator, question string, answerOptions []string, settings Settings) (*Poll, *ErrorMessage)

NewPoll creates a new poll with the given parameter.

func NewSettingsFromStrings added in v1.4.0

func NewSettingsFromStrings(strs []string) (Settings, *ErrorMessage)

NewSettingsFromStrings creates a new settings with the given parameter.

Types

type AnswerOption

type AnswerOption struct {
	Answer string
	Voter  []string
}

AnswerOption stores a possible answer and a list of user who voted for this

type ErrorMessage added in v1.3.0

type ErrorMessage struct {
	Message *i18n.Message
	Data    map[string]interface{}
}

ErrorMessage contains error messsage for a user that can be localized. It should not be wrapped and instead always returned.

type IDToNameConverter added in v1.3.0

type IDToNameConverter func(userID string) (string, *model.AppError)

IDToNameConverter converts a given userID to a human readable name.

type Metadata added in v1.4.0

type Metadata struct {
	VotedAnswers           []string `json:"voted_answers"` // VotedAnswers is list of answer that the user with "UserID" have voted for the poll with "PollID"
	PollID                 string   `json:"poll_id"`
	UserID                 string   `json:"user_id"`
	AdminPermission        bool     `json:"admin_permission"` // AdminPermission will be true if the user with "UserID" has admin permission for the poll with "PollID", otherwise false.
	SettingPublicAddOption bool     `json:"setting_public_add_option"`
}

Metadata stores personalized metadata of a poll.

func (*Metadata) ToMap added in v1.4.0

func (m *Metadata) ToMap() map[string]interface{}

ToMap returns a Metadata as a map

type Poll

type Poll struct {
	ID            string
	PostID        string `json:"post_id,omitempty"`
	CreatedAt     int64
	Creator       string
	Question      string
	AnswerOptions []*AnswerOption
	Settings      Settings
}

Poll stores all needed information for a poll

func DecodePollFromByte

func DecodePollFromByte(b []byte) *Poll

DecodePollFromByte tries to create a poll from a byte array

func (*Poll) AddAnswerOption added in v1.1.0

func (p *Poll) AddAnswerOption(newAnswerOption string) *ErrorMessage

AddAnswerOption adds a new AnswerOption to a poll

func (*Poll) Copy

func (p *Poll) Copy() *Poll

Copy deep copies a poll

func (*Poll) EncodeToByte

func (p *Poll) EncodeToByte() []byte

EncodeToByte returns a poll as a byte array

func (*Poll) GetMetadata added in v1.4.0

func (p *Poll) GetMetadata(userID string, permission bool) *Metadata

GetMetadata returns personalized metadata of a poll.

func (*Poll) GetVotedAnswers added in v1.4.0

func (p *Poll) GetVotedAnswers(userID string) []string

GetVotedAnswers collect voted answers by a user and returns it as string array.

func (*Poll) HasVoted

func (p *Poll) HasVoted(userID string) bool

HasVoted return true if a given user has voted in this poll

func (*Poll) IsMultiVote added in v1.4.0

func (p *Poll) IsMultiVote() bool

IsMultiVote return true if poll is set to multi vote

func (*Poll) ResetVotes added in v1.4.0

func (p *Poll) ResetVotes(userID string)

ResetVotes remove votes by a given user

func (*Poll) ToEndPollPost

func (p *Poll) ToEndPollPost(localizer *i18n.Localizer, authorName string, convert IDToNameConverter) (*model.Post, *model.AppError)

ToEndPollPost returns the poll end message

func (*Poll) ToPostActions

func (p *Poll) ToPostActions(localizer *i18n.Localizer, pluginID, authorName string) []*model.SlackAttachment

ToPostActions returns the poll as a message

func (*Poll) UpdateVote

func (p *Poll) UpdateVote(userID string, index int) (*i18n.Message, error)

UpdateVote performs a vote for a given user

type Settings added in v1.2.0

type Settings struct {
	Anonymous       bool
	Progress        bool
	PublicAddOption bool
	MaxVotes        int `json:"max_votes"`
}

Settings stores possible settings for a poll

func NewSettingsFromSubmission added in v1.4.0

func NewSettingsFromSubmission(submission map[string]interface{}) Settings

NewSettingsFromSubmission creates a new settings with the given parameter.

Jump to

Keyboard shortcuts

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