| 
									
										
										
										
											2023-01-03 11:55:46 -08:00
										 |  |  | // Copyright 2020 Signal Messenger, LLC
 | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import * as React from 'react'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-26 16:51:55 -04:00
										 |  |  | import { Button, ButtonSize, ButtonVariant } from '../Button'; | 
					
						
							| 
									
										
										
										
											2021-09-07 14:55:03 -05:00
										 |  |  | import { SystemMessage } from './SystemMessage'; | 
					
						
							| 
									
										
										
										
											2021-11-20 09:41:21 -06:00
										 |  |  | import type { LocalizerType, ThemeType } from '../../types/Util'; | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { ConversationType } from '../../state/ducks/conversations'; | 
					
						
							| 
									
										
										
										
											2021-11-20 09:41:21 -06:00
										 |  |  | import type { PreferredBadgeSelectorType } from '../../state/selectors/badges'; | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  | import { Intl } from '../Intl'; | 
					
						
							|  |  |  | import { ContactName } from './ContactName'; | 
					
						
							|  |  |  | import { GroupV1MigrationDialog } from '../GroupV1MigrationDialog'; | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  | import * as log from '../../logging/log'; | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export type PropsDataType = { | 
					
						
							| 
									
										
										
										
											2020-12-01 15:45:39 -08:00
										 |  |  |   areWeInvited: boolean; | 
					
						
							| 
									
										
										
										
											2022-12-08 01:41:37 -05:00
										 |  |  |   conversationId: string; | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  |   droppedMembers: Array<ConversationType>; | 
					
						
							|  |  |  |   invitedMembers: Array<ConversationType>; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export type PropsHousekeepingType = { | 
					
						
							| 
									
										
										
										
											2021-11-20 09:41:21 -06:00
										 |  |  |   getPreferredBadge: PreferredBadgeSelectorType; | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  |   i18n: LocalizerType; | 
					
						
							| 
									
										
										
										
											2021-11-20 09:41:21 -06:00
										 |  |  |   theme: ThemeType; | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export type PropsType = PropsDataType & PropsHousekeepingType; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function GroupV1Migration(props: PropsType): React.ReactElement { | 
					
						
							| 
									
										
										
										
											2021-11-20 09:41:21 -06:00
										 |  |  |   const { | 
					
						
							|  |  |  |     areWeInvited, | 
					
						
							| 
									
										
										
										
											2022-12-08 01:41:37 -05:00
										 |  |  |     conversationId, | 
					
						
							| 
									
										
										
										
											2021-11-20 09:41:21 -06:00
										 |  |  |     droppedMembers, | 
					
						
							|  |  |  |     getPreferredBadge, | 
					
						
							|  |  |  |     i18n, | 
					
						
							|  |  |  |     invitedMembers, | 
					
						
							|  |  |  |     theme, | 
					
						
							|  |  |  |   } = props; | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  |   const [showingDialog, setShowingDialog] = React.useState(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const showDialog = React.useCallback(() => { | 
					
						
							|  |  |  |     setShowingDialog(true); | 
					
						
							|  |  |  |   }, [setShowingDialog]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const dismissDialog = React.useCallback(() => { | 
					
						
							|  |  |  |     setShowingDialog(false); | 
					
						
							|  |  |  |   }, [setShowingDialog]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2021-09-07 14:55:03 -05:00
										 |  |  |     <> | 
					
						
							|  |  |  |       <SystemMessage | 
					
						
							|  |  |  |         icon="group" | 
					
						
							|  |  |  |         contents={ | 
					
						
							|  |  |  |           <> | 
					
						
							|  |  |  |             <p>{i18n('GroupV1--Migration--was-upgraded')}</p> | 
					
						
							|  |  |  |             <p> | 
					
						
							|  |  |  |               {areWeInvited ? ( | 
					
						
							|  |  |  |                 i18n('GroupV1--Migration--invited--you') | 
					
						
							|  |  |  |               ) : ( | 
					
						
							|  |  |  |                 <> | 
					
						
							|  |  |  |                   {renderUsers( | 
					
						
							|  |  |  |                     invitedMembers, | 
					
						
							|  |  |  |                     i18n, | 
					
						
							|  |  |  |                     'GroupV1--Migration--invited' | 
					
						
							|  |  |  |                   )} | 
					
						
							|  |  |  |                   {renderUsers( | 
					
						
							|  |  |  |                     droppedMembers, | 
					
						
							|  |  |  |                     i18n, | 
					
						
							|  |  |  |                     'GroupV1--Migration--removed' | 
					
						
							|  |  |  |                   )} | 
					
						
							|  |  |  |                 </> | 
					
						
							|  |  |  |               )} | 
					
						
							|  |  |  |             </p> | 
					
						
							|  |  |  |           </> | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         button={ | 
					
						
							|  |  |  |           <Button | 
					
						
							|  |  |  |             onClick={showDialog} | 
					
						
							|  |  |  |             size={ButtonSize.Small} | 
					
						
							|  |  |  |             variant={ButtonVariant.SystemMessage} | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             {i18n('GroupV1--Migration--learn-more')} | 
					
						
							|  |  |  |           </Button> | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       /> | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  |       {showingDialog ? ( | 
					
						
							| 
									
										
										
										
											2021-03-03 14:09:58 -06:00
										 |  |  |         <GroupV1MigrationDialog | 
					
						
							|  |  |  |           areWeInvited={areWeInvited} | 
					
						
							| 
									
										
										
										
											2022-12-08 01:41:37 -05:00
										 |  |  |           conversationId={conversationId} | 
					
						
							| 
									
										
										
										
											2021-03-03 14:09:58 -06:00
										 |  |  |           droppedMembers={droppedMembers} | 
					
						
							| 
									
										
										
										
											2021-11-20 09:41:21 -06:00
										 |  |  |           getPreferredBadge={getPreferredBadge} | 
					
						
							| 
									
										
										
										
											2021-03-03 14:09:58 -06:00
										 |  |  |           hasMigrated | 
					
						
							|  |  |  |           i18n={i18n} | 
					
						
							|  |  |  |           invitedMembers={invitedMembers} | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |           migrate={() => log.warn('GroupV1Migration: Modal called migrate()')} | 
					
						
							| 
									
										
										
										
											2021-03-03 14:09:58 -06:00
										 |  |  |           onClose={dismissDialog} | 
					
						
							| 
									
										
										
										
											2021-11-20 09:41:21 -06:00
										 |  |  |           theme={theme} | 
					
						
							| 
									
										
										
										
											2021-03-03 14:09:58 -06:00
										 |  |  |         /> | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  |       ) : null} | 
					
						
							| 
									
										
										
										
											2021-09-07 14:55:03 -05:00
										 |  |  |     </> | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function renderUsers( | 
					
						
							|  |  |  |   members: Array<ConversationType>, | 
					
						
							|  |  |  |   i18n: LocalizerType, | 
					
						
							|  |  |  |   keyPrefix: string | 
					
						
							|  |  |  | ): React.ReactElement | null { | 
					
						
							|  |  |  |   if (!members || members.length === 0) { | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (members.length === 1) { | 
					
						
							|  |  |  |     return ( | 
					
						
							| 
									
										
										
										
											2021-09-07 14:55:03 -05:00
										 |  |  |       <p> | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  |         <Intl | 
					
						
							|  |  |  |           i18n={i18n} | 
					
						
							|  |  |  |           id={`${keyPrefix}--one`} | 
					
						
							| 
									
										
										
										
											2021-09-16 11:15:43 -05:00
										 |  |  |           components={[<ContactName title={members[0].title} />]} | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  |         /> | 
					
						
							| 
									
										
										
										
											2021-09-07 14:55:03 -05:00
										 |  |  |       </p> | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 14:55:03 -05:00
										 |  |  |   return <p>{i18n(`${keyPrefix}--many`, [members.length.toString()])}</p>; | 
					
						
							| 
									
										
										
										
											2020-11-20 09:30:45 -08:00
										 |  |  | } |