Disallow KeyVerificationRequest as thread root (#7182)
This commit is contained in:
parent
7658187186
commit
925136d016
3 changed files with 26 additions and 10 deletions
|
@ -39,6 +39,7 @@ import { mediaFromMxc } from "./customisations/Media";
|
||||||
import ErrorDialog from "./components/views/dialogs/ErrorDialog";
|
import ErrorDialog from "./components/views/dialogs/ErrorDialog";
|
||||||
|
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
import { MsgType } from "matrix-js-sdk/src/@types/event";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dispatches:
|
* Dispatches:
|
||||||
|
@ -55,8 +56,8 @@ Override both the content body and the TextForEvent handler for specific msgtype
|
||||||
This is useful when the content body contains fallback text that would explain that the client can't handle a particular
|
This is useful when the content body contains fallback text that would explain that the client can't handle a particular
|
||||||
type of tile.
|
type of tile.
|
||||||
*/
|
*/
|
||||||
const typehandlers = {
|
const msgTypeHandlers = {
|
||||||
"m.key.verification.request": (event) => {
|
[MsgType.KeyVerificationRequest]: (event) => {
|
||||||
const name = (event.sender || {}).name;
|
const name = (event.sender || {}).name;
|
||||||
return _t("%(name)s is requesting verification", { name });
|
return _t("%(name)s is requesting verification", { name });
|
||||||
},
|
},
|
||||||
|
@ -71,8 +72,8 @@ export const Notifier = {
|
||||||
pendingEncryptedEventIds: [],
|
pendingEncryptedEventIds: [],
|
||||||
|
|
||||||
notificationMessageForEvent: function(ev: MatrixEvent): string {
|
notificationMessageForEvent: function(ev: MatrixEvent): string {
|
||||||
if (typehandlers.hasOwnProperty(ev.getContent().msgtype)) {
|
if (msgTypeHandlers.hasOwnProperty(ev.getContent().msgtype)) {
|
||||||
return typehandlers[ev.getContent().msgtype](ev);
|
return msgTypeHandlers[ev.getContent().msgtype](ev);
|
||||||
}
|
}
|
||||||
return TextForEvent.textForEvent(ev);
|
return TextForEvent.textForEvent(ev);
|
||||||
},
|
},
|
||||||
|
@ -97,7 +98,7 @@ export const Notifier = {
|
||||||
title = room.name;
|
title = room.name;
|
||||||
// notificationMessageForEvent includes sender,
|
// notificationMessageForEvent includes sender,
|
||||||
// but we already have the sender here
|
// but we already have the sender here
|
||||||
if (ev.getContent().body && !typehandlers.hasOwnProperty(ev.getContent().msgtype)) {
|
if (ev.getContent().body && !msgTypeHandlers.hasOwnProperty(ev.getContent().msgtype)) {
|
||||||
msg = ev.getContent().body;
|
msg = ev.getContent().body;
|
||||||
}
|
}
|
||||||
} else if (ev.getType() === 'm.room.member') {
|
} else if (ev.getType() === 'm.room.member') {
|
||||||
|
@ -108,7 +109,7 @@ export const Notifier = {
|
||||||
title = ev.sender.name + " (" + room.name + ")";
|
title = ev.sender.name + " (" + room.name + ")";
|
||||||
// notificationMessageForEvent includes sender,
|
// notificationMessageForEvent includes sender,
|
||||||
// but we've just out sender in the title
|
// but we've just out sender in the title
|
||||||
if (ev.getContent().body && !typehandlers.hasOwnProperty(ev.getContent().msgtype)) {
|
if (ev.getContent().body && !msgTypeHandlers.hasOwnProperty(ev.getContent().msgtype)) {
|
||||||
msg = ev.getContent().body;
|
msg = ev.getContent().body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ import { RoomPermalinkCreator } from '../../../utils/permalinks/Permalinks';
|
||||||
import ReplyChain from '../elements/ReplyChain';
|
import ReplyChain from '../elements/ReplyChain';
|
||||||
import { dispatchShowThreadEvent } from '../../../dispatcher/dispatch-actions/threads';
|
import { dispatchShowThreadEvent } from '../../../dispatcher/dispatch-actions/threads';
|
||||||
import ReactionPicker from "../emojipicker/ReactionPicker";
|
import ReactionPicker from "../emojipicker/ReactionPicker";
|
||||||
|
import { MsgType } from 'matrix-js-sdk/src/@types/event';
|
||||||
|
|
||||||
interface IOptionsButtonProps {
|
interface IOptionsButtonProps {
|
||||||
mxEvent: MatrixEvent;
|
mxEvent: MatrixEvent;
|
||||||
|
@ -210,6 +211,21 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private readonly forbiddenThreadHeadMsgType = [
|
||||||
|
MsgType.KeyVerificationRequest,
|
||||||
|
];
|
||||||
|
|
||||||
|
private get showReplyInThreadAction(): boolean {
|
||||||
|
const isThreadEnabled = SettingsStore.getValue("feature_thread");
|
||||||
|
const inNotThreadTimeline = this.context.timelineRenderingType !== TimelineRenderingType.Thread;
|
||||||
|
|
||||||
|
const isAllowedMessageType = !this.forbiddenThreadHeadMsgType.includes(
|
||||||
|
this.props.mxEvent.getContent().msgtype as MsgType,
|
||||||
|
);
|
||||||
|
|
||||||
|
return isThreadEnabled && inNotThreadTimeline && isAllowedMessageType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a given fn on the set of possible events to test. The first event
|
* Runs a given fn on the set of possible events to test. The first event
|
||||||
* that passes the checkFn will have fn executed on it. Both functions take
|
* that passes the checkFn will have fn executed on it. Both functions take
|
||||||
|
@ -294,8 +310,7 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
|
||||||
onClick={this.onReplyClick}
|
onClick={this.onReplyClick}
|
||||||
key="reply"
|
key="reply"
|
||||||
/>
|
/>
|
||||||
{ (SettingsStore.getValue("feature_thread")
|
{ (this.showReplyInThreadAction) && (
|
||||||
&& this.context.timelineRenderingType !== TimelineRenderingType.Thread) && (
|
|
||||||
<RovingAccessibleTooltipButton
|
<RovingAccessibleTooltipButton
|
||||||
className="mx_MessageActionBar_maskButton mx_MessageActionBar_threadButton"
|
className="mx_MessageActionBar_maskButton mx_MessageActionBar_threadButton"
|
||||||
title={_t("Reply in thread")}
|
title={_t("Reply in thread")}
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
|
|
||||||
import React, { createRef } from 'react';
|
import React, { createRef } from 'react';
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
import { EventType, MsgType } from "matrix-js-sdk/src/@types/event";
|
||||||
import { EventStatus, MatrixEvent } from "matrix-js-sdk/src/models/event";
|
import { EventStatus, MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||||
import { Relations } from "matrix-js-sdk/src/models/relations";
|
import { Relations } from "matrix-js-sdk/src/models/relations";
|
||||||
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||||
|
@ -130,7 +130,7 @@ export function getHandlerTile(ev) {
|
||||||
// not even when showing hidden events
|
// not even when showing hidden events
|
||||||
if (type === "m.room.message") {
|
if (type === "m.room.message") {
|
||||||
const content = ev.getContent();
|
const content = ev.getContent();
|
||||||
if (content && content.msgtype === "m.key.verification.request") {
|
if (content && content.msgtype === MsgType.KeyVerificationRequest) {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
const me = client && client.getUserId();
|
const me = client && client.getUserId();
|
||||||
if (ev.getSender() !== me && content.to !== me) {
|
if (ev.getSender() !== me && content.to !== me) {
|
||||||
|
|
Loading…
Reference in a new issue