service

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 20 Imported by: 30

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

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              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) Close added in v1.4.0

func (s *DataStore) Close() error

Close store service

func (*DataStore) Count added in v1.4.0

func (s *DataStore) Count(locator store.Locator) (int, error)

Count gets number of comments for the post

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) Delete added in v1.4.0

func (s *DataStore) Delete(locator store.Locator, commentID string, mode store.DeleteMode) error

Delete comment by id

func (*DataStore) DeleteAll added in v1.4.0

func (s *DataStore) DeleteAll(siteID string) error

DeleteAll removes all data from site

func (*DataStore) DeleteUser added in v1.4.0

func (s *DataStore) DeleteUser(siteID string, userID string, mode store.DeleteMode) error

DeleteUser removes all comments from user

func (*DataStore) DeleteUserDetail added in v1.5.0

func (s *DataStore) DeleteUserDetail(siteID string, userID string, detail engine.UserDetail) error

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

func (s *DataStore) GetUserEmail(siteID string, userID string) (string, error)

GetUserEmail gets user email

func (*DataStore) HasReplies

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) Info added in v1.4.0

func (s *DataStore) Info(locator store.Locator, readonlyAge int) (store.PostInfo, error)

Info get post info

func (*DataStore) IsAdmin

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

IsAdmin checks if usesID in the list of admins

func (*DataStore) IsBlocked added in v1.4.0

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

IsBlocked checks if user blocked

func (*DataStore) IsReadOnly added in v1.4.0

func (s *DataStore) IsReadOnly(locator store.Locator) bool

IsReadOnly checks if post read-only

func (*DataStore) IsVerified added in v1.4.0

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

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) List added in v1.4.0

func (s *DataStore) List(siteID string, limit int, skip int) ([]store.PostInfo, error)

List of commented posts

func (*DataStore) Metas

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

Metas returns metadata for users and posts

func (*DataStore) Put added in v1.4.0

func (s *DataStore) Put(locator store.Locator, comment store.Comment) error

Put updates comment, mutable parts only

func (*DataStore) ResubmitStagingImages added in v1.6.0

func (s *DataStore) ResubmitStagingImages(sites []string) error

ResubmitStagingImages retrieves timestamp of the oldest image in staging and calls s.submitImages on all comments newer than it

func (*DataStore) SetBlock added in v1.4.0

func (s *DataStore) SetBlock(siteID string, userID string, status bool, ttl time.Duration) error

SetBlock set/reset verified status for user

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) SetReadOnly added in v1.4.0

func (s *DataStore) SetReadOnly(locator store.Locator, status bool) error

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

func (s *DataStore) SetUserEmail(siteID string, userID string, value string) (string, error)

SetUserEmail sets user email

func (*DataStore) SetVerified added in v1.4.0

func (s *DataStore) SetVerified(siteID string, userID string, status bool) error

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) UserCount added in v1.4.0

func (s *DataStore) UserCount(siteID, userID string) (int, error)

UserCount is comments count by user

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

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(req VoteReq) (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 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

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

PostMetaData keeps info about post flags

type RestrictedWordsLister

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

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

func (*RestrictedWordsMatcher) Match

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

Match matches comment text against restricted words for specified site

type StaticRestrictedWordsLister

type StaticRestrictedWordsLister struct {
	Words []string
}

StaticRestrictedWordsLister provides same restricted words in comments for every site

func (StaticRestrictedWordsLister) List

func (l StaticRestrictedWordsLister) List(_ 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 Tree added in v1.4.0

type Tree struct {
	Nodes []*Node        `json:"comments"`
	Info  store.PostInfo `json:"info,omitempty"`
}

Tree is formatter making tree from the list of comments

func MakeTree added in v1.4.0

func MakeTree(comments []store.Comment, sortType string, readOnlyAge int) *Tree

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

type VoteReq added in v1.5.0

type VoteReq struct {
	Locator   store.Locator
	CommentID string
	UserID    string
	UserIP    string
	Val       bool
}

VoteReq is the request ot make a vote

Jump to

Keyboard shortcuts

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