diff --git a/backend/app/rest/api/rest_public.go b/backend/app/rest/api/rest_public.go index 2625a774..93711374 100644 --- a/backend/app/rest/api/rest_public.go +++ b/backend/app/rest/api/rest_public.go @@ -386,16 +386,20 @@ func (s *public) robotsCtrl(w http.ResponseWriter, r *http.Request) { func (s *public) applyView(comments []store.Comment, view string) []store.Comment { if strings.EqualFold(view, "user") { - projection := make([]store.Comment, len(comments)) - for i, c := range comments { + projection := make([]store.Comment, 0, len(comments)) + for _, c := range comments { + if c.Deleted { + continue + } p := store.Comment{ ID: c.ID, User: c.User, } - projection[i] = p + projection = append(projection, p) } return projection } + return comments } diff --git a/backend/app/rest/api/rest_public_test.go b/backend/app/rest/api/rest_public_test.go index 7348cf22..577ece33 100644 --- a/backend/app/rest/api/rest_public_test.go +++ b/backend/app/rest/api/rest_public_test.go @@ -232,7 +232,7 @@ func TestRest_FindReadOnly(t *testing.T) { } func TestRest_FindUserView(t *testing.T) { - ts, _, teardown := startupT(t) + ts, srv, teardown := startupT(t) defer teardown() res, code := get(t, ts.URL+"/api/v1/find?site=remark42&url=https://radio-t.com/blah1&view=user") @@ -265,6 +265,18 @@ func TestRest_FindUserView(t *testing.T) { assert.Equal(t, "dev", comments.Comments[1].User.ID) assert.Equal(t, "", comments.Comments[0].Text) assert.Equal(t, "", comments.Comments[1].Text) + + err = srv.DataService.Delete(store.Locator{SiteID: "remark42", URL: "https://radio-t.com/blah1"}, id1, store.SoftDelete) + assert.NoError(t, err) + srv.Cache.Flush(cache.FlusherRequest{}) + + res, code = get(t, ts.URL+"/api/v1/find?site=remark42&url=https://radio-t.com/blah1&sort=+time&view=user") + assert.Equal(t, 200, code) + comments = commentsWithInfo{} + err = json.Unmarshal([]byte(res), &comments) + assert.NoError(t, err) + require.Equal(t, 1, len(comments.Comments), "1 comment left") + assert.Equal(t, id2, comments.Comments[0].ID) } func TestRest_Last(t *testing.T) {