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

Commit de881d2

Browse files
authored
Remove the Forward and Share buttons for location messages only (#7423)
1 parent d6af729 commit de881d2

File tree

1 file changed

+52
-27
lines changed

1 file changed

+52
-27
lines changed

src/components/views/context_menus/MessageContextMenu.tsx

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
1717

18-
import React from 'react';
18+
import React, { ReactElement } from 'react';
1919
import { EventStatus, MatrixEvent } from 'matrix-js-sdk/src/models/event';
2020
import { EventType, RelationType } from "matrix-js-sdk/src/@types/event";
2121
import { Relations } from 'matrix-js-sdk/src/models/relations';
2222
import { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls";
23+
import { LOCATION_EVENT_TYPE } from 'matrix-js-sdk/src/@types/location';
2324

2425
import { MatrixClientPeg } from '../../../MatrixClientPeg';
2526
import dis from '../../../dispatcher/dispatcher';
@@ -313,13 +314,15 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
313314
}
314315

315316
if (isContentActionable(mxEvent)) {
316-
forwardButton = (
317-
<IconizedContextMenuOption
318-
iconClassName="mx_MessageContextMenu_iconForward"
319-
label={_t("Forward")}
320-
onClick={this.onForwardClick}
321-
/>
322-
);
317+
if (canForward(mxEvent)) {
318+
forwardButton = (
319+
<IconizedContextMenuOption
320+
iconClassName="mx_MessageContextMenu_iconForward"
321+
label={_t("Forward")}
322+
onClick={this.onForwardClick}
323+
/>
324+
);
325+
}
323326

324327
if (this.state.canPin) {
325328
pinButton = (
@@ -352,26 +355,29 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
352355
}
353356
}
354357

355-
let permalink;
356-
if (this.props.permalinkCreator) {
357-
permalink = this.props.permalinkCreator.forEvent(this.props.mxEvent.getId());
358-
}
359-
const permalinkButton = (
360-
<IconizedContextMenuOption
361-
iconClassName="mx_MessageContextMenu_iconPermalink"
362-
onClick={this.onPermalinkClick}
363-
label={_t('Share')}
364-
element="a"
365-
{
366-
// XXX: Typescript signature for AccessibleButton doesn't work properly for non-inputs like `a`
367-
...{
368-
href: permalink,
369-
target: "_blank",
370-
rel: "noreferrer noopener",
358+
let permalink: string | null = null;
359+
let permalinkButton: ReactElement | null = null;
360+
if (canShare(mxEvent)) {
361+
if (this.props.permalinkCreator) {
362+
permalink = this.props.permalinkCreator.forEvent(this.props.mxEvent.getId());
363+
}
364+
permalinkButton = (
365+
<IconizedContextMenuOption
366+
iconClassName="mx_MessageContextMenu_iconPermalink"
367+
onClick={this.onPermalinkClick}
368+
label={_t('Share')}
369+
element="a"
370+
{
371+
// XXX: Typescript signature for AccessibleButton doesn't work properly for non-inputs like `a`
372+
...{
373+
href: permalink,
374+
target: "_blank",
375+
rel: "noreferrer noopener",
376+
}
371377
}
372-
}
373-
/>
374-
);
378+
/>
379+
);
380+
}
375381

376382
if (this.canEndPoll(mxEvent)) {
377383
endPollButton = (
@@ -486,3 +492,22 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
486492
);
487493
}
488494
}
495+
496+
function canForward(event: MatrixEvent): boolean {
497+
return !isLocationEvent(event);
498+
}
499+
500+
function canShare(event: MatrixEvent): boolean {
501+
return !isLocationEvent(event);
502+
}
503+
504+
function isLocationEvent(event: MatrixEvent): boolean {
505+
const eventType = event.getType();
506+
return (
507+
LOCATION_EVENT_TYPE.matches(eventType) ||
508+
(
509+
eventType === EventType.RoomMessage &&
510+
LOCATION_EVENT_TYPE.matches(event.getContent().msgtype)
511+
)
512+
);
513+
}

0 commit comments

Comments
 (0)