fix: hide post
This commit is contained in:
@@ -174,6 +174,12 @@ func (s *PostService) Delete(ctx context.Context, postID, callerID string) error
|
||||
return s.posts.Delete(ctx, postID, callerID)
|
||||
}
|
||||
|
||||
// SetHidden hides/unhides a post from timelines + public collections.
|
||||
// Owner-only — the repo scopes the update to the caller.
|
||||
func (s *PostService) SetHidden(ctx context.Context, postID, callerID string, hidden bool) error {
|
||||
return s.posts.SetHidden(ctx, postID, callerID, hidden)
|
||||
}
|
||||
|
||||
// ReplaceImages swaps the image set on a post. Owner-only — every
|
||||
// reshare is its own posts row, owned by the resharer, so this works
|
||||
// uniformly for canonical posts and reshares.
|
||||
@@ -438,6 +444,36 @@ func (s *PostService) ListMine(ctx context.Context, userID string, limit, offset
|
||||
return posts, total, nil
|
||||
}
|
||||
|
||||
// ListHidden is the owner's "Hidden" tab — their hidden posts only, hydrated
|
||||
// like ListMine so the cards render fully and the menu offers Unhide.
|
||||
func (s *PostService) ListHidden(ctx context.Context, userID string, limit, offset int) ([]model.Post, int, error) {
|
||||
if limit <= 0 || limit > 50 {
|
||||
limit = 20
|
||||
}
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
posts, total, err := s.posts.ListHiddenByUser(ctx, userID, limit, offset)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
for i := range posts {
|
||||
if posts[i].ResharedFromPostID != nil {
|
||||
posts[i].ViewerHasReshared = true
|
||||
}
|
||||
}
|
||||
if err := s.hydrateLikesSlice(ctx, userID, posts); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if err := s.hydrateMentionsSlice(ctx, posts); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if err := s.hydratePinnedSlice(ctx, userID, posts); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return posts, total, nil
|
||||
}
|
||||
|
||||
// ImagePresign returns a one-shot R2 PUT URL for a post image.
|
||||
// The key is namespaced under post-images/<user_id>/<random>.<ext>. We
|
||||
// don't tie it to a post_id at presign time because the post might not
|
||||
@@ -654,6 +690,18 @@ func (s *CollectionService) Get(ctx context.Context, id, viewerID string) (*mode
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
// Hidden posts never appear in PUBLIC collections. Private collections are
|
||||
// owner-only (gated above) and keep hidden posts so the owner can still
|
||||
// see and manage them there.
|
||||
if c.IsPublic {
|
||||
visible := make([]model.Post, 0, len(posts))
|
||||
for _, p := range posts {
|
||||
if !p.IsHidden {
|
||||
visible = append(visible, p)
|
||||
}
|
||||
}
|
||||
posts = visible
|
||||
}
|
||||
// PostsIn returns posts without images (single-table boundary). Hydrate
|
||||
// them in one batched query so callers — and the post cards rendered
|
||||
// inside collection carousels — can show the post's first image as
|
||||
|
||||
Reference in New Issue
Block a user