add the ability to change your profile per-room

Fixes #177
This commit is contained in:
Henry Hiles 2026-11-26 14:31:24 -05:00
commit 8d4745cc12
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
3 changed files with 232 additions and 4 deletions

View file

@ -55,6 +55,10 @@ class const EditableAvatar({
child: Builder(
builder: (context) => IconButton.filled(
tooltip: "Edit avatar",
// The theme's default barely contrasts with the button
style: IconButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.onPrimary,
),
icon: Icon(Icons.edit),
onPressed: saving.active
? null

View file

@ -10,6 +10,7 @@ import "package:nexus/controllers/client.dart";
import "package:nexus/models/room_notification_level.dart";
import "package:nexus/controllers/room_settings_sections.dart";
import "package:nexus/widgets/settings/settings_layout.dart";
import "package:nexus/widgets/users/room_profile_sheet.dart";
import "package:nexus/controllers/via.dart";
import "package:nexus/models/room.dart";
import "package:flutter_hooks/flutter_hooks.dart";
@ -168,6 +169,15 @@ final class const RoomMenuButton(
title: Text("Invite"),
),
),
PopupMenuItem(
onTap: () => context.showAdaptiveSheet(
(_) => RoomProfileSheet(room!.metadata!.id),
),
child: ListTile(
leading: Icon(Icons.manage_accounts),
title: Text("Room Profile"),
),
),
PopupMenuItem(
onTap: () => showDialog(
context: context,

View file

@ -0,0 +1,77 @@
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:material_ui/material_ui.dart";
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
import "package:nexus/controllers/client_state.dart";
import "package:nexus/controllers/room_profile.dart";
import "package:nexus/helpers/extensions/better_when.dart";
import "package:nexus/helpers/extensions/get_localpart.dart";
import "package:nexus/main.dart";
import "package:nexus/models/profile_response.dart";
import "package:nexus/widgets/avatars/avatar_or_hash.dart";
import "package:nexus/widgets/avatars/editable_avatar.dart";
import "package:nexus/widgets/settings/inline_text_field.dart";
/// Edits the avatar and display name the current user has in [roomId].
class const RoomProfileSheet(final String roomId, {super.key})
extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final userId = ref.watch(ClientStateController.provider)?.userId ?? "";
final controller = ref.read(
RoomProfileController.provider(roomId).notifier,
);
Future<void> setField(String field, Object? value) =>
controller.setFields(.new({field: value})).onError(showError);
return SheetLayout(
title: Text("Room Profile"),
actions: [
TextButton(
onPressed: () => controller.reset().onError(showError),
child: Text("Use Global Profile"),
),
TextButton(onPressed: Navigator.of(context).pop, child: Text("Done")),
],
children: [
Text(
"Your avatar and display name in this room only. Changing your global profile may replace them.",
),
ref
.watch(RoomProfileController.provider(roomId))
.betterWhen(
skipLoadingOnReload: true,
data: (member) {
final name = member?.displayName ?? userId.localpart ?? userId;
return Column(
spacing: 8,
children: [
EditableAvatar(
hasAvatar: member?.avatarUrl != null,
onChanged: (url) =>
setField(Profile.avatarUrlKey, url?.toString()),
child: AvatarOrHash(
member?.avatarUrl,
name,
dimension: 200,
),
),
InlineTextField(
value: member?.displayName,
hint: userId.localpart ?? userId,
style: Theme.of(context).textTheme.headlineLarge,
onChanged: member == null
? null
: (value) => setField(
Profile.displayNameKey,
value.isEmpty ? null : value,
),
),
],
);
},
),
],
);
}
}