service

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 20 Imported by: 0

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 = fmt.Errorf("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
	AdminEdits             bool // allow admin unlimited edits
	// contains filtered or unexported fields
}

DataStore wraps store.Interface with additional methods

func (*DataStore) BlockedUsers

func (s *DataStore) BlockedUsers(siteID string) (res []store.BlockedUser, err error)

BlockedUsers returns list with all blocked users for given siteID

func (*DataStore) Close

func (s *DataStore) Close() error

Close store service

func (*DataStore) Count

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

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

Delete comment by id

func (*DataStore) DeleteAll

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

DeleteAll removes all data from site

func (*DataStore) DeleteUser

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

DeleteUser removes all comments from user

func (*DataStore) DeleteUserDetail

func (s *DataStore) DeleteUserDetail(siteID, 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, sortMethod 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

func (s *DataStore) FindSince(locator store.Locator, sortMethod 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

func (s *DataStore) Get(locator store.Locator, commentID string, user store.User) (store.Comment, error)

Get comment by ID

func (*DataStore) GetUserEmail

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

GetUserEmail gets user email

func (*DataStore) GetUserTelegram added in v1.9.0

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

GetUserTelegram gets user telegram

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

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

Info get post info

func (*DataStore) IsAdmin

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

IsAdmin checks if usesID in the list of admins

func (*DataStore) IsBlocked

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

IsBlocked checks if user blocked

func (*DataStore) IsReadOnly

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

IsReadOnly checks if post read-only

func (*DataStore) IsVerified

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

IsVerified checks if user verified

func (*DataStore) Last

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

func (s *DataStore) List(siteID string, limit, 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

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

Put updates comment, mutable parts only

func (*DataStore) ResubmitStagingImages

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

func (s *DataStore) SetBlock(siteID, 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

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

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

SetUserEmail sets user email

func (*DataStore) SetUserTelegram added in v1.9.0

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

SetUserTelegram sets user telegram

func (*DataStore) SetVerified

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

SetVerified set/reset verified status for user

func (*DataStore) User

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

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

UserCount is comments count by user

func (*DataStore) UserReplies

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. It also validates the absence of relative links as they are almost never the intention of the commenter, usually added by mistakes and only create confusion.

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
	Admin   bool
}

EditRequest contains fields needed for comment update

type Node

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, 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) Close

func (t *TitleExtractor) Close() error

Close title extractor

func (*TitleExtractor) Get

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

Get page for url and return title

type Tree

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

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

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