Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 00984e4

Browse files
authored
Fix effect of URL preview toggle not updating live (#8561)
* Remove unused state and fix canPeek * Fix effect of URL preview toggle not updating live * Remove stale context fields
1 parent 464eb93 commit 00984e4

File tree

4 files changed

+11
-35
lines changed

4 files changed

+11
-35
lines changed

src/components/structures/RoomView.tsx

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { MatrixError } from 'matrix-js-sdk/src/http-api';
3636
import { ClientEvent } from "matrix-js-sdk/src/client";
3737
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
3838
import { THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread';
39+
import { HistoryVisibility } from 'matrix-js-sdk/src/@types/partials';
3940

4041
import shouldHideEvent from '../../shouldHideEvent';
4142
import { _t } from '../../languageHandler';
@@ -166,7 +167,6 @@ export interface IRoomState {
166167
searchHighlights?: string[];
167168
searchInProgress?: boolean;
168169
callState?: CallState;
169-
guestsCanJoin: boolean;
170170
canPeek: boolean;
171171
showApps: boolean;
172172
isPeeking: boolean;
@@ -250,7 +250,6 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
250250
numUnreadMessages: 0,
251251
searchResults: null,
252252
callState: null,
253-
guestsCanJoin: false,
254253
canPeek: false,
255254
showApps: false,
256255
isPeeking: false,
@@ -284,11 +283,9 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
284283
context.on(ClientEvent.Room, this.onRoom);
285284
context.on(RoomEvent.Timeline, this.onRoomTimeline);
286285
context.on(RoomEvent.Name, this.onRoomName);
287-
context.on(RoomEvent.AccountData, this.onRoomAccountData);
288286
context.on(RoomStateEvent.Events, this.onRoomStateEvents);
289287
context.on(RoomStateEvent.Update, this.onRoomStateUpdate);
290288
context.on(RoomEvent.MyMembership, this.onMyMembership);
291-
context.on(ClientEvent.AccountData, this.onAccountData);
292289
context.on(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatus);
293290
context.on(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
294291
context.on(CryptoEvent.UserTrustStatusChanged, this.onUserVerificationChanged);
@@ -326,6 +323,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
326323
SettingsStore.watchSetting("showHiddenEventsInTimeline", null, (...[,,, value]) =>
327324
this.setState({ showHiddenEvents: value as boolean }),
328325
),
326+
SettingsStore.watchSetting("urlPreviewsEnabled", null, this.onUrlPreviewsEnabledChange),
327+
SettingsStore.watchSetting("urlPreviewsEnabled_e2ee", null, this.onUrlPreviewsEnabledChange),
329328
];
330329
}
331330

@@ -722,11 +721,9 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
722721
this.context.removeListener(ClientEvent.Room, this.onRoom);
723722
this.context.removeListener(RoomEvent.Timeline, this.onRoomTimeline);
724723
this.context.removeListener(RoomEvent.Name, this.onRoomName);
725-
this.context.removeListener(RoomEvent.AccountData, this.onRoomAccountData);
726724
this.context.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
727725
this.context.removeListener(RoomEvent.MyMembership, this.onMyMembership);
728726
this.context.removeListener(RoomStateEvent.Update, this.onRoomStateUpdate);
729-
this.context.removeListener(ClientEvent.AccountData, this.onAccountData);
730727
this.context.removeListener(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatus);
731728
this.context.removeListener(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
732729
this.context.removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserVerificationChanged);
@@ -1054,19 +1051,10 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
10541051
}
10551052

10561053
private calculatePeekRules(room: Room) {
1057-
const guestAccessEvent = room.currentState.getStateEvents("m.room.guest_access", "");
1058-
if (guestAccessEvent && guestAccessEvent.getContent().guest_access === "can_join") {
1059-
this.setState({
1060-
guestsCanJoin: true,
1061-
});
1062-
}
1063-
1064-
const historyVisibility = room.currentState.getStateEvents("m.room.history_visibility", "");
1065-
if (historyVisibility && historyVisibility.getContent().history_visibility === "world_readable") {
1066-
this.setState({
1067-
canPeek: true,
1068-
});
1069-
}
1054+
const historyVisibility = room.currentState.getStateEvents(EventType.RoomHistoryVisibility, "");
1055+
this.setState({
1056+
canPeek: historyVisibility?.getContent().history_visibility === HistoryVisibility.WorldReadable,
1057+
});
10701058
}
10711059

10721060
private updatePreviewUrlVisibility({ roomId }: Room) {
@@ -1136,24 +1124,12 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
11361124
this.setState({ e2eStatus });
11371125
}
11381126

1139-
private onAccountData = (event: MatrixEvent) => {
1140-
const type = event.getType();
1141-
if ((type === "org.matrix.preview_urls" || type === "im.vector.web.settings") && this.state.room) {
1142-
// non-e2ee url previews are stored in legacy event type `org.matrix.room.preview_urls`
1127+
private onUrlPreviewsEnabledChange = () => {
1128+
if (this.state.room) {
11431129
this.updatePreviewUrlVisibility(this.state.room);
11441130
}
11451131
};
11461132

1147-
private onRoomAccountData = (event: MatrixEvent, room: Room) => {
1148-
if (room.roomId == this.state.roomId) {
1149-
const type = event.getType();
1150-
if (type === "org.matrix.room.preview_urls" || type === "im.vector.web.settings") {
1151-
// non-e2ee url previews are stored in legacy event type `org.matrix.room.preview_urls`
1152-
this.updatePreviewUrlVisibility(room);
1153-
}
1154-
}
1155-
};
1156-
11571133
private onRoomStateEvents = (ev: MatrixEvent, state: RoomState) => {
11581134
// ignore if we don't have a room yet
11591135
if (!this.state.room || this.state.room.roomId !== state.roomId) return;

src/components/structures/TimelinePanel.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ interface IEventIndexOpts {
213213
*/
214214
class TimelinePanel extends React.Component<IProps, IState> {
215215
static contextType = RoomContext;
216+
public context!: React.ContextType<typeof RoomContext>;
216217

217218
// a map from room id to read marker event timestamp
218219
static roomReadMarkerTsMap: Record<string, number> = {};
@@ -242,6 +243,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
242243

243244
constructor(props, context) {
244245
super(props, context);
246+
this.context = context;
245247

246248
debuglog("mounting");
247249

src/contexts/RoomContext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const RoomContext = createContext<IRoomState>({
3535
shouldPeek: true,
3636
membersLoaded: false,
3737
numUnreadMessages: 0,
38-
guestsCanJoin: false,
3938
canPeek: false,
4039
showApps: false,
4140
isPeeking: false,

test/components/views/rooms/MessageComposerButtons-test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ function createRoomState(room: Room, narrow: boolean): IRoomState {
209209
shouldPeek: true,
210210
membersLoaded: false,
211211
numUnreadMessages: 0,
212-
guestsCanJoin: false,
213212
canPeek: false,
214213
showApps: false,
215214
isPeeking: false,

0 commit comments

Comments
 (0)