Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -14,18 +14,18 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { ClipboardEvent, createRef, KeyboardEvent } from 'react';
|
||||
import EMOJI_REGEX from 'emojibase-regex';
|
||||
import { IContent, MatrixEvent, IEventRelation } from 'matrix-js-sdk/src/models/event';
|
||||
import { DebouncedFunc, throttle } from 'lodash';
|
||||
import React, { ClipboardEvent, createRef, KeyboardEvent } from "react";
|
||||
import EMOJI_REGEX from "emojibase-regex";
|
||||
import { IContent, MatrixEvent, IEventRelation } 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 { Room } from 'matrix-js-sdk/src/models/room';
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { Composer as ComposerEvent } from "@matrix-org/analytics-events/types/typescript/Composer";
|
||||
import { THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread';
|
||||
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
|
||||
|
||||
import dis from '../../../dispatcher/dispatcher';
|
||||
import EditorModel from '../../../editor/model';
|
||||
import dis from "../../../dispatcher/dispatcher";
|
||||
import EditorModel from "../../../editor/model";
|
||||
import {
|
||||
containsEmote,
|
||||
htmlSerializeIfNeeded,
|
||||
|
@ -34,37 +34,37 @@ import {
|
|||
stripPrefix,
|
||||
textSerialize,
|
||||
unescapeMessage,
|
||||
} from '../../../editor/serialize';
|
||||
} from "../../../editor/serialize";
|
||||
import BasicMessageComposer, { REGEX_EMOTICON } from "./BasicMessageComposer";
|
||||
import { CommandPartCreator, Part, PartCreator, SerializedPart } from '../../../editor/parts';
|
||||
import { findEditableEvent } from '../../../utils/EventUtils';
|
||||
import { CommandPartCreator, Part, PartCreator, SerializedPart } from "../../../editor/parts";
|
||||
import { findEditableEvent } from "../../../utils/EventUtils";
|
||||
import SendHistoryManager from "../../../SendHistoryManager";
|
||||
import { CommandCategories } from '../../../SlashCommands';
|
||||
import ContentMessages from '../../../ContentMessages';
|
||||
import { CommandCategories } from "../../../SlashCommands";
|
||||
import ContentMessages from "../../../ContentMessages";
|
||||
import { withMatrixClientHOC, MatrixClientProps } from "../../../contexts/MatrixClientContext";
|
||||
import { Action } from "../../../dispatcher/actions";
|
||||
import { containsEmoji } from "../../../effects/utils";
|
||||
import { CHAT_EFFECTS } from '../../../effects';
|
||||
import { CHAT_EFFECTS } from "../../../effects";
|
||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||
import { getKeyBindingsManager } from '../../../KeyBindingsManager';
|
||||
import SettingsStore from '../../../settings/SettingsStore';
|
||||
import { getKeyBindingsManager } from "../../../KeyBindingsManager";
|
||||
import SettingsStore from "../../../settings/SettingsStore";
|
||||
import { RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks";
|
||||
import { ActionPayload } from "../../../dispatcher/payloads";
|
||||
import { decorateStartSendingTime, sendRoundTripMetric } from "../../../sendTimePerformanceMetrics";
|
||||
import RoomContext, { TimelineRenderingType } from '../../../contexts/RoomContext';
|
||||
import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext";
|
||||
import DocumentPosition from "../../../editor/position";
|
||||
import { ComposerType } from "../../../dispatcher/payloads/ComposerInsertPayload";
|
||||
import { getSlashCommand, isSlashCommand, runSlashCommand, shouldSendAnyway } from "../../../editor/commands";
|
||||
import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
|
||||
import { PosthogAnalytics } from "../../../PosthogAnalytics";
|
||||
import { addReplyToMessageContent } from '../../../utils/Reply';
|
||||
import { doMaybeLocalRoomAction } from '../../../utils/local-room';
|
||||
import { addReplyToMessageContent } from "../../../utils/Reply";
|
||||
import { doMaybeLocalRoomAction } from "../../../utils/local-room";
|
||||
|
||||
// Merges favouring the given relation
|
||||
export function attachRelation(content: IContent, relation?: IEventRelation): void {
|
||||
if (relation) {
|
||||
content['m.relates_to'] = {
|
||||
...(content['m.relates_to'] || {}),
|
||||
content["m.relates_to"] = {
|
||||
...(content["m.relates_to"] || {}),
|
||||
...relation,
|
||||
};
|
||||
}
|
||||
|
@ -124,8 +124,7 @@ export function isQuickReaction(model: EditorModel): boolean {
|
|||
const hasShortcut = text.startsWith("+") || text.startsWith("+ ");
|
||||
const emojiMatch = text.match(EMOJI_REGEX);
|
||||
if (hasShortcut && emojiMatch && emojiMatch.length == 1) {
|
||||
return emojiMatch[0] === text.substring(1) ||
|
||||
emojiMatch[0] === text.substring(2);
|
||||
return emojiMatch[0] === text.substring(1) || emojiMatch[0] === text.substring(2);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -163,9 +162,13 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
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);
|
||||
}, 60000, { leading: true, trailing: false });
|
||||
this.prepareToEncrypt = throttle(
|
||||
() => {
|
||||
this.props.mxClient.prepareToEncrypt(this.props.room);
|
||||
},
|
||||
60000,
|
||||
{ leading: true, trailing: false },
|
||||
);
|
||||
}
|
||||
|
||||
window.addEventListener("beforeunload", this.saveStoredEditorState);
|
||||
|
@ -174,14 +177,14 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
const parts = this.restoreStoredEditorState(partCreator) || [];
|
||||
this.model = new EditorModel(parts, partCreator);
|
||||
this.dispatcherRef = dis.register(this.onAction);
|
||||
this.sendHistoryManager = new SendHistoryManager(this.props.room.roomId, 'mx_cider_history_');
|
||||
this.sendHistoryManager = new SendHistoryManager(this.props.room.roomId, "mx_cider_history_");
|
||||
}
|
||||
|
||||
public componentDidUpdate(prevProps: ISendMessageComposerProps): void {
|
||||
const replyingToThread = this.props.relation?.key === THREAD_RELATION_TYPE.name;
|
||||
const differentEventTarget = this.props.relation?.event_id !== prevProps.relation?.event_id;
|
||||
|
||||
const threadChanged = replyingToThread && (differentEventTarget);
|
||||
const threadChanged = replyingToThread && differentEventTarget;
|
||||
if (threadChanged) {
|
||||
const partCreator = new CommandPartCreator(this.props.room, this.props.mxClient);
|
||||
const parts = this.restoreStoredEditorState(partCreator) || [];
|
||||
|
@ -223,9 +226,9 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
case KeyBindingAction.EditPrevMessage:
|
||||
// selection must be collapsed and caret at start
|
||||
if (this.editorRef.current?.isSelectionCollapsed() && this.editorRef.current?.isCaretAtStart()) {
|
||||
const events =
|
||||
this.context.liveTimeline.getEvents()
|
||||
.concat(replyingToThread ? [] : this.props.room.getPendingEvents());
|
||||
const events = this.context.liveTimeline
|
||||
.getEvents()
|
||||
.concat(replyingToThread ? [] : this.props.room.getPendingEvents());
|
||||
const editEvent = findEditableEvent({
|
||||
events,
|
||||
isForward: false,
|
||||
|
@ -243,7 +246,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
break;
|
||||
case KeyBindingAction.CancelReplyOrEdit:
|
||||
dis.dispatch({
|
||||
action: 'reply_to_event',
|
||||
action: "reply_to_event",
|
||||
event: null,
|
||||
context: this.context.timelineRenderingType,
|
||||
});
|
||||
|
@ -275,7 +278,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
}
|
||||
const { parts, replyEventId } = this.sendHistoryManager.getItem(delta);
|
||||
dis.dispatch({
|
||||
action: 'reply_to_event',
|
||||
action: "reply_to_event",
|
||||
event: replyEventId ? this.props.room.findEventById(replyEventId) : null,
|
||||
context: this.context.timelineRenderingType,
|
||||
});
|
||||
|
@ -295,23 +298,26 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
let shouldReact = true;
|
||||
const lastMessage = events[i];
|
||||
const userId = MatrixClientPeg.get().getUserId();
|
||||
const messageReactions = this.props.room.relations
|
||||
.getChildEventsForEvent(lastMessage.getId(), RelationType.Annotation, EventType.Reaction);
|
||||
const messageReactions = this.props.room.relations.getChildEventsForEvent(
|
||||
lastMessage.getId(),
|
||||
RelationType.Annotation,
|
||||
EventType.Reaction,
|
||||
);
|
||||
|
||||
// if we have already sent this reaction, don't redact but don't re-send
|
||||
if (messageReactions) {
|
||||
const myReactionEvents = messageReactions.getAnnotationsBySender()[userId] || [];
|
||||
const myReactionKeys = [...myReactionEvents]
|
||||
.filter(event => !event.isRedacted())
|
||||
.map(event => event.getRelation().key);
|
||||
.filter((event) => !event.isRedacted())
|
||||
.map((event) => event.getRelation().key);
|
||||
shouldReact = !myReactionKeys.includes(reaction);
|
||||
}
|
||||
if (shouldReact) {
|
||||
MatrixClientPeg.get().sendEvent(lastMessage.getRoomId(), EventType.Reaction, {
|
||||
"m.relates_to": {
|
||||
"rel_type": RelationType.Annotation,
|
||||
"event_id": lastMessage.getId(),
|
||||
"key": reaction,
|
||||
rel_type: RelationType.Annotation,
|
||||
event_id: lastMessage.getId(),
|
||||
key: reaction,
|
||||
},
|
||||
});
|
||||
dis.dispatch({ action: "message_sent" });
|
||||
|
@ -341,7 +347,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
PosthogAnalytics.instance.trackEvent<ComposerEvent>(posthogEvent);
|
||||
|
||||
// Replace emoticon at the end of the message
|
||||
if (SettingsStore.getValue('MessageComposerInput.autoReplaceEmoji')) {
|
||||
if (SettingsStore.getValue("MessageComposerInput.autoReplaceEmoji")) {
|
||||
const indexOfLastPart = model.parts.length - 1;
|
||||
const positionInLastPart = model.parts[indexOfLastPart].text.length;
|
||||
this.editorRef.current?.replaceEmoticon(
|
||||
|
@ -357,9 +363,8 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
if (!containsEmote(model) && isSlashCommand(this.model)) {
|
||||
const [cmd, args, commandText] = getSlashCommand(this.model);
|
||||
if (cmd) {
|
||||
const threadId = this.props.relation?.rel_type === THREAD_RELATION_TYPE.name
|
||||
? this.props.relation?.event_id
|
||||
: null;
|
||||
const threadId =
|
||||
this.props.relation?.rel_type === THREAD_RELATION_TYPE.name ? this.props.relation?.event_id : null;
|
||||
|
||||
let commandSuccessful: boolean;
|
||||
[content, commandSuccessful] = await runSlashCommand(cmd, args, this.props.room.roomId, threadId);
|
||||
|
@ -379,7 +384,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
} else {
|
||||
shouldSend = false;
|
||||
}
|
||||
} else if (!await shouldSendAnyway(commandText)) {
|
||||
} else if (!(await shouldSendAnyway(commandText))) {
|
||||
// if !sendAnyway bail to let the user edit the composer and try again
|
||||
return;
|
||||
}
|
||||
|
@ -408,9 +413,8 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
decorateStartSendingTime(content);
|
||||
}
|
||||
|
||||
const threadId = this.props.relation?.rel_type === THREAD_RELATION_TYPE.name
|
||||
? this.props.relation.event_id
|
||||
: null;
|
||||
const threadId =
|
||||
this.props.relation?.rel_type === THREAD_RELATION_TYPE.name ? this.props.relation.event_id : null;
|
||||
|
||||
const prom = doMaybeLocalRoomAction(
|
||||
roomId,
|
||||
|
@ -421,7 +425,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
// Clear reply_to_event as we put the message into the queue
|
||||
// if the send fails, retry will handle resending.
|
||||
dis.dispatch({
|
||||
action: 'reply_to_event',
|
||||
action: "reply_to_event",
|
||||
event: null,
|
||||
context: this.context.timelineRenderingType,
|
||||
});
|
||||
|
@ -438,7 +442,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
}
|
||||
});
|
||||
if (SettingsStore.getValue("Performance.addSendMessageTimingMetadata")) {
|
||||
prom.then(resp => {
|
||||
prom.then((resp) => {
|
||||
sendRoundTripMetric(this.props.mxClient, roomId, resp.event_id);
|
||||
});
|
||||
}
|
||||
|
@ -486,10 +490,10 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
if (json) {
|
||||
try {
|
||||
const { parts: serializedParts, replyEventId } = JSON.parse(json);
|
||||
const parts: Part[] = serializedParts.map(p => partCreator.deserializePart(p));
|
||||
const parts: Part[] = serializedParts.map((p) => partCreator.deserializePart(p));
|
||||
if (replyEventId) {
|
||||
dis.dispatch({
|
||||
action: 'reply_to_event',
|
||||
action: "reply_to_event",
|
||||
event: this.props.room.findEventById(replyEventId),
|
||||
context: this.context.timelineRenderingType,
|
||||
});
|
||||
|
@ -521,7 +525,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
if (this.props.disabled) return;
|
||||
|
||||
switch (payload.action) {
|
||||
case 'reply_to_event':
|
||||
case "reply_to_event":
|
||||
case Action.FocusSendMessageComposer:
|
||||
if ((payload.context ?? TimelineRenderingType.Room) === this.context.timelineRenderingType) {
|
||||
this.editorRef.current?.focus();
|
||||
|
@ -569,9 +573,8 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
|||
};
|
||||
|
||||
render() {
|
||||
const threadId = this.props.relation?.rel_type === THREAD_RELATION_TYPE.name
|
||||
? this.props.relation.event_id
|
||||
: null;
|
||||
const threadId =
|
||||
this.props.relation?.rel_type === THREAD_RELATION_TYPE.name ? this.props.relation.event_id : null;
|
||||
return (
|
||||
<div className="mx_SendMessageComposer" onClick={this.focusComposer} onKeyDown={this.onKeyDown}>
|
||||
<BasicMessageComposer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue