fix: use live comment content in feed and dashboard previews#36631
fix: use live comment content in feed and dashboard previews#36631alessandroferra wants to merge 3 commits intogo-gitea:mainfrom
Conversation
Add Action.GetCommentPreview() to prefer the loaded Comment.Content over the snapshot stored in Action.Content. Introduce TruncateToPreviewLines and MarkdownToHTMLWithPreviewLimit so that long comments are capped at 5 lines / 1000 characters in both the Atom feed and the dashboard template.
45129f1 to
5b404bf
Compare
|
Thanks, this is a welcome change. I think there must be a open issue about this topic too. |
|
Comment authored by AI on behalf of @silverwind Nice idea — showing live comment content instead of the stale 200-char snapshot is a real improvement. A few things I noticed: 1. Missing truncation for The comment action types ( case activities_model.ActionPullReviewDismissed:
desc = ctx.Locale.TrString("action.review_dismissed_reason") + "\n\n" + act.GetCommentPreview()Since 2. Truncating markdown source before rendering can break syntax The PR description says "truncates to 5 lines / 1000 characters before rendering so markdown constructs are never split mid-syntax", but truncating by raw line/char count can absolutely split markdown constructs. For example:
The markdown renderer will handle these gracefully enough (unclosed blocks just render as-is), so this isn't a blocker, but the claim in the description should be corrected. Truncating before rendering is still better than trying to truncate rendered HTML. 3. Naming convention: The existing method uses 4. Minor: output = template.HTML(string(output) + `<span class="text grey">…</span>`)Is Overall the approach is sound and the tests are thorough. The main actionable item is #1 (missing truncation for dismissed reviews in the feed). |
|
Ignore the suggestion regarding fenced code block truncation, that is WIP separately in #36604. |
Extract renderCommentPreview helper to deduplicate feed truncation logic. Apply truncation to ActionPullReviewDismissed. Migrate truncation indicator from text grey to tw-text-text-light.
|
Thanks for the thorough review! Addressed in ae885cc: 1. Missing truncation for Fixed. Extracted a Worth noting this was already unbounded before this PR, the switch to live content just made it more visible. Before this PR, 2. Markdown truncation wording Agreed, good catch, the wording overstated it. I tested all the cases you mentioned (unclosed fences, partial tables, broken links, broken inline code, and mermaid diagrams) against the live instance. The renderer auto-closes blocks and falls back to plain text for incomplete constructs, no broken HTML or visual artifacts. Only updated the summary to:
So it's more correct. 3. Naming:
4. CSS class: Updated to |
|
About the open issue, i tried to search for it but i couldn't find it. This is the closest match but is closed: #26868 |
|
Yeah, there's no issue about. I was imagining things 😆. |
Summary
Dashboard activity feeds and RSS/Atom feeds display a 200-character snapshot of comment text captured at creation time. When a user edits their comment the snapshot is never refreshed, so every feed consumer sees stale content indefinitely.
Action.GetCommentPreview()that returns the liveComment.Content(already bulk-loaded byLoadComments) and falls back to theAction.Contentsnapshot for old rows or deleted commentsMarkdownToHtmlcall in the dashboard template withMarkdownToHTMLWithPreviewLimit, which truncates markdown source to 5 lines / 1000 runes before rendering to bound preview size. Incomplete markdown constructs are handled gracefully by the renderer.Affected action types:
ActionCommentIssue,ActionCommentPull,ActionApprovePullRequest,ActionRejectPullRequest,ActionPullReviewDismissed.No new database queries,
GetCommentPreview()reads from theCommentstruct thatLoadAttributesalready populates.Test plan
go test -tags sqlite,sqlite_unlock_notify -run TestGetCommentPreview ./models/activities/and 6 subtests passgo test -run TestTruncateToPreviewLines ./modules/templates/and 6 subtests passgo test -run TestMarkdownToHTMLWithPreviewLimit ./modules/templates/and 3 subtests passmake lint-gowith 0 issues.rss/.atomfeed entry reflects the editNotes
<description>field in RSS/Atom entries currently mixes plain text and rendered HTML. This is a pre-existing inconsistency (noted by the TODO atconvert.go) and is not changed by this PR.MaxPreviewLinesandMaxPreviewCharsare exported constants, so they can be adjusted or made configurable later without touching the rendering logic.