Use context provided RoomViewStore within the RoomView component hierarchy (#31077)
* Update ContentMessages.ts Update ContentMessages.ts * update PlaybackQueue.ts * Update SpaceHierarchy.tsx * Update ThreadView.tsx * Update RoomCallBanner.tsx * Update useRoomCall.tsx * Update DateSeparator.tsx * Update TimelineCard.tsx * Update UserInfoBasicOptions * Update slask-commands/utils.ts * lint * Update PlaybackQueue, MVoiceMessageBody and UserInfoBasicOptionsView tests. * Update RoomHeader-test.tsx * lint * Add ts docs * Update utils-test.tsx * Update message-test.ts * coverage * lint * Improve naming --------- Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -1128,6 +1128,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
||||
[payload.file],
|
||||
roomId,
|
||||
undefined,
|
||||
this.state.replyToEvent,
|
||||
this.context.client,
|
||||
);
|
||||
}
|
||||
@@ -2047,6 +2048,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
||||
Array.from(dataTransfer.files),
|
||||
roomId,
|
||||
undefined,
|
||||
this.state.replyToEvent,
|
||||
this.context.client,
|
||||
TimelineRenderingType.Room,
|
||||
);
|
||||
|
||||
@@ -67,10 +67,11 @@ import { type JoinRoomReadyPayload } from "../../dispatcher/payloads/JoinRoomRea
|
||||
import { KeyBindingAction } from "../../accessibility/KeyboardShortcuts";
|
||||
import { getKeyBindingsManager } from "../../KeyBindingsManager";
|
||||
import { getTopic } from "../../hooks/room/useTopic";
|
||||
import { SdkContextClass } from "../../contexts/SDKContext";
|
||||
import { getDisplayAliasForAliasSet } from "../../Rooms";
|
||||
import SettingsStore from "../../settings/SettingsStore";
|
||||
import { filterBoolean } from "../../utils/arrays.ts";
|
||||
import { type RoomViewStore } from "../../stores/RoomViewStore.tsx";
|
||||
import RoomContext from "../../contexts/RoomContext.ts";
|
||||
|
||||
interface IProps {
|
||||
space: Room;
|
||||
@@ -404,7 +405,20 @@ export const showRoom = (cli: MatrixClient, hierarchy: RoomHierarchy, roomId: st
|
||||
});
|
||||
};
|
||||
|
||||
export const joinRoom = async (cli: MatrixClient, hierarchy: RoomHierarchy, roomId: string): Promise<unknown> => {
|
||||
/**
|
||||
* Join a room.
|
||||
* @param cli The Matrix client
|
||||
* @param roomViewStore The RoomViewStore instance
|
||||
* @param hierarchy The RoomHierarchy instance
|
||||
* @param roomId The ID of the room to join
|
||||
* @returns A promise that resolves when the room has been joined
|
||||
*/
|
||||
export const joinRoom = async (
|
||||
cli: MatrixClient,
|
||||
roomViewStore: RoomViewStore,
|
||||
hierarchy: RoomHierarchy,
|
||||
roomId: string,
|
||||
): Promise<unknown> => {
|
||||
// Don't let the user view a room they won't be able to either peek or join:
|
||||
// fail earlier so they don't have to click back to the directory.
|
||||
if (cli.isGuest()) {
|
||||
@@ -418,10 +432,10 @@ export const joinRoom = async (cli: MatrixClient, hierarchy: RoomHierarchy, room
|
||||
});
|
||||
} catch (err: unknown) {
|
||||
if (err instanceof MatrixError) {
|
||||
SdkContextClass.instance.roomViewStore.showJoinRoomError(err, roomId);
|
||||
roomViewStore.showJoinRoomError(err, roomId);
|
||||
} else {
|
||||
logger.warn("Got a non-MatrixError while joining room", err);
|
||||
SdkContextClass.instance.roomViewStore.showJoinRoomError(
|
||||
roomViewStore.showJoinRoomError(
|
||||
new MatrixError({
|
||||
error: _t("error|unknown"),
|
||||
}),
|
||||
@@ -761,6 +775,7 @@ const ManageButtons: React.FC<IManageButtonsProps> = ({ hierarchy, selected, set
|
||||
|
||||
const SpaceHierarchy: React.FC<IProps> = ({ space, initialText = "", showRoom, additionalButtons }) => {
|
||||
const cli = useContext(MatrixClientContext);
|
||||
const roomContext = useContext(RoomContext);
|
||||
const [query, setQuery] = useState(initialText);
|
||||
|
||||
const [selected, setSelected] = useState(new Map<string, Set<string>>()); // Map<parentId, Set<childId>>
|
||||
@@ -855,10 +870,10 @@ const SpaceHierarchy: React.FC<IProps> = ({ space, initialText = "", showRoom, a
|
||||
onJoinRoomClick={async (roomId, parents) => {
|
||||
for (const parent of parents) {
|
||||
if (cli.getRoom(parent)?.getMyMembership() !== KnownMembership.Join) {
|
||||
await joinRoom(cli, hierarchy, parent);
|
||||
await joinRoom(cli, roomContext.roomViewStore, hierarchy, parent);
|
||||
}
|
||||
}
|
||||
await joinRoom(cli, hierarchy, roomId);
|
||||
await joinRoom(cli, roomContext.roomViewStore, hierarchy, roomId);
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -49,7 +49,6 @@ import { type ButtonEvent } from "../views/elements/AccessibleButton";
|
||||
import Spinner from "../views/elements/Spinner";
|
||||
import { type ComposerInsertPayload, ComposerType } from "../../dispatcher/payloads/ComposerInsertPayload";
|
||||
import Heading from "../views/typography/Heading";
|
||||
import { SdkContextClass } from "../../contexts/SDKContext";
|
||||
import { type ThreadPayload } from "../../dispatcher/payloads/ThreadPayload";
|
||||
import { ScopedRoomContextProvider } from "../../contexts/ScopedRoomContext.tsx";
|
||||
|
||||
@@ -124,7 +123,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
|
||||
const roomId = this.props.mxEvent.getRoomId();
|
||||
SettingsStore.unwatchSetting(this.layoutWatcherRef);
|
||||
|
||||
const hasRoomChanged = SdkContextClass.instance.roomViewStore.getRoomId() !== roomId;
|
||||
const hasRoomChanged = this.context.roomViewStore.getRoomId() !== roomId;
|
||||
if (this.props.initialEvent && !hasRoomChanged) {
|
||||
dis.dispatch<ViewRoomPayload>({
|
||||
action: Action.ViewRoom,
|
||||
@@ -334,6 +333,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
|
||||
Array.from(dataTransfer.files),
|
||||
roomId,
|
||||
this.threadRelation,
|
||||
this.context.replyToEvent,
|
||||
MatrixClientPeg.safeGet(),
|
||||
TimelineRenderingType.Thread,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user