add dynamic hinting and latching for PMPs

This commit is contained in:
Henry Hiles 2026-11-26 16:06:08 -05:00
commit c786344bf2
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
2 changed files with 120 additions and 37 deletions

View file

@ -27,6 +27,9 @@ import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:nexus/controllers/attachment.dart";
import "package:nexus/controllers/client.dart";
import "package:nexus/controllers/settings.dart";
import "package:nexus/controllers/account_data.dart";
import "package:nexus/controllers/subprofiles.dart";
import "package:nexus/models/settings.dart";
import "package:nexus/controllers/image_picker.dart";
import "package:nexus/helpers/file_dialog_helper.dart";
import "package:image_picker/image_picker.dart";
@ -433,6 +436,20 @@ class const Composer(
attachment != null && attachment.$2 == null) {
return;
}
if (ref.read(SettingsController.provider).value case Settings(
subprofiles: true,
latchSubprofiles: true,
)) {
final subprofiles = ref.read(SubprofilesController.provider(roomId));
if (subprofiles.triggeredBy(controller.text) case final triggered?
when triggered.id != subprofiles.current?.id) {
ref
.read(AccountDataController.provider.notifier)
.setRoomProfile(roomId, triggered.id)
.onError(showError);
}
}
onSend(
"${TextCommand.prefixOf(textCommands)}${controller.formattedText}",
shouldMention: shouldMention.value,
@ -566,7 +583,7 @@ class const Composer(
),
)
? [
SubprofileButton(roomId),
SubprofileButton(roomId, controller: controller),
IconButton(
onPressed: hasReplacement
? null

View file

@ -1,15 +1,21 @@
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:flutter_hooks/flutter_hooks.dart";
import "package:hooks_riverpod/hooks_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/subprofiles.dart";
import "package:nexus/controllers/settings.dart";
import "package:nexus/main.dart";
import "package:nexus/models/room_subprofiles.dart";
import "package:nexus/widgets/avatars/avatar_or_hash.dart";
/// Chooses the subprofile messages are sent as in [roomId], if subprofiles are on.
class const SubprofileButton(final String roomId, {super.key})
extends ConsumerWidget {
/// Chooses the subprofile messages are sent as in [roomId], if subprofiles are
/// on. It shows the one the text in [controller] would trigger, if any.
class const SubprofileButton(
final String roomId, {
required final TextEditingController controller,
super.key,
}) extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final enabled = ref.watch(
@ -17,10 +23,14 @@ class const SubprofileButton(final String roomId, {super.key})
(settings) => settings.value?.subprofiles ?? false,
),
);
final (:profiles, :current) = ref.watch(
SubprofilesController.provider(roomId),
final subprofiles = ref.watch(SubprofilesController.provider(roomId));
final RoomSubprofiles(:profiles, :current) = subprofiles;
final triggered = useListenableSelector(
controller,
() => subprofiles.triggeredBy(controller.text),
);
if (!enabled || profiles.isEmpty) return const SizedBox.shrink();
final shown = triggered ?? current;
Future<void> choose(String profileId) => ref
.read(AccountDataController.provider.notifier)
@ -45,14 +55,17 @@ class const SubprofileButton(final String roomId, {super.key})
}
return AdaptiveMenuButton<void>(
tooltip: switch (current) {
final current? => "Sending as ${current.displayName ?? current.id}",
null => "Choose subprofile",
tooltip: switch ((triggered, current)) {
(final triggered?, _) =>
"Sending this message as ${triggered.displayName ?? triggered.id}",
(null, final current?) =>
"Sending as ${current.displayName ?? current.id}",
(null, null) => "Choose subprofile",
},
icon: switch (current) {
final current? => AvatarOrHash(
current.avatarUrl,
current.displayName ?? current.id,
icon: switch (shown) {
final shown? => AvatarOrHash(
shown.avatarUrl,
shown.displayName ?? shown.id,
),
null => Icon(Icons.person),
},