Update archive implementation
This commit is contained in:
parent
270d3802ac
commit
b5a35ad723
9 changed files with 139 additions and 60 deletions
|
|
@ -232,8 +232,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
void archiveChat() async {
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: room
|
||||
.leave, // Edit - Add room.archive method in pangea_room_extension.dart
|
||||
future: room.archive,
|
||||
);
|
||||
if (success.error != null) return;
|
||||
context.go('/rooms');
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/class_det
|
|||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/class_invitation_buttons.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/class_name_button.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/room_rules_editor.dart';
|
||||
import 'package:fluffychat/pangea/utils/archive_space.dart';
|
||||
import 'package:fluffychat/pangea/utils/lock_room.dart';
|
||||
import 'package:fluffychat/pangea/widgets/class/add_class_and_invite.dart';
|
||||
import 'package:fluffychat/pangea/widgets/class/add_space_toggles.dart';
|
||||
|
|
@ -557,13 +556,10 @@ class ChatDetailsView extends StatelessWidget {
|
|||
context: context,
|
||||
future: () async {
|
||||
room.isSpace
|
||||
? await archiveSpace(
|
||||
// Edit - contents
|
||||
room,
|
||||
? await room.archiveSpace(
|
||||
Matrix.of(context).client,
|
||||
)
|
||||
: await room
|
||||
.leave(); // Edit - archive, not leave
|
||||
: await room.archive();
|
||||
},
|
||||
);
|
||||
if (success.error == null) {
|
||||
|
|
@ -602,9 +598,7 @@ class ChatDetailsView extends StatelessWidget {
|
|||
context: context,
|
||||
future: () async {
|
||||
room.isSpace
|
||||
? await archiveSpace(
|
||||
// Edit = leaveSpace
|
||||
room,
|
||||
? await room.leaveSpace(
|
||||
Matrix.of(context).client,
|
||||
)
|
||||
: await room.leave();
|
||||
|
|
|
|||
|
|
@ -679,6 +679,31 @@ class ChatListController extends State<ChatList>
|
|||
// Pangea#
|
||||
}
|
||||
|
||||
// #Pangea
|
||||
Future<void> leaveAction() async {
|
||||
final confirmed = await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
cancelLabel: L10n.of(context)!.cancel,
|
||||
message: L10n.of(context)!.leaveRoomDescription,
|
||||
) ==
|
||||
OkCancelResult.ok;
|
||||
if (!confirmed) return;
|
||||
final bool leftActiveRoom =
|
||||
selectedRoomIds.contains(Matrix.of(context).activeRoomId);
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => _leaveSelectedRooms(),
|
||||
);
|
||||
setState(() {});
|
||||
if (leftActiveRoom) {
|
||||
context.go('/rooms');
|
||||
}
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
void dismissStatusList() async {
|
||||
final result = await showOkCancelAlertDialog(
|
||||
title: L10n.of(context)!.hidePresences,
|
||||
|
|
@ -729,16 +754,31 @@ class ChatListController extends State<ChatList>
|
|||
final roomId = selectedRoomIds.first;
|
||||
try {
|
||||
// #Pangea
|
||||
// await client.getRoomById(roomId)!.leave();
|
||||
await client.getRoomById(roomId)!.archive();
|
||||
// Pangea#
|
||||
} finally {
|
||||
toggleSelection(roomId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #Pangea
|
||||
Future<void> _leaveSelectedRooms() async {
|
||||
final client = Matrix.of(context).client;
|
||||
while (selectedRoomIds.isNotEmpty) {
|
||||
final roomId = selectedRoomIds.first;
|
||||
try {
|
||||
if (client.getRoomById(roomId)!.isUnread) {
|
||||
await client.getRoomById(roomId)!.markUnread(false);
|
||||
}
|
||||
// Pangea#
|
||||
await client.getRoomById(roomId)!.leave();
|
||||
} finally {
|
||||
toggleSelection(roomId);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
Future<void> addToSpace() async {
|
||||
final selectedSpace = await showConfirmationDialog<String>(
|
||||
|
|
|
|||
|
|
@ -190,8 +190,7 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
|
|||
IconButton(
|
||||
icon: const Icon(Icons.arrow_forward),
|
||||
tooltip: L10n.of(context)!.leave,
|
||||
onPressed:
|
||||
controller.archiveAction, // Edit - make leaveAction
|
||||
onPressed: controller.leaveAction,
|
||||
),
|
||||
// Pangea#
|
||||
]
|
||||
|
|
|
|||
|
|
@ -53,11 +53,39 @@ class ChatListItem extends StatelessWidget {
|
|||
message: L10n.of(context)!.archiveRoomDescription,
|
||||
);
|
||||
if (confirmed == OkCancelResult.cancel) return;
|
||||
// #Pangea
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
// #Pangea
|
||||
// future: () => room.leave(),
|
||||
future: () => room.archive(),
|
||||
// Pangea#
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// #Pangea
|
||||
Future<void> leaveAction(BuildContext context) async {
|
||||
{
|
||||
if ([Membership.leave, Membership.ban].contains(room.membership)) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.forget(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final confirmed = await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
cancelLabel: L10n.of(context)!.no,
|
||||
message: L10n.of(context)!.leaveRoomDescription,
|
||||
);
|
||||
if (confirmed == OkCancelResult.cancel) return;
|
||||
if (room.isUnread) {
|
||||
await room.markUnread(false);
|
||||
}
|
||||
// Pangea#
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.leave(),
|
||||
|
|
@ -65,6 +93,7 @@ class ChatListItem extends StatelessWidget {
|
|||
return;
|
||||
}
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import 'package:fluffychat/pangea/constants/class_default_values.dart';
|
|||
import 'package:fluffychat/pangea/constants/pangea_room_types.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/sync_update_extension.dart';
|
||||
import 'package:fluffychat/pangea/utils/archive_space.dart';
|
||||
import 'package:fluffychat/pangea/utils/chat_list_handle_space_tap.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
|
|
@ -283,22 +282,29 @@ class _SpaceViewState extends State<SpaceView> {
|
|||
_onJoinSpaceChild(spaceChild!);
|
||||
break;
|
||||
case SpaceChildContextAction.leave:
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
// #Pangea
|
||||
// future: room!.leave,
|
||||
future: () async {
|
||||
if (room!.isUnread) {
|
||||
await room.markUnread(false);
|
||||
}
|
||||
await room.leave(); // Edit - use leaveAction?
|
||||
if (Matrix.of(context).activeRoomId == room.id) {
|
||||
context.go('/rooms');
|
||||
}
|
||||
},
|
||||
// Pangea#
|
||||
);
|
||||
// #Pangea
|
||||
widget.controller.cancelAction();
|
||||
if (room == null) return;
|
||||
widget.controller.toggleSelection(room.id);
|
||||
room.isSpace
|
||||
? await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
await room.leaveSpace(
|
||||
Matrix.of(context).client,
|
||||
);
|
||||
widget.controller.selectedRoomIds.clear();
|
||||
},
|
||||
)
|
||||
: await widget.controller.leaveAction();
|
||||
_refresh();
|
||||
break;
|
||||
// await showFutureLoadingDialog(
|
||||
// context: context,
|
||||
// future: room!.leave,
|
||||
// );
|
||||
// break;
|
||||
// Pangea#
|
||||
case SpaceChildContextAction.removeFromSpace:
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
|
|
@ -306,8 +312,7 @@ class _SpaceViewState extends State<SpaceView> {
|
|||
);
|
||||
break;
|
||||
// #Pangea
|
||||
case SpaceChildContextAction
|
||||
.archive: // Edit - change behavior to archive space for all users
|
||||
case SpaceChildContextAction.archive:
|
||||
widget.controller.cancelAction();
|
||||
// #Pangea
|
||||
if (room == null) return;
|
||||
|
|
@ -317,8 +322,7 @@ class _SpaceViewState extends State<SpaceView> {
|
|||
? await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
await archiveSpace(
|
||||
room,
|
||||
await room.archiveSpace(
|
||||
Matrix.of(context).client,
|
||||
);
|
||||
widget.controller.selectedRoomIds.clear();
|
||||
|
|
|
|||
|
|
@ -808,6 +808,43 @@ extension PangeaRoom on Room {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> archive() async {
|
||||
final participants = await requestParticipants();
|
||||
final students = participants
|
||||
.where(
|
||||
(e) =>
|
||||
e.powerLevel < ClassDefaultValues.powerLevelOfAdmin &&
|
||||
e.id != BotName.byEnvironment,
|
||||
)
|
||||
.toList();
|
||||
for (final student in students) {
|
||||
await kick(student.id);
|
||||
}
|
||||
if (isUnread) {
|
||||
await markUnread(false);
|
||||
}
|
||||
await leave();
|
||||
}
|
||||
|
||||
Future<void> archiveSpace(Client client) async {
|
||||
final List<Room> children = await getChildRooms();
|
||||
for (final Room child in children) {
|
||||
await child.archive();
|
||||
}
|
||||
await archive();
|
||||
}
|
||||
|
||||
Future<void> leaveSpace(Client client) async {
|
||||
final List<Room> children = await getChildRooms();
|
||||
for (final Room child in children) {
|
||||
if (child.isUnread) {
|
||||
await child.markUnread(false);
|
||||
}
|
||||
await child.leave();
|
||||
}
|
||||
await leave();
|
||||
}
|
||||
|
||||
bool canIAddSpaceChild(Room? room) {
|
||||
if (!isSpace) {
|
||||
ErrorHandler.logError(
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
Future<void> archiveSpace(Room? space, Client client) async {
|
||||
if (space == null) {
|
||||
ErrorHandler.logError(
|
||||
e: 'Tried to archive a space that is null. This should not happen.',
|
||||
s: StackTrace.current,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Room> children = await space.getChildRooms();
|
||||
for (final Room child in children) {
|
||||
if (child.isUnread) {
|
||||
await child.markUnread(false);
|
||||
}
|
||||
await child.leave();
|
||||
}
|
||||
await space.leave();
|
||||
}
|
||||
|
|
@ -191,8 +191,7 @@ class ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
if (confirmed == OkCancelResult.ok) {
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
widget.room.leave(), // Edit - archive, not leave
|
||||
future: () => widget.room.archive(),
|
||||
);
|
||||
if (success.error == null) {
|
||||
context.go('/rooms');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue