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

Tidy up timelineRenderingType to be passed over context #7872

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/structures/MessagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,6 @@ export default class MessagePanel extends React.Component<IProps, IState> {
showReadReceipts={this.props.showReadReceipts}
callEventGrouper={callEventGrouper}
hideSender={this.state.hideSender}
timelineRenderingType={this.context.timelineRenderingType}
/>
</TileErrorBoundary>,
);
Expand Down
26 changes: 16 additions & 10 deletions src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import TopUnreadMessagesBar from "../views/rooms/TopUnreadMessagesBar";
import SpaceStore from "../../stores/spaces/SpaceStore";
import { showThread } from '../../dispatcher/dispatch-actions/threads';
import { fetchInitialEvent } from "../../utils/EventUtils";
import { ComposerType } from "../../dispatcher/payloads/ComposerInsertPayload";
import { ComposerInsertPayload, ComposerType } from "../../dispatcher/payloads/ComposerInsertPayload";
import AppsDrawer from '../views/rooms/AppsDrawer';
import { RightPanelPhases } from '../../stores/right-panel/RightPanelStorePhases';
import { ActionPayload } from "../../dispatcher/payloads";
Expand Down Expand Up @@ -153,7 +153,6 @@ export interface IRoomState {
isInitialEventHighlighted?: boolean;
replyToEvent?: MatrixEvent;
numUnreadMessages: number;
searching: boolean;
searchTerm?: string;
searchScope?: SearchScope;
searchResults?: XOR<{}, ISearchResults>;
Expand Down Expand Up @@ -240,7 +239,6 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
shouldPeek: true,
membersLoaded: !llMembers,
numUnreadMessages: 0,
searching: false,
searchResults: null,
callState: null,
guestsCanJoin: false,
Expand Down Expand Up @@ -894,14 +892,17 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
case Action.ComposerInsert: {
if (payload.composerType) break;

if (this.state.searching && payload.timelineRenderingType === TimelineRenderingType.Room) {
if (this.state.timelineRenderingType === TimelineRenderingType.Search &&
payload.timelineRenderingType === TimelineRenderingType.Search
) {
// we don't have the composer rendered in this state, so bring it back first
await this.onCancelSearchClick();
}

// re-dispatch to the correct composer
dis.dispatch({
...payload,
dis.dispatch<ComposerInsertPayload>({
...(payload as ComposerInsertPayload),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use a union type on the signature payload: ActionPayload | ComposerInsertPayload | etc then the switch will do the type assertion and the cast of payload here won't be needed.

Copy link
Member Author

@t3chguy t3chguy Feb 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

payload: ActionPayload | ComposerInsertPayload doesn't work, to my knowledge we'd need to eliminate ActionPayload and only use the union type of the actual cases, most of the actual Payload types are missing definitions at this time.

image

timelineRenderingType: TimelineRenderingType.Room,
composerType: this.state.editState ? ComposerType.Edit : ComposerType.Send,
});
break;
Expand Down Expand Up @@ -1345,7 +1346,10 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {

return searchPromise.then((results) => {
debuglog("search complete");
if (this.unmounted || !this.state.searching || this.searchId != localSearchId) {
if (this.unmounted ||
this.state.timelineRenderingType !== TimelineRenderingType.Search ||
this.searchId != localSearchId
) {
logger.error("Discarding stale search results");
return false;
}
Expand Down Expand Up @@ -1553,14 +1557,16 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {

private onSearchClick = () => {
this.setState({
searching: !this.state.searching,
timelineRenderingType: this.state.timelineRenderingType === TimelineRenderingType.Search
? TimelineRenderingType.Room
: TimelineRenderingType.Search,
});
};

private onCancelSearchClick = (): Promise<void> => {
return new Promise<void>(resolve => {
this.setState({
searching: false,
timelineRenderingType: TimelineRenderingType.Room,
searchResults: null,
}, resolve);
});
Expand Down Expand Up @@ -1886,7 +1892,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {

let aux = null;
let previewBar;
if (this.state.searching) {
if (this.state.timelineRenderingType === TimelineRenderingType.Search) {
aux = <SearchBar
searchInProgress={this.state.searchInProgress}
onCancelClick={this.onCancelSearchClick}
Expand Down
9 changes: 3 additions & 6 deletions src/components/views/rooms/EventTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ interface IProps {
// whether or not to display thread info
showThreadInfo?: boolean;

timelineRenderingType?: TimelineRenderingType;

// if specified and `true`, the message his behing
// hidden for moderation from other users but is
// displayed to the current user either because they're
Expand Down Expand Up @@ -672,7 +670,7 @@ export default class EventTile extends React.Component<IProps, IState> {
}

private renderThreadInfo(): React.ReactNode {
if (this.props.timelineRenderingType === TimelineRenderingType.Search && this.props.mxEvent.threadRootId) {
if (this.context.timelineRenderingType === TimelineRenderingType.Search && this.props.mxEvent.threadRootId) {
return (
<p className="mx_ThreadSummaryIcon">{ _t("From a thread") }</p>
);
Expand Down Expand Up @@ -982,11 +980,10 @@ export default class EventTile extends React.Component<IProps, IState> {
}

private onSenderProfileClick = () => {
if (!this.props.timelineRenderingType) return;
dis.dispatch<ComposerInsertPayload>({
action: Action.ComposerInsert,
userId: this.props.mxEvent.getSender(),
timelineRenderingType: this.props.timelineRenderingType,
timelineRenderingType: this.context.timelineRenderingType,
});
};

Expand All @@ -1012,7 +1009,7 @@ export default class EventTile extends React.Component<IProps, IState> {
event_id: this.props.mxEvent.getId(),
highlighted: true,
room_id: this.props.mxEvent.getRoomId(),
metricsTrigger: this.props.timelineRenderingType === TimelineRenderingType.Search
metricsTrigger: this.context.timelineRenderingType === TimelineRenderingType.Search
? "MessageSearch"
: undefined,
});
Expand Down
1 change: 0 additions & 1 deletion src/components/views/rooms/SearchResultTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export default class SearchResultTile extends React.Component<IProps> {
isTwelveHour={isTwelveHour}
alwaysShowTimestamps={alwaysShowTimestamps}
enableFlair={enableFlair}
timelineRenderingType={TimelineRenderingType.Search}
lastInSection={lastInSection}
continuation={continuation}
callEventGrouper={this.callEventGroupers.get(mxEv.getContent().call_id)}
Expand Down
1 change: 0 additions & 1 deletion src/contexts/RoomContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const RoomContext = createContext<IRoomState>({
shouldPeek: true,
membersLoaded: false,
numUnreadMessages: 0,
searching: false,
guestsCanJoin: false,
canPeek: false,
showApps: false,
Expand Down