forked from Nexus/nexus
parent
f80ceb0736
commit
3b7a4c0cd4
2 changed files with 469 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ import "dart:io";
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:collection/collection.dart";
|
||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||
import "package:nexus/widgets/composer/persona_button.dart";
|
||||
import "package:nexus/controllers/bot_argument_suggestions.dart";
|
||||
import "package:nexus/controllers/bot_command_draft.dart";
|
||||
import "package:nexus/controllers/bot_commands.dart";
|
||||
|
|
@ -565,6 +566,7 @@ class const Composer(
|
|||
),
|
||||
)
|
||||
? [
|
||||
PersonaButton(roomId),
|
||||
IconButton(
|
||||
onPressed: hasReplacement
|
||||
? null
|
||||
|
|
|
|||
74
lib/widgets/composer/persona_button.dart
Normal file
74
lib/widgets/composer/persona_button.dart
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/controllers/account_data.dart";
|
||||
import "package:nexus/controllers/personas.dart";
|
||||
import "package:nexus/controllers/settings.dart";
|
||||
import "package:nexus/main.dart";
|
||||
import "package:nexus/widgets/avatars/avatar_or_hash.dart";
|
||||
|
||||
/// Chooses the persona messages are sent as in [roomId], if personas are on.
|
||||
class const PersonaButton(final String roomId, {super.key})
|
||||
extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final enabled = ref.watch(
|
||||
SettingsController.provider.select(
|
||||
(settings) => settings.value?.personas ?? false,
|
||||
),
|
||||
);
|
||||
final (:profiles, :current) = ref.watch(
|
||||
PersonasController.provider(roomId),
|
||||
);
|
||||
if (!enabled || profiles.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
Future<void> choose(String profileId) => ref
|
||||
.read(AccountDataController.provider.notifier)
|
||||
.setRoomProfile(roomId, profileId)
|
||||
.onError(showError);
|
||||
|
||||
PopupMenuItem<void> item({
|
||||
required String id,
|
||||
required Widget leading,
|
||||
required String title,
|
||||
}) {
|
||||
final selected = (current?.id ?? "") == id;
|
||||
return PopupMenuItem(
|
||||
onTap: () => choose(id),
|
||||
child: ListTile(
|
||||
selected: selected,
|
||||
leading: leading,
|
||||
title: Text(title),
|
||||
trailing: selected ? Icon(Icons.check) : null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return AdaptiveMenuButton<void>(
|
||||
tooltip: switch (current) {
|
||||
final current? => "Sending as ${current.displayName ?? current.id}",
|
||||
null => "Choose persona",
|
||||
},
|
||||
icon: switch (current) {
|
||||
final current? => AvatarOrHash(
|
||||
current.avatarUrl,
|
||||
current.displayName ?? current.id,
|
||||
),
|
||||
null => Icon(Icons.person),
|
||||
},
|
||||
itemBuilder: (_) => [
|
||||
item(id: "", leading: Icon(Icons.person), title: "Yourself"),
|
||||
...profiles.map(
|
||||
(profile) => item(
|
||||
id: profile.id,
|
||||
leading: AvatarOrHash(
|
||||
profile.avatarUrl,
|
||||
profile.displayName ?? profile.id,
|
||||
),
|
||||
title: profile.displayName ?? profile.id,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue