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
4 changed files with 120 additions and 37 deletions

View file

@ -87,26 +87,22 @@ class AccountDataController extends Notifier<AccountData> {
Future<void> setRoomProfile(String roomId, String profileId) async {
const type = AccountData.perMessageProfilesKey;
final current = ref
final rooms = ref.read(RoomsController.provider.notifier);
final previous = ref
.read(RoomsController.provider)[roomId]
?.accountData[type];
final content = {...?previous, "default_profile_id": profileId};
await ref
.read(ClientController.provider.notifier)
.setAccountData(
.new(
type: type,
roomId: roomId,
content: {...?current, "default_profile_id": profileId},
),
);
await ref
.read(RoomsController.provider.notifier)
.awaitRooms(
(rooms) =>
rooms[roomId]?.accountData[type]?["default_profile_id"] ==
profileId,
);
// Shown straight away, rather than once it comes down sync
rooms.setAccountData(roomId, type, content);
try {
await ref
.read(ClientController.provider.notifier)
.setAccountData(.new(type: type, roomId: roomId, content: content));
} catch (_) {
rooms.setAccountData(roomId, type, previous);
rethrow;
}
}
/// Saves [rule] of [kind], creating it if it's new, or otherwise changing only

View file

@ -136,6 +136,24 @@ class RoomsController extends Notifier<IMap<String, Room>> {
.add(event.eventId, event.rowId);
});
void setAccountData(
String roomId,
String type,
Map<String, dynamic>? content,
) {
if (state[roomId] case final room?) {
state = state.add(
roomId,
room.copyWith(
accountData: switch (content) {
final content? => room.accountData.add(type, content),
null => room.accountData.remove(type),
},
),
);
}
}
void update(
IMap<String, Room> rooms, [
ISet<String> leftRooms = const .empty(),

View file

@ -467,6 +467,21 @@ class SettingsSectionsController
),
),
if (settings.subprofiles) ...[
.new(
title: "Latch Triggered Subprofiles",
description: "After you send a message with a subprofile's trigger, keep sending as it in that room until you choose another.",
icon: Icons.push_pin,
builder: (title, description, icon) => SwitchListTile(
title: Text(title),
subtitle: Text(description),
secondary: Icon(icon),
value: settings.latchSubprofiles,
onChanged: (value) => ref
.read(SettingsController.provider.notifier)
.set(settings.copyWith(latchSubprofiles: value))
.onError(showError),
),
),
if (subprofiles.profiles.isNotEmpty)
.new(
title: "Default Subprofile",

View file

@ -6,11 +6,7 @@ import "package:nexus/controllers/account_data.dart";
import "package:nexus/controllers/rooms.dart";
import "package:nexus/models/account_data.dart";
import "package:nexus/models/per_message_profiles.dart";
typedef RoomSubprofiles = ({
IList<StoredProfile> profiles,
StoredProfile? current,
});
import "package:nexus/models/room_subprofiles.dart";
class SubprofilesController(final String roomId)
extends Notifier<RoomSubprofiles> {
@ -44,8 +40,10 @@ class SubprofilesController(final String roomId)
);
final currentId = room?.defaultProfileId ?? global.defaultProfileId;
return (
return .new(
profiles: profiles,
triggerOrder: (room?.profiles ?? const IList<StoredProfile>.empty())
.addAll(global.profiles),
current: currentId == null || currentId.isEmpty
? null
: profiles.firstWhereOrNull((profile) => profile.id == currentId),