Bugfix with comments and blocked user IDs
This commit is contained in:
parent
b788480eb6
commit
ab7a823ad5
|
@ -1,6 +1,7 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.nonshy.com/nonshy/website/pkg/log"
|
||||
|
@ -71,11 +72,21 @@ func PaginateComments(user *User, tableName string, tableID uint64, pager *Pagin
|
|||
cs = []*Comment{}
|
||||
query = (&Comment{}).Preload()
|
||||
blockedUserIDs = BlockedUserIDs(user.ID)
|
||||
wheres = []string{}
|
||||
placeholders = []interface{}{}
|
||||
)
|
||||
|
||||
wheres = append(wheres, "table_name = ? AND table_id = ?")
|
||||
placeholders = append(placeholders, tableName, tableID)
|
||||
|
||||
if len(blockedUserIDs) > 0 {
|
||||
wheres = append(wheres, "user_id NOT IN ?")
|
||||
placeholders = append(placeholders, blockedUserIDs)
|
||||
}
|
||||
|
||||
query = query.Where(
|
||||
"table_name = ? AND table_id = ? AND user_id NOT IN ?",
|
||||
tableName, tableID, blockedUserIDs,
|
||||
strings.Join(wheres, " AND "),
|
||||
placeholders...,
|
||||
).Order(pager.Sort)
|
||||
|
||||
query.Model(&Comment{}).Count(&pager.Total)
|
||||
|
@ -92,10 +103,21 @@ func ListComments(user *User, tableName string, tableID uint64) ([]*Comment, err
|
|||
var (
|
||||
cs []*Comment
|
||||
blockedUserIDs = BlockedUserIDs(user.ID)
|
||||
wheres = []string{}
|
||||
placeholders = []interface{}{}
|
||||
)
|
||||
|
||||
wheres = append(wheres, "table_name = ? AND table_id = ?")
|
||||
placeholders = append(placeholders, tableName, tableID)
|
||||
|
||||
if len(blockedUserIDs) > 0 {
|
||||
wheres = append(wheres, "user_id NOT IN ?")
|
||||
placeholders = append(placeholders, blockedUserIDs)
|
||||
}
|
||||
|
||||
result := (&Comment{}).Preload().Where(
|
||||
"table_name = ? AND table_id = ? AND user_id NOT IN ?",
|
||||
tableName, tableID, blockedUserIDs,
|
||||
strings.Join(wheres, " AND "),
|
||||
placeholders...,
|
||||
).Order("created_at asc").Find(&cs)
|
||||
return cs, result.Error
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user