diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index f6e9fcdc4f..f72b65a943 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -56,7 +56,7 @@ import AccessibleButton from "../views/elements/AccessibleButton"; import RightPanelStore from "../../stores/right-panel/RightPanelStore"; import { haveTileForEvent } from "../views/rooms/EventTile"; import RoomContext, { TimelineRenderingType } from "../../contexts/RoomContext"; -import MatrixClientContext, { withMatrixClientHOC, MatrixClientProps } from "../../contexts/MatrixClientContext"; +import MatrixClientContext, { MatrixClientProps, withMatrixClientHOC } from "../../contexts/MatrixClientContext"; import { E2EStatus, shieldStatusForRoom } from '../../utils/ShieldUtils'; import { Action } from "../../dispatcher/actions"; import { IMatrixClientCreds } from "../../MatrixClientPeg"; @@ -1777,7 +1777,10 @@ export class RoomView extends React.Component { onHiddenHighlightsClick = () => { const oldRoom = this.getOldRoom(); if (!oldRoom) return; - dis.dispatch({ action: "view_room", room_id: oldRoom.roomId }); + dis.dispatch({ + action: Action.ViewRoom, + room_id: oldRoom.roomId, + }); }; render() { diff --git a/src/components/structures/SpaceHierarchy.tsx b/src/components/structures/SpaceHierarchy.tsx index 9e7f1df272..14bfbfbfa3 100644 --- a/src/components/structures/SpaceHierarchy.tsx +++ b/src/components/structures/SpaceHierarchy.tsx @@ -327,7 +327,7 @@ export const showRoom = (cli: MatrixClient, hierarchy: RoomHierarchy, roomId: st const roomAlias = getDisplayAliasForRoom(room) || undefined; dis.dispatch({ - action: "view_room", + action: Action.ViewRoom, should_peek: true, _type: "room_directory", // instrumentation room_alias: roomAlias, diff --git a/src/components/structures/SpaceRoomView.tsx b/src/components/structures/SpaceRoomView.tsx index 7ad894243b..ffa2c5e4ed 100644 --- a/src/components/structures/SpaceRoomView.tsx +++ b/src/components/structures/SpaceRoomView.tsx @@ -834,7 +834,7 @@ export default class SpaceRoomView extends React.PureComponent { }; private onAction = (payload: ActionPayload) => { - if (payload.action === "view_room" && payload.room_id === this.props.space.roomId) { + if (payload.action === Action.ViewRoom && payload.room_id === this.props.space.roomId) { this.setState({ phase: Phase.Landing }); return; } @@ -862,7 +862,7 @@ export default class SpaceRoomView extends React.PureComponent { private goToFirstRoom = async () => { if (this.state.firstRoomId) { defaultDispatcher.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: this.state.firstRoomId, }); return; diff --git a/src/components/views/context_menus/RoomContextMenu.tsx b/src/components/views/context_menus/RoomContextMenu.tsx index ee7e7e1694..5bcf8e5e25 100644 --- a/src/components/views/context_menus/RoomContextMenu.tsx +++ b/src/components/views/context_menus/RoomContextMenu.tsx @@ -43,6 +43,7 @@ import { ROOM_NOTIFICATIONS_TAB } from "../dialogs/RoomSettingsDialog"; import { useEventEmitterState } from "../../../hooks/useEventEmitter"; import RightPanelStore from "../../../stores/right-panel/RightPanelStore"; import DMRoomMap from "../../../utils/DMRoomMap"; +import { Action } from "../../../dispatcher/actions"; interface IProps extends IContextMenuProps { room: Room; @@ -239,7 +240,7 @@ const RoomContextMenu = ({ room, onFinished, ...props }: IProps) => { const ensureViewingRoom = () => { if (RoomViewStore.getRoomId() === room.roomId) return; dis.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: room.roomId, }, true); }; diff --git a/src/components/views/context_menus/SpaceContextMenu.tsx b/src/components/views/context_menus/SpaceContextMenu.tsx index 6c7d6f6597..0525f4f175 100644 --- a/src/components/views/context_menus/SpaceContextMenu.tsx +++ b/src/components/views/context_menus/SpaceContextMenu.tsx @@ -18,9 +18,7 @@ import React, { useContext } from "react"; import { Room } from "matrix-js-sdk/src/models/room"; import { EventType } from "matrix-js-sdk/src/@types/event"; -import { - IProps as IContextMenuProps, -} from "../../structures/ContextMenu"; +import { IProps as IContextMenuProps } from "../../structures/ContextMenu"; import IconizedContextMenu, { IconizedContextMenuOption, IconizedContextMenuOptionList } from "./IconizedContextMenu"; import { _t } from "../../../languageHandler"; import { @@ -180,7 +178,7 @@ const SpaceContextMenu = ({ space, hideHeader, onFinished, ...props }: IProps) = ev.stopPropagation(); defaultDispatcher.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: space.roomId, }); onFinished(); diff --git a/src/components/views/dialogs/CreateSpaceFromCommunityDialog.tsx b/src/components/views/dialogs/CreateSpaceFromCommunityDialog.tsx index 363f48fd09..9674054e69 100644 --- a/src/components/views/dialogs/CreateSpaceFromCommunityDialog.tsx +++ b/src/components/views/dialogs/CreateSpaceFromCommunityDialog.tsx @@ -227,7 +227,7 @@ const CreateSpaceFromCommunityDialog: React.FC = ({ matrixClient: cli, g const onSpaceClick = () => { dis.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: roomId, }); }; diff --git a/src/components/views/dialogs/ForwardDialog.tsx b/src/components/views/dialogs/ForwardDialog.tsx index 626615ef64..0fddc2f3c5 100644 --- a/src/components/views/dialogs/ForwardDialog.tsx +++ b/src/components/views/dialogs/ForwardDialog.tsx @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React, { useMemo, useState, useEffect } from "react"; +import React, { useEffect, useMemo, useState } from "react"; import classnames from "classnames"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { Room } from "matrix-js-sdk/src/models/room"; @@ -23,7 +23,7 @@ import { RoomMember } from "matrix-js-sdk/src/models/room-member"; import { _t } from "../../../languageHandler"; import dis from "../../../dispatcher/dispatcher"; -import { useSettingValue, useFeatureEnabled } from "../../../hooks/useSettings"; +import { useFeatureEnabled, useSettingValue } from "../../../hooks/useSettings"; import { UIFeature } from "../../../settings/UIFeature"; import { Layout } from "../../../settings/enums/Layout"; import { IDialogProps } from "./IDialogProps"; @@ -45,6 +45,7 @@ import EntityTile from "../rooms/EntityTile"; import BaseAvatar from "../avatars/BaseAvatar"; import SpaceStore from "../../../stores/spaces/SpaceStore"; import { roomContextDetailsText } from "../../../Rooms"; +import { Action } from "../../../dispatcher/actions"; const AVATAR_SIZE = 30; @@ -76,7 +77,7 @@ const Entry: React.FC = ({ room, event, matrixClient: cli, onFinish const jumpToRoom = () => { dis.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: room.roomId, }); onFinished(true); diff --git a/src/components/views/dialogs/SpotlightDialog.tsx b/src/components/views/dialogs/SpotlightDialog.tsx index 50d14e33a3..7bbe3baa24 100644 --- a/src/components/views/dialogs/SpotlightDialog.tsx +++ b/src/components/views/dialogs/SpotlightDialog.tsx @@ -221,7 +221,7 @@ const SpotlightDialog: React.FC = ({ initialText = "", onFinished }) => } defaultDispatcher.dispatch({ - action: 'view_room', + action: Action.ViewRoom, room_id: roomId, }); onFinished(); diff --git a/src/components/views/rooms/RecentlyViewedButton.tsx b/src/components/views/rooms/RecentlyViewedButton.tsx index 9a2630e3ed..84d6c91abd 100644 --- a/src/components/views/rooms/RecentlyViewedButton.tsx +++ b/src/components/views/rooms/RecentlyViewedButton.tsx @@ -25,6 +25,7 @@ import RoomAvatar from "../avatars/RoomAvatar"; import dis from "../../../dispatcher/dispatcher"; import InteractiveTooltip, { Direction } from "../elements/InteractiveTooltip"; import { roomContextDetailsText } from "../../../Rooms"; +import { Action } from "../../../dispatcher/actions"; const RecentlyViewedButton = () => { const tooltipRef = useRef(); @@ -40,7 +41,7 @@ const RecentlyViewedButton = () => { key={crumb.roomId} onClick={() => { dis.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: crumb.roomId, }); tooltipRef.current?.hideTooltip(); diff --git a/src/components/views/rooms/RoomBreadcrumbs.tsx b/src/components/views/rooms/RoomBreadcrumbs.tsx index e99876d845..f3d69b1f28 100644 --- a/src/components/views/rooms/RoomBreadcrumbs.tsx +++ b/src/components/views/rooms/RoomBreadcrumbs.tsx @@ -27,6 +27,7 @@ import { UPDATE_EVENT } from "../../../stores/AsyncStore"; import { RovingAccessibleTooltipButton } from "../../../accessibility/RovingTabIndex"; import Toolbar from "../../../accessibility/Toolbar"; import { replaceableComponent } from "../../../utils/replaceableComponent"; +import { Action } from "../../../dispatcher/actions"; interface IProps { } @@ -78,7 +79,10 @@ export default class RoomBreadcrumbs extends React.PureComponent private viewRoom = (room: Room, index: number) => { Analytics.trackEvent("Breadcrumbs", "click_node", String(index)); - defaultDispatcher.dispatch({ action: "view_room", room_id: room.roomId }); + defaultDispatcher.dispatch({ + action: Action.ViewRoom, + room_id: room.roomId, + }); }; public render(): React.ReactElement { diff --git a/src/components/views/rooms/RoomList.tsx b/src/components/views/rooms/RoomList.tsx index c36df0546d..47b96e374f 100644 --- a/src/components/views/rooms/RoomList.tsx +++ b/src/components/views/rooms/RoomList.tsx @@ -47,12 +47,12 @@ import AccessibleButton from "../elements/AccessibleButton"; import { CommunityPrototypeStore } from "../../../stores/CommunityPrototypeStore"; import SpaceStore from "../../../stores/spaces/SpaceStore"; import { + isMetaSpace, ISuggestedRoom, MetaSpace, SpaceKey, - UPDATE_SUGGESTED_ROOMS, UPDATE_SELECTED_SPACE, - isMetaSpace, + UPDATE_SUGGESTED_ROOMS, } from "../../../stores/spaces"; import { shouldShowSpaceInvite, showAddExistingRooms, showCreateNewRoom, showSpaceInvite } from "../../../utils/space"; import { replaceableComponent } from "../../../utils/replaceableComponent"; @@ -215,7 +215,7 @@ const UntaggedAuxButton = ({ tabIndex }: IAuxButtonProps) => { e.stopPropagation(); closeMenu(); defaultDispatcher.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: activeSpace.roomId, }); }} @@ -497,7 +497,7 @@ export default class RoomList extends React.PureComponent { private onExplore = () => { if (!isMetaSpace(this.props.activeSpace)) { defaultDispatcher.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: this.props.activeSpace, }); } else { @@ -522,7 +522,7 @@ export default class RoomList extends React.PureComponent { ); const viewRoom = () => { defaultDispatcher.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_alias: room.canonical_alias || room.aliases?.[0], room_id: room.room_id, via_servers: room.viaServers, diff --git a/src/components/views/rooms/RoomListHeader.tsx b/src/components/views/rooms/RoomListHeader.tsx index a744236dc1..57b91eaeb9 100644 --- a/src/components/views/rooms/RoomListHeader.tsx +++ b/src/components/views/rooms/RoomListHeader.tsx @@ -97,7 +97,7 @@ const PrototypeCommunityContextMenu = (props: ComponentProps { }; private onAction = (payload: ActionPayload) => { - if (payload.action === "view_room" && payload.show_room_tile && this.state.rooms) { + if (payload.action === Action.ViewRoom && payload.show_room_tile && this.state.rooms) { // XXX: we have to do this a tick later because we have incorrect intermediate props during a room change // where we lose the room we are changing from temporarily and then it comes back in an update right after. setImmediate(() => { diff --git a/src/components/views/rooms/RoomTile.tsx b/src/components/views/rooms/RoomTile.tsx index 7cf89de4db..97750f01af 100644 --- a/src/components/views/rooms/RoomTile.tsx +++ b/src/components/views/rooms/RoomTile.tsx @@ -197,7 +197,10 @@ export default class RoomTile extends React.PureComponent { } private onAction = (payload: ActionPayload) => { - if (payload.action === "view_room" && payload.room_id === this.props.room.roomId && payload.show_room_tile) { + if (payload.action === Action.ViewRoom && + payload.room_id === this.props.room.roomId && + payload.show_room_tile + ) { setImmediate(() => { this.scrollIntoView(); }); diff --git a/src/components/views/settings/JoinRuleSettings.tsx b/src/components/views/settings/JoinRuleSettings.tsx index de4cccf5a4..4ec832ca49 100644 --- a/src/components/views/settings/JoinRuleSettings.tsx +++ b/src/components/views/settings/JoinRuleSettings.tsx @@ -33,6 +33,7 @@ import { arrayHasDiff } from "../../../utils/arrays"; import { useLocalEcho } from "../../../hooks/useLocalEcho"; import dis from "../../../dispatcher/dispatcher"; import { ROOM_SECURITY_TAB } from "../dialogs/RoomSettingsDialog"; +import { Action } from "../../../dispatcher/actions"; interface IProps { room: Room; @@ -267,7 +268,7 @@ const JoinRuleSettings = ({ room, promptUpgrade, aliasWarning, onError, beforeCh // switch to the new room in the background dis.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: roomId, }); diff --git a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx index 949730fdcd..d3f99f31dc 100644 --- a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx @@ -36,6 +36,7 @@ import { useDispatcher } from "../../../../../hooks/useDispatcher"; import { CreateEventField, IGroupSummary } from "../../../dialogs/CreateSpaceFromCommunityDialog"; import { createSpaceFromCommunity } from "../../../../../utils/space"; import Spinner from "../../../elements/Spinner"; +import { Action } from "../../../../../dispatcher/actions"; interface IProps { closeSettingsFn(success: boolean): void; @@ -112,7 +113,7 @@ const CommunityMigrator = ({ onFinished }) => { onClick={() => { if (community.spaceId) { dis.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: community.spaceId, }); onFinished(); diff --git a/src/linkify-matrix.ts b/src/linkify-matrix.ts index 668b062f59..bd3e6f3be5 100644 --- a/src/linkify-matrix.ts +++ b/src/linkify-matrix.ts @@ -116,7 +116,10 @@ function onUserClick(event: MouseEvent, userId: string) { } function onAliasClick(event: MouseEvent, roomAlias: string) { event.preventDefault(); - dis.dispatch({ action: 'view_room', room_alias: roomAlias }); + dis.dispatch({ + action: Action.ViewRoom, + room_alias: roomAlias, + }); } function onGroupClick(event: MouseEvent, groupId: string) { event.preventDefault(); diff --git a/src/stores/RoomViewStore.tsx b/src/stores/RoomViewStore.tsx index 21ba48902a..56b88483f9 100644 --- a/src/stores/RoomViewStore.tsx +++ b/src/stores/RoomViewStore.tsx @@ -251,16 +251,10 @@ class RoomViewStore extends Store { } } + // Re-fire the payload with the newly found room_id dis.dispatch({ - action: Action.ViewRoom, + ...payload, room_id: roomId, - event_id: payload.event_id, - highlighted: payload.highlighted, - room_alias: payload.room_alias, - auto_join: payload.auto_join, - oob_data: payload.oob_data, - viaServers: payload.via_servers, - wasContextSwitch: payload.context_switch, }); } } diff --git a/src/stores/right-panel/RightPanelStore.ts b/src/stores/right-panel/RightPanelStore.ts index df2cbe468c..b714263e70 100644 --- a/src/stores/right-panel/RightPanelStore.ts +++ b/src/stores/right-panel/RightPanelStore.ts @@ -362,44 +362,43 @@ export default class RightPanelStore extends ReadyWatchingStore { // this.loadCacheFromSettings(); }; - onDispatch(payload: ActionPayload) { + onDispatch = (payload: ActionPayload) => { switch (payload.action) { case 'view_group': case Action.ViewRoom: { - const _this = RightPanelStore.instance; - if (payload.room_id === _this.viewedRoomId) break; // skip this transition, probably a permalink + if (payload.room_id === this.viewedRoomId) break; // skip this transition, probably a permalink // Put group in the same/similar view to what was open from the previously viewed room // Is contradictory to the new "per room" philosophy but it is the legacy behavior for groups. - if ((_this.isViewingRoom ? Action.ViewRoom : "view_group") != payload.action) { - if (payload.action == Action.ViewRoom && MEMBER_INFO_PHASES.includes(_this.currentCard?.phase)) { + if ((this.isViewingRoom ? Action.ViewRoom : "view_group") != payload.action) { + if (payload.action == Action.ViewRoom && MEMBER_INFO_PHASES.includes(this.currentCard?.phase)) { // switch from group to room - _this.setRightPanelCache({ phase: RightPanelPhases.RoomMemberList, state: {} }); + this.setRightPanelCache({ phase: RightPanelPhases.RoomMemberList, state: {} }); } else if ( payload.action == "view_group" && - _this.currentCard?.phase === RightPanelPhases.GroupMemberInfo + this.currentCard?.phase === RightPanelPhases.GroupMemberInfo ) { // switch from room to group - _this.setRightPanelCache({ phase: RightPanelPhases.GroupMemberList, state: {} }); + this.setRightPanelCache({ phase: RightPanelPhases.GroupMemberList, state: {} }); } } // Update the current room here, so that all the other functions dont need to be room dependant. // The right panel store always will return the state for the current room. - _this.viewedRoomId = payload.room_id; - _this.isViewingRoom = payload.action == Action.ViewRoom; + this.viewedRoomId = payload.room_id; + this.isViewingRoom = payload.action == Action.ViewRoom; // load values from byRoomCache with the viewedRoomId. - if (_this.isReady) { + if (this.isReady) { // we need the client to be ready to get the events form the ids of the settings // the loading will be done in the onReady function (to catch up with the changes done here before it was ready) // all the logic in this case is not necessary anymore as soon as groups are dropped and we use: onRoomViewStoreUpdate - _this.loadCacheFromSettings(); - _this.emitAndUpdateSettings(); + this.loadCacheFromSettings(); + this.emitAndUpdateSettings(); } break; } } - } + }; public static get instance(): RightPanelStore { if (!RightPanelStore.internalInstance) { diff --git a/src/stores/spaces/SpaceStore.ts b/src/stores/spaces/SpaceStore.ts index 1379b47926..63b0073191 100644 --- a/src/stores/spaces/SpaceStore.ts +++ b/src/stores/spaces/SpaceStore.ts @@ -157,7 +157,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient { if (space) { const roomId = this.getNotificationState(space).getFirstRoomWithNotifications(); defaultDispatcher.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: roomId, context_switch: true, }); @@ -174,7 +174,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient { }); if (unreadRoom) { defaultDispatcher.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: unreadRoom.roomId, context_switch: true, }); @@ -222,13 +222,13 @@ export class SpaceStoreClass extends AsyncStoreWithClient { this.isRoomInSpace(space, roomId) ) { defaultDispatcher.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: roomId, context_switch: true, }); } else if (cliSpace) { defaultDispatcher.dispatch({ - action: "view_room", + action: Action.ViewRoom, room_id: space, context_switch: true, }); @@ -1061,7 +1061,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient { if (!spacesEnabled || !this.matrixClient) return; switch (payload.action) { - case "view_room": { + case Action.ViewRoom: { // Don't auto-switch rooms when reacting to a context-switch or for new rooms being created // as this is not helpful and can create loops of rooms/space switching if (payload.context_switch || payload.justCreatedOpts) break; diff --git a/test/stores/SpaceStore-test.ts b/test/stores/SpaceStore-test.ts index 52aff5b381..1f796a1f28 100644 --- a/test/stores/SpaceStore-test.ts +++ b/test/stores/SpaceStore-test.ts @@ -34,6 +34,7 @@ import { MatrixClientPeg } from "../../src/MatrixClientPeg"; import defaultDispatcher from "../../src/dispatcher/dispatcher"; import SettingsStore from "../../src/settings/SettingsStore"; import { SettingLevel } from "../../src/settings/SettingLevel"; +import { Action } from "../../src/dispatcher/actions"; jest.useFakeTimers(); @@ -92,7 +93,7 @@ describe("SpaceStore", () => { let rooms = []; const mkRoom = (roomId: string) => testUtils.mkRoom(client, roomId, rooms); const mkSpace = (spaceId: string, children: string[] = []) => testUtils.mkSpace(client, spaceId, rooms, children); - const viewRoom = roomId => defaultDispatcher.dispatch({ action: "view_room", room_id: roomId }, true); + const viewRoom = roomId => defaultDispatcher.dispatch({ action: Action.ViewRoom, room_id: roomId }, true); const run = async () => { client.getRoom.mockImplementation(roomId => rooms.find(room => room.roomId === roomId)); @@ -680,7 +681,7 @@ describe("SpaceStore", () => { await run(); dispatcherRef = defaultDispatcher.register(payload => { - if (payload.action === "view_room" || payload.action === "view_home_page") { + if (payload.action === Action.ViewRoom || payload.action === "view_home_page") { currentRoom = payload.room_id || null; } });