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