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

Commit

Permalink
Fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariusz Niemczyk committed Oct 1, 2021
1 parent 1a37305 commit bb88559
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/components/structures/MessagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
defaultDispatcher.dispatch({
action: Action.EditEvent,
event: this.props.room.findEventById(pendingEditItem),
renderingContext: this.context.renderingContext,
timelineRenderingType: this.context.timelineRenderingType,
});
}
}
Expand Down Expand Up @@ -563,7 +563,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {

private get pendingEditItem(): string | undefined {
try {
return localStorage.getItem(`mx_edit_room_${this.props.room.roomId}_${this.context.renderingContext}`);
return localStorage.getItem(`mx_edit_room_${this.props.room.roomId}_${this.context.timelineRenderingType}`);
} catch (err) {
logger.error(err);
return undefined;
Expand Down
8 changes: 4 additions & 4 deletions src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { Layout } from "../../settings/Layout";
import AccessibleButton from "../views/elements/AccessibleButton";
import RightPanelStore from "../../stores/RightPanelStore";
import { haveTileForEvent } from "../views/rooms/EventTile";
import RoomContext, { AppRenderingContext } from "../../contexts/RoomContext";
import RoomContext, { TimelineRenderingType } from "../../contexts/RoomContext";
import MatrixClientContext, { withMatrixClientHOC, MatrixClientProps } from "../../contexts/MatrixClientContext";
import { E2EStatus, shieldStatusForRoom } from '../../utils/ShieldUtils';
import { Action } from "../../dispatcher/actions";
Expand Down Expand Up @@ -188,7 +188,7 @@ export interface IRoomState {
// if it did we don't want the room to be marked as read as soon as it is loaded.
wasContextSwitch?: boolean;
editState?: EditorStateTransfer;
renderingContext: AppRenderingContext;
timelineRenderingType: TimelineRenderingType;
liveTimeline?: EventTimeline;
}

Expand Down Expand Up @@ -250,7 +250,7 @@ class RoomView extends React.Component<IRoomProps, IRoomState> {
showDisplaynameChanges: true,
matrixClientIsReady: this.context && this.context.isInitialSyncComplete(),
dragCounter: 0,
renderingContext: AppRenderingContext.Room,
timelineRenderingType: TimelineRenderingType.Room,
liveTimeline: undefined,
};

Expand Down Expand Up @@ -815,7 +815,7 @@ class RoomView extends React.Component<IRoomProps, IRoomState> {

case Action.EditEvent: {
// Quit early if we're trying to edit events in wrong rendering context
if (payload.renderingContext !== this.state.renderingContext) return;
if (payload.timelineRenderingType !== this.state.timelineRenderingType) return;
const editState = payload.event ? new EditorStateTransfer(payload.event) : null;
this.setState({ editState }, () => {
if (payload.event) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/structures/ThreadView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { Action } from '../../dispatcher/actions';
import { MatrixClientPeg } from '../../MatrixClientPeg';
import { E2EStatus } from '../../utils/ShieldUtils';
import EditorStateTransfer from '../../utils/EditorStateTransfer';
import RoomContext, { AppRenderingContext } from '../../contexts/RoomContext';
import RoomContext, { TimelineRenderingType } from '../../contexts/RoomContext';

interface IProps {
room: Room;
Expand Down Expand Up @@ -99,7 +99,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
switch (payload.action) {
case Action.EditEvent: {
// Quit early if it's not a thread context
if (payload.renderingContext !== AppRenderingContext.Thread) return;
if (payload.timelineRenderingType !== TimelineRenderingType.Thread) return;
// Quit early if that's not a thread event
if (payload.event && !payload.event.getThread()) return;
const editState = payload.event ? new EditorStateTransfer(payload.event) : null;
Expand Down Expand Up @@ -149,7 +149,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
return (
<RoomContext.Provider value={{
...this.context,
renderingContext: AppRenderingContext.Thread,
timelineRenderingType: TimelineRenderingType.Thread,
liveTimeline: this.state?.thread?.timelineSet?.getLiveTimeline(),
}}>

Expand Down
6 changes: 3 additions & 3 deletions src/components/views/messages/MessageActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Action } from '../../../dispatcher/actions';
import { RightPanelPhases } from '../../../stores/RightPanelStorePhases';
import { aboveLeftOf, ContextMenu, ContextMenuTooltipButton, useContextMenu } from '../../structures/ContextMenu';
import { isContentActionable, canEditContent } from '../../../utils/EventUtils';
import RoomContext, { AppRenderingContext } from "../../../contexts/RoomContext";
import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext";
import Toolbar from "../../../accessibility/Toolbar";
import { RovingAccessibleTooltipButton, useRovingTabIndex } from "../../../accessibility/RovingTabIndex";
import { replaceableComponent } from "../../../utils/replaceableComponent";
Expand Down Expand Up @@ -209,7 +209,7 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
dis.dispatch({
action: Action.EditEvent,
event: this.props.mxEvent,
renderingContext: this.context.renderingContext,
timelineRenderingType: this.context.timelineRenderingType,
});
};

Expand Down Expand Up @@ -289,7 +289,7 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
// Like the resend button, the react and reply buttons need to appear before the edit.
// The only catch is we do the reply button first so that we can make sure the react
// button is the very first button without having to do length checks for `splice()`.
if (this.context.canReply && this.context.renderingContext === AppRenderingContext.Room) {
if (this.context.canReply && this.context.timelineRenderingType === TimelineRenderingType.Room) {
toolbarOpts.splice(0, 0, <>
<RovingAccessibleTooltipButton
className="mx_MessageActionBar_maskButton mx_MessageActionBar_replyButton"
Expand Down
12 changes: 6 additions & 6 deletions src/components/views/rooms/EditMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
dis.dispatch({
action: Action.EditEvent,
event: previousEvent,
renderingContext: this.context.renderingContext,
timelineRenderingType: this.context.timelineRenderingType,
});
event.preventDefault();
}
Expand All @@ -190,14 +190,14 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
dis.dispatch({
action: Action.EditEvent,
event: nextEvent,
renderingContext: this.context.renderingContext,
timelineRenderingType: this.context.timelineRenderingType,
});
} else {
this.clearStoredEditorState();
dis.dispatch({
action: Action.EditEvent,
event: null,
renderingContext: this.context.renderingContext,
timelineRenderingType: this.context.timelineRenderingType,
});
dis.fire(Action.FocusSendMessageComposer);
}
Expand All @@ -208,7 +208,7 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
};

private get editorRoomKey(): string {
return `mx_edit_room_${this.getRoom().roomId}_${this.context.renderingContext}`;
return `mx_edit_room_${this.getRoom().roomId}_${this.context.timelineRenderingType}`;
}

private get editorStateKey(): string {
Expand All @@ -227,7 +227,7 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
dis.dispatch({
action: Action.EditEvent,
event: null,
renderingContext: this.context.renderingContext,
timelineRenderingType: this.context.timelineRenderingType,
});
dis.fire(Action.FocusSendMessageComposer);
};
Expand Down Expand Up @@ -422,7 +422,7 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
dis.dispatch({
action: Action.EditEvent,
event: null,
renderingContext: this.context.renderingContext,
timelineRenderingType: this.context.timelineRenderingType,
});
dis.fire(Action.FocusSendMessageComposer);
};
Expand Down
14 changes: 4 additions & 10 deletions src/components/views/rooms/SendMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import EMOJI_REGEX from 'emojibase-regex';
import { IContent, MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { DebouncedFunc, throttle } from 'lodash';
import { EventType, RelationType } from "matrix-js-sdk/src/@types/event";
import { logger } from "matrix-js-sdk/src/logger";

import dis from '../../../dispatcher/dispatcher';
import EditorModel from '../../../editor/model';
Expand Down Expand Up @@ -55,9 +56,6 @@ import ErrorDialog from "../dialogs/ErrorDialog";
import QuestionDialog from "../dialogs/QuestionDialog";
import { ActionPayload } from "../../../dispatcher/payloads";
import { decorateStartSendingTime, sendRoundTripMetric } from "../../../sendTimePerformanceMetrics";

import { logger } from "matrix-js-sdk/src/logger";
import type { EventTimeline } from 'matrix-js-sdk/src/models/event-timeline';
import RoomContext from '../../../contexts/RoomContext';

function addReplyToMessageContent(
Expand Down Expand Up @@ -134,7 +132,6 @@ export function isQuickReaction(model: EditorModel): boolean {

interface ISendMessageComposerProps extends MatrixClientProps {
room: Room;
liveTimeline: EventTimeline;
placeholder?: string;
permalinkCreator: RoomPermalinkCreator;
replyInThread?: boolean;
Expand All @@ -146,8 +143,6 @@ interface ISendMessageComposerProps extends MatrixClientProps {
@replaceableComponent("views.rooms.SendMessageComposer")
export class SendMessageComposer extends React.Component<ISendMessageComposerProps> {
static contextType = RoomContext;
context!: React.ContextType<typeof RoomContext>;

private readonly prepareToEncrypt?: DebouncedFunc<() => void>;
private readonly editorRef = createRef<BasicMessageComposer>();
private model: EditorModel = null;
Expand All @@ -157,7 +152,6 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro

constructor(props: ISendMessageComposerProps, context: React.ContextType<typeof RoomContext>) {
super(props);
this.context = context; // otherwise React will only set it prior to render due to type def above
if (this.props.mxClient.isCryptoEnabled() && this.props.mxClient.isRoomEncrypted(this.props.room.roomId)) {
this.prepareToEncrypt = throttle(() => {
this.props.mxClient.prepareToEncrypt(this.props.room);
Expand Down Expand Up @@ -206,7 +200,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
// selection must be collapsed and caret at start
if (this.editorRef.current?.isSelectionCollapsed() && this.editorRef.current?.isCaretAtStart()) {
const events =
this.props.liveTimeline.getEvents()
this.context.liveTimeline.getEvents()
.concat(this.props.replyInThread ? [] : this.props.room.getPendingEvents());
const editEvent = findEditableEvent({
events,
Expand All @@ -218,7 +212,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
dis.dispatch({
action: Action.EditEvent,
event: editEvent,
renderingContext: this.context.renderingContext,
timelineRenderingType: this.context.timelineRenderingType,
});
}
}
Expand Down Expand Up @@ -285,7 +279,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
}

private sendQuickReaction(): void {
const timeline = this.props.room.getLiveTimeline();
const timeline = this.context.liveTimeline();
const events = timeline.getEvents();
const reaction = this.model.parts[1].text;
for (let i = events.length - 1; i >= 0; i--) {
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/RoomContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { createContext } from "react";
import { IRoomState } from "../components/structures/RoomView";
import { Layout } from "../settings/Layout";

export enum AppRenderingContext {
export enum TimelineRenderingType {
Room,
Thread
}
Expand Down Expand Up @@ -58,7 +58,7 @@ const RoomContext = createContext<IRoomState>({
showDisplaynameChanges: true,
matrixClientIsReady: false,
dragCounter: 0,
renderingContext: AppRenderingContext.Room,
timelineRenderingType: TimelineRenderingType.Room,
liveTimeline: undefined,
});
RoomContext.displayName = "RoomContext";
Expand Down

0 comments on commit bb88559

Please sign in to comment.