Skip to content

Commit

Permalink
design: Nicer user bottom sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Aug 11, 2023
1 parent 195694a commit 924e4bc
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 160 deletions.
3 changes: 2 additions & 1 deletion assets/l10n/intl_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2540,5 +2540,6 @@
"replace": "Ersetzen",
"@replace": {},
"sendTypingNotifications": "Tippbenachrichtigungen senden",
"@sendTypingNotifications": {}
"@sendTypingNotifications": {},
"profileNotFound": "Der Benutzer konnte auf dem Server nicht gefunden werden. Vielleicht gibt es ein Verbindungsproblem oder der Benutzer existiert nicht."
}
3 changes: 2 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2500,5 +2500,6 @@
"placeholders": {
"provider": {}
}
}
},
"profileNotFound": "The user could not be found on the server. Maybe there is a connection problem or the user doesn't exist."
}
7 changes: 3 additions & 4 deletions lib/pages/chat_list/chat_list_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import 'package:fluffychat/pages/chat_list/chat_list_item.dart';
import 'package:fluffychat/pages/chat_list/search_title.dart';
import 'package:fluffychat/pages/chat_list/space_view.dart';
import 'package:fluffychat/pages/chat_list/stories_header.dart';
import 'package:fluffychat/pages/user_bottom_sheet/user_bottom_sheet.dart';
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/utils/stream_extension.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/profile_bottom_sheet.dart';
import 'package:fluffychat/widgets/public_room_bottom_sheet.dart';
import '../../config/themes.dart';
import '../../widgets/connection_status_header.dart';
Expand Down Expand Up @@ -150,9 +150,8 @@ class ChatListViewBody extends StatelessWidget {
userSearchResult.results[i].avatarUrl,
onPressed: () => showAdaptiveBottomSheet(
context: context,
builder: (c) => ProfileBottomSheet(
userId:
userSearchResult.results[i].userId,
builder: (c) => UserBottomSheet(
profile: userSearchResult.results[i],
outerContext: context,
),
),
Expand Down
88 changes: 75 additions & 13 deletions lib/pages/user_bottom_sheet/user_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,76 @@ enum UserBottomSheetAction {
ignore,
}

class LoadProfileBottomSheet extends StatelessWidget {
final String userId;
final BuildContext outerContext;

const LoadProfileBottomSheet({
super.key,
required this.userId,
required this.outerContext,
});

@override
Widget build(BuildContext context) {
return FutureBuilder<ProfileInformation>(
future: Matrix.of(context)
.client
.getUserProfile(userId)
.timeout(const Duration(seconds: 3)),
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return Scaffold(
appBar: AppBar(
leading: CloseButton(
onPressed: Navigator.of(context, rootNavigator: false).pop,
),
),
body: const Center(
child: CircularProgressIndicator.adaptive(),
),
);
}
return UserBottomSheet(
outerContext: outerContext,
profile: Profile(
userId: userId,
avatarUrl: snapshot.data?.avatarUrl,
displayName: snapshot.data?.displayname,
),
profileSearchError: snapshot.error,
);
},
);
}
}

class UserBottomSheet extends StatefulWidget {
final User user;
final User? user;
final Profile? profile;
final Function? onMention;
final BuildContext outerContext;
final Object? profileSearchError;

const UserBottomSheet({
Key? key,
required this.user,
this.user,
this.profile,
required this.outerContext,
this.onMention,
}) : super(key: key);
this.profileSearchError,
}) : assert(user != null || profile != null),
super(key: key);

@override
UserBottomSheetController createState() => UserBottomSheetController();
}

class UserBottomSheetController extends State<UserBottomSheet> {
void participantAction(UserBottomSheetAction action) async {
final user = widget.user;
final userId = user?.id ?? widget.profile?.userId;
if (userId == null) throw ('user or profile must not be null!');
// ignore: prefer_function_declarations_over_variables
final Function askConfirmation = () async => (await showOkCancelAlertDialog(
useRootNavigator: false,
Expand All @@ -50,7 +102,8 @@ class UserBottomSheetController extends State<UserBottomSheet> {
OkCancelResult.ok);
switch (action) {
case UserBottomSheetAction.report:
final event = widget.user;
if (user == null) throw ('User must not be null for this action!');

final score = await showConfirmationDialog<int>(
context: context,
title: L10n.of(context)!.reportUser,
Expand Down Expand Up @@ -85,8 +138,8 @@ class UserBottomSheetController extends State<UserBottomSheet> {
final result = await showFutureLoadingDialog(
context: context,
future: () => Matrix.of(context).client.reportContent(
event.roomId!,
event.eventId,
user.roomId!,
user.eventId,
reason: reason.single,
score: score,
),
Expand All @@ -97,54 +150,61 @@ class UserBottomSheetController extends State<UserBottomSheet> {
);
break;
case UserBottomSheetAction.mention:
if (user == null) throw ('User must not be null for this action!');
Navigator.of(context, rootNavigator: false).pop();
widget.onMention!();
break;
case UserBottomSheetAction.ban:
if (user == null) throw ('User must not be null for this action!');
if (await askConfirmation()) {
await showFutureLoadingDialog(
context: context,
future: () => widget.user.ban(),
future: () => user.ban(),
);
Navigator.of(context, rootNavigator: false).pop();
}
break;
case UserBottomSheetAction.unban:
if (user == null) throw ('User must not be null for this action!');
if (await askConfirmation()) {
await showFutureLoadingDialog(
context: context,
future: () => widget.user.unban(),
future: () => user.unban(),
);
Navigator.of(context, rootNavigator: false).pop();
}
break;
case UserBottomSheetAction.kick:
if (user == null) throw ('User must not be null for this action!');
if (await askConfirmation()) {
await showFutureLoadingDialog(
context: context,
future: () => widget.user.kick(),
future: () => user.kick(),
);
Navigator.of(context, rootNavigator: false).pop();
}
break;
case UserBottomSheetAction.permission:
if (user == null) throw ('User must not be null for this action!');
final newPermission = await showPermissionChooser(
context,
currentLevel: widget.user.powerLevel,
currentLevel: user.powerLevel,
);
if (newPermission != null) {
if (newPermission == 100 && await askConfirmation() == false) break;
await showFutureLoadingDialog(
context: context,
future: () => widget.user.setPower(newPermission),
future: () => user.setPower(newPermission),
);
Navigator.of(context, rootNavigator: false).pop();
}
break;
case UserBottomSheetAction.message:
final roomIdResult = await showFutureLoadingDialog(
context: context,
future: () => widget.user.startDirectChat(),
future: () => Matrix.of(context)
.client
.startDirectChat(user?.id ?? widget.profile!.userId),
);
if (roomIdResult.error != null) return;
widget.outerContext.go(['', 'rooms', roomIdResult.result!].join('/'));
Expand All @@ -154,7 +214,9 @@ class UserBottomSheetController extends State<UserBottomSheet> {
if (await askConfirmation()) {
await showFutureLoadingDialog(
context: context,
future: () => Matrix.of(context).client.ignoreUser(widget.user.id),
future: () => Matrix.of(context)
.client
.ignoreUser(user?.id ?? widget.profile!.userId),
);
}
}
Expand Down
Loading

0 comments on commit 924e4bc

Please sign in to comment.