comments

package
v0.0.0-...-d78814b Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ListDBName = "comments/mailing-list"

ListDBName is the path to the singleton mailing list manager.

Variables

DB is a reference to the parent app's JsonDB object.

Functions

This section is empty.

Types

type ByCreated

type ByCreated []*Comment

func (ByCreated) Len

func (a ByCreated) Len() int

func (ByCreated) Less

func (a ByCreated) Less(i, j int) bool

func (ByCreated) Swap

func (a ByCreated) Swap(i, j int)

type Comment

type Comment struct {
	ID          string    `json:"id"`
	UserID      int       `json:"userId,omitempty"`
	Name        string    `json:"name,omitempty"`
	Email       string    `json:"email,omitempty"`
	Avatar      string    `json:"avatar"`
	Body        string    `json:"body"`
	EditToken   string    `json:"editToken"`
	DeleteToken string    `json:"deleteToken"`
	Created     time.Time `json:"created"`
	Updated     time.Time `json:"updated"`

	// Private form use only.
	CSRF      string        `json:"-"`
	Subscribe bool          `json:"-"`
	ThreadID  string        `json:"-"`
	OriginURL string        `json:"-"`
	Subject   string        `json:"-"`
	HTML      template.HTML `json:"-"`
	Trap1     string        `json:"-"`
	Trap2     string        `json:"-"`

	// Even privater fields.
	IsAuthenticated bool   `json:"-"`
	Username        string `json:"-"`
	Editable        bool   `json:"-"`
	Editing         bool   `json:"-"`
}

Comment contains the data for a single comment in a thread.

func (*Comment) LoadAvatar

func (c *Comment) LoadAvatar()

LoadAvatar calculates the user's avatar for the comment.

func (*Comment) ParseForm

func (c *Comment) ParseForm(r *http.Request)

ParseForm populates a Comment from a form.

func (*Comment) Validate

func (c *Comment) Validate() error

Validate checks the comment's fields for validity.

type MailingList

type MailingList struct {
	Threads map[string]Subscription
}

MailingList manages subscription data for all comment threads.

func LoadMailingList

func LoadMailingList() *MailingList

LoadMailingList loads the mailing list, or initializes it if it doesn't exist.

func (*MailingList) List

func (m *MailingList) List(thread string) []string

List the subscribers for a thread.

func (*MailingList) Subscribe

func (m *MailingList) Subscribe(thread, email string) error

Subscribe to a comment thread.

func (*MailingList) Unsubscribe

func (m *MailingList) Unsubscribe(thread, email string) bool

Unsubscribe from a comment thread. Returns true if the removal was successful; false indicates the email was not subscribed.

func (*MailingList) UnsubscribeAll

func (m *MailingList) UnsubscribeAll(email string) bool

UnsubscribeAll removes the email from all mailing lists.

type Subscription

type Subscription struct {
	Emails map[string]bool
}

Subscription is the data for a single thread's subscribers.

type Thread

type Thread struct {
	ID       string     `json:"id"`
	Comments []*Comment `json:"comments"`
}

Thread contains a thread of comments, for a blog post or otherwise.

func Load

func Load(id string) (Thread, error)

Load a comment thread.

func New

func New(id string) Thread

New initializes a new comment thread.

func (*Thread) Delete

func (t *Thread) Delete(id string) error

Delete a comment by its ID.

func (*Thread) Find

func (t *Thread) Find(id string) (*Comment, error)

Find a comment by its ID.

func (*Thread) FindByDeleteToken

func (t *Thread) FindByDeleteToken(token string) (*Comment, error)

FindByDeleteToken finds a comment by its deletion token.

func (*Thread) Post

func (t *Thread) Post(c *Comment) error

Post a comment to a thread.

Jump to

Keyboard shortcuts

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