forked from Nexus/nexus
tweak PMP support
This commit is contained in:
parent
3b7a4c0cd4
commit
4800123044
8 changed files with 69 additions and 61 deletions
|
|
@ -43,7 +43,7 @@ import "package:nexus/widgets/settings/block_user_field.dart";
|
|||
import "package:nexus/widgets/settings/dialog_list_tile.dart";
|
||||
import "package:nexus/widgets/settings/enable_image_packs_sheet.dart";
|
||||
import "package:nexus/widgets/settings/keyword_field.dart";
|
||||
import "package:nexus/widgets/settings/persona_sheet.dart";
|
||||
import "package:nexus/widgets/settings/subprofile_sheet.dart";
|
||||
import "package:nexus/widgets/users/user_bottom_sheet.dart";
|
||||
import "package:nexus/widgets/encryption/reset_encryption_sheet.dart";
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ class SettingsSectionsController
|
|||
@override
|
||||
Future<IMap<String, IList<SettingsCategory>>> build() async {
|
||||
final settings = await ref.watch(SettingsController.provider.future);
|
||||
final personas = ref.watch(
|
||||
final subprofiles = ref.watch(
|
||||
AccountDataController.provider.select((data) => data.perMessageProfiles),
|
||||
);
|
||||
// Not awaited, so a slow homeserver doesn't hold up the rest of settings
|
||||
|
|
@ -448,47 +448,49 @@ class SettingsSectionsController
|
|||
]),
|
||||
),
|
||||
.new(
|
||||
title: "Personas",
|
||||
title: "Subprofiles",
|
||||
icon: Icons.groups,
|
||||
settings: .new([
|
||||
.new(
|
||||
title: "Enable Personas",
|
||||
title: "Enable Subprofiles",
|
||||
description: "Send messages as other names and avatars, chosen per room from the composer.",
|
||||
icon: Icons.groups,
|
||||
builder: (title, description, icon) => SwitchListTile(
|
||||
title: Text(title),
|
||||
subtitle: Text(description),
|
||||
secondary: Icon(icon),
|
||||
value: settings.personas,
|
||||
value: settings.subprofiles,
|
||||
onChanged: (value) => ref
|
||||
.read(SettingsController.provider.notifier)
|
||||
.set(settings.copyWith(personas: value))
|
||||
.set(settings.copyWith(subprofiles: value))
|
||||
.onError(showError),
|
||||
),
|
||||
),
|
||||
if (settings.personas) ...[
|
||||
if (personas.profiles.isNotEmpty)
|
||||
if (settings.subprofiles) ...[
|
||||
if (subprofiles.profiles.isNotEmpty)
|
||||
.new(
|
||||
title: "Default Persona",
|
||||
description: "Who you send as in rooms you haven't chosen a persona for.",
|
||||
title: "Default Subprofile",
|
||||
description: "Who you send as in rooms you haven't chosen a subprofile for.",
|
||||
icon: Icons.person_pin,
|
||||
builder: (title, description, icon) =>
|
||||
DialogListTile<String>(
|
||||
icon: Icon(icon),
|
||||
title: title,
|
||||
subtitle: Text(description),
|
||||
value: personas.defaultProfileId ?? "",
|
||||
value: subprofiles.defaultProfileId ?? "",
|
||||
options: [
|
||||
"",
|
||||
...personas.profiles.map((profile) => profile.id),
|
||||
...subprofiles.profiles.map(
|
||||
(profile) => profile.id,
|
||||
),
|
||||
],
|
||||
getName: (id) => switch (personas.byId(id)) {
|
||||
getName: (id) => switch (subprofiles.byId(id)) {
|
||||
final profile? => profile.displayName ?? id,
|
||||
null => "Yourself",
|
||||
null => "Account Profile",
|
||||
},
|
||||
onChanged: (id) => accountData
|
||||
.setPerMessageProfiles(
|
||||
personas.copyWith(
|
||||
subprofiles.copyWith(
|
||||
defaultProfileId: id.isEmpty ? null : id,
|
||||
),
|
||||
)
|
||||
|
|
@ -496,20 +498,20 @@ class SettingsSectionsController
|
|||
),
|
||||
),
|
||||
header(
|
||||
"Personas",
|
||||
"Subprofiles",
|
||||
"The names and avatars you can send messages as.",
|
||||
Icons.groups,
|
||||
),
|
||||
...personas.profiles.map(
|
||||
(persona) => Setting(
|
||||
title: persona.displayName ?? persona.id,
|
||||
description: "A persona.",
|
||||
...subprofiles.profiles.map(
|
||||
(subprofile) => Setting(
|
||||
title: subprofile.displayName ?? subprofile.id,
|
||||
description: "A subprofile.",
|
||||
icon: Icons.person,
|
||||
builder: (title, _, _) => Builder(
|
||||
builder: (context) => ListTile(
|
||||
leading: AvatarOrHash(persona.avatarUrl, title),
|
||||
leading: AvatarOrHash(subprofile.avatarUrl, title),
|
||||
title: Text(title),
|
||||
subtitle: switch (persona.triggers.firstOrNull) {
|
||||
subtitle: switch (subprofile.triggers.firstOrNull) {
|
||||
final trigger? => Text(
|
||||
"Trigger: ${trigger.prefix}text${trigger.suffix}",
|
||||
),
|
||||
|
|
@ -517,14 +519,14 @@ class SettingsSectionsController
|
|||
},
|
||||
trailing: Icon(Icons.chevron_right),
|
||||
onTap: () => context.showAdaptiveSheet(
|
||||
(_) => PersonaSheet(persona: persona),
|
||||
(_) => SubprofileSheet(subprofile: subprofile),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
.new(
|
||||
title: "Add Persona",
|
||||
title: "Add Subprofile",
|
||||
description: "Create a name and avatar to send messages as.",
|
||||
icon: Icons.add,
|
||||
builder: (title, _, icon) => Builder(
|
||||
|
|
@ -532,7 +534,7 @@ class SettingsSectionsController
|
|||
leading: Icon(icon),
|
||||
title: Text(title),
|
||||
onTap: () => context.showAdaptiveSheet(
|
||||
(_) => const PersonaSheet(),
|
||||
(_) => const SubprofileSheet(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -7,14 +7,15 @@ import "package:nexus/controllers/rooms.dart";
|
|||
import "package:nexus/models/account_data.dart";
|
||||
import "package:nexus/models/per_message_profiles.dart";
|
||||
|
||||
typedef RoomPersonas = ({
|
||||
typedef RoomSubprofiles = ({
|
||||
IList<StoredProfile> profiles,
|
||||
StoredProfile? current,
|
||||
});
|
||||
|
||||
class PersonasController(final String roomId) extends Notifier<RoomPersonas> {
|
||||
class SubprofilesController(final String roomId)
|
||||
extends Notifier<RoomSubprofiles> {
|
||||
@override
|
||||
RoomPersonas build() {
|
||||
RoomSubprofiles build() {
|
||||
final global = ref.watch(
|
||||
AccountDataController.provider.select((data) => data.perMessageProfiles),
|
||||
);
|
||||
|
|
@ -52,5 +53,7 @@ class PersonasController(final String roomId) extends Notifier<RoomPersonas> {
|
|||
}
|
||||
|
||||
static final provider = NotifierProvider.autoDispose
|
||||
.family<PersonasController, RoomPersonas, String>(PersonasController.new);
|
||||
.family<SubprofilesController, RoomSubprofiles, String>(
|
||||
SubprofilesController.new,
|
||||
);
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ class const Settings({
|
|||
final RoomOrder roomOrder = .unreadFirst,
|
||||
final NameColor nameColor = .powerLevel,
|
||||
final ShowAndSend typingIndicators = .showAndSend,
|
||||
final bool personas = false,
|
||||
final bool subprofiles = false,
|
||||
|
||||
/// When not sending, read receipts are still sent privately, so that the
|
||||
/// user's other devices know what has been read.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in a new issue