import "package:collection/collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:freezed_annotation/freezed_annotation.dart"; part "per_message_profiles.freezed.dart"; part "per_message_profiles.g.dart"; @Freezed(toJson: false, fromJson: false) @JsonSerializable(includeIfNull: false) class const PerMessageProfiles({ final String? defaultProfileId, final IList profiles = const .empty(), }) with _$PerMessageProfiles { StoredProfile? byId(String? id) => profiles.firstWhereOrNull((profile) => profile.id == id); Map toJson() => _$PerMessageProfilesToJson(this); factory PerMessageProfiles.fromJson(Map json) => _$PerMessageProfilesFromJson(json); } @Freezed(toJson: false, fromJson: false) @JsonSerializable(includeIfNull: false) class const StoredProfile({ required final String id, @JsonKey(name: "displayname") final String? displayName, final Uri? avatarUrl, final IList triggers = const .empty(), }) with _$StoredProfile { Map toJson() => _$StoredProfileToJson(this); factory StoredProfile.fromJson(Map json) => _$StoredProfileFromJson(json); } @Freezed(toJson: false, fromJson: false) @JsonSerializable(includeIfNull: false) class const ProfileTrigger({ final String prefix = "", 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 toJson() => _$ProfileTriggerToJson(this); factory ProfileTrigger.fromJson(Map json) => _$ProfileTriggerFromJson(json); }