Change GetPosts() to have includePinned parameter, change all calls to match

This commit is contained in:
Noëlle Anthony 2019-05-28 14:54:56 -04:00
parent b6da5d9711
commit 95e84a1d0e
6 changed files with 13 additions and 9 deletions

View File

@ -127,7 +127,7 @@ func handleFetchCollectionOutbox(app *app, w http.ResponseWriter, r *http.Reques
ocp := activitystreams.NewOrderedCollectionPage(accountRoot, "outbox", res.TotalPosts, p)
ocp.OrderedItems = []interface{}{}
posts, err := app.db.GetPosts(c, p, false, true)
posts, err := app.db.GetPosts(c, p, false, true, false)
for _, pp := range *posts {
pp.Collection = res
o := pp.ActivityObject()

View File

@ -492,7 +492,7 @@ func fetchCollectionPosts(app *app, w http.ResponseWriter, r *http.Request) erro
}
}
posts, err := app.db.GetPosts(c, page, isCollOwner, false)
posts, err := app.db.GetPosts(c, page, isCollOwner, false, false)
if err != nil {
return err
}
@ -723,7 +723,7 @@ func handleViewCollection(app *app, w http.ResponseWriter, r *http.Request) erro
return impart.HTTPError{http.StatusFound, redirURL}
}
coll.Posts, _ = app.db.GetPosts(c, page, cr.isCollOwner, false)
coll.Posts, _ = app.db.GetPosts(c, page, cr.isCollOwner, false, false)
// Serve collection
displayPage := CollectionPage{

View File

@ -104,7 +104,7 @@ type writestore interface {
ClaimPosts(userID int64, collAlias string, posts *[]ClaimPostRequest) (*[]ClaimPostResult, error)
GetPostsCount(c *CollectionObj, includeFuture bool)
GetPosts(c *Collection, page int, includeFuture, forceRecentFirst bool) (*[]PublicPost, error)
GetPosts(c *Collection, page int, includeFuture, forceRecentFirst, includePinned bool) (*[]PublicPost, error)
GetPostsTagged(c *Collection, tag string, page int, includeFuture bool) (*[]PublicPost, error)
GetAPFollowers(c *Collection) (*[]RemoteUser, error)
@ -1065,7 +1065,7 @@ func (db *datastore) GetPostsCount(c *CollectionObj, includeFuture bool) {
// GetPosts retrieves all standard (non-pinned) posts for the given Collection.
// It will return future posts if `includeFuture` is true.
// TODO: change includeFuture to isOwner, since that's how it's used
func (db *datastore) GetPosts(c *Collection, page int, includeFuture, forceRecentFirst bool) (*[]PublicPost, error) {
func (db *datastore) GetPosts(c *Collection, page int, includeFuture, forceRecentFirst, includePinned bool) (*[]PublicPost, error) {
collID := c.ID
cf := c.NewFormat()
@ -1089,7 +1089,11 @@ func (db *datastore) GetPosts(c *Collection, page int, includeFuture, forceRecen
if !includeFuture {
timeCondition = "AND created <= " + db.now()
}
rows, err := db.Query("SELECT "+postCols+" FROM posts WHERE collection_id = ? AND pinned_position IS NULL "+timeCondition+" ORDER BY created "+order+limitStr, collID)
pinnedCondition := ""
if !includePinned {
pinnedCondition = "AND pinned_position IS NULL"
}
rows, err := db.Query("SELECT "+postCols+" FROM posts WHERE collection_id = ? "+pinnedCondition+" "+timeCondition+" ORDER BY created "+order+limitStr, collID)
if err != nil {
log.Error("Failed selecting from posts: %v", err)
return nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't retrieve collection posts."}

View File

@ -111,7 +111,7 @@ func compileFullExport(app *app, u *User) *ExportUser {
var collObjs []CollectionObj
for _, c := range *colls {
co := &CollectionObj{Collection: c}
co.Posts, err = app.db.GetPosts(&c, 0, true, false)
co.Posts, err = app.db.GetPosts(&c, 0, true, false, true)
if err != nil {
log.Error("unable to get collection posts: %v", err)
}

View File

@ -56,7 +56,7 @@ func ViewFeed(app *app, w http.ResponseWriter, req *http.Request) error {
if tag != "" {
coll.Posts, _ = app.db.GetPostsTagged(c, tag, 1, false)
} else {
coll.Posts, _ = app.db.GetPosts(c, 1, false, true)
coll.Posts, _ = app.db.GetPosts(c, 1, false, true, false)
}
author := ""

View File

@ -64,7 +64,7 @@ func handleViewSitemap(app *app, w http.ResponseWriter, r *http.Request) error {
host = c.CanonicalURL()
sm := buildSitemap(host, pre)
posts, err := app.db.GetPosts(c, 0, false, false)
posts, err := app.db.GetPosts(c, 0, false, false, false)
if err != nil {
log.Error("Error getting posts: %v", err)
return err