Skip to content

Commit 01cd27e

Browse files
committed
Do not show membership/profile events in public rooms
1 parent bb07f84 commit 01cd27e

9 files changed

Lines changed: 10 additions & 70 deletions

File tree

apps/web/src/components/structures/RoomView.tsx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,6 @@ export interface IRoomState {
269269
showHiddenEvents: boolean;
270270
showReadReceipts: boolean;
271271
showRedactions: boolean;
272-
showJoinLeaves: boolean;
273-
showAvatarChanges: boolean;
274-
showDisplaynameChanges: boolean;
275272
matrixClientIsReady: boolean;
276273
showUrlPreview: boolean;
277274
e2eStatus?: E2EStatus;
@@ -499,9 +496,6 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
499496
showHiddenEvents: SettingsStore.getValue("showHiddenEventsInTimeline"),
500497
showReadReceipts: true,
501498
showRedactions: true,
502-
showJoinLeaves: true,
503-
showAvatarChanges: true,
504-
showDisplaynameChanges: true,
505499
// Default to false to avoid any accidental leakage.
506500
showUrlPreview: false,
507501
matrixClientIsReady: context.client?.isInitialSyncComplete(),
@@ -656,9 +650,6 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
656650
shouldPeek: shouldPeek,
657651
showReadReceipts: SettingsStore.getValue("showReadReceipts", roomId),
658652
showRedactions: SettingsStore.getValue("showRedactions", roomId),
659-
showJoinLeaves: SettingsStore.getValue("showJoinLeaves", roomId),
660-
showAvatarChanges: SettingsStore.getValue("showAvatarChanges", roomId),
661-
showDisplaynameChanges: SettingsStore.getValue("showDisplaynameChanges", roomId),
662653
wasContextSwitch: wasContextSwitch,
663654
mainSplitContentType: room ? this.getMainSplitContentType(room) : undefined,
664655
initialEventId: undefined, // default to clearing this, will get set later in the method if needed
@@ -723,15 +714,6 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
723714
SettingsStore.watchSetting("showRedactions", roomId, (...[, , , value]) =>
724715
this.setState({ showRedactions: value as boolean }),
725716
),
726-
SettingsStore.watchSetting("showJoinLeaves", roomId, (...[, , , value]) =>
727-
this.setState({ showJoinLeaves: value as boolean }),
728-
),
729-
SettingsStore.watchSetting("showAvatarChanges", roomId, (...[, , , value]) =>
730-
this.setState({ showAvatarChanges: value as boolean }),
731-
),
732-
SettingsStore.watchSetting("showDisplaynameChanges", roomId, (...[, , , value]) =>
733-
this.setState({ showDisplaynameChanges: value as boolean }),
734-
),
735717
]);
736718

737719
if (!initial && this.state.shouldPeek && !newState.shouldPeek) {

apps/web/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
153153
"showTypingNotifications",
154154
"showRedactions",
155155
"showReadReceipts",
156-
"showJoinLeaves",
157-
"showDisplaynameChanges",
158156
"showChatEffects",
159-
"showAvatarChanges",
160157
"Pill.shouldShowPillAvatar",
161158
"TextualBody.enableBigEmoji",
162159
"scrollToBottomOnMessageSent",

apps/web/src/contexts/RoomContext.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ const RoomContext = createContext<RoomContextType>({
6262
showHiddenEvents: false,
6363
showReadReceipts: true,
6464
showRedactions: true,
65-
showJoinLeaves: true,
66-
showAvatarChanges: true,
67-
showDisplaynameChanges: true,
6865
matrixClientIsReady: false,
6966
showUrlPreview: false,
7067
timelineRenderingType: TimelineRenderingType.Room,

apps/web/src/settings/Settings.tsx

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,6 @@ export interface Settings {
252252
"Notifications.tac_only_notifications": IBaseSetting<boolean>;
253253
"useCompactLayout": IBaseSetting<boolean>;
254254
"showRedactions": IBaseSetting<boolean>;
255-
"showJoinLeaves": IBaseSetting<boolean>;
256-
"showAvatarChanges": IBaseSetting<boolean>;
257-
"showDisplaynameChanges": IBaseSetting<boolean>;
258255
"showReadReceipts": IBaseSetting<boolean>;
259256
"showTwelveHourTimestamps": IBaseSetting<boolean>;
260257
"alwaysShowTimestamps": IBaseSetting<boolean>;
@@ -819,24 +816,6 @@ export const SETTINGS: Settings = {
819816
default: true,
820817
invertedSettingName: "hideRedactions",
821818
},
822-
"showJoinLeaves": {
823-
supportedLevels: LEVELS_ROOM_SETTINGS_WITH_ROOM,
824-
displayName: _td("settings|show_join_leave"),
825-
default: true,
826-
invertedSettingName: "hideJoinLeaves",
827-
},
828-
"showAvatarChanges": {
829-
supportedLevels: LEVELS_ROOM_SETTINGS_WITH_ROOM,
830-
displayName: _td("settings|show_avatar_changes"),
831-
default: true,
832-
invertedSettingName: "hideAvatarChanges",
833-
},
834-
"showDisplaynameChanges": {
835-
supportedLevels: LEVELS_ROOM_SETTINGS_WITH_ROOM,
836-
displayName: _td("settings|show_displayname_changes"),
837-
default: true,
838-
invertedSettingName: "hideDisplaynameChanges",
839-
},
840819
"showReadReceipts": {
841820
supportedLevels: LEVELS_ROOM_SETTINGS,
842821
displayName: _td("settings|show_read_receipts"),

apps/web/src/settings/handlers/AccountSettingsHandler.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,7 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
135135
}
136136

137137
const settings = this.getSettings();
138-
let preferredValue = settings?.[settingName];
139-
140-
if (preferredValue === null || preferredValue === undefined) {
141-
// Honour the old setting on read only
142-
if (settingName === "hideAvatarChanges" || settingName === "hideDisplaynameChanges") {
143-
preferredValue = settings?.["hideAvatarDisplaynameChanges"];
144-
}
145-
}
138+
const preferredValue = settings?.[settingName];
146139

147140
return preferredValue;
148141
}

apps/web/src/shouldHideEvent.ts

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

9-
import { type MatrixEvent, EventType, RelationType, M_POLL_END } from "matrix-js-sdk/src/matrix";
9+
import { type MatrixEvent, EventType, JoinRule, RelationType, M_POLL_END } from "matrix-js-sdk/src/matrix";
1010
import { KnownMembership } from "matrix-js-sdk/src/types";
1111

12+
import { MatrixClientPeg } from "./MatrixClientPeg";
1213
import SettingsStore from "./settings/SettingsStore";
1314
import { type IRoomState } from "./components/structures/RoomView";
1415
import { type SettingKey } from "./settings/Settings.tsx";
@@ -70,9 +71,13 @@ export default function shouldHideEvent(ev: MatrixEvent, ctx?: IRoomState): bool
7071
const eventDiff = memberEventDiff(ev);
7172

7273
if (eventDiff.isMemberEvent) {
73-
if ((eventDiff.isJoin || eventDiff.isPart) && !isEnabled("showJoinLeaves")) return true;
74-
if (eventDiff.isAvatarChange && !isEnabled("showAvatarChanges")) return true;
75-
if (eventDiff.isDisplaynameChange && !isEnabled("showDisplaynameChanges")) return true;
74+
const cli = MatrixClientPeg.get();
75+
const room = cli?.getRoom(ev.getRoomId());
76+
const isInviteOnly = room?.getJoinRule() === JoinRule.Invite;
77+
78+
if ((eventDiff.isJoin || eventDiff.isPart) && isInviteOnly) return true;
79+
if (eventDiff.isAvatarChange && isInviteOnly) return true;
80+
if (eventDiff.isDisplaynameChange && isInviteOnly) return true;
7681
}
7782

7883
return false;

apps/web/test/test-utils/room.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ export function getRoomContext(room: Room, override: Partial<RoomContextType>):
7272
showHiddenEvents: false,
7373
showReadReceipts: true,
7474
showRedactions: true,
75-
showJoinLeaves: true,
76-
showAvatarChanges: true,
77-
showDisplaynameChanges: true,
7875
showUrlPreview: false,
7976
matrixClientIsReady: false,
8077
timelineRenderingType: TimelineRenderingType.Room,

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ describe("MessagePanel", function () {
8787
canSendMessages: true,
8888
showReadReceipts: true,
8989
showRedactions: false,
90-
showJoinLeaves: false,
91-
showAvatarChanges: false,
92-
showDisplaynameChanges: true,
9390
showHiddenEvents: false,
9491
} as unknown as RoomContextType;
9592

@@ -101,10 +98,6 @@ describe("MessagePanel", function () {
10198

10299
beforeEach(function () {
103100
jest.clearAllMocks();
104-
// HACK: We assume all settings want to be disabled
105-
jest.spyOn(SettingsStore, "getValue").mockImplementation((arg) => {
106-
return arg === "showDisplaynameChanges";
107-
});
108101

109102
sdkContext = new SdkContextClass();
110103

apps/web/test/unit-tests/components/views/rooms/SendMessageComposer-test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ describe("<SendMessageComposer/>", () => {
6565
showHiddenEvents: false,
6666
showReadReceipts: true,
6767
showRedactions: true,
68-
showJoinLeaves: true,
69-
showAvatarChanges: true,
70-
showDisplaynameChanges: true,
7168
showUrlPreview: false,
7269
matrixClientIsReady: false,
7370
timelineRenderingType: TimelineRenderingType.Room,

0 commit comments

Comments
 (0)