Move Format from DisplayCollection to CollectionObj

This commit is contained in:
Matt Baer 2020-01-09 16:48:22 -05:00
parent a2a9f60976
commit 812136357e

View file

@ -63,6 +63,7 @@ type (
TotalPosts int `json:"total_posts"` TotalPosts int `json:"total_posts"`
Owner *User `json:"owner,omitempty"` Owner *User `json:"owner,omitempty"`
Posts *[]PublicPost `json:"posts,omitempty"` Posts *[]PublicPost `json:"posts,omitempty"`
Format *CollectionFormat
} }
DisplayCollection struct { DisplayCollection struct {
*CollectionObj *CollectionObj
@ -70,7 +71,6 @@ type (
IsTopLevel bool IsTopLevel bool
CurrentPage int CurrentPage int
TotalPages int TotalPages int
Format *CollectionFormat
Suspended bool Suspended bool
} }
SubmittedCollection struct { SubmittedCollection struct {
@ -556,6 +556,13 @@ type CollectionPage struct {
CanInvite bool CanInvite bool
} }
func NewCollectionObj(c *Collection) *CollectionObj {
return &CollectionObj{
Collection: *c,
Format: c.NewFormat(),
}
}
func (c *CollectionObj) ScriptDisplay() template.JS { func (c *CollectionObj) ScriptDisplay() template.JS {
return template.JS(c.Script) return template.JS(c.Script)
} }
@ -705,11 +712,10 @@ func checkUserForCollection(app *App, cr *collectionReq, r *http.Request, isPost
func newDisplayCollection(c *Collection, cr *collectionReq, page int) *DisplayCollection { func newDisplayCollection(c *Collection, cr *collectionReq, page int) *DisplayCollection {
coll := &DisplayCollection{ coll := &DisplayCollection{
CollectionObj: &CollectionObj{Collection: *c}, CollectionObj: NewCollectionObj(c),
CurrentPage: page, CurrentPage: page,
Prefix: cr.prefix, Prefix: cr.prefix,
IsTopLevel: isSingleUser, IsTopLevel: isSingleUser,
Format: c.NewFormat(),
} }
c.db.GetPostsCount(coll.CollectionObj, cr.isCollOwner) c.db.GetPostsCount(coll.CollectionObj, cr.isCollOwner)
return coll return coll