Skip to content

Commit 59ccc11

Browse files
authored
Revert 'Hide the names of banned users behind a spoiler tag#32424' (#32635)
* Revert 'Hide the names of banned users behind a spoiler tag#32424' * Empty commit to trigger test re-run
1 parent f6d72f1 commit 59ccc11

6 files changed

Lines changed: 13 additions & 144 deletions

File tree

apps/web/src/TextForEvent.tsx

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import { highlightEvent, isLocationEvent } from "./utils/EventUtils";
3939
import { getSenderName } from "./utils/event/getSenderName";
4040
import PosthogTrackers from "./PosthogTrackers.ts";
4141
import { ElementCallEventType } from "./call-types.ts";
42-
import Spoiler from "./components/views/elements/Spoiler.tsx";
4342

4443
function getRoomMemberDisplayname(client: MatrixClient, event: MatrixEvent, userId = event.getSender()): string {
4544
const roomId = event.getRoomId();
@@ -108,7 +107,7 @@ function textForMemberEvent(
108107
client: MatrixClient,
109108
allowJSX: boolean,
110109
showHiddenEvents?: boolean,
111-
): (() => Renderable) | null {
110+
): (() => string) | null {
112111
// XXX: SYJS-16 "sender is sometimes null for join messages"
113112
const senderName = ev.sender?.name || getRoomMemberDisplayname(client, ev);
114113
const targetName = ev.target?.name || getRoomMemberDisplayname(client, ev, ev.getStateKey());
@@ -134,26 +133,10 @@ function textForMemberEvent(
134133
}
135134
}
136135
case KnownMembership.Ban:
137-
if (allowJSX) {
138-
return reason
139-
? () =>
140-
_t(
141-
"timeline|m.room.member|ban_reason_spoiler",
142-
{ senderName, reason },
143-
{ user: () => <Spoiler>{targetName}</Spoiler> },
144-
)
145-
: () =>
146-
_t(
147-
"timeline|m.room.member|ban_spoiler",
148-
{ senderName },
149-
{ user: () => <Spoiler>{targetName}</Spoiler> },
150-
);
151-
}
152-
153-
return reason
154-
? () => _t("timeline|m.room.member|ban_reason", { senderName, reason })
155-
: () => _t("timeline|m.room.member|ban", { senderName });
156-
136+
return () =>
137+
reason
138+
? _t("timeline|m.room.member|ban_reason", { senderName, targetName, reason })
139+
: _t("timeline|m.room.member|ban", { senderName, targetName });
157140
case KnownMembership.Join:
158141
if (prevContent && prevContent.membership === KnownMembership.Join) {
159142
const modDisplayname = getModification(prevContent.displayname, content.displayname);

apps/web/src/components/views/elements/EventListSummary.tsx

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
88
Please see LICENSE files in the repository root for full details.
99
*/
1010

11-
import React, { type ReactElement, type ComponentProps, type ReactNode } from "react";
11+
import React, { type ComponentProps, type ReactNode } from "react";
1212
import { EventType, type MatrixEvent, MatrixEventEvent, type RoomMember } from "matrix-js-sdk/src/matrix";
1313
import { KnownMembership } from "matrix-js-sdk/src/types";
1414
import { throttle } from "lodash";
@@ -25,7 +25,6 @@ import AccessibleButton from "./AccessibleButton";
2525
import RoomContext from "../../../contexts/RoomContext";
2626
import { arrayHasDiff } from "../../../utils/arrays.ts";
2727
import { objectHasDiff } from "../../../utils/objects.ts";
28-
import Spoiler from "./Spoiler.tsx";
2928

3029
const onPinnedMessagesClick = (): void => {
3130
RightPanelStore.instance.setCard({ phase: RightPanelPhases.PinnedMessages }, false);
@@ -223,15 +222,7 @@ export default class EventListSummary extends React.Component<Props, State> {
223222
): ReactNode {
224223
const summaries = orderedTransitionSequences.map((transitions) => {
225224
const userNames = eventAggregates[transitions];
226-
let spoileredUserNames: ReactElement[];
227-
228-
if (containsBanned(transitions)) {
229-
spoileredUserNames = userNames.map((u) => <Spoiler key={u}>{u}</Spoiler>);
230-
} else {
231-
spoileredUserNames = userNames.map((u) => <>{u}</>);
232-
}
233-
234-
const nameList = this.renderNameList(spoileredUserNames);
225+
const nameList = this.renderNameList(userNames);
235226

236227
const splitTransitions = transitions.split(SEP) as TransitionType[];
237228

@@ -243,11 +234,7 @@ export default class EventListSummary extends React.Component<Props, State> {
243234
const coalescedTransitions = EventListSummary.coalesceRepeatedTransitions(canonicalTransitions);
244235

245236
const descs = coalescedTransitions.map((t) => {
246-
return EventListSummary.getDescriptionForTransition(
247-
t.transitionType,
248-
spoileredUserNames.length,
249-
t.repeats,
250-
);
237+
return EventListSummary.getDescriptionForTransition(t.transitionType, userNames.length, t.repeats);
251238
});
252239

253240
const desc = formatList(descs);
@@ -268,7 +255,7 @@ export default class EventListSummary extends React.Component<Props, State> {
268255
* more items in `users` than `this.props.summaryLength`, which is the number of names
269256
* included before "and [n] others".
270257
*/
271-
private renderNameList(users: ReactElement[]): ReactElement {
258+
private renderNameList(users: string[]): string {
272259
return formatList(users, this.props.summaryLength);
273260
}
274261

@@ -631,11 +618,3 @@ export default class EventListSummary extends React.Component<Props, State> {
631618
);
632619
}
633620
}
634-
635-
/**
636-
* Returns true if the provided list comma-separated list of transitions
637-
* contains an item "banned".
638-
*/
639-
function containsBanned(transitions: string): boolean {
640-
return transitions.startsWith(TransitionType.Banned) || transitions.includes(`,${TransitionType.Banned}`);
641-
}

apps/web/src/i18n/strings/en_EN.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3483,10 +3483,8 @@
34833483
"m.room.member": {
34843484
"accepted_3pid_invite": "%(targetName)s accepted the invitation for %(displayName)s",
34853485
"accepted_invite": "%(targetName)s accepted an invitation",
3486-
"ban": "%(senderName)s banned a user",
3487-
"ban_reason": "%(senderName)s banned a user: %(reason)s",
3488-
"ban_reason_spoiler": "%(senderName)s banned <user/>: %(reason)s",
3489-
"ban_spoiler": "%(senderName)s banned <user/>",
3486+
"ban": "%(senderName)s banned %(targetName)s",
3487+
"ban_reason": "%(senderName)s banned %(targetName)s: %(reason)s",
34903488
"change_avatar": "%(senderName)s changed their profile picture",
34913489
"change_name": "%(oldDisplayName)s changed their display name to %(displayName)s",
34923490
"change_name_avatar": "%(oldDisplayName)s changed their display name and profile picture",

apps/web/test/unit-tests/TextForEvent-test.tsx

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { KnownMembership } from "matrix-js-sdk/src/types";
2020
import { render } from "jest-matrix-react";
2121
import { type ReactElement } from "react";
2222
import { type Mocked, mocked } from "jest-mock";
23-
import React from "react";
2423

2524
import { hasText, textForEvent } from "../../src/TextForEvent";
2625
import SettingsStore from "../../src/settings/SettingsStore";
@@ -29,7 +28,6 @@ import { MatrixClientPeg } from "../../src/MatrixClientPeg";
2928
import UserIdentifierCustomisations from "../../src/customisations/UserIdentifier";
3029
import { getSenderName } from "../../src/utils/event/getSenderName";
3130
import { ElementCallEventType } from "../../src/call-types";
32-
import Spoiler from "../../src/components/views/elements/Spoiler";
3331

3432
jest.mock("../../src/settings/SettingsStore");
3533
jest.mock("../../src/customisations/UserIdentifier", () => ({
@@ -564,50 +562,6 @@ describe("TextForEvent", () => {
564562
),
565563
).toMatchInlineSnapshot(`"Member rejected the invitation: I don't want to be in this room."`);
566564
});
567-
568-
it("shows single-user bans with a spoiler on display name", () => {
569-
mocked(mockClient.getRoom).mockReturnValue({
570-
getMember: jest.fn().mockImplementation((userId) => {
571-
return { rawDisplayName: userId === "@admin:example.com" ? "Admin" : "Bad User" };
572-
}),
573-
} as unknown as Mocked<Room>);
574-
575-
expect(textForEvent(banEventWithReason(), mockClient, true)).toEqual(
576-
<span>
577-
Admin banned <Spoiler>Bad User</Spoiler>: bad behaviour
578-
</span>,
579-
);
580-
});
581-
582-
it("hides user name for single-user bans with reason when JSX is not allowed", () => {
583-
mocked(mockClient.getRoom).mockReturnValue({
584-
getMember: jest.fn().mockImplementation((userId) => {
585-
return { rawDisplayName: userId === "@admin:example.com" ? "Admin" : "Bad User" };
586-
}),
587-
} as unknown as Mocked<Room>);
588-
589-
expect(textForEvent(banEventWithReason(), mockClient)).toEqual("Admin banned a user: bad behaviour");
590-
});
591-
592-
it("shows single-user bans with a spoiler on user ID", () => {
593-
mocked(mockClient.getRoom).mockReturnValue({
594-
getMember: jest.fn().mockReturnValue({ rawDisplayName: undefined }),
595-
} as unknown as Mocked<Room>);
596-
597-
expect(textForEvent(banEvent(), mockClient, true)).toEqual(
598-
<span>
599-
@admin:example.com banned <Spoiler>@bad_name:bad_server.co</Spoiler>
600-
</span>,
601-
);
602-
});
603-
604-
it("hides user name for single-user bans when JSX is not allowed", () => {
605-
mocked(mockClient.getRoom).mockReturnValue({
606-
getMember: jest.fn().mockReturnValue({ rawDisplayName: undefined }),
607-
} as unknown as Mocked<Room>);
608-
609-
expect(textForEvent(banEvent(), mockClient)).toEqual("@admin:example.com banned a user");
610-
});
611565
});
612566

613567
describe("textForJoinRulesEvent()", () => {
@@ -763,26 +717,3 @@ describe("TextForEvent", () => {
763717
});
764718
});
765719
});
766-
767-
function banEvent(): MatrixEvent {
768-
return new MatrixEvent({
769-
type: "m.room.member",
770-
sender: "@admin:example.com",
771-
content: {
772-
membership: KnownMembership.Ban,
773-
},
774-
state_key: "@bad_name:bad_server.co",
775-
});
776-
}
777-
778-
function banEventWithReason(): MatrixEvent {
779-
return new MatrixEvent({
780-
type: "m.room.member",
781-
sender: "@admin:example.com",
782-
content: {
783-
membership: KnownMembership.Ban,
784-
reason: "bad behaviour",
785-
},
786-
state_key: "@bad_name:bad_server.co",
787-
});
788-
}

apps/web/test/unit-tests/components/structures/__snapshots__/MessagePanel-test.tsx.snap

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ exports[`MessagePanel should handle lots of membership events quickly 1`] = `
120120
<span
121121
class="mx_TextualEvent mx_GenericEventListSummary_summary"
122122
>
123-
<span>
124-
@user:id made no changes 100 times
125-
</span>
123+
@user:id made no changes 100 times
126124
</span>
127125
</div>
128126
</div>

apps/web/test/unit-tests/components/views/elements/EventListSummary-test.tsx

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,7 @@ describe("EventListSummary", function () {
265265

266266
const { container } = renderComponent(props);
267267
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
268-
269-
// The sequence was summarised correctly
270268
expect(summary).toHaveTextContent("user_1 was unbanned, joined and left 7 times and was invited");
271-
272-
// And there is no spoiler on the user's name since they were not banned
273-
expect(summary).not.toContainHTML("mx_EventTile_spoiler_content");
274269
});
275270

276271
it("truncates multiple sequences of repetitions with other events between", function () {
@@ -314,14 +309,9 @@ describe("EventListSummary", function () {
314309

315310
const { container } = renderComponent(props);
316311
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
317-
318-
// The sequence was summarised correctly
319312
expect(summary).toHaveTextContent(
320-
"user_1 was unbanned, joined and left 2 times, was banned, joined and left 3 times and was invited",
313+
"user_1 was unbanned, joined and left 2 times, was banned, " + "joined and left 3 times and was invited",
321314
);
322-
323-
// And the banned user's name is hidden within a spoiler
324-
expect(summary).toContainHTML('<span class="mx_EventTile_spoiler_content">user_1</span>');
325315
});
326316

327317
it("handles multiple users following the same sequence of memberships", function () {
@@ -371,14 +361,9 @@ describe("EventListSummary", function () {
371361

372362
const { container } = renderComponent(props);
373363
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
374-
375-
// The sequence was summarised correctly
376364
expect(summary).toHaveTextContent(
377365
"user_1 and one other were unbanned, joined and left 2 times and were banned",
378366
);
379-
380-
// And the banned user's name is hidden within a spoiler
381-
expect(summary).toContainHTML('<span class="mx_EventTile_spoiler_content">user_1</span>');
382367
});
383368

384369
it("handles many users following the same sequence of memberships", function () {
@@ -408,14 +393,9 @@ describe("EventListSummary", function () {
408393

409394
const { container } = renderComponent(props);
410395
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
411-
412-
// The sequence was summarised correctly
413396
expect(summary).toHaveTextContent(
414397
"user_0 and 19 others were unbanned, joined and left 2 times and were banned",
415398
);
416-
417-
// And the banned user's name is hidden within a spoiler
418-
expect(summary).toContainHTML('<span class="mx_EventTile_spoiler_content">user_0</span>');
419399
});
420400

421401
it("correctly orders sequences of transitions by the order of their first event", function () {

0 commit comments

Comments
 (0)