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

Commit c727942

Browse files
authored
Autofocus correct composer after sending reaction (#7950)
1 parent 61cd463 commit c727942

File tree

4 files changed

+39
-23
lines changed

4 files changed

+39
-23
lines changed

src/components/structures/RoomView.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ import { JoinRoomPayload } from "../../dispatcher/payloads/JoinRoomPayload";
107107
import { DoAfterSyncPreparedPayload } from '../../dispatcher/payloads/DoAfterSyncPreparedPayload';
108108
import FileDropTarget from './FileDropTarget';
109109
import Measured from '../views/elements/Measured';
110+
import { FocusComposerPayload } from '../../dispatcher/payloads/FocusComposerPayload';
110111

111112
const DEBUG = false;
112113
let debuglog = function(msg: string) {};
@@ -918,8 +919,11 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
918919
}
919920

920921
case Action.FocusAComposer: {
921-
// re-dispatch to the correct composer
922-
dis.fire(this.state.editState ? Action.FocusEditMessageComposer : Action.FocusSendMessageComposer);
922+
dis.dispatch<FocusComposerPayload>({
923+
...(payload as FocusComposerPayload),
924+
// re-dispatch to the correct composer
925+
action: this.state.editState ? Action.FocusEditMessageComposer : Action.FocusSendMessageComposer,
926+
});
923927
break;
924928
}
925929

src/components/views/emojipicker/ReactionPicker.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@ limitations under the License.
1717

1818
import React from 'react';
1919
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
20+
import { Relations, RelationsEvent } from 'matrix-js-sdk/src/models/relations';
21+
import { EventType, RelationType } from 'matrix-js-sdk/src/@types/event';
2022

2123
import EmojiPicker from "./EmojiPicker";
2224
import { MatrixClientPeg } from "../../../MatrixClientPeg";
2325
import dis from "../../../dispatcher/dispatcher";
2426
import { replaceableComponent } from "../../../utils/replaceableComponent";
2527
import { Action } from '../../../dispatcher/actions';
28+
import RoomContext from "../../../contexts/RoomContext";
29+
import { FocusComposerPayload } from '../../../dispatcher/payloads/FocusComposerPayload';
2630

2731
interface IProps {
2832
mxEvent: MatrixEvent;
29-
reactions: any; // TODO type this once js-sdk is more typescripted
33+
reactions?: Relations;
3034
onFinished(): void;
3135
}
3236

@@ -36,8 +40,11 @@ interface IState {
3640

3741
@replaceableComponent("views.emojipicker.ReactionPicker")
3842
class ReactionPicker extends React.Component<IProps, IState> {
39-
constructor(props) {
40-
super(props);
43+
static contextType = RoomContext;
44+
public context!: React.ContextType<typeof RoomContext>;
45+
46+
constructor(props: IProps, context: React.ContextType<typeof RoomContext>) {
47+
super(props, context);
4148

4249
this.state = {
4350
selectedEmojis: new Set(Object.keys(this.getReactions())),
@@ -54,17 +61,17 @@ class ReactionPicker extends React.Component<IProps, IState> {
5461

5562
private addListeners() {
5663
if (this.props.reactions) {
57-
this.props.reactions.on("Relations.add", this.onReactionsChange);
58-
this.props.reactions.on("Relations.remove", this.onReactionsChange);
59-
this.props.reactions.on("Relations.redaction", this.onReactionsChange);
64+
this.props.reactions.on(RelationsEvent.Add, this.onReactionsChange);
65+
this.props.reactions.on(RelationsEvent.Remove, this.onReactionsChange);
66+
this.props.reactions.on(RelationsEvent.Redaction, this.onReactionsChange);
6067
}
6168
}
6269

6370
componentWillUnmount() {
6471
if (this.props.reactions) {
65-
this.props.reactions.removeListener("Relations.add", this.onReactionsChange);
66-
this.props.reactions.removeListener("Relations.remove", this.onReactionsChange);
67-
this.props.reactions.removeListener("Relations.redaction", this.onReactionsChange);
72+
this.props.reactions.removeListener(RelationsEvent.Add, this.onReactionsChange);
73+
this.props.reactions.removeListener(RelationsEvent.Remove, this.onReactionsChange);
74+
this.props.reactions.removeListener(RelationsEvent.Redaction, this.onReactionsChange);
6875
}
6976
}
7077

@@ -85,28 +92,31 @@ class ReactionPicker extends React.Component<IProps, IState> {
8592
});
8693
};
8794

88-
onChoose = (reaction: string) => {
95+
private onChoose = (reaction: string) => {
8996
this.componentWillUnmount();
9097
this.props.onFinished();
9198
const myReactions = this.getReactions();
9299
if (myReactions.hasOwnProperty(reaction)) {
93-
MatrixClientPeg.get().redactEvent(
94-
this.props.mxEvent.getRoomId(),
95-
myReactions[reaction],
96-
);
97-
dis.fire(Action.FocusAComposer);
100+
MatrixClientPeg.get().redactEvent(this.props.mxEvent.getRoomId(), myReactions[reaction]);
101+
dis.dispatch<FocusComposerPayload>({
102+
action: Action.FocusAComposer,
103+
context: this.context.timelineRenderingType,
104+
});
98105
// Tell the emoji picker not to bump this in the more frequently used list.
99106
return false;
100107
} else {
101-
MatrixClientPeg.get().sendEvent(this.props.mxEvent.getRoomId(), "m.reaction", {
108+
MatrixClientPeg.get().sendEvent(this.props.mxEvent.getRoomId(), EventType.Reaction, {
102109
"m.relates_to": {
103-
"rel_type": "m.annotation",
110+
"rel_type": RelationType.Annotation,
104111
"event_id": this.props.mxEvent.getId(),
105112
"key": reaction,
106113
},
107114
});
108115
dis.dispatch({ action: "message_sent" });
109-
dis.fire(Action.FocusAComposer);
116+
dis.dispatch<FocusComposerPayload>({
117+
action: Action.FocusAComposer,
118+
context: this.context.timelineRenderingType,
119+
});
110120
return true;
111121
}
112122
};

src/dispatcher/actions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ export enum Action {
7777

7878
/**
7979
* Focuses the user's cursor to the edit message composer or send message
80-
* composer based on the current edit state. No additional payload
81-
* information required.
80+
* composer based on the current edit state. Should be used with a FocusComposerPayload.
8281
*/
8382
FocusAComposer = "focus_a_composer",
8483

src/dispatcher/payloads/FocusComposerPayload.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import { Action } from "../actions";
1919
import { TimelineRenderingType } from "../../contexts/RoomContext";
2020

2121
export interface FocusComposerPayload extends ActionPayload {
22-
action: Action.FocusEditMessageComposer | Action.FocusSendMessageComposer | "reply_to_event";
22+
action: Action.FocusAComposer
23+
| Action.FocusEditMessageComposer
24+
| Action.FocusSendMessageComposer
25+
| "reply_to_event";
2326

2427
context?: TimelineRenderingType; // defaults to Room type for backwards compatibility
2528
}

0 commit comments

Comments
 (0)