Merge pull request #169 from writeas/future-pins

prevent future posts from showing in pins
pull/157/head
Matt Baer 5 years ago committed by GitHub
commit 9256293123
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      collections.go
  2. 10
      database.go
  3. 2
      posts.go

@ -771,7 +771,8 @@ func handleViewCollection(app *App, w http.ResponseWriter, r *http.Request) erro
displayPage.Collections = pubColls displayPage.Collections = pubColls
} }
} }
if owner == nil { isOwner := owner != nil
if !isOwner {
// 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)
if err != nil { if err != nil {
@ -784,7 +785,7 @@ 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) displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, isOwner)
err = templates["collection"].ExecuteTemplate(w, "collection", displayPage) err = templates["collection"].ExecuteTemplate(w, "collection", displayPage)
if err != nil { if err != nil {
@ -868,7 +869,8 @@ func handleViewCollectionTag(app *App, w http.ResponseWriter, r *http.Request) e
displayPage.Collections = pubColls displayPage.Collections = pubColls
} }
} }
if owner == nil { isOwner := owner != nil
if !isOwner {
// 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)
if err != nil { if err != nil {
@ -880,7 +882,7 @@ 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) displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, isOwner)
err = templates["collection-tags"].ExecuteTemplate(w, "collection-tags", displayPage) err = templates["collection-tags"].ExecuteTemplate(w, "collection-tags", displayPage)
if err != nil { if err != nil {

@ -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,13 @@ 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) timeCondition := ""
if !includeFuture {
timeCondition = "AND created <= " + db.now()
}
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 "+timeCondition+" 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."}

@ -1380,7 +1380,7 @@ Are you sure it was ever here?`,
IsCustomDomain: cr.isCustomDomain, IsCustomDomain: cr.isCustomDomain,
IsFound: postFound, IsFound: postFound,
} }
tp.PinnedPosts, _ = app.db.GetPinnedPosts(coll) tp.PinnedPosts, _ = app.db.GetPinnedPosts(coll, p.IsOwner)
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…
Cancel
Save