@@ -36,6 +36,7 @@ type Props = {
3636 activeChannelClaim : ?ChannelClaim ,
3737 playingUri : PlayingUri ,
3838 moderationDelegatorsById : { [ string ] : { global : boolean , delegators : { name : string , claimId : string } } } ,
39+ moderationDelegatesById : { [ ?string ] : ?Array < Object > } ,
3940 authorCanonicalUri : ?string ,
4041 authorId : string ,
4142 // --- perform ---
@@ -47,6 +48,7 @@ type Props = {
4748 doSetActiveChannel : ( string ) => void ,
4849 pinComment : ( string , string , boolean ) => Promise < any > ,
4950 commentModAddDelegate : ( string , string , ChannelClaim ) => void ,
51+ commentModRemoveDelegate : ( string , string , ChannelClaim ) => void ,
5052 setQuickReply : ( any ) => void ,
5153 handleDismissPin ?: ( ) => void ,
5254} ;
@@ -66,6 +68,7 @@ function CommentMenuList(props: Props) {
6668 isPinned,
6769 playingUri,
6870 moderationDelegatorsById,
71+ moderationDelegatesById,
6972 authorCanonicalUri,
7073 isAuthenticated,
7174 disableEdit,
@@ -81,6 +84,7 @@ function CommentMenuList(props: Props) {
8184 doSetActiveChannel,
8285 pinComment,
8386 commentModAddDelegate,
87+ commentModRemoveDelegate,
8488 setQuickReply,
8589 handleDismissPin,
8690 } = props ;
@@ -95,6 +99,8 @@ function CommentMenuList(props: Props) {
9599 const contentChannelClaim = getChannelFromClaim ( claim ) ;
96100 const contentChannelPermanentUrl = contentChannelClaim && contentChannelClaim . permanent_url ;
97101
102+ const delegates = moderationDelegatesById [ contentChannelClaim ?. claim_id ] ;
103+
98104 const activeModeratorInfo = activeChannelClaim && moderationDelegatorsById [ activeChannelClaim . claim_id ] ;
99105 const activeChannelIsCreator = activeChannelClaim && activeChannelClaim . permanent_url === contentChannelPermanentUrl ;
100106 const activeChannelIsAdmin = activeChannelClaim && activeModeratorInfo && activeModeratorInfo . global ;
@@ -103,6 +109,10 @@ function CommentMenuList(props: Props) {
103109 contentChannelClaim &&
104110 activeModeratorInfo &&
105111 Object . values ( activeModeratorInfo . delegators ) . includes ( contentChannelClaim . claim_id ) ;
112+ const authorIsModerator =
113+ claimIsMine && // only check for own claims
114+ Array . isArray ( delegates ) &&
115+ delegates . some ( ( delegate ) => delegate . channelId === authorId ) ;
106116
107117 function handleDeleteComment ( ) {
108118 if ( playingUri . source === 'comment' ) {
@@ -126,6 +136,13 @@ function CommentMenuList(props: Props) {
126136 }
127137 }
128138
139+ function removeModerator ( ) {
140+ if ( activeChannelClaim && authorUri ) {
141+ const { channelName, channelClaimId } = parseURI ( authorUri ) ;
142+ if ( channelName && channelClaimId ) commentModRemoveDelegate ( channelClaimId , channelName , activeChannelClaim ) ;
143+ }
144+ }
145+
129146 function getBlockOptionElem ( ) {
130147 const isPersonalBlockTheOnlyOption = ! activeChannelIsModerator && ! activeChannelIsAdmin ;
131148 const isTimeoutBlockAvailable = claimIsMine || activeChannelIsModerator ;
@@ -256,17 +273,32 @@ function CommentMenuList(props: Props) {
256273 { __ ( 'Dismiss Pin' ) }
257274 </ MenuItem >
258275 ) }
259- { /* todo: filter out already active mods (bug with activeModeratorInfo?) */ }
260- { activeChannelIsCreator && activeChannelClaim && activeChannelClaim . permanent_url !== authorUri && (
261- < MenuItem className = "comment__menu-option" onSelect = { assignAsModerator } >
276+ { activeChannelIsCreator &&
277+ activeChannelClaim &&
278+ activeChannelClaim . permanent_url !== authorUri &&
279+ ! authorIsModerator && (
280+ < MenuItem className = "comment__menu-option" onSelect = { assignAsModerator } >
281+ < div className = "menu__link" >
282+ < Icon aria-hidden icon = { ICONS . ADD } />
283+ { __ ( 'Add as moderator' ) }
284+ </ div >
285+ < span className = "comment__menu-help" >
286+ { activeChannelClaim
287+ ? __ ( 'Assign this user to moderate %channel%.' , { channel : activeChannelClaim . name } )
288+ : __ ( 'Assign this user to moderate your channel.' ) }
289+ </ span >
290+ </ MenuItem >
291+ ) }
292+ { activeChannelIsCreator && authorIsModerator && (
293+ < MenuItem className = "comment__menu-option" onSelect = { removeModerator } >
262294 < div className = "menu__link" >
263- < Icon aria-hidden icon = { ICONS . ADD } />
264- { __ ( 'Add as moderator' ) }
295+ < Icon aria-hidden icon = { ICONS . REMOVE } />
296+ { __ ( 'Remove as moderator' ) }
265297 </ div >
266298 < span className = "comment__menu-help" >
267299 { activeChannelClaim
268- ? __ ( 'Assign this user to moderate %channel%.' , { channel : activeChannelClaim . name } )
269- : __ ( 'Assign this user to moderate your channel.' ) }
300+ ? __ ( 'Remove this user as a moderator of %channel%.' , { channel : activeChannelClaim . name } )
301+ : __ ( 'Remove this user as a moderator of your channel.' ) }
270302 </ span >
271303 </ MenuItem >
272304 ) }
0 commit comments