Skip to content

Commit fd27fce

Browse files
danielepdanielepintore0koGusted
authored andcommitted
fix(ui): strike through deleted comment revisions (go-gitea#8458)
Resolves go-gitea#8403 There's a issue with the comment history items that are deleted, they can be deleted by the author of the comment or by those that have write access. However when the item is deleted, it shows that the one who wrote that revision of the comment deleted it, which is not always true. Strike-through the item instead. Co-authored-by: Daniele Pintore <[email protected]> Co-authored-by: 0ko <[email protected]> Co-authored-by: Gusted <[email protected]> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8458 Reviewed-by: 0ko <[email protected]> Co-authored-by: danielep <[email protected]> Co-committed-by: danielep <[email protected]>
1 parent 64cfb35 commit fd27fce

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

options/locale/locale_en-US.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,6 @@ issues.review.resolve_conversation = Resolve conversation
18231823
issues.review.un_resolve_conversation = Unresolve conversation
18241824
issues.review.resolved_by = marked this conversation as resolved
18251825
issues.reference_issue.body = Body
1826-
issues.content_history.deleted = deleted
18271826
issues.content_history.edited = edited
18281827
issues.content_history.created = created
18291828
issues.content_history.delete_from_history = Delete from history

routers/web/repo/issue_content_history.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package repo
55

66
import (
77
"bytes"
8+
"fmt"
89
"html"
910
"net/http"
1011
"strings"
@@ -54,15 +55,18 @@ func GetContentHistoryList(ctx *context.Context) {
5455
var results []map[string]any
5556
for _, item := range items {
5657
var actionText string
57-
if item.IsDeleted {
58-
actionTextDeleted := ctx.Locale.TrString("repo.issues.content_history.deleted")
59-
actionText = "<i data-history-is-deleted='1'>" + actionTextDeleted + "</i>"
60-
} else if item.IsFirstCreated {
58+
contentFmt := "%s<strong>%s</strong> %s %s"
59+
if item.IsFirstCreated {
6160
actionText = ctx.Locale.TrString("repo.issues.content_history.created")
6261
} else {
6362
actionText = ctx.Locale.TrString("repo.issues.content_history.edited")
6463
}
6564

65+
if item.IsDeleted {
66+
actionText = "<span data-history-is-deleted='1'>" + actionText + "</span>"
67+
contentFmt = "<s>" + contentFmt + "</s>"
68+
}
69+
6670
username := item.UserName
6771
if setting.UI.DefaultShowFullName && strings.TrimSpace(item.UserFullName) != "" {
6872
username = strings.TrimSpace(item.UserFullName)
@@ -73,9 +77,10 @@ func GetContentHistoryList(ctx *context.Context) {
7377
name := html.EscapeString(username)
7478
avatarHTML := string(templates.AvatarHTML(src, 28, class, username))
7579
timeSinceHTML := string(templates.TimeSince(item.EditedUnix))
80+
content := fmt.Sprintf(contentFmt, avatarHTML, name, actionText, timeSinceHTML)
7681

7782
results = append(results, map[string]any{
78-
"name": avatarHTML + "<strong>" + name + "</strong> " + actionText + " " + timeSinceHTML,
83+
"name": content,
7984
"value": item.HistoryID,
8085
})
8186
}

tests/e2e/issue-comment.test.e2e.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// web_src/js/features/comp/**
33
// web_src/js/features/repo-**
44
// templates/repo/issue/view_content/*
5+
// routers/web/repo/issue_content_history.go
56
// @watch end
67

78
import {expect} from '@playwright/test';
8-
import {test, save_visual} from './utils_e2e.ts';
9+
import {test, dynamic_id, save_visual} from './utils_e2e.ts';
910

1011
test.use({user: 'user2'});
1112

@@ -236,3 +237,34 @@ test('Emoji suggestions', async ({page}) => {
236237
const item = suggestionList.locator(`li:has-text("forgejo")`);
237238
await expect(item.locator('img')).toHaveAttribute('src', '/assets/img/emoji/forgejo.png');
238239
});
240+
241+
test('Comment history', async ({page}) => {
242+
const response = await page.goto('/user2/repo1/issues/new');
243+
expect(response?.status()).toBe(200);
244+
245+
// Create a new issue.
246+
await page.getByPlaceholder('Title').fill('Just a title');
247+
await page.getByPlaceholder('Leave a comment').fill('Hi, have you considered using a rotating fish as logo?');
248+
await page.getByRole('button', {name: 'Create issue'}).click();
249+
await expect(page).toHaveURL(/\/user2\/repo1\/issues\/\d+$/);
250+
251+
page.on('dialog', (dialog) => dialog.accept());
252+
253+
// Make a change.
254+
const editorTextarea = page.locator('[id="_combo_markdown_editor_1"]');
255+
await page.click('.comment-container .context-menu');
256+
await page.click('.comment-container .menu>.edit-content');
257+
await editorTextarea.fill(dynamic_id());
258+
await page.click('.comment-container .edit .save');
259+
260+
// Reload the page so the edited bit is rendered.
261+
await page.reload();
262+
263+
await page.getByText('• edited').click();
264+
await page.click('.content-history-menu .item:nth-child(1)');
265+
await page.getByText('Options').click();
266+
await page.getByText('Delete from history').click();
267+
268+
await page.getByText('• edited').click();
269+
await expect(page.locator(".content-history-menu .item s span[data-history-is-deleted='1']")).toBeVisible();
270+
});

web_src/css/repo.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,10 @@ details.repo-search-result summary::marker {
21322132
gap: 4px;
21332133
}
21342134

2135+
.comment-header-left > .content-history-menu.active s {
2136+
text-decoration-thickness: 10%;
2137+
}
2138+
21352139
.comment-body {
21362140
background: var(--color-box-body);
21372141
border: none !important;

0 commit comments

Comments
 (0)