Move ViewUser action callback to RoomView
This commit is contained in:
parent
dc70ea5059
commit
b37a808985
4 changed files with 69 additions and 48 deletions
|
@ -129,6 +129,8 @@ import { WaitingForThirdPartyRoomView } from "./WaitingForThirdPartyRoomView";
|
||||||
import { isNotUndefined } from "../../Typeguards";
|
import { isNotUndefined } from "../../Typeguards";
|
||||||
import { CancelAskToJoinPayload } from "../../dispatcher/payloads/CancelAskToJoinPayload";
|
import { CancelAskToJoinPayload } from "../../dispatcher/payloads/CancelAskToJoinPayload";
|
||||||
import { SubmitAskToJoinPayload } from "../../dispatcher/payloads/SubmitAskToJoinPayload";
|
import { SubmitAskToJoinPayload } from "../../dispatcher/payloads/SubmitAskToJoinPayload";
|
||||||
|
import RightPanelStore from "../../stores/right-panel/RightPanelStore";
|
||||||
|
import { setPhase } from "../../utils/room/setPhase";
|
||||||
|
|
||||||
const DEBUG = false;
|
const DEBUG = false;
|
||||||
const PREVENT_MULTIPLE_JITSI_WITHIN = 30_000;
|
const PREVENT_MULTIPLE_JITSI_WITHIN = 30_000;
|
||||||
|
@ -1251,6 +1253,31 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
||||||
this.messagePanel?.jumpToLiveTimeline();
|
this.messagePanel?.jumpToLiveTimeline();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Action.ViewUser:
|
||||||
|
if (payload.member) {
|
||||||
|
if (payload.push) {
|
||||||
|
RightPanelStore.instance.pushCard({
|
||||||
|
phase: RightPanelPhases.RoomMemberInfo,
|
||||||
|
state: { member: payload.member },
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
RightPanelStore.instance.setCards([
|
||||||
|
{ phase: RightPanelPhases.RoomSummary },
|
||||||
|
{ phase: RightPanelPhases.RoomMemberList },
|
||||||
|
{ phase: RightPanelPhases.RoomMemberInfo, state: { member: payload.member } },
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setPhase(RightPanelPhases.RoomMemberList);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "view_3pid_invite":
|
||||||
|
if (payload.event) {
|
||||||
|
setPhase(RightPanelPhases.Room3pidMemberInfo, { memberInfoEvent: payload.event });
|
||||||
|
} else {
|
||||||
|
setPhase(RightPanelPhases.RoomMemberList);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,8 @@ import React from "react";
|
||||||
import dis from "../../../dispatcher/dispatcher";
|
import dis from "../../../dispatcher/dispatcher";
|
||||||
import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
|
import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
|
||||||
import { RightPanelPhases } from "../../../stores/right-panel/RightPanelStorePhases";
|
import { RightPanelPhases } from "../../../stores/right-panel/RightPanelStorePhases";
|
||||||
import { IRightPanelCardState } from "../../../stores/right-panel/RightPanelStoreIPanelState";
|
|
||||||
import { UPDATE_EVENT } from "../../../stores/AsyncStore";
|
import { UPDATE_EVENT } from "../../../stores/AsyncStore";
|
||||||
import { NotificationColor } from "../../../stores/notifications/NotificationColor";
|
import { NotificationColor } from "../../../stores/notifications/NotificationColor";
|
||||||
import { ActionPayload } from "../../../dispatcher/payloads";
|
|
||||||
|
|
||||||
export enum HeaderKind {
|
export enum HeaderKind {
|
||||||
Room = "room",
|
Room = "room",
|
||||||
|
@ -59,7 +57,6 @@ export default abstract class HeaderButtons<P = {}> extends React.Component<IPro
|
||||||
|
|
||||||
public componentDidMount(): void {
|
public componentDidMount(): void {
|
||||||
RightPanelStore.instance.on(UPDATE_EVENT, this.onRightPanelStoreUpdate);
|
RightPanelStore.instance.on(UPDATE_EVENT, this.onRightPanelStoreUpdate);
|
||||||
this.dispatcherRef = dis.register(this.onAction.bind(this)); // used by subclasses
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount(): void {
|
public componentWillUnmount(): void {
|
||||||
|
@ -68,18 +65,6 @@ export default abstract class HeaderButtons<P = {}> extends React.Component<IPro
|
||||||
if (this.dispatcherRef) dis.unregister(this.dispatcherRef);
|
if (this.dispatcherRef) dis.unregister(this.dispatcherRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract onAction(payload: ActionPayload): void;
|
|
||||||
|
|
||||||
public setPhase(phase: RightPanelPhases, cardState?: Partial<IRightPanelCardState>): void {
|
|
||||||
const rps = RightPanelStore.instance;
|
|
||||||
if (rps.currentCard.phase == phase && !cardState && rps.isOpen) {
|
|
||||||
rps.togglePanel(null);
|
|
||||||
} else {
|
|
||||||
RightPanelStore.instance.setCard({ phase, state: cardState });
|
|
||||||
if (!rps.isOpen) rps.togglePanel(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public isPhase(phases: string | string[]): boolean {
|
public isPhase(phases: string | string[]): boolean {
|
||||||
if (!RightPanelStore.instance.isOpen) return false;
|
if (!RightPanelStore.instance.isOpen) return false;
|
||||||
if (Array.isArray(phases)) {
|
if (Array.isArray(phases)) {
|
||||||
|
|
|
@ -26,7 +26,6 @@ import { _t } from "../../../languageHandler";
|
||||||
import HeaderButton from "./HeaderButton";
|
import HeaderButton from "./HeaderButton";
|
||||||
import HeaderButtons, { HeaderKind } from "./HeaderButtons";
|
import HeaderButtons, { HeaderKind } from "./HeaderButtons";
|
||||||
import { RightPanelPhases } from "../../../stores/right-panel/RightPanelStorePhases";
|
import { RightPanelPhases } from "../../../stores/right-panel/RightPanelStorePhases";
|
||||||
import { Action } from "../../../dispatcher/actions";
|
|
||||||
import { ActionPayload } from "../../../dispatcher/payloads";
|
import { ActionPayload } from "../../../dispatcher/payloads";
|
||||||
import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
|
import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
|
||||||
import { useReadPinnedEvents, usePinnedEvents } from "./PinnedMessagesCard";
|
import { useReadPinnedEvents, usePinnedEvents } from "./PinnedMessagesCard";
|
||||||
|
@ -41,6 +40,7 @@ import { SummarizedNotificationState } from "../../../stores/notifications/Summa
|
||||||
import PosthogTrackers from "../../../PosthogTrackers";
|
import PosthogTrackers from "../../../PosthogTrackers";
|
||||||
import { ButtonEvent } from "../elements/AccessibleButton";
|
import { ButtonEvent } from "../elements/AccessibleButton";
|
||||||
import { doesRoomOrThreadHaveUnreadMessages } from "../../../Unread";
|
import { doesRoomOrThreadHaveUnreadMessages } from "../../../Unread";
|
||||||
|
import { setPhase } from "../../../utils/room/setPhase";
|
||||||
|
|
||||||
const ROOM_INFO_PHASES = [
|
const ROOM_INFO_PHASES = [
|
||||||
RightPanelPhases.RoomSummary,
|
RightPanelPhases.RoomSummary,
|
||||||
|
@ -203,59 +203,34 @@ export default class LegacyRoomHeaderButtons extends HeaderButtons<IProps> {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
protected onAction(payload: ActionPayload): void {
|
protected onAction(payload: ActionPayload): void {}
|
||||||
if (payload.action === Action.ViewUser) {
|
|
||||||
if (payload.member) {
|
|
||||||
if (payload.push) {
|
|
||||||
RightPanelStore.instance.pushCard({
|
|
||||||
phase: RightPanelPhases.RoomMemberInfo,
|
|
||||||
state: { member: payload.member },
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
RightPanelStore.instance.setCards([
|
|
||||||
{ phase: RightPanelPhases.RoomSummary },
|
|
||||||
{ phase: RightPanelPhases.RoomMemberList },
|
|
||||||
{ phase: RightPanelPhases.RoomMemberInfo, state: { member: payload.member } },
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.setPhase(RightPanelPhases.RoomMemberList);
|
|
||||||
}
|
|
||||||
} else if (payload.action === "view_3pid_invite") {
|
|
||||||
if (payload.event) {
|
|
||||||
this.setPhase(RightPanelPhases.Room3pidMemberInfo, { memberInfoEvent: payload.event });
|
|
||||||
} else {
|
|
||||||
this.setPhase(RightPanelPhases.RoomMemberList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private onRoomSummaryClicked = (): void => {
|
private onRoomSummaryClicked = (): void => {
|
||||||
// use roomPanelPhase rather than this.state.phase as it remembers the latest one if we close
|
// use roomPanelPhase rather than this.state.phase as it remembers the latest one if we close
|
||||||
const currentPhase = RightPanelStore.instance.currentCard.phase;
|
const currentPhase = RightPanelStore.instance.currentCard.phase;
|
||||||
if (currentPhase && ROOM_INFO_PHASES.includes(currentPhase)) {
|
if (currentPhase && ROOM_INFO_PHASES.includes(currentPhase)) {
|
||||||
if (this.state.phase === currentPhase) {
|
if (this.state.phase === currentPhase) {
|
||||||
this.setPhase(currentPhase);
|
setPhase(currentPhase);
|
||||||
} else {
|
} else {
|
||||||
this.setPhase(currentPhase, RightPanelStore.instance.currentCard.state);
|
setPhase(currentPhase, RightPanelStore.instance.currentCard.state);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This toggles for us, if needed
|
// This toggles for us, if needed
|
||||||
this.setPhase(RightPanelPhases.RoomSummary);
|
setPhase(RightPanelPhases.RoomSummary);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private onNotificationsClicked = (): void => {
|
private onNotificationsClicked = (): void => {
|
||||||
// This toggles for us, if needed
|
// This toggles for us, if needed
|
||||||
this.setPhase(RightPanelPhases.NotificationPanel);
|
setPhase(RightPanelPhases.NotificationPanel);
|
||||||
};
|
};
|
||||||
|
|
||||||
private onPinnedMessagesClicked = (): void => {
|
private onPinnedMessagesClicked = (): void => {
|
||||||
// This toggles for us, if needed
|
// This toggles for us, if needed
|
||||||
this.setPhase(RightPanelPhases.PinnedMessages);
|
setPhase(RightPanelPhases.PinnedMessages);
|
||||||
};
|
};
|
||||||
private onTimelineCardClicked = (): void => {
|
private onTimelineCardClicked = (): void => {
|
||||||
this.setPhase(RightPanelPhases.Timeline);
|
setPhase(RightPanelPhases.Timeline);
|
||||||
};
|
};
|
||||||
|
|
||||||
private onThreadsPanelClicked = (ev: ButtonEvent): void => {
|
private onThreadsPanelClicked = (ev: ButtonEvent): void => {
|
||||||
|
|
34
src/utils/room/setPhase.ts
Normal file
34
src/utils/room/setPhase.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
Copyright 2023 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import RightPanelStore from "../../stores/right-panel/RightPanelStore";
|
||||||
|
import { IRightPanelCardState } from "../../stores/right-panel/RightPanelStoreIPanelState";
|
||||||
|
import { RightPanelPhases } from "../../stores/right-panel/RightPanelStorePhases";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to toggle a right panel view.
|
||||||
|
* @param phase The right panel phase.
|
||||||
|
* @param cardState The state within the phase.
|
||||||
|
*/
|
||||||
|
export function setPhase(phase: RightPanelPhases, cardState?: Partial<IRightPanelCardState>): void {
|
||||||
|
const rps = RightPanelStore.instance;
|
||||||
|
if (rps.currentCard.phase == phase && !cardState && rps.isOpen) {
|
||||||
|
rps.togglePanel(null);
|
||||||
|
} else {
|
||||||
|
RightPanelStore.instance.setCard({ phase, state: cardState });
|
||||||
|
if (!rps.isOpen) rps.togglePanel(null);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue