diff --git a/app/rest/cache.go b/app/rest/cache.go index a85227e0..37f62706 100644 --- a/app/rest/cache.go +++ b/app/rest/cache.go @@ -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 { diff --git a/app/store/comment.go b/app/store/comment.go index 58b79925..ebdd5df0 100644 --- a/app/store/comment.go +++ b/app/store/comment.go @@ -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() diff --git a/app/store/store.go b/app/store/store.go index 551ae62e..d4753c37 100644 --- a/app/store/store.go +++ b/app/store/store.go @@ -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 {