service

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const UnlimitedVotes = -1

UnlimitedVotes doesn't restrict MaxVotes

Variables

View Source
var ErrRestrictedWordsFound = errors.New("comment contains restricted words")

ErrRestrictedWordsFound returned in case comment text contains restricted words

Functions

This section is empty.

Types

type DataStore

type DataStore struct {
	engine.Interface
	EditDuration           time.Duration
	AdminStore             admin.Store
	MaxCommentSize         int
	MaxVotes               int
	TitleExtractor         *TitleExtractor
	RestrictedWordsMatcher *RestrictedWordsMatcher
	// contains filtered or unexported fields
}

DataStore wraps store.Interface with additional methods

func (*DataStore) Counts

func (s *DataStore) Counts(siteID string, postIDs []string) ([]store.PostInfo, error)

Counts returns postID+count list for given comments

func (*DataStore) Create

func (s *DataStore) Create(comment store.Comment) (commentID string, err error)

Create prepares comment and forward to Interface.Create

func (*DataStore) EditComment

func (s *DataStore) EditComment(locator store.Locator, commentID string, req EditRequest) (comment store.Comment, err error)

EditComment to edit text and update Edit info

func (*DataStore) HasReplies added in v1.2.0

func (s *DataStore) HasReplies(comment store.Comment) bool

HasReplies checks if there is any reply to the comments Loads last maxLastCommentsReply comments and compare parent id to the comment's id Comments with replies cached for 5 minutes

func (*DataStore) IsAdmin

func (s *DataStore) IsAdmin(siteID string, userID string) bool

IsAdmin checks if usesID in the list of admins

func (*DataStore) Metas

func (s *DataStore) Metas(siteID string) (umetas []UserMetaData, pmetas []PostMetaData, err error)

Metas returns metadata for users and posts

func (*DataStore) SetMetas

func (s *DataStore) SetMetas(siteID string, umetas []UserMetaData, pmetas []PostMetaData) (err error)

SetMetas saves metadata for users and posts

func (*DataStore) SetPin

func (s *DataStore) SetPin(locator store.Locator, commentID string, status bool) error

SetPin pin/un-pin comment as special

func (*DataStore) SetTitle

func (s *DataStore) SetTitle(locator store.Locator, commentID string) (comment store.Comment, err error)

SetTitle puts title from the locator.URL page and overwrites any existing title

func (*DataStore) ValidateComment

func (s *DataStore) ValidateComment(c *store.Comment) error

ValidateComment checks if comment size below max and user fields set

func (*DataStore) Vote

func (s *DataStore) Vote(locator store.Locator, commentID string, userID string, val bool) (comment store.Comment, err error)

Vote for comment by id and locator

type EditRequest

type EditRequest struct {
	Text    string
	Orig    string
	Summary string
	Delete  bool
}

EditRequest contains fields needed for comment update

type PostMetaData

type PostMetaData struct {
	URL      string `json:"url"`
	ReadOnly bool   `json:"read_only"`
}

PostMetaData keeps info about post flags

type RestrictedWordsLister added in v1.2.0

type RestrictedWordsLister interface {
	List(siteID string) (restricted []string, err error)
}

RestrictedWordsLister provides restricted words in comments per site

type RestrictedWordsMatcher added in v1.2.0

type RestrictedWordsMatcher struct {
	// contains filtered or unexported fields
}

RestrictedWordsMatcher matches comment text against restricted words

func NewRestrictedWordsMatcher added in v1.2.0

func NewRestrictedWordsMatcher(lister RestrictedWordsLister) *RestrictedWordsMatcher

NewRestrictedWordsMatcher creates new RestrictedWordsMatcher using provided RestrictedWordsLister

func (*RestrictedWordsMatcher) Match added in v1.2.0

func (m *RestrictedWordsMatcher) Match(siteID string, text string) bool

Match matches comment text against restricted words for specified site

type StaticRestrictedWordsLister added in v1.2.0

type StaticRestrictedWordsLister struct {
	Words []string
}

StaticRestrictedWordsLister provides same restricted words in comments for every site

func (StaticRestrictedWordsLister) List added in v1.2.0

func (l StaticRestrictedWordsLister) List(siteID string) (restricted []string, err error)

List provides restricted words in comments (ignores siteID)

type TitleExtractor

type TitleExtractor struct {
	// contains filtered or unexported fields
}

TitleExtractor gets html title from remote page, cached

func NewTitleExtractor

func NewTitleExtractor(client http.Client) *TitleExtractor

NewTitleExtractor makes extractor with cache. If memory cache failed, switching to no-cache

func (*TitleExtractor) Get

func (t *TitleExtractor) Get(url string) (string, error)

Get page for url and return title

type UserMetaData

type UserMetaData struct {
	ID      string `json:"id"`
	Blocked struct {
		Status bool      `json:"status"`
		Until  time.Time `json:"until"`
	} `json:"blocked"`
	Verified bool `json:"verified"`
}

UserMetaData keeps info about user flags

Jump to

Keyboard shortcuts

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