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

View file

@ -41,6 +41,11 @@ class const ProfileTrigger({
final String suffix = "",
final bool keepTrigger = false,
}) with _$ProfileTrigger {
bool matches(String text) =>
text.length >= prefix.length + suffix.length &&
text.startsWith(prefix) &&
text.endsWith(suffix);
Map<String, Object?> toJson() => _$ProfileTriggerToJson(this);
factory ProfileTrigger.fromJson(Map<String, Object?> json) =>

View file

@ -0,0 +1,20 @@
import "package:collection/collection.dart";
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/per_message_profiles.dart";
part "room_subprofiles.freezed.dart";
@freezed
class const RoomSubprofiles({
required final IList<StoredProfile> profiles,
// Each trigger is tried in this order, as gomuks does when sending
required final IList<StoredProfile> triggerOrder,
final StoredProfile? current,
}) with _$RoomSubprofiles {
StoredProfile? triggeredBy(String text) => triggerOrder.firstWhereOrNull(
(profile) =>
profile.id.isNotEmpty &&
profile.triggers.any((trigger) => trigger.matches(text)),
);
}

View file

@ -24,6 +24,7 @@ class const Settings({
final NameColor nameColor = .powerLevel,
final ShowAndSend typingIndicators = .showAndSend,
final bool subprofiles = false,
final bool latchSubprofiles = false,
/// When not sending, read receipts are still sent privately, so that the
/// user's other devices know what has been read.