refactor: Invite users when upgrading private room
This commit is contained in:
parent
adbdaf6e41
commit
3d73391aa5
1 changed files with 34 additions and 2 deletions
|
|
@ -197,7 +197,6 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
|
|||
if (newVersion == null ||
|
||||
OkCancelResult.cancel ==
|
||||
await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
okLabel: L10n.of(context).yes,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
|
|
@ -209,7 +208,40 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
|
|||
}
|
||||
final result = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.client.upgradeRoom(room.id, newVersion),
|
||||
futureWithProgress: (onProgress) async {
|
||||
final newRoomId = await room.client.upgradeRoom(room.id, newVersion);
|
||||
var newRoom = room.client.getRoomById(newRoomId);
|
||||
while (newRoom == null) {
|
||||
await room.client.onSync.stream.first;
|
||||
newRoom = room.client.getRoomById(newRoomId);
|
||||
}
|
||||
|
||||
if ({JoinRules.invite, JoinRules.knock, JoinRules.knockRestricted}
|
||||
.contains(room.joinRules)) {
|
||||
final users = await room.requestParticipants([
|
||||
Membership.join,
|
||||
Membership.invite,
|
||||
]);
|
||||
users.removeWhere((user) => user.id == room.client.userID);
|
||||
for (final (i, user) in users.indexed) {
|
||||
try {
|
||||
Logs().v('Inviting...', user.id);
|
||||
await newRoom.invite(user.id);
|
||||
onProgress(i / users.length);
|
||||
} on MatrixException catch (e) {
|
||||
final retryAfterMs = e.retryAfterMs;
|
||||
if (e.error != MatrixError.M_LIMIT_EXCEEDED ||
|
||||
retryAfterMs == null) {
|
||||
rethrow;
|
||||
}
|
||||
Logs().d('Limit exceeded. Retry after $retryAfterMs');
|
||||
await Future.delayed(Duration(milliseconds: retryAfterMs));
|
||||
await newRoom.invite(user.id);
|
||||
onProgress(i / users.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
if (result.error != null) return;
|
||||
if (!mounted) return;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue