Documentation ¶
Overview ¶
Package service wraps engine interfaces with common logic unrelated to any particular engine implementation. All consumers should be using service.DataStore and not the naked engine!
Index ¶
- Constants
- Variables
- type DataStore
- func (s *DataStore) BlockedUsers(siteID string) (res []store.BlockedUser, err error)
- func (s *DataStore) Close() error
- func (s *DataStore) Count(locator store.Locator) (int, error)
- func (s *DataStore) Counts(siteID string, postIDs []string) ([]store.PostInfo, error)
- func (s *DataStore) Create(comment store.Comment) (commentID string, err error)
- func (s *DataStore) Delete(locator store.Locator, commentID string, mode store.DeleteMode) error
- func (s *DataStore) DeleteAll(siteID string) error
- func (s *DataStore) DeleteUser(siteID string, userID string, mode store.DeleteMode) error
- func (s *DataStore) DeleteUserDetail(siteID string, userID string, detail engine.UserDetail) error
- func (s *DataStore) EditComment(locator store.Locator, commentID string, req EditRequest) (comment store.Comment, err error)
- func (s *DataStore) Find(locator store.Locator, sort string, user store.User) ([]store.Comment, error)
- func (s *DataStore) FindSince(locator store.Locator, sort string, user store.User, since time.Time) ([]store.Comment, error)
- func (s *DataStore) Get(locator store.Locator, commentID string, user store.User) (store.Comment, error)
- func (s *DataStore) GetUserEmail(siteID string, userID string) (string, error)
- func (s *DataStore) HasReplies(comment store.Comment) bool
- func (s *DataStore) Info(locator store.Locator, readonlyAge int) (store.PostInfo, error)
- func (s *DataStore) IsAdmin(siteID string, userID string) bool
- func (s *DataStore) IsBlocked(siteID string, userID string) bool
- func (s *DataStore) IsReadOnly(locator store.Locator) bool
- func (s *DataStore) IsVerified(siteID string, userID string) bool
- func (s *DataStore) Last(siteID string, limit int, since time.Time, user store.User) ([]store.Comment, error)
- func (s *DataStore) List(siteID string, limit int, skip int) ([]store.PostInfo, error)
- func (s *DataStore) Metas(siteID string) (umetas []UserMetaData, pmetas []PostMetaData, err error)
- func (s *DataStore) Put(locator store.Locator, comment store.Comment) error
- func (s *DataStore) ResubmitStagingImages(sites []string) error
- func (s *DataStore) SetBlock(siteID string, userID string, status bool, ttl time.Duration) error
- func (s *DataStore) SetMetas(siteID string, umetas []UserMetaData, pmetas []PostMetaData) (err error)
- func (s *DataStore) SetPin(locator store.Locator, commentID string, status bool) error
- func (s *DataStore) SetReadOnly(locator store.Locator, status bool) error
- func (s *DataStore) SetTitle(locator store.Locator, commentID string) (comment store.Comment, err error)
- func (s *DataStore) SetUserEmail(siteID string, userID string, value string) (string, error)
- func (s *DataStore) SetVerified(siteID string, userID string, status bool) error
- func (s *DataStore) User(siteID, userID string, limit, skip int, user store.User) ([]store.Comment, error)
- func (s *DataStore) UserCount(siteID, userID string) (int, error)
- func (s *DataStore) UserReplies(siteID, userID string, limit int, duration time.Duration) ([]store.Comment, string, error)
- func (s *DataStore) ValidateComment(c *store.Comment) error
- func (s *DataStore) Vote(req VoteReq) (comment store.Comment, err error)
- type EditRequest
- type Node
- type PostMetaData
- type RestrictedWordsLister
- type RestrictedWordsMatcher
- type StaticRestrictedWordsLister
- type TitleExtractor
- type Tree
- type UserMetaData
- type VoteReq
Constants ¶
const UnlimitedVotes = -1
UnlimitedVotes doesn't restrict MaxVotes
Variables ¶
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 engine.Interface EditDuration time.Duration AdminStore admin.Store MaxCommentSize int MaxVotes int RestrictSameIPVotes struct { Enabled bool Duration time.Duration } PositiveScore bool TitleExtractor *TitleExtractor RestrictedWordsMatcher *RestrictedWordsMatcher ImageService *image.Service // contains filtered or unexported fields }
DataStore wraps store.Interface with additional methods
func (*DataStore) BlockedUsers ¶ added in v1.5.0
func (s *DataStore) BlockedUsers(siteID string) (res []store.BlockedUser, err error)
BlockedUsers returns list with all blocked users for given siteID
func (*DataStore) DeleteUser ¶ added in v1.4.0
DeleteUser removes all comments from user
func (*DataStore) DeleteUserDetail ¶ added in v1.5.0
DeleteUserDetail deletes user detail
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) Find ¶
func (s *DataStore) Find(locator store.Locator, sort string, user store.User) ([]store.Comment, error)
Find wraps engine's Find call and alter results if needed. User used to alter comments in order to differentiate between user's comments vs others comments.
func (*DataStore) FindSince ¶ added in v1.4.0
func (s *DataStore) FindSince(locator store.Locator, sort string, user store.User, since time.Time) ([]store.Comment, error)
FindSince wraps engine's Find call and alter results if needed. Returns comments after since tx
func (*DataStore) Get ¶ added in v1.4.0
func (s *DataStore) Get(locator store.Locator, commentID string, user store.User) (store.Comment, error)
Get comment by ID
func (*DataStore) GetUserEmail ¶ added in v1.5.0
GetUserEmail gets user email
func (*DataStore) HasReplies ¶
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) IsReadOnly ¶ added in v1.4.0
IsReadOnly checks if post read-only
func (*DataStore) IsVerified ¶ added in v1.4.0
IsVerified checks if user verified
func (*DataStore) Last ¶ added in v1.4.0
func (s *DataStore) Last(siteID string, limit int, since time.Time, user store.User) ([]store.Comment, error)
Last gets last comments for site, cross-post. Limited by count and optional since ts
func (*DataStore) Metas ¶
func (s *DataStore) Metas(siteID string) (umetas []UserMetaData, pmetas []PostMetaData, err error)
Metas returns metadata for users and posts
func (*DataStore) ResubmitStagingImages ¶ added in v1.6.0
ResubmitStagingImages retrieves timestamp of the oldest image in staging and calls s.submitImages on all comments newer than it
func (*DataStore) SetMetas ¶
func (s *DataStore) SetMetas(siteID string, umetas []UserMetaData, pmetas []PostMetaData) (err error)
SetMetas saves metadata for users and posts
func (*DataStore) SetReadOnly ¶ added in v1.4.0
SetReadOnly set/reset read-only flag
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) SetUserEmail ¶ added in v1.5.0
SetUserEmail sets user email
func (*DataStore) SetVerified ¶ added in v1.4.0
SetVerified set/reset verified status for user
func (*DataStore) User ¶ added in v1.4.0
func (s *DataStore) User(siteID, userID string, limit, skip int, user store.User) ([]store.Comment, error)
User gets comment for given userID on siteID
func (*DataStore) UserReplies ¶ added in v1.4.0
func (s *DataStore) UserReplies(siteID, userID string, limit int, duration time.Duration) ([]store.Comment, string, error)
UserReplies returns list of all comments replied to given user
func (*DataStore) ValidateComment ¶
ValidateComment checks if comment size below max and user fields set
type EditRequest ¶
EditRequest contains fields needed for comment update
type Node ¶ added in v1.4.0
type Node struct { Comment store.Comment `json:"comment"` Replies []*Node `json:"replies,omitempty"` // contains filtered or unexported fields }
Node is a comment with optional replies
type PostMetaData ¶
PostMetaData keeps info about post flags
type RestrictedWordsLister ¶
RestrictedWordsLister provides restricted words in comments per site
type RestrictedWordsMatcher ¶
type RestrictedWordsMatcher struct {
// contains filtered or unexported fields
}
RestrictedWordsMatcher matches comment text against restricted words
func NewRestrictedWordsMatcher ¶
func NewRestrictedWordsMatcher(lister RestrictedWordsLister) *RestrictedWordsMatcher
NewRestrictedWordsMatcher creates new RestrictedWordsMatcher using provided RestrictedWordsLister
type StaticRestrictedWordsLister ¶
type StaticRestrictedWordsLister struct {
Words []string
}
StaticRestrictedWordsLister provides same restricted words in comments for every site
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
type Tree ¶ added in v1.4.0
Tree is formatter making tree from the list of comments
func MakeTree ¶ added in v1.4.0
MakeTree gets unsorted list of comments and produces Tree It will make store.PostInfo by itself and will mark Info.ReadOnly based on passed readOnlyAge Tree maker is local and has no access to the data store. By this reason it has to make Info and won't be able to handle store's read-only status. This status should be set by caller.
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"` Details engine.UserDetailEntry `json:"details,omitempty"` }
UserMetaData keeps info about user flags and details