tweak PMP support

This commit is contained in:
Henry Hiles 2026-11-26 15:50:57 -05:00
commit 4800123044
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
5 changed files with 69 additions and 61 deletions

View file

@ -3,7 +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/widgets/composer/subprofile_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";
@ -566,7 +566,7 @@ class const Composer(
),
)
? [
PersonaButton(roomId),
SubprofileButton(roomId),
IconButton(
onPressed: hasReplacement
? null

View file

@ -2,23 +2,23 @@ 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/subprofiles.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})
/// Chooses the subprofile messages are sent as in [roomId], if subprofiles are on.
class const SubprofileButton(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,
(settings) => settings.value?.subprofiles ?? false,
),
);
final (:profiles, :current) = ref.watch(
PersonasController.provider(roomId),
SubprofilesController.provider(roomId),
);
if (!enabled || profiles.isEmpty) return const SizedBox.shrink();
@ -47,7 +47,7 @@ class const PersonaButton(final String roomId, {super.key})
return AdaptiveMenuButton<void>(
tooltip: switch (current) {
final current? => "Sending as ${current.displayName ?? current.id}",
null => "Choose persona",
null => "Choose subprofile",
},
icon: switch (current) {
final current? => AvatarOrHash(
@ -57,7 +57,7 @@ class const PersonaButton(final String roomId, {super.key})
null => Icon(Icons.person),
},
itemBuilder: (_) => [
item(id: "", leading: Icon(Icons.person), title: "Yourself"),
item(id: "", leading: Icon(Icons.person), title: "Account Profile"),
...profiles.map(
(profile) => item(
id: profile.id,

View file

@ -1,6 +1,7 @@
import "package:material_ui/material_ui.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:nexus/controllers/author.dart";
import "package:nexus/controllers/user.dart";
import "package:nexus/helpers/extensions/get_localpart.dart";
import "package:nexus/helpers/extensions/show_user_popover.dart";
import "package:nexus/helpers/extensions/displayname_color.dart";
@ -34,7 +35,7 @@ class const MessageDisplayname(
),
if (event.pmp != null)
Text(
"(via ${event.sender})",
"(${ref.watch(UserController.provider(.new(roomId: event.roomId, userId: event.sender))).value?.displayName ?? event.sender.localpart})",
style: Theme.of(context).textTheme.labelSmall
?.copyWith(color: color, fontWeight: .bold),
maxLines: 1,

View file

@ -9,16 +9,18 @@ import "package:nexus/models/per_message_profiles.dart";
import "package:nexus/widgets/avatars/avatar_or_hash.dart";
import "package:nexus/widgets/avatars/editable_avatar.dart";
class const PersonaSheet({final StoredProfile? persona, super.key})
class const SubprofileSheet({final StoredProfile? subprofile, super.key})
extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final saving = Saving.use();
final trigger = persona?.triggers.firstOrNull;
final nameController = useTextEditingController(text: persona?.displayName);
final trigger = subprofile?.triggers.firstOrNull;
final nameController = useTextEditingController(
text: subprofile?.displayName,
);
final prefixController = useTextEditingController(text: trigger?.prefix);
final suffixController = useTextEditingController(text: trigger?.suffix);
final avatar = useState(persona?.avatarUrl);
final avatar = useState(subprofile?.avatarUrl);
final name = useValueListenable(nameController).text.trim();
final accountData = ref.read(AccountDataController.provider.notifier);
@ -35,24 +37,24 @@ class const PersonaSheet({final StoredProfile? persona, super.key})
final suffix = suffixController.text;
final edited = StoredProfile(
id:
persona?.id ??
subprofile?.id ??
DateTime.now().microsecondsSinceEpoch.toRadixString(36),
displayName: name,
avatarUrl: avatar.value,
triggers: .new([
if (prefix.isNotEmpty || suffix.isNotEmpty)
(trigger ?? const .new()).copyWith(prefix: prefix, suffix: suffix),
...?persona?.triggers.skip(1),
...?subprofile?.triggers.skip(1),
]),
);
final profiles = current();
return update(
profiles.copyWith(
profiles: persona == null
profiles: subprofile == null
? profiles.profiles.add(edited)
: profiles.profiles.replaceFirstWhere(
(profile) => profile.id == persona!.id,
(profile) => profile.id == subprofile!.id,
(_) => edited,
),
),
@ -64,9 +66,9 @@ class const PersonaSheet({final StoredProfile? persona, super.key})
return update(
profiles.copyWith(
profiles: profiles.profiles.removeWhere(
(profile) => profile.id == persona!.id,
(profile) => profile.id == subprofile!.id,
),
defaultProfileId: profiles.defaultProfileId == persona!.id
defaultProfileId: profiles.defaultProfileId == subprofile!.id
? null
: profiles.defaultProfileId,
),
@ -74,9 +76,9 @@ class const PersonaSheet({final StoredProfile? persona, super.key})
}
return SheetLayout(
title: Text(persona == null ? "Add Persona" : "Edit Persona"),
title: Text(subprofile == null ? "Add Subprofile" : "Edit Subprofile"),
actions: [
if (persona != null)
if (subprofile != null)
TextButton(
onPressed: saving.active ? null : delete,
style: TextButton.styleFrom(
@ -98,19 +100,19 @@ class const PersonaSheet({final StoredProfile? persona, super.key})
onChanged: (url) async => avatar.value = url,
child: AvatarOrHash(
avatar.value,
name.isEmpty ? "Persona" : name,
name.isEmpty ? "Subprofile" : name,
dimension: 120,
),
),
),
TextField(
controller: nameController,
autofocus: persona == null,
autofocus: subprofile == null,
textCapitalization: .words,
decoration: const .new(labelText: "Display name"),
),
Text(
"Optionally, messages that start with the prefix *and* end with the suffix are sent as this persona, without them. Leave one empty to only need the other. Both are case-sensitive.",
"Optionally, messages that start with the prefix *and* end with the suffix are sent as this subprofile, without them. Leave one empty to only need the other. Both are case-sensitive.",
),
Row(
spacing: 8,

View file

@ -3,15 +3,12 @@ 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/author.dart";
import "package:nexus/controllers/user.dart";
import "package:nexus/helpers/extensions/displayname_color.dart";
import "package:nexus/helpers/extensions/get_localpart.dart";
import "package:nexus/helpers/extensions/show_user_popover.dart";
import "package:nexus/models/event.dart";
/// A user's [name] in text, opening their popover when tapped. Unlike a widget
/// in text, it wraps and ellipsizes with the rest of it.
// Can't be const, since it sets the recognizer's onTapUp
// ignore: prefer_const_constructors_in_immutables
class UserSpan(
BuildContext context,
@ -59,7 +56,8 @@ class UserSpan(
children: [
if (event.pmp != null)
TextSpan(
text: " (via ${event.sender})",
text:
"(${ref.watch(UserController.provider(.new(roomId: event.roomId, userId: event.sender))).value?.displayName ?? event.sender.localpart})",
recognizer: recognizer,
style: Theme.of(context).textTheme.labelSmall
?.copyWith(color: color, fontWeight: .bold),