initial interface for notifications
This commit is contained in:
@@ -24,6 +24,7 @@ func NewLoadingCache(defaultExpiration, cleanupInterval time.Duration, postFlush
|
||||
return &loadingCache{bytesCache: cache.New(defaultExpiration, cleanupInterval), postFlushFn: postFlushFn}
|
||||
}
|
||||
|
||||
// Get is loading cache method to get value by key or load via fn if not found
|
||||
func (lc *loadingCache) Get(key string, ttl time.Duration, fn func() ([]byte, error)) (data []byte, err error) {
|
||||
if b, ok := lc.bytesCache.Get(key); ok {
|
||||
log.Printf("[DEBUG] cache hit %s", key)
|
||||
@@ -38,6 +39,7 @@ func (lc *loadingCache) Get(key string, ttl time.Duration, fn func() ([]byte, er
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Flush clears cache and calls postFlushFn async
|
||||
func (lc *loadingCache) Flush() {
|
||||
lc.bytesCache.Flush()
|
||||
if lc.postFlushFn != nil {
|
||||
|
||||
@@ -58,6 +58,12 @@ type BlockedUser struct {
|
||||
Timestamp time.Time `json:"time"`
|
||||
}
|
||||
|
||||
// NotifUser holds id and destination for notifiable user
|
||||
type NotifUser struct {
|
||||
ID string `json:"id"`
|
||||
Destination string `json:"destination"`
|
||||
}
|
||||
|
||||
// Sanitize clean dangerous html/js from the comment
|
||||
func (c *Comment) Sanitize() {
|
||||
p := bluemonday.UGCPolicy()
|
||||
|
||||
@@ -33,6 +33,23 @@ type Admin interface {
|
||||
Blocked(siteID string) ([]BlockedUser, error) // get list of blocked users
|
||||
}
|
||||
|
||||
// Notifier defines all store ops for update modifications
|
||||
type Notifier interface {
|
||||
Set(locator Locator, user NotifUser, scope NotifScope, status bool) error // subscribe / unsubscribe user to locator updates
|
||||
Status(locator Locator, userID string) bool // get subscription status for user & locator
|
||||
List(locator Locator) ([]NotifUser, error) // list all subscribed users
|
||||
}
|
||||
|
||||
// NotifScope defines "enum" of notification scopes
|
||||
type NotifScope int
|
||||
|
||||
// All NotifScope values
|
||||
const (
|
||||
ScopeSite NotifScope = 1
|
||||
ScopePost NotifScope = 2
|
||||
ScopeReply NotifScope = 3
|
||||
)
|
||||
|
||||
func sortComments(comments []Comment, sortFld string) []Comment {
|
||||
sort.Slice(comments, func(i, j int) bool {
|
||||
switch sortFld {
|
||||
|
||||
Reference in New Issue
Block a user