Skip to content

Commit

Permalink
Merge pull request #270 from pangeachat/archive-dif-from-leave
Browse files Browse the repository at this point in the history
Distinct archive and leave buttons
  • Loading branch information
ggurdin authored Jun 6, 2024
2 parents 6a3d047 + 199e711 commit ddb17cb
Show file tree
Hide file tree
Showing 18 changed files with 783 additions and 315 deletions.
8 changes: 6 additions & 2 deletions assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3708,7 +3708,7 @@
},
"noTeachersFound": "No teachers found to report to",
"pleaseEnterANumber": "Please enter a number greater than 0",
"archiveRoomDescription": "The chat will be moved to the archive. Other users will be able to see that you have left the chat.",
"archiveRoomDescription": "The chat will be moved to the archive for yourself and other non-admin users.",
"roomUpgradeDescription": "The chat will then be recreated with the new room version. All participants will be notified that they need to switch to the new chat. You can find out more about room versions at https://spec.matrix.org/latest/rooms/",
"removeDevicesDescription": "You will be logged out of this device and will no longer be able to receive messages.",
"banUserDescription": "The user will be banned from the chat and will not be able to enter the chat again until they are unbanned.",
Expand Down Expand Up @@ -3947,5 +3947,9 @@
"studentAnalyticsNotAvailable": "Student data not currently available",
"roomDataMissing": "Some data may be missing from rooms in which you are not a member.",
"updatePhoneOS": "You may need to update your device's OS version.",
"wordsPerMinute": "Words per minute"
"wordsPerMinute": "Words per minute",
"leaveRoomDescription": "The chat will be moved to the archive. Other users will be able to see that you have left the chat.",
"archiveSpaceDescription": "All chats within this space will be moved to the archive for yourself and other non-admin users.",
"leaveSpaceDescription": "All chats within this space will be moved to the archive. Other users will be able to see that you have left the space.",
"onlyAdminDescription": "Since there are no other admins, all other participants will also be removed."
}
2 changes: 1 addition & 1 deletion assets/l10n/intl_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3698,7 +3698,7 @@
"@optionalRedactReason": {},
"dehydrate": "Exportar sesión y borrar dispositivo",
"@dehydrate": {},
"archiveRoomDescription": "",
"archiveRoomDescription": "El chat se moverá al archivo para ti y para otros usuarios que no sean administradores",
"@archiveRoomDescription": {},
"pleaseEnterRecoveryKeyDescription": "Para desbloquear sus mensajes antiguos, ingrese su clave de recuperación que se generó en una sesión anterior. Su clave de recuperación NO es su contraseña.",
"@pleaseEnterRecoveryKeyDescription": {},
Expand Down
11 changes: 11 additions & 0 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ class ChatController extends State<ChatPageWithRoom>
context.go('/rooms');
}

// #Pangea
void archiveChat() async {
final success = await showFutureLoadingDialog(
context: context,
future: room.archive,
);
if (success.error != null) return;
context.go('/rooms');
}
// Pangea#

EmojiPickerType emojiPickerType = EmojiPickerType.keyboard;

// #Pangea
Expand Down
28 changes: 27 additions & 1 deletion lib/pages/chat/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,29 @@ class ChatView extends StatelessWidget {
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [
// #Pangea
if (controller.room.isRoomAdmin)
TextButton.icon(
style: TextButton.styleFrom(
padding:
const EdgeInsets.all(
16,
),
foregroundColor:
Theme.of(context)
.colorScheme
.error,
),
icon: const Icon(
Icons.archive_outlined,
),
onPressed:
controller.archiveChat,
label: Text(
L10n.of(context)!.archive,
),
),
// Pangea#
TextButton.icon(
style: TextButton.styleFrom(
padding: const EdgeInsets.all(
Expand All @@ -378,7 +401,10 @@ class ChatView extends StatelessWidget {
.error,
),
icon: const Icon(
Icons.archive_outlined,
// #Pangea
// Icons.archive_outlined,
Icons.arrow_forward,
// Pangea#
),
onPressed: controller.leaveChat,
label: Text(
Expand Down
135 changes: 104 additions & 31 deletions lib/pages/chat_details/chat_details_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -522,52 +521,126 @@ class ChatDetailsView extends StatelessWidget {
),
const Divider(height: 1),
if (!room.isDirectChat)
ListTile(
title: Text(
room.isSpace
? L10n.of(context)!.archiveSpace
: L10n.of(context)!.archive,
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
if (room.isRoomAdmin)
ListTile(
title: Text(
room.isSpace
? L10n.of(context)!.archiveSpace
: L10n.of(context)!.archive,
style: TextStyle(
color:
Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
),
leading: CircleAvatar(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
foregroundColor: iconColor,
child: const Icon(
Icons.archive_outlined,
leading: CircleAvatar(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
foregroundColor: iconColor,
child: const Icon(
Icons.archive_outlined,
),
),
onTap: () async {
OkCancelResult confirmed = OkCancelResult.ok;
bool shouldGo = false;
// archiveSpace has its own popup; only show if not space
if (!room.isSpace) {
confirmed = await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context)!.areYouSure,
okLabel: L10n.of(context)!.ok,
cancelLabel: L10n.of(context)!.cancel,
message: L10n.of(context)!
.archiveRoomDescription,
);
}
if (confirmed == OkCancelResult.ok) {
if (room.isSpace) {
shouldGo = await room.archiveSpace(
context,
Matrix.of(context).client,
);
} else {
final success =
await showFutureLoadingDialog(
context: context,
future: () async {
await room.archive();
},
);
shouldGo = (success.error == null);
}
if (shouldGo) {
context.go('/rooms');
}
}
},
),
onTap: () async {
final confirmed = await showOkCancelAlertDialog(
ListTile(
title: Text(
L10n.of(context)!.leave,
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
leading: CircleAvatar(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
foregroundColor: iconColor,
child: const Icon(
Icons.arrow_forward,
),
),
onTap: () async {
OkCancelResult confirmed = OkCancelResult.ok;
bool shouldGo = false;
// If user is only admin, room will be archived
final bool onlyAdmin = await room.isOnlyAdmin();
// archiveSpace has its own popup; only show if not space
if (!room.isSpace) {
confirmed = await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context)!.areYouSure,
okLabel: L10n.of(context)!.ok,
cancelLabel: L10n.of(context)!.cancel,
message:
L10n.of(context)!.archiveRoomDescription,
message: onlyAdmin
? L10n.of(context)!.onlyAdminDescription
: L10n.of(context)!.leaveRoomDescription,
);
if (confirmed == OkCancelResult.ok) {
}
if (confirmed == OkCancelResult.ok) {
if (room.isSpace) {
shouldGo = onlyAdmin
? await room.archiveSpace(
context,
Matrix.of(context).client,
onlyAdmin: true,
)
: await room.leaveSpace(
context,
Matrix.of(context).client,
);
} else {
final success = await showFutureLoadingDialog(
context: context,
future: () async {
room.isSpace
? await archiveSpace(
room,
Matrix.of(context).client,
)
onlyAdmin
? await room.archive()
: await room.leave();
},
);
if (success.error == null) {
context.go('/rooms');
}
shouldGo = (success.error == null);
}
},
),
if (shouldGo) {
context.go('/rooms');
}
}
},
),
if (room.isRoomAdmin && !room.isDirectChat)
SwitchListTile.adaptive(
activeColor: AppConfig.activeToggleColor,
Expand Down
61 changes: 56 additions & 5 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,8 @@ class ChatListController extends State<ChatList>

//#Pangea
classStream = pangeaController.classController.stateStream.listen((event) {
if (event["activeSpaceId"] != null && mounted) {
// if (event["activeSpaceId"] != null && mounted) {
if (mounted) {
setActiveSpace(event["activeSpaceId"]);
}
});
Expand Down Expand Up @@ -679,6 +680,38 @@ class ChatListController extends State<ChatList>
// Pangea#
}

// #Pangea
Future<void> leaveAction() async {
final bool onlyAdmin = await Matrix.of(context)
.client
.getRoomById(selectedRoomIds.first)
?.isOnlyAdmin() ??
false;
final confirmed = await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context)!.areYouSure,
okLabel: L10n.of(context)!.yes,
cancelLabel: L10n.of(context)!.cancel,
message: onlyAdmin
? L10n.of(context)!.onlyAdminDescription
: L10n.of(context)!.leaveRoomDescription,
) ==
OkCancelResult.ok;
if (!confirmed) return;
final bool leftActiveRoom =
selectedRoomIds.contains(Matrix.of(context).activeRoomId);
await showFutureLoadingDialog(
context: context,
future: () => _leaveSelectedRooms(onlyAdmin),
);
setState(() {});
if (leftActiveRoom) {
context.go('/rooms');
}
}
// Pangea#

void dismissStatusList() async {
final result = await showOkCancelAlertDialog(
title: L10n.of(context)!.hidePresences,
Expand Down Expand Up @@ -729,17 +762,35 @@ class ChatListController extends State<ChatList>
final roomId = selectedRoomIds.first;
try {
// #Pangea
if (client.getRoomById(roomId)!.isUnread) {
await client.getRoomById(roomId)!.markUnread(false);
}
// await client.getRoomById(roomId)!.leave();
await client.getRoomById(roomId)!.archive();
// Pangea#
await client.getRoomById(roomId)!.leave();
} finally {
toggleSelection(roomId);
}
}
}

// #Pangea
Future<void> _leaveSelectedRooms(bool onlyAdmin) async {
final client = Matrix.of(context).client;
while (selectedRoomIds.isNotEmpty) {
final roomId = selectedRoomIds.first;
try {
final room = client.getRoomById(roomId);
if (!room!.isSpace &&
room.membership == Membership.join &&
room.isUnread) {
await room.markUnread(false);
}
onlyAdmin ? await room.archive() : await room.leave();
} finally {
toggleSelection(roomId);
}
}
}
// Pangea#

Future<void> addToSpace() async {
final selectedSpace = await showConfirmationDialog<String>(
context: context,
Expand Down
35 changes: 28 additions & 7 deletions lib/pages/chat_list/chat_list_header.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat_list/chat_list.dart';
import 'package:fluffychat/pages/chat_list/client_chooser_button.dart';
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';

Expand Down Expand Up @@ -168,14 +170,33 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
tooltip: L10n.of(context)!.toggleMuted,
onPressed: controller.toggleMuted,
),
IconButton(
// #Pangea
// icon: const Icon(Icons.delete_outlined),
icon: const Icon(Icons.archive_outlined),
// #Pangea
if (controller.selectedRoomIds.length == 1 &&
!(Matrix.of(context)
.client
.getRoomById(controller.selectedRoomIds.single)
?.isRoomAdmin ??
false))
IconButton(
icon: const Icon(Icons.arrow_forward),
tooltip: L10n.of(context)!.leave,
onPressed: controller.leaveAction,
),
if (controller.selectedRoomIds.length == 1 &&
(Matrix.of(context)
.client
.getRoomById(controller.selectedRoomIds.single)
?.isRoomAdmin ??
false))
// Pangea#
tooltip: L10n.of(context)!.archive,
onPressed: controller.archiveAction,
),
IconButton(
// #Pangea
// icon: const Icon(Icons.delete_outlined),
icon: const Icon(Icons.archive_outlined),
// Pangea#
tooltip: L10n.of(context)!.archive,
onPressed: controller.archiveAction,
),
]
: null,
);
Expand Down
Loading

0 comments on commit ddb17cb

Please sign in to comment.