@@ -25,6 +25,7 @@ import { getAppearNote } from '@/scripts/tms/get-appear-note.js';
25
25
import { numberquote } from '@/scripts/tms/numberquote.js' ;
26
26
import { pakuru } from '@/scripts/tms/pakuru.js' ;
27
27
import { tooltipFromElement } from '@/scripts/tms/tooltip-from-element.js' ;
28
+ import { smallerVisibility } from '@/scripts/tms/visibility.js' ;
28
29
import { tmsStore } from '@/tms/store.js' ;
29
30
30
31
export async function getNoteClipMenu ( props : {
@@ -486,126 +487,124 @@ export function getNoteMenu(props: {
486
487
} ;
487
488
}
488
489
489
- type Visibility = 'public' | 'home' | 'followers' | 'specified' ;
490
-
491
- // defaultStore.state.visibilityがstringなためstringも受け付けている
492
- function smallerVisibility ( a : Visibility | string , b : Visibility | string ) : Visibility {
493
- if ( a === 'specified' || b === 'specified' ) return 'specified' ;
494
- if ( a === 'followers' || b === 'followers' ) return 'followers' ;
495
- if ( a === 'home' || b === 'home' ) return 'home' ;
496
- // if (a === 'public' || b === 'public')
497
- return 'public' ;
498
- }
499
-
500
490
export function getRenoteMenu ( props : {
501
491
note : Misskey . entities . Note ;
502
492
renoteButton : ShallowRef < HTMLElement | undefined > ;
503
493
mock ?: boolean ;
494
+ canRenote ?: boolean ;
504
495
} ) {
505
496
const appearNote = getAppearNote ( props . note ) ;
497
+ const canRenote = props . canRenote ?? true ;
498
+
499
+ const rippleEffect = ( ) : void => {
500
+ const el = props . renoteButton . value ;
501
+ if ( el == null ) return ;
502
+ const rect = el . getBoundingClientRect ( ) ;
503
+ const x = rect . left + ( el . offsetWidth / 2 ) ;
504
+ const y = rect . top + ( el . offsetHeight / 2 ) ;
505
+ os . popup ( MkRippleEffect , { x, y } , { } , 'end' ) ;
506
+ } ;
507
+
508
+ const tooltipEffect = ( text : string ) : void => {
509
+ tooltipFromElement ( {
510
+ targetElement : props . renoteButton . value ,
511
+ primary : true ,
512
+ text,
513
+ } ) ;
514
+ } ;
515
+
516
+ const errorDialog = ( err : unknown ) : void => {
517
+ os . alert ( {
518
+ type : 'error' ,
519
+ text : parseErrorMessage ( err ) ,
520
+ } ) ;
521
+ } ;
506
522
507
523
const channelRenoteItems : MenuItem [ ] = [ ] ;
508
524
const normalRenoteItems : MenuItem [ ] = [ ] ;
509
525
const pakuruItems : MenuItem [ ] = [ ] ;
510
526
511
- if ( appearNote . channel ) {
512
- channelRenoteItems . push ( ... [ {
527
+ if ( canRenote && appearNote . channel != null ) {
528
+ channelRenoteItems . push ( {
513
529
text : i18n . ts . inChannelRenote ,
514
530
icon : 'ti ti-repeat' ,
515
531
action : ( ) => {
516
- const el = props . renoteButton . value ;
517
- if ( el ) {
518
- const rect = el . getBoundingClientRect ( ) ;
519
- const x = rect . left + ( el . offsetWidth / 2 ) ;
520
- const y = rect . top + ( el . offsetHeight / 2 ) ;
521
- os . popup ( MkRippleEffect , { x, y } , { } , 'end' ) ;
522
- }
523
-
524
- if ( ! props . mock ) {
525
- misskeyApi ( 'notes/create' , {
526
- renoteId : appearNote . id ,
527
- channelId : appearNote . channelId ,
528
- } ) . then ( ( ) => {
529
- os . toast ( i18n . ts . renoted ) ;
530
- } ) ;
531
- }
532
+ rippleEffect ( ) ;
533
+ if ( props . mock ) return tooltipEffect ( i18n . ts . renoted ) ;
534
+ misskeyApi ( 'notes/create' , {
535
+ renoteId : appearNote . id ,
536
+ channelId : appearNote . channelId ,
537
+ } ) . then ( ( ) => tooltipEffect ( i18n . ts . renoted ) ) . catch ( errorDialog ) ;
532
538
} ,
533
- } , {
534
- text : i18n . ts . inChannelQuote ,
535
- icon : 'ti ti-quote' ,
536
- action : ( ) => {
537
- if ( ! props . mock ) {
539
+ } ) ;
540
+ if ( ! props . mock ) {
541
+ channelRenoteItems . push ( {
542
+ text : i18n . ts . inChannelQuote ,
543
+ icon : 'ti ti-quote' ,
544
+ action : ( ) => {
538
545
os . post ( {
539
546
renote : appearNote ,
540
547
channel : appearNote . channel ,
541
548
} ) ;
542
- }
543
- } ,
544
- } ] ) ;
549
+ } ,
550
+ } ) ;
551
+ }
545
552
}
546
553
547
- if ( ! appearNote . channel || appearNote . channel . allowRenoteToExternal ) {
548
- normalRenoteItems . push ( ...[ {
549
- text : i18n . ts . renote ,
554
+ if ( canRenote && ( appearNote . channel == null || appearNote . channel . allowRenoteToExternal ) ) {
555
+ let renoteVisibility = appearNote . visibility ;
556
+ const renoteLocalOnly = appearNote . localOnly ?? false ;
557
+
558
+ if ( appearNote . channel ?. isSensitive || $i ?. isSilenced ) {
559
+ renoteVisibility = smallerVisibility ( [ renoteVisibility , 'home' ] ) ;
560
+ }
561
+
562
+ const renoteButtonText = ( ( ) => {
563
+ if ( renoteVisibility === 'home' ) {
564
+ if ( renoteLocalOnly ) return i18n . ts . _tms . disableFederationHomeRenote ;
565
+ return i18n . ts . _tms . homeRenote ;
566
+ }
567
+ if ( renoteVisibility === 'followers' ) {
568
+ if ( renoteLocalOnly ) return i18n . ts . _tms . disableFederationFollowersRenote ;
569
+ return i18n . ts . _tms . followersRenote ;
570
+ }
571
+ if ( renoteLocalOnly ) return i18n . ts . _tms . disableFederationRenote ;
572
+ return i18n . ts . renote ;
573
+ } ) ( ) ;
574
+
575
+ normalRenoteItems . push ( {
576
+ text : renoteButtonText ,
550
577
icon : 'ti ti-repeat' ,
551
578
action : ( ) => {
552
- const el = props . renoteButton . value ;
553
- if ( el ) {
554
- const rect = el . getBoundingClientRect ( ) ;
555
- const x = rect . left + ( el . offsetWidth / 2 ) ;
556
- const y = rect . top + ( el . offsetHeight / 2 ) ;
557
- os . popup ( MkRippleEffect , { x, y } , { } , 'end' ) ;
558
- }
559
-
560
- const configuredVisibility = defaultStore . state . rememberNoteVisibility ? defaultStore . state . visibility : defaultStore . state . defaultNoteVisibility ;
561
- const localOnly = defaultStore . state . rememberNoteVisibility ? defaultStore . state . localOnly : defaultStore . state . defaultNoteLocalOnly ;
562
-
563
- let visibility = appearNote . visibility ;
564
- visibility = smallerVisibility ( visibility , configuredVisibility ) ;
565
- if ( appearNote . channel ?. isSensitive ) {
566
- visibility = smallerVisibility ( visibility , 'home' ) ;
567
- }
568
-
569
- if ( ! props . mock ) {
570
- misskeyApi ( 'notes/create' , {
571
- localOnly,
572
- visibility,
573
- renoteId : appearNote . id ,
574
- } ) . then ( ( ) => {
575
- os . toast ( i18n . ts . renoted ) ;
576
- } ) ;
577
- }
579
+ rippleEffect ( ) ;
580
+ if ( props . mock ) return tooltipEffect ( i18n . ts . renoted ) ;
581
+ misskeyApi ( 'notes/create' , {
582
+ renoteId : appearNote . id ,
583
+ visibility : renoteVisibility ,
584
+ localOnly : renoteLocalOnly ,
585
+ } ) . then ( ( ) => tooltipEffect ( i18n . ts . renoted ) ) . catch ( errorDialog ) ;
578
586
} ,
579
- } , ( props . mock ) ? undefined : {
580
- text : i18n . ts . quote ,
581
- icon : 'ti ti-quote' ,
582
- action : ( ) => {
583
- os . post ( {
584
- renote : appearNote ,
585
- } ) ;
586
- } ,
587
- } ] ) ;
587
+ } ) ;
588
+ if ( ! props . mock ) {
589
+ normalRenoteItems . push ( {
590
+ text : i18n . ts . quote ,
591
+ icon : 'ti ti-quote' ,
592
+ action : ( ) => {
593
+ os . post ( {
594
+ renote : appearNote ,
595
+ } ) ;
596
+ } ,
597
+ } ) ;
598
+ }
588
599
}
589
600
590
601
if ( tmsStore . state . enablePakuru ) {
591
602
pakuruItems . push ( {
592
603
text : i18n . ts . _tms . pakuru ,
593
604
icon : 'ti ti-swipe' ,
594
605
action : ( ) => {
595
- const tooltip = ( ) : void => {
596
- tooltipFromElement ( {
597
- targetElement : props . renoteButton . value ,
598
- text : i18n . ts . _tms . didPakuru ,
599
- primary : true ,
600
- } ) ;
601
- } ;
602
- if ( props . mock ) return tooltip ( ) ;
603
- pakuru ( appearNote ) . then ( ( ) => tooltip ( ) ) . catch ( ( err ) => {
604
- os . alert ( {
605
- type : 'error' ,
606
- text : parseErrorMessage ( err ) ,
607
- } ) ;
608
- } ) ;
606
+ if ( props . mock ) return tooltipEffect ( i18n . ts . _tms . didPakuru ) ;
607
+ pakuru ( appearNote ) . then ( ( ) => tooltipEffect ( i18n . ts . _tms . didPakuru ) ) . catch ( errorDialog ) ;
609
608
} ,
610
609
} ) ;
611
610
}
@@ -615,20 +614,8 @@ export function getRenoteMenu(props: {
615
614
text : i18n . ts . _tms . numberquote ,
616
615
icon : 'ti ti-exposure-plus-1' ,
617
616
action : ( ) => {
618
- const tooltip = ( ) : void => {
619
- tooltipFromElement ( {
620
- targetElement : props . renoteButton . value ,
621
- text : i18n . ts . _tms . didNumberquote ,
622
- primary : true ,
623
- } ) ;
624
- } ;
625
- if ( props . mock ) return tooltip ( ) ;
626
- numberquote ( appearNote ) . then ( ( ) => tooltip ( ) ) . catch ( ( err ) => {
627
- os . alert ( {
628
- type : 'error' ,
629
- text : parseErrorMessage ( err ) ,
630
- } ) ;
631
- } ) ;
617
+ if ( props . mock ) return tooltipEffect ( i18n . ts . _tms . didNumberquote ) ;
618
+ numberquote ( appearNote ) . then ( ( ) => tooltipEffect ( i18n . ts . _tms . didNumberquote ) ) . catch ( errorDialog ) ;
632
619
} ,
633
620
} ) ;
634
621
}
0 commit comments