fix: hide post
This commit is contained in:
@@ -234,6 +234,27 @@ func (h *PostHandler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
response.NoContent(w)
|
||||
}
|
||||
|
||||
// Hide — POST /posts/{id}/hide. Owner hides the post from timelines + public
|
||||
// collections.
|
||||
func (h *PostHandler) Hide(w http.ResponseWriter, r *http.Request) {
|
||||
uid := middleware.UserID(r.Context())
|
||||
if err := h.svc.SetHidden(r.Context(), chi.URLParam(r, "id"), uid, true); err != nil {
|
||||
mapSocialErr(w, err)
|
||||
return
|
||||
}
|
||||
response.NoContent(w)
|
||||
}
|
||||
|
||||
// Unhide — DELETE /posts/{id}/hide. Restores the post to timelines.
|
||||
func (h *PostHandler) Unhide(w http.ResponseWriter, r *http.Request) {
|
||||
uid := middleware.UserID(r.Context())
|
||||
if err := h.svc.SetHidden(r.Context(), chi.URLParam(r, "id"), uid, false); err != nil {
|
||||
mapSocialErr(w, err)
|
||||
return
|
||||
}
|
||||
response.NoContent(w)
|
||||
}
|
||||
|
||||
func (h *PostHandler) ListMine(w http.ResponseWriter, r *http.Request) {
|
||||
uid := middleware.UserID(r.Context())
|
||||
limit, offset := parseLimitOffset(r)
|
||||
@@ -245,6 +266,19 @@ func (h *PostHandler) ListMine(w http.ResponseWriter, r *http.Request) {
|
||||
response.JSONWithMeta(w, http.StatusOK, posts, paginationMeta(total, limit, offset))
|
||||
}
|
||||
|
||||
// ListHidden — GET /posts/hidden. The caller's hidden posts (auth required),
|
||||
// for the /u/me "Hidden" tab where they can unhide them.
|
||||
func (h *PostHandler) ListHidden(w http.ResponseWriter, r *http.Request) {
|
||||
uid := middleware.UserID(r.Context())
|
||||
limit, offset := parseLimitOffset(r)
|
||||
posts, total, err := h.svc.ListHidden(r.Context(), uid, limit, offset)
|
||||
if err != nil {
|
||||
mapSocialErr(w, err)
|
||||
return
|
||||
}
|
||||
response.JSONWithMeta(w, http.StatusOK, posts, paginationMeta(total, limit, offset))
|
||||
}
|
||||
|
||||
// Feed — GET /feed?limit=&offset=. The global personalised home feed (auth
|
||||
// required). Returns at most `limit` posts; the client infers "more" from a
|
||||
// full page (no total count for an unbounded global feed).
|
||||
@@ -602,6 +636,16 @@ func (h *ProfileHandler) Get(w http.ResponseWriter, r *http.Request) {
|
||||
response.Error(w, http.StatusInternalServerError, "could not load profile")
|
||||
return
|
||||
}
|
||||
// Hidden-post count is meaningful only to the owner (drives the /u/me
|
||||
// "Hidden" tab). Compute it just for self; 0 for everyone else.
|
||||
hiddenCount := 0
|
||||
if middleware.UserID(r.Context()) == u.ID {
|
||||
hiddenCount, err = h.posts.CountHiddenByUser(r.Context(), u.ID)
|
||||
if err != nil {
|
||||
response.Error(w, http.StatusInternalServerError, "could not load profile")
|
||||
return
|
||||
}
|
||||
}
|
||||
cols, err := h.collections.ListPublicByUser(r.Context(), u.ID)
|
||||
if err != nil {
|
||||
response.Error(w, http.StatusInternalServerError, "could not load collections")
|
||||
@@ -625,6 +669,7 @@ func (h *ProfileHandler) Get(w http.ResponseWriter, r *http.Request) {
|
||||
"joined_at": u.CreatedAt,
|
||||
"country": u.Country,
|
||||
"post_count": count,
|
||||
"hidden_count": hiddenCount,
|
||||
"follower_count": followers,
|
||||
"following_count": following,
|
||||
"relationship": rel,
|
||||
@@ -672,7 +717,8 @@ func (h *ProfileHandler) Feed(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
limit, offset := parseLimitOffset(r)
|
||||
// gateByBlock already resolved the owner, so list by id rather than
|
||||
// re-resolving the handle.
|
||||
// re-resolving the handle. Hidden posts never appear here (they live in
|
||||
// the owner's separate Hidden tab).
|
||||
posts, total, err := h.posts.ListByUser(r.Context(), owner.ID, limit, offset)
|
||||
if err != nil {
|
||||
mapSocialErr(w, err)
|
||||
|
||||
Reference in New Issue
Block a user