Skip to content

Commit

Permalink
Merge pull request #214 from writeas/fix-hostname-fediverse
Browse files Browse the repository at this point in the history
Fix fediverse post IDs
  • Loading branch information
thebaer committed Nov 27, 2019
2 parents 59d892e + c81927a commit 88a3ed7
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions posts.go
Expand Up @@ -1048,24 +1048,33 @@ func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error {
if err != nil {
return err
}
coll.hostName = app.cfg.App.Host
_, err = apiCheckCollectionPermissions(app, r, coll)
if err != nil {
return err
}
collID = coll.ID
}

p, err := app.db.GetPost(vars["post"], collID)
if err != nil {
return err
}
if coll == nil && p.CollectionID.Valid {
// Collection post is getting fetched by post ID, not coll alias + post slug, so get coll info now.
coll, err = app.db.GetCollectionByID(p.CollectionID.Int64)
if err != nil {
return err
}
}
if coll != nil {
coll.hostName = app.cfg.App.Host
_, err = apiCheckCollectionPermissions(app, r, coll)
if err != nil {
return err
}
}

suspended, err := app.db.IsUserSuspended(p.OwnerID.Int64)
if err != nil {
log.Error("fetch post: %v", err)
return ErrInternalGeneral
}

if suspended {
return ErrPostNotFound
}
Expand All @@ -1074,13 +1083,6 @@ func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error {

accept := r.Header.Get("Accept")
if strings.Contains(accept, "application/activity+json") {
// Fetch information about the collection this belongs to
if coll == nil && p.CollectionID.Valid {
coll, err = app.db.GetCollectionByID(p.CollectionID.Int64)
if err != nil {
return err
}
}
if coll == nil {
// This is a draft post; 404 for now
// TODO: return ActivityObject
Expand Down

0 comments on commit 88a3ed7

Please sign in to comment.