diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index a7a4ec2a9e..1539037cf8 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -36,6 +36,7 @@ import { MatrixError } from 'matrix-js-sdk/src/http-api'; import { ClientEvent } from "matrix-js-sdk/src/client"; import { CryptoEvent } from "matrix-js-sdk/src/crypto"; import { THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread'; +import { HistoryVisibility } from 'matrix-js-sdk/src/@types/partials'; import shouldHideEvent from '../../shouldHideEvent'; import { _t } from '../../languageHandler'; @@ -166,7 +167,6 @@ export interface IRoomState { searchHighlights?: string[]; searchInProgress?: boolean; callState?: CallState; - guestsCanJoin: boolean; canPeek: boolean; showApps: boolean; isPeeking: boolean; @@ -250,7 +250,6 @@ export class RoomView extends React.Component { numUnreadMessages: 0, searchResults: null, callState: null, - guestsCanJoin: false, canPeek: false, showApps: false, isPeeking: false, @@ -284,11 +283,9 @@ export class RoomView extends React.Component { context.on(ClientEvent.Room, this.onRoom); context.on(RoomEvent.Timeline, this.onRoomTimeline); context.on(RoomEvent.Name, this.onRoomName); - context.on(RoomEvent.AccountData, this.onRoomAccountData); context.on(RoomStateEvent.Events, this.onRoomStateEvents); context.on(RoomStateEvent.Update, this.onRoomStateUpdate); context.on(RoomEvent.MyMembership, this.onMyMembership); - context.on(ClientEvent.AccountData, this.onAccountData); context.on(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatus); context.on(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged); context.on(CryptoEvent.UserTrustStatusChanged, this.onUserVerificationChanged); @@ -326,6 +323,8 @@ export class RoomView extends React.Component { SettingsStore.watchSetting("showHiddenEventsInTimeline", null, (...[,,, value]) => this.setState({ showHiddenEvents: value as boolean }), ), + SettingsStore.watchSetting("urlPreviewsEnabled", null, this.onUrlPreviewsEnabledChange), + SettingsStore.watchSetting("urlPreviewsEnabled_e2ee", null, this.onUrlPreviewsEnabledChange), ]; } @@ -722,11 +721,9 @@ export class RoomView extends React.Component { this.context.removeListener(ClientEvent.Room, this.onRoom); this.context.removeListener(RoomEvent.Timeline, this.onRoomTimeline); this.context.removeListener(RoomEvent.Name, this.onRoomName); - this.context.removeListener(RoomEvent.AccountData, this.onRoomAccountData); this.context.removeListener(RoomStateEvent.Events, this.onRoomStateEvents); this.context.removeListener(RoomEvent.MyMembership, this.onMyMembership); this.context.removeListener(RoomStateEvent.Update, this.onRoomStateUpdate); - this.context.removeListener(ClientEvent.AccountData, this.onAccountData); this.context.removeListener(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatus); this.context.removeListener(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged); this.context.removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserVerificationChanged); @@ -1054,19 +1051,10 @@ export class RoomView extends React.Component { } private calculatePeekRules(room: Room) { - const guestAccessEvent = room.currentState.getStateEvents("m.room.guest_access", ""); - if (guestAccessEvent && guestAccessEvent.getContent().guest_access === "can_join") { - this.setState({ - guestsCanJoin: true, - }); - } - - const historyVisibility = room.currentState.getStateEvents("m.room.history_visibility", ""); - if (historyVisibility && historyVisibility.getContent().history_visibility === "world_readable") { - this.setState({ - canPeek: true, - }); - } + const historyVisibility = room.currentState.getStateEvents(EventType.RoomHistoryVisibility, ""); + this.setState({ + canPeek: historyVisibility?.getContent().history_visibility === HistoryVisibility.WorldReadable, + }); } private updatePreviewUrlVisibility({ roomId }: Room) { @@ -1136,24 +1124,12 @@ export class RoomView extends React.Component { this.setState({ e2eStatus }); } - private onAccountData = (event: MatrixEvent) => { - const type = event.getType(); - if ((type === "org.matrix.preview_urls" || type === "im.vector.web.settings") && this.state.room) { - // non-e2ee url previews are stored in legacy event type `org.matrix.room.preview_urls` + private onUrlPreviewsEnabledChange = () => { + if (this.state.room) { this.updatePreviewUrlVisibility(this.state.room); } }; - private onRoomAccountData = (event: MatrixEvent, room: Room) => { - if (room.roomId == this.state.roomId) { - const type = event.getType(); - if (type === "org.matrix.room.preview_urls" || type === "im.vector.web.settings") { - // non-e2ee url previews are stored in legacy event type `org.matrix.room.preview_urls` - this.updatePreviewUrlVisibility(room); - } - } - }; - private onRoomStateEvents = (ev: MatrixEvent, state: RoomState) => { // ignore if we don't have a room yet if (!this.state.room || this.state.room.roomId !== state.roomId) return; diff --git a/src/components/structures/TimelinePanel.tsx b/src/components/structures/TimelinePanel.tsx index c92836e1a7..89dc979260 100644 --- a/src/components/structures/TimelinePanel.tsx +++ b/src/components/structures/TimelinePanel.tsx @@ -213,6 +213,7 @@ interface IEventIndexOpts { */ class TimelinePanel extends React.Component { static contextType = RoomContext; + public context!: React.ContextType; // a map from room id to read marker event timestamp static roomReadMarkerTsMap: Record = {}; @@ -242,6 +243,7 @@ class TimelinePanel extends React.Component { constructor(props, context) { super(props, context); + this.context = context; debuglog("mounting"); diff --git a/src/contexts/RoomContext.ts b/src/contexts/RoomContext.ts index cbf56e8a4a..6dd705870a 100644 --- a/src/contexts/RoomContext.ts +++ b/src/contexts/RoomContext.ts @@ -35,7 +35,6 @@ const RoomContext = createContext({ shouldPeek: true, membersLoaded: false, numUnreadMessages: 0, - guestsCanJoin: false, canPeek: false, showApps: false, isPeeking: false, diff --git a/test/components/views/rooms/MessageComposerButtons-test.tsx b/test/components/views/rooms/MessageComposerButtons-test.tsx index 1ec08e455d..d9f867b67e 100644 --- a/test/components/views/rooms/MessageComposerButtons-test.tsx +++ b/test/components/views/rooms/MessageComposerButtons-test.tsx @@ -209,7 +209,6 @@ function createRoomState(room: Room, narrow: boolean): IRoomState { shouldPeek: true, membersLoaded: false, numUnreadMessages: 0, - guestsCanJoin: false, canPeek: false, showApps: false, isPeeking: false,