@@ -15,11 +15,12 @@ See the License for the specific language governing permissions and
15
15
limitations under the License.
16
16
*/
17
17
18
- import React from 'react' ;
18
+ import React , { ReactElement } from 'react' ;
19
19
import { EventStatus , MatrixEvent } from 'matrix-js-sdk/src/models/event' ;
20
20
import { EventType , RelationType } from "matrix-js-sdk/src/@types/event" ;
21
21
import { Relations } from 'matrix-js-sdk/src/models/relations' ;
22
22
import { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls" ;
23
+ import { LOCATION_EVENT_TYPE } from 'matrix-js-sdk/src/@types/location' ;
23
24
24
25
import { MatrixClientPeg } from '../../../MatrixClientPeg' ;
25
26
import dis from '../../../dispatcher/dispatcher' ;
@@ -313,13 +314,15 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
313
314
}
314
315
315
316
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
+ }
323
326
324
327
if ( this . state . canPin ) {
325
328
pinButton = (
@@ -352,26 +355,29 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
352
355
}
353
356
}
354
357
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
+ }
371
377
}
372
- }
373
- />
374
- ) ;
378
+ />
379
+ ) ;
380
+ }
375
381
376
382
if ( this . canEndPoll ( mxEvent ) ) {
377
383
endPollButton = (
@@ -486,3 +492,22 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
486
492
) ;
487
493
}
488
494
}
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