mirror of https://github.com/vector-im/riot-web
Deduplicate some code
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>pull/21833/head
parent
8e456b062a
commit
2660e25d6e
|
@ -54,6 +54,7 @@ import TooltipButton from '../elements/TooltipButton';
|
||||||
import ReadReceiptMarker from "./ReadReceiptMarker";
|
import ReadReceiptMarker from "./ReadReceiptMarker";
|
||||||
import MessageActionBar from "../messages/MessageActionBar";
|
import MessageActionBar from "../messages/MessageActionBar";
|
||||||
import ReactionsRow from '../messages/ReactionsRow';
|
import ReactionsRow from '../messages/ReactionsRow';
|
||||||
|
import { getEventDisplayInfo } from '../../../utils/EventUtils';
|
||||||
|
|
||||||
const eventTileTypes = {
|
const eventTileTypes = {
|
||||||
[EventType.RoomMessage]: 'messages.MessageEvent',
|
[EventType.RoomMessage]: 'messages.MessageEvent',
|
||||||
|
@ -845,35 +846,9 @@ export default class EventTile extends React.Component<IProps, IState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
//console.info("EventTile showUrlPreview for %s is %s", this.props.mxEvent.getId(), this.props.showUrlPreview);
|
const msgtype = this.props.mxEvent.getContent().msgtype;
|
||||||
|
const { tileHandler, isBubbleMessage, isInfoMessage } = getEventDisplayInfo(this.props.mxEvent);
|
||||||
|
|
||||||
const content = this.props.mxEvent.getContent();
|
|
||||||
const msgtype = content.msgtype;
|
|
||||||
const eventType = this.props.mxEvent.getType();
|
|
||||||
|
|
||||||
let tileHandler = getHandlerTile(this.props.mxEvent);
|
|
||||||
|
|
||||||
// Info messages are basically information about commands processed on a room
|
|
||||||
let isBubbleMessage = eventType.startsWith("m.key.verification") ||
|
|
||||||
(eventType === EventType.RoomMessage && msgtype && msgtype.startsWith("m.key.verification")) ||
|
|
||||||
(eventType === EventType.RoomCreate) ||
|
|
||||||
(eventType === EventType.RoomEncryption) ||
|
|
||||||
(tileHandler === "messages.MJitsiWidgetEvent");
|
|
||||||
let isInfoMessage = (
|
|
||||||
!isBubbleMessage && eventType !== EventType.RoomMessage &&
|
|
||||||
eventType !== EventType.Sticker && eventType !== EventType.RoomCreate
|
|
||||||
);
|
|
||||||
|
|
||||||
// If we're showing hidden events in the timeline, we should use the
|
|
||||||
// source tile when there's no regular tile for an event and also for
|
|
||||||
// replace relations (which otherwise would display as a confusing
|
|
||||||
// duplicate of the thing they are replacing).
|
|
||||||
if (SettingsStore.getValue("showHiddenEventsInTimeline") && !haveTileForEvent(this.props.mxEvent)) {
|
|
||||||
tileHandler = "messages.ViewSourceEvent";
|
|
||||||
isBubbleMessage = false;
|
|
||||||
// Reuse info message avatar and sender profile styling
|
|
||||||
isInfoMessage = true;
|
|
||||||
}
|
|
||||||
// This shouldn't happen: the caller should check we support this type
|
// This shouldn't happen: the caller should check we support this type
|
||||||
// before trying to instantiate us
|
// before trying to instantiate us
|
||||||
if (!tileHandler) {
|
if (!tileHandler) {
|
||||||
|
|
|
@ -28,6 +28,7 @@ import MImageReplyBody from "../messages/MImageReplyBody";
|
||||||
import * as sdk from '../../../index';
|
import * as sdk from '../../../index';
|
||||||
import { EventType, MsgType, RelationType } from 'matrix-js-sdk/src/@types/event';
|
import { EventType, MsgType, RelationType } from 'matrix-js-sdk/src/@types/event';
|
||||||
import { replaceableComponent } from '../../../utils/replaceableComponent';
|
import { replaceableComponent } from '../../../utils/replaceableComponent';
|
||||||
|
import { getEventDisplayInfo } from '../../../utils/EventUtils';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
mxEvent: MatrixEvent;
|
mxEvent: MatrixEvent;
|
||||||
|
@ -80,28 +81,9 @@ export default class ReplyTile extends React.PureComponent<IProps> {
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const content = this.props.mxEvent.getContent();
|
const msgtype = this.props.mxEvent.getContent().msgtype;
|
||||||
const msgtype = content.msgtype;
|
|
||||||
const eventType = this.props.mxEvent.getType();
|
|
||||||
|
|
||||||
// Info messages are basically information about commands processed on a room
|
const { tileHandler, isInfoMessage } = getEventDisplayInfo(this.props.mxEvent);
|
||||||
let isInfoMessage = ![
|
|
||||||
EventType.RoomMessage,
|
|
||||||
EventType.Sticker,
|
|
||||||
EventType.RoomCreate,
|
|
||||||
].includes(eventType as EventType);
|
|
||||||
|
|
||||||
let tileHandler = getHandlerTile(this.props.mxEvent);
|
|
||||||
// If we're showing hidden events in the timeline, we should use the
|
|
||||||
// source tile when there's no regular tile for an event and also for
|
|
||||||
// replace relations (which otherwise would display as a confusing
|
|
||||||
// duplicate of the thing they are replacing).
|
|
||||||
const useSource = !tileHandler || this.props.mxEvent.isRelation(RelationType.Replace);
|
|
||||||
if (useSource && SettingsStore.getValue("showHiddenEventsInTimeline")) {
|
|
||||||
tileHandler = "messages.ViewSourceEvent";
|
|
||||||
// Reuse info message avatar and sender profile styling
|
|
||||||
isInfoMessage = true;
|
|
||||||
}
|
|
||||||
// This shouldn't happen: the caller should check we support this type
|
// This shouldn't happen: the caller should check we support this type
|
||||||
// before trying to instantiate us
|
// before trying to instantiate us
|
||||||
if (!tileHandler) {
|
if (!tileHandler) {
|
||||||
|
|
|
@ -19,6 +19,9 @@ import { MatrixEvent, EventStatus } from 'matrix-js-sdk/src/models/event';
|
||||||
|
|
||||||
import { MatrixClientPeg } from '../MatrixClientPeg';
|
import { MatrixClientPeg } from '../MatrixClientPeg';
|
||||||
import shouldHideEvent from "../shouldHideEvent";
|
import shouldHideEvent from "../shouldHideEvent";
|
||||||
|
import { getHandlerTile, haveTileForEvent } from "../components/views/rooms/EventTile";
|
||||||
|
import SettingsStore from "../settings/SettingsStore";
|
||||||
|
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether an event should allow actions like reply, reactions, edit, etc.
|
* Returns whether an event should allow actions like reply, reactions, edit, etc.
|
||||||
|
@ -96,3 +99,38 @@ export function findEditableEvent(room: Room, isForward: boolean, fromEventId: s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getEventDisplayInfo(mxEvent: MatrixEvent): {
|
||||||
|
isInfoMessage: boolean;
|
||||||
|
tileHandler;
|
||||||
|
isBubbleMessage: boolean;
|
||||||
|
} {
|
||||||
|
const content = mxEvent.getContent();
|
||||||
|
const msgtype = content.msgtype;
|
||||||
|
const eventType = mxEvent.getType();
|
||||||
|
|
||||||
|
let tileHandler = getHandlerTile(mxEvent);
|
||||||
|
|
||||||
|
// Info messages are basically information about commands processed on a room
|
||||||
|
let isBubbleMessage = eventType.startsWith("m.key.verification") ||
|
||||||
|
(eventType === EventType.RoomMessage && msgtype && msgtype.startsWith("m.key.verification")) ||
|
||||||
|
(eventType === EventType.RoomCreate) ||
|
||||||
|
(eventType === EventType.RoomEncryption) ||
|
||||||
|
(tileHandler === "messages.MJitsiWidgetEvent");
|
||||||
|
let isInfoMessage = (
|
||||||
|
!isBubbleMessage && eventType !== EventType.RoomMessage &&
|
||||||
|
eventType !== EventType.Sticker && eventType !== EventType.RoomCreate
|
||||||
|
);
|
||||||
|
|
||||||
|
// If we're showing hidden events in the timeline, we should use the
|
||||||
|
// source tile when there's no regular tile for an event and also for
|
||||||
|
// replace relations (which otherwise would display as a confusing
|
||||||
|
// duplicate of the thing they are replacing).
|
||||||
|
if (SettingsStore.getValue("showHiddenEventsInTimeline") && !haveTileForEvent(mxEvent)) {
|
||||||
|
tileHandler = "messages.ViewSourceEvent";
|
||||||
|
isBubbleMessage = false;
|
||||||
|
// Reuse info message avatar and sender profile styling
|
||||||
|
isInfoMessage = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { tileHandler, isInfoMessage, isBubbleMessage };
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue