mirror of
https://github.com/writefreely/writefreely
synced 2024-11-24 09:33:11 +00:00
prevent future posts from showing in pins
this changes GetPinnedPosts to accept an includeFutre bool, which returns future dated pinned posts when true.
This commit is contained in:
parent
8557119451
commit
b373aad298
4 changed files with 27 additions and 7 deletions
|
@ -769,6 +769,7 @@ func handleViewCollection(app *App, w http.ResponseWriter, r *http.Request) erro
|
||||||
displayPage.Collections = pubColls
|
displayPage.Collections = pubColls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
isOwner := owner != nil
|
||||||
if owner == nil {
|
if owner == nil {
|
||||||
// Current user doesn't own collection; retrieve owner information
|
// Current user doesn't own collection; retrieve owner information
|
||||||
owner, err = app.db.GetUserByID(coll.OwnerID)
|
owner, err = app.db.GetUserByID(coll.OwnerID)
|
||||||
|
@ -782,7 +783,11 @@ func handleViewCollection(app *App, w http.ResponseWriter, r *http.Request) erro
|
||||||
|
|
||||||
// Add more data
|
// Add more data
|
||||||
// TODO: fix this mess of collections inside collections
|
// TODO: fix this mess of collections inside collections
|
||||||
displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj)
|
if isOwner {
|
||||||
|
displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, true)
|
||||||
|
} else {
|
||||||
|
displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, false)
|
||||||
|
}
|
||||||
|
|
||||||
err = templates["collection"].ExecuteTemplate(w, "collection", displayPage)
|
err = templates["collection"].ExecuteTemplate(w, "collection", displayPage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -866,6 +871,7 @@ func handleViewCollectionTag(app *App, w http.ResponseWriter, r *http.Request) e
|
||||||
displayPage.Collections = pubColls
|
displayPage.Collections = pubColls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
isOwner := owner != nil
|
||||||
if owner == nil {
|
if owner == nil {
|
||||||
// Current user doesn't own collection; retrieve owner information
|
// Current user doesn't own collection; retrieve owner information
|
||||||
owner, err = app.db.GetUserByID(coll.OwnerID)
|
owner, err = app.db.GetUserByID(coll.OwnerID)
|
||||||
|
@ -878,7 +884,11 @@ func handleViewCollectionTag(app *App, w http.ResponseWriter, r *http.Request) e
|
||||||
coll.Owner = displayPage.Owner
|
coll.Owner = displayPage.Owner
|
||||||
// Add more data
|
// Add more data
|
||||||
// TODO: fix this mess of collections inside collections
|
// TODO: fix this mess of collections inside collections
|
||||||
displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj)
|
if isOwner {
|
||||||
|
displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, true)
|
||||||
|
} else {
|
||||||
|
displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, false)
|
||||||
|
}
|
||||||
|
|
||||||
err = templates["collection-tags"].ExecuteTemplate(w, "collection-tags", displayPage)
|
err = templates["collection-tags"].ExecuteTemplate(w, "collection-tags", displayPage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
12
database.go
12
database.go
|
@ -94,7 +94,7 @@ type writestore interface {
|
||||||
|
|
||||||
UpdatePostPinState(pinned bool, postID string, collID, ownerID, pos int64) error
|
UpdatePostPinState(pinned bool, postID string, collID, ownerID, pos int64) error
|
||||||
GetLastPinnedPostPos(collID int64) int64
|
GetLastPinnedPostPos(collID int64) int64
|
||||||
GetPinnedPosts(coll *CollectionObj) (*[]PublicPost, error)
|
GetPinnedPosts(coll *CollectionObj, includeFuture bool) (*[]PublicPost, error)
|
||||||
RemoveCollectionRedirect(t *sql.Tx, alias string) error
|
RemoveCollectionRedirect(t *sql.Tx, alias string) error
|
||||||
GetCollectionRedirect(alias string) (new string)
|
GetCollectionRedirect(alias string) (new string)
|
||||||
IsCollectionAttributeOn(id int64, attr string) bool
|
IsCollectionAttributeOn(id int64, attr string) bool
|
||||||
|
@ -1533,9 +1533,15 @@ func (db *datastore) GetLastPinnedPostPos(collID int64) int64 {
|
||||||
return lastPos.Int64
|
return lastPos.Int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *datastore) GetPinnedPosts(coll *CollectionObj) (*[]PublicPost, error) {
|
func (db *datastore) GetPinnedPosts(coll *CollectionObj, includeFuture bool) (*[]PublicPost, error) {
|
||||||
// FIXME: sqlite-backed instances don't include ellipsis on truncated titles
|
// FIXME: sqlite-backed instances don't include ellipsis on truncated titles
|
||||||
rows, err := db.Query("SELECT id, slug, title, "+db.clip("content", 80)+", pinned_position FROM posts WHERE collection_id = ? AND pinned_position IS NOT NULL ORDER BY pinned_position ASC", coll.ID)
|
rows := &sql.Rows{}
|
||||||
|
var err error
|
||||||
|
if includeFuture {
|
||||||
|
rows, err = db.Query("SELECT id, slug, title, "+db.clip("content", 80)+", pinned_position FROM posts WHERE collection_id = ? AND pinned_position IS NOT NULL ORDER BY pinned_position ASC", coll.ID)
|
||||||
|
} else {
|
||||||
|
rows, err = db.Query("SELECT id, slug, title, "+db.clip("content", 80)+", pinned_position FROM posts WHERE collection_id = ? AND pinned_position IS NOT NULL AND created <= "+db.now()+" ORDER BY pinned_position ASC", coll.ID)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed selecting pinned posts: %v", err)
|
log.Error("Failed selecting pinned posts: %v", err)
|
||||||
return nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't retrieve pinned posts."}
|
return nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't retrieve pinned posts."}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -63,7 +63,7 @@ require (
|
||||||
github.com/writeas/slug v1.2.0
|
github.com/writeas/slug v1.2.0
|
||||||
github.com/writeas/web-core v1.0.0
|
github.com/writeas/web-core v1.0.0
|
||||||
github.com/writefreely/go-nodeinfo v1.2.0
|
github.com/writefreely/go-nodeinfo v1.2.0
|
||||||
golang.org/x/crypto v0.0.0-20190208162236-193df9c0f06f // indirect
|
golang.org/x/crypto v0.0.0-20190208162236-193df9c0f06f
|
||||||
golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1 // indirect
|
golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1 // indirect
|
||||||
golang.org/x/net v0.0.0-20190206173232-65e2d4e15006 // indirect
|
golang.org/x/net v0.0.0-20190206173232-65e2d4e15006 // indirect
|
||||||
golang.org/x/sys v0.0.0-20190209173611-3b5209105503 // indirect
|
golang.org/x/sys v0.0.0-20190209173611-3b5209105503 // indirect
|
||||||
|
|
6
posts.go
6
posts.go
|
@ -1380,7 +1380,11 @@ Are you sure it was ever here?`,
|
||||||
IsCustomDomain: cr.isCustomDomain,
|
IsCustomDomain: cr.isCustomDomain,
|
||||||
IsFound: postFound,
|
IsFound: postFound,
|
||||||
}
|
}
|
||||||
tp.PinnedPosts, _ = app.db.GetPinnedPosts(coll)
|
if p.IsOwner {
|
||||||
|
tp.PinnedPosts, _ = app.db.GetPinnedPosts(coll, true)
|
||||||
|
} else {
|
||||||
|
tp.PinnedPosts, _ = app.db.GetPinnedPosts(coll, false)
|
||||||
|
}
|
||||||
tp.IsPinned = len(*tp.PinnedPosts) > 0 && PostsContains(tp.PinnedPosts, p)
|
tp.IsPinned = len(*tp.PinnedPosts) > 0 && PostsContains(tp.PinnedPosts, p)
|
||||||
|
|
||||||
if !postFound {
|
if !postFound {
|
||||||
|
|
Loading…
Reference in a new issue