refactor: Invite users when upgrading private room

This commit is contained in:
Christian Kußowski 2025-11-01 09:58:16 +01:00
parent adbdaf6e41
commit 3d73391aa5
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652

View file

@ -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;