@@ -16,6 +16,7 @@ import Modal from "../Modal";
1616import SettingsStore from "../settings/SettingsStore" ;
1717import AskInviteAnywayDialog from "../components/views/dialogs/AskInviteAnywayDialog" ;
1818import ConfirmUserActionDialog from "../components/views/dialogs/ConfirmUserActionDialog" ;
19+ import { openInviteProgressDialog } from "../components/views/dialogs/InviteProgressDialog.tsx" ;
1920
2021export enum InviteState {
2122 Invited = "invited" ,
@@ -44,6 +45,12 @@ const USER_BANNED = "IO.ELEMENT.BANNED";
4445export interface MultiInviterOptions {
4546 /** Optional callback, fired after each invite */
4647 progressCallback ?: ( ) => void ;
48+
49+ /**
50+ * By default, we will pop up a "Preparing invitations..." dialog while the invites are being sent. Set this to
51+ * `true` to inhibit it (in which case, you probably want to implement another bit of feedback UI).
52+ */
53+ inhibitProgressDialog ?: boolean ;
4754}
4855
4956/**
@@ -88,49 +95,59 @@ export default class MultiInviter {
8895 this . addresses . push ( ...addresses ) ;
8996 this . reason = reason ;
9097
91- for ( const addr of this . addresses ) {
92- if ( getAddressType ( addr ) === null ) {
93- this . completionStates [ addr ] = InviteState . Error ;
94- this . errors [ addr ] = {
95- errcode : "M_INVALID" ,
96- errorText : _t ( "invite|invalid_address" ) ,
97- } ;
98- }
98+ let closeDialog : ( ( ) => void ) | undefined ;
99+ if ( ! this . options . inhibitProgressDialog ) {
100+ closeDialog = openInviteProgressDialog ( ) ;
99101 }
100102
101- for ( const addr of this . addresses ) {
102- // don't try to invite it if it's an invalid address
103- // (it will already be marked as an error though,
104- // so no need to do so again)
105- if ( getAddressType ( addr ) === null ) {
106- continue ;
103+ try {
104+ for ( const addr of this . addresses ) {
105+ if ( getAddressType ( addr ) === null ) {
106+ this . completionStates [ addr ] = InviteState . Error ;
107+ this . errors [ addr ] = {
108+ errcode : "M_INVALID" ,
109+ errorText : _t ( "invite|invalid_address" ) ,
110+ } ;
111+ }
107112 }
108113
109- // don't re-invite (there's no way in the UI to do this, but
110- // for sanity's sake)
111- if ( this . completionStates [ addr ] === InviteState . Invited ) {
112- continue ;
113- }
114+ for ( const addr of this . addresses ) {
115+ // don't try to invite it if it's an invalid address
116+ // (it will already be marked as an error though,
117+ // so no need to do so again)
118+ if ( getAddressType ( addr ) === null ) {
119+ continue ;
120+ }
121+
122+ // don't re-invite (there's no way in the UI to do this, but
123+ // for sanity's sake)
124+ if ( this . completionStates [ addr ] === InviteState . Invited ) {
125+ continue ;
126+ }
114127
115- await this . doInvite ( addr , false ) ;
128+ await this . doInvite ( addr , false ) ;
116129
117- if ( this . _fatal ) {
118- // `doInvite` suffered a fatal error. The error should have been recorded in `errors`; it's up
119- // to the caller to report back to the user.
120- return this . completionStates ;
130+ if ( this . _fatal ) {
131+ // `doInvite` suffered a fatal error. The error should have been recorded in `errors`; it's up
132+ // to the caller to report back to the user.
133+ return this . completionStates ;
134+ }
121135 }
122- }
123136
124- if ( Object . keys ( this . errors ) . length > 0 ) {
125- // There were problems inviting some people - see if we can invite them
126- // without caring if they exist or not.
127- const unknownProfileUsers = Object . keys ( this . errors ) . filter ( ( a ) =>
128- UNKNOWN_PROFILE_ERRORS . includes ( this . errors [ a ] . errcode ) ,
129- ) ;
137+ if ( Object . keys ( this . errors ) . length > 0 ) {
138+ // There were problems inviting some people - see if we can invite them
139+ // without caring if they exist or not.
140+ const unknownProfileUsers = Object . keys ( this . errors ) . filter ( ( a ) =>
141+ UNKNOWN_PROFILE_ERRORS . includes ( this . errors [ a ] . errcode ) ,
142+ ) ;
130143
131- if ( unknownProfileUsers . length > 0 ) {
132- await this . handleUnknownProfileUsers ( unknownProfileUsers ) ;
144+ if ( unknownProfileUsers . length > 0 ) {
145+ await this . handleUnknownProfileUsers ( unknownProfileUsers ) ;
146+ }
133147 }
148+ } finally {
149+ // Remember to close the progress dialog, if we opened one.
150+ closeDialog ?.( ) ;
134151 }
135152
136153 return this . completionStates ;
0 commit comments