@@ -19,24 +19,6 @@ export type ReportSettings = {
1919export type NewBlocksMap = Map < string , BlocksForUser >
2020type BlocksForUser = { chatBlocked ?: boolean ; followBlocked ?: boolean ; report ?: ReportSettings }
2121
22- export type Props = {
23- adderUsername ?: string
24- blockUserByDefault ?: boolean
25- context ?: BlockModalContext
26- conversationIDKey ?: string
27- filterUserByDefault ?: boolean
28- finishWaiting : boolean
29- flagUserByDefault ?: boolean
30- isBlocked : ( username : string , which : BlockType ) => boolean
31- loadingWaiting : boolean
32- onClose : ( ) => void
33- onFinish : ( newBlocks : NewBlocksMap , blockTeam : boolean , report ?: ReportSettings ) => void
34- otherUsernames ?: Array < string >
35- refreshBlocks : ( ) => void
36- reportsUserByDefault ?: boolean
37- teamname ?: string
38- }
39-
4022type OwnProps = {
4123 blockUserByDefault ?: boolean
4224 filterUserByDefault ?: boolean
@@ -141,9 +123,102 @@ const ReportOptions = (props: ReportOptionsProps) => {
141123// In order to have this play nicely with scrolling and keyboards, put all the stuff in a List.
142124type Item = 'topStuff' | { username : string }
143125
144- const BlockModal = React . memo ( function BlockModal ( p : Props ) {
145- const { finishWaiting, onClose, refreshBlocks, context, blockUserByDefault, otherUsernames} = p
146- const { reportsUserByDefault, flagUserByDefault, conversationIDKey, adderUsername} = p
126+ const Container = React . memo ( function BlockModal ( ownProps : OwnProps ) {
127+ const { context, conversationIDKey, blockUserByDefault = false , filterUserByDefault = false } = ownProps
128+ const { flagUserByDefault = false , reportsUserByDefault = false , team : teamname } = ownProps
129+ let { username : adderUsername , others} = ownProps
130+ const waitingForLeave = C . Waiting . useAnyWaiting (
131+ teamname ? C . Teams . leaveTeamWaitingKey ( teamname ) : undefined
132+ )
133+ const waitingForBlocking = C . Waiting . useAnyWaiting ( Constants . setUserBlocksWaitingKey )
134+ const waitingForReport = C . Waiting . useAnyWaiting ( Constants . reportUserWaitingKey )
135+ if ( others ?. length === 1 && ! adderUsername ) {
136+ adderUsername = others [ 0 ]
137+ others = undefined
138+ }
139+
140+ const _allKnownBlocks = C . useUsersState ( s => s . blockMap )
141+ const loadingWaiting = C . Waiting . useAnyWaiting ( Constants . getUserBlocksWaitingKey )
142+
143+ const onClose = C . useRouterState ( s => s . dispatch . navigateUp )
144+ const leaveTeam = C . useTeamsState ( s => s . dispatch . leaveTeam )
145+ const leaveTeamAndBlock = React . useCallback (
146+ ( teamname : string ) => {
147+ leaveTeam ( teamname , true , 'chat' )
148+ } ,
149+ [ leaveTeam ]
150+ )
151+ const getBlockState = C . useUsersState ( s => s . dispatch . getBlockState )
152+ const _reportUser = C . useUsersState ( s => s . dispatch . reportUser )
153+ const refreshBlocksFor = getBlockState
154+ const reportUser = React . useCallback (
155+ ( username : string , conversationIDKey : string | undefined , report : ReportSettings ) => {
156+ _reportUser ( {
157+ comment : report . extraNotes ,
158+ conversationIDKey,
159+ includeTranscript : report . includeTranscript && ! ! conversationIDKey ,
160+ reason : report . reason ,
161+ username,
162+ } )
163+ } ,
164+ [ _reportUser ]
165+ )
166+ const setConversationStatus = C . useChatContext ( s => s . dispatch . blockConversation )
167+ const _setUserBlocks = C . useUsersState ( s => s . dispatch . setUserBlocks )
168+ const setUserBlocks = React . useCallback (
169+ ( newBlocks : NewBlocksMap ) => {
170+ // Convert our state block array to action payload.
171+ const blocks = [ ...newBlocks . entries ( ) ]
172+ . filter (
173+ ( [ _ , userBlocks ] ) => userBlocks . chatBlocked !== undefined || userBlocks . followBlocked !== undefined
174+ )
175+ . map ( ( [ username , userBlocks ] ) => ( {
176+ setChatBlock : userBlocks . chatBlocked ,
177+ setFollowBlock : userBlocks . followBlocked ,
178+ username,
179+ } ) )
180+ if ( blocks . length ) {
181+ _setUserBlocks ( blocks )
182+ }
183+ } ,
184+ [ _setUserBlocks ]
185+ )
186+
187+ const otherUsernames = others && others . length > 0 ? others : undefined
188+ const finishWaiting = waitingForLeave || waitingForBlocking || waitingForReport
189+ const isBlocked = ( username : string , which : BlockType ) => {
190+ const blockObj = _allKnownBlocks . get ( username )
191+ return blockObj ? blockObj [ which ] : false
192+ }
193+
194+ const onFinish = ( newBlocks : NewBlocksMap , blockTeam : boolean ) => {
195+ let takingAction = false
196+ if ( blockTeam ) {
197+ if ( teamname ) {
198+ takingAction = true
199+ leaveTeamAndBlock ( teamname )
200+ } else if ( conversationIDKey ) {
201+ takingAction = true
202+ const anyReported = [ ...newBlocks . values ( ) ] . some ( v => v . report !== undefined )
203+ setConversationStatus ( anyReported )
204+ }
205+ }
206+ if ( newBlocks . size ) {
207+ takingAction = true
208+ setUserBlocks ( newBlocks )
209+ }
210+ newBlocks . forEach ( ( { report} , username ) => report && reportUser ( username , conversationIDKey , report ) )
211+ if ( ! takingAction ) {
212+ onClose ( )
213+ }
214+ }
215+ const refreshBlocks = React . useCallback ( ( ) => {
216+ const usernames = [ ...( adderUsername ? [ adderUsername ] : [ ] ) , ...( otherUsernames || [ ] ) ]
217+ if ( usernames . length ) {
218+ refreshBlocksFor ( usernames )
219+ }
220+ } , [ adderUsername , otherUsernames , refreshBlocksFor ] )
221+
147222 const [ blockTeam , setBlockTeam ] = React . useState ( true )
148223 const [ finishClicked , setFinishClicked ] = React . useState ( false )
149224 // newBlocks holds a Map of blocks that will be applied when user clicks
@@ -205,7 +280,7 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
205280 return current [ which ] || false
206281 }
207282 // If we don't have a checkbox, check the store for current block value.
208- return p . isBlocked ( username , which )
283+ return isBlocked ( username , which )
209284 }
210285
211286 const setReportForUsername = ( username : string , shouldReport : boolean ) => {
@@ -263,9 +338,9 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
263338 }
264339 }
265340
266- const onFinish = ( ) => {
341+ const onClickFinish = ( ) => {
267342 setFinishClicked ( true )
268- p . onFinish ( newBlocks , blockTeam )
343+ onFinish ( newBlocks , blockTeam )
269344 }
270345
271346 const shouldShowReport = ( username : string ) : boolean => {
@@ -290,8 +365,8 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
290365 < CheckboxRow
291366 text = {
292367 ! teamLabel
293- ? `${ p . filterUserByDefault ? 'Filter' : 'Block' } ${ username } `
294- : `${ p . filterUserByDefault ? 'Filter' : 'Block' } ${ username } from messaging me directly`
368+ ? `${ filterUserByDefault ? 'Filter' : 'Block' } ${ username } `
369+ : `${ filterUserByDefault ? 'Filter' : 'Block' } ${ username } from messaging me directly`
295370 }
296371 onCheck = { checked => setBlockFor ( username , 'chatBlocked' , checked ) }
297372 checked = { getBlockFor ( username , 'chatBlocked' ) }
@@ -335,8 +410,6 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
335410 </ >
336411 )
337412
338- const { teamname} = p
339-
340413 const header = {
341414 leftButton : Styles . isMobile ? (
342415 < Kb . Text onClick = { onClose } type = "BodyPrimaryLink" >
@@ -346,7 +419,7 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
346419 title : < Kb . Icon type = "iconfont-user-block" sizeType = "Big" color = { Styles . globalColors . red } /> ,
347420 }
348421
349- if ( p . loadingWaiting ) {
422+ if ( loadingWaiting ) {
350423 return (
351424 < Kb . Modal mode = "Default" header = { header } >
352425 < Kb . Box style = { styles . loadingAnimationBox } >
@@ -393,7 +466,7 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
393466 content : (
394467 < Kb . ButtonBar fullWidth = { true } style = { styles . buttonBar } >
395468 { ! Styles . isMobile && < Kb . Button fullWidth = { true } label = "Cancel" onClick = { onClose } type = "Dim" /> }
396- < Kb . WaitingButton label = "Finish" onClick = { onFinish } fullWidth = { true } type = "Danger" />
469+ < Kb . WaitingButton label = "Finish" onClick = { onClickFinish } fullWidth = { true } type = "Danger" />
397470 </ Kb . ButtonBar >
398471 ) ,
399472 } }
@@ -421,117 +494,6 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
421494 )
422495} )
423496
424- const Container = ( ownProps : OwnProps ) => {
425- const { context, conversationIDKey, blockUserByDefault = false , filterUserByDefault = false } = ownProps
426- const { flagUserByDefault = false , reportsUserByDefault = false , team : teamname } = ownProps
427- let { username : adderUsername , others} = ownProps
428- const waitingForLeave = C . Waiting . useAnyWaiting (
429- teamname ? C . Teams . leaveTeamWaitingKey ( teamname ) : undefined
430- )
431- const waitingForBlocking = C . Waiting . useAnyWaiting ( Constants . setUserBlocksWaitingKey )
432- const waitingForReport = C . Waiting . useAnyWaiting ( Constants . reportUserWaitingKey )
433- if ( others ?. length === 1 && ! adderUsername ) {
434- adderUsername = others [ 0 ]
435- others = undefined
436- }
437-
438- const _allKnownBlocks = C . useUsersState ( s => s . blockMap )
439- const loadingWaiting = C . Waiting . useAnyWaiting ( Constants . getUserBlocksWaitingKey )
440-
441- const onClose = C . useRouterState ( s => s . dispatch . navigateUp )
442- const leaveTeam = C . useTeamsState ( s => s . dispatch . leaveTeam )
443- const leaveTeamAndBlock = React . useCallback (
444- ( teamname : string ) => {
445- leaveTeam ( teamname , true , 'chat' )
446- } ,
447- [ leaveTeam ]
448- )
449- const getBlockState = C . useUsersState ( s => s . dispatch . getBlockState )
450- const _reportUser = C . useUsersState ( s => s . dispatch . reportUser )
451- const refreshBlocksFor = getBlockState
452- const reportUser = React . useCallback (
453- ( username : string , conversationIDKey : string | undefined , report : ReportSettings ) => {
454- _reportUser ( {
455- comment : report . extraNotes ,
456- conversationIDKey,
457- includeTranscript : report . includeTranscript && ! ! conversationIDKey ,
458- reason : report . reason ,
459- username,
460- } )
461- } ,
462- [ _reportUser ]
463- )
464- const setConversationStatus = C . useChatContext ( s => s . dispatch . blockConversation )
465- const _setUserBlocks = C . useUsersState ( s => s . dispatch . setUserBlocks )
466- const setUserBlocks = React . useCallback (
467- ( newBlocks : NewBlocksMap ) => {
468- // Convert our state block array to action payload.
469- const blocks = [ ...newBlocks . entries ( ) ]
470- . filter (
471- ( [ _ , userBlocks ] ) => userBlocks . chatBlocked !== undefined || userBlocks . followBlocked !== undefined
472- )
473- . map ( ( [ username , userBlocks ] ) => ( {
474- setChatBlock : userBlocks . chatBlocked ,
475- setFollowBlock : userBlocks . followBlocked ,
476- username,
477- } ) )
478- if ( blocks . length ) {
479- _setUserBlocks ( blocks )
480- }
481- } ,
482- [ _setUserBlocks ]
483- )
484-
485- const otherUsernames = others && others . length > 0 ? others : undefined
486- const props = {
487- adderUsername,
488- blockUserByDefault,
489- context,
490- conversationIDKey,
491- filterUserByDefault,
492- finishWaiting : waitingForLeave || waitingForBlocking || waitingForReport ,
493- flagUserByDefault,
494- isBlocked : ( username : string , which : BlockType ) => {
495- const blockObj = _allKnownBlocks . get ( username )
496- return blockObj ? blockObj [ which ] : false
497- } ,
498- loadingWaiting,
499- onClose,
500- onFinish : ( newBlocks : NewBlocksMap , blockTeam : boolean ) => {
501- let takingAction = false
502- if ( blockTeam ) {
503- if ( teamname ) {
504- takingAction = true
505- leaveTeamAndBlock ( teamname )
506- } else if ( conversationIDKey ) {
507- takingAction = true
508- const anyReported = [ ...newBlocks . values ( ) ] . some ( v => v . report !== undefined )
509- setConversationStatus ( anyReported )
510- }
511- }
512- if ( newBlocks . size ) {
513- takingAction = true
514- setUserBlocks ( newBlocks )
515- }
516- newBlocks . forEach ( ( { report} , username ) => report && reportUser ( username , conversationIDKey , report ) )
517- if ( ! takingAction ) {
518- onClose ( )
519- }
520- } ,
521- otherUsernames,
522- refreshBlocks : ( ) => {
523- const usernames = [ ...( adderUsername ? [ adderUsername ] : [ ] ) , ...( otherUsernames || [ ] ) ]
524- if ( usernames . length ) {
525- refreshBlocksFor ( usernames )
526- }
527- } ,
528- reportsUserByDefault,
529- teamname,
530- }
531-
532- return < BlockModal { ...props } />
533- }
534-
535497export default Container
536498
537499const getListHeightStyle = ( numOthers : number , expanded : boolean ) => ( {
0 commit comments