block list with ts
This commit is contained in:
+8
-4
@@ -312,8 +312,8 @@ func (b *BoltDB) IsBlocked(siteID string, userID string) (blocked bool) {
|
||||
}
|
||||
|
||||
// Blocked get lists of blocked users for given site
|
||||
func (b *BoltDB) Blocked(siteID string) (userIDs []string, err error) {
|
||||
userIDs = []string{}
|
||||
func (b *BoltDB) Blocked(siteID string) (users []BlockedUser, err error) {
|
||||
users = []BlockedUser{}
|
||||
bdb, err := b.db(siteID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -325,12 +325,16 @@ func (b *BoltDB) Blocked(siteID string) (userIDs []string, err error) {
|
||||
return nil
|
||||
}
|
||||
return bucket.ForEach(func(k []byte, v []byte) error {
|
||||
userIDs = append(userIDs, string(k))
|
||||
ts, err := time.ParseInLocation(time.RFC3339Nano, string(v), time.Local)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "can't parse block ts")
|
||||
}
|
||||
users = append(users, BlockedUser{ID: string(k), Timestamp: ts})
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
||||
return userIDs, err
|
||||
return users, err
|
||||
}
|
||||
|
||||
// List returns list of buckets, which is list of all commented posts
|
||||
|
||||
@@ -139,7 +139,11 @@ func TestBoltDB_BlockList(t *testing.T) {
|
||||
|
||||
ids, err := b.Blocked("radio-t")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []string{"user1", "user2"}, ids)
|
||||
|
||||
assert.Equal(t, 2, len(ids))
|
||||
assert.Equal(t, "user1", ids[0].ID)
|
||||
assert.Equal(t, "user2", ids[1].ID)
|
||||
t.Logf("%+v", ids)
|
||||
}
|
||||
|
||||
func TestBoltDB_List(t *testing.T) {
|
||||
|
||||
@@ -56,6 +56,12 @@ type PostInfo struct {
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
// BlockedUser holds id and ts for blocked user
|
||||
type BlockedUser struct {
|
||||
ID string `json:"id"`
|
||||
Timestamp time.Time `json:"time"`
|
||||
}
|
||||
|
||||
// GenID generates sha1(random) string
|
||||
func (c *Comment) GenID() error {
|
||||
b := make([]byte, 64)
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ type Admin interface {
|
||||
Delete(locator Locator, commentID string) error // delete comment by id
|
||||
SetBlock(siteID string, userID string, status bool) error // block or unblock user
|
||||
IsBlocked(siteID string, userID string) bool // check if user blocked
|
||||
Blocked(siteID string) (userIDs []string, err error) // get list of blocked users
|
||||
Blocked(siteID string) ([]BlockedUser, error) // get list of blocked users
|
||||
}
|
||||
|
||||
func sortComments(comments []Comment, sortFld string) []Comment {
|
||||
|
||||
Reference in New Issue
Block a user