forked from Nexus/nexus
parent
f80ceb0736
commit
3b7a4c0cd4
4 changed files with 469 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/per_message_profiles.dart";
|
||||
import "package:nexus/models/push_rules.dart";
|
||||
|
||||
part "account_data.freezed.dart";
|
||||
|
|
@ -27,6 +28,8 @@ class const AccountData({
|
|||
final PushRules pushRules = const .new(),
|
||||
@JsonKey(name: AccountData.ignoredUserListKey)
|
||||
final IgnoredUserList ignoredUserList = const .new(),
|
||||
@JsonKey(name: AccountData.perMessageProfilesKey)
|
||||
final PerMessageProfiles perMessageProfiles = const .new(),
|
||||
}) with _$AccountData {
|
||||
static const invitePermissionConfigKey = "m.invite_permission_config";
|
||||
static const directKey = "m.direct";
|
||||
|
|
@ -35,6 +38,7 @@ class const AccountData({
|
|||
static const legacyImagePackRoomsKey = "im.ponies.emote_rooms";
|
||||
static const pushRulesKey = "m.push_rules";
|
||||
static const ignoredUserListKey = "m.ignored_user_list";
|
||||
static const perMessageProfilesKey = "fi.mau.msc4461.per_message_profiles.v3";
|
||||
|
||||
ImagePackRooms get enabledImagePacks =>
|
||||
imagePackRooms ?? legacyImagePackRooms ?? const .new();
|
||||
|
|
|
|||
48
lib/models/per_message_profiles.dart
Normal file
48
lib/models/per_message_profiles.dart
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
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<StoredProfile> profiles = const .empty(),
|
||||
}) with _$PerMessageProfiles {
|
||||
StoredProfile? byId(String? id) =>
|
||||
profiles.firstWhereOrNull((profile) => profile.id == id);
|
||||
|
||||
Map<String, Object?> toJson() => _$PerMessageProfilesToJson(this);
|
||||
|
||||
factory PerMessageProfiles.fromJson(Map<String, Object?> 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<ProfileTrigger> triggers = const .empty(),
|
||||
}) with _$StoredProfile {
|
||||
Map<String, Object?> toJson() => _$StoredProfileToJson(this);
|
||||
|
||||
factory StoredProfile.fromJson(Map<String, Object?> 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 {
|
||||
Map<String, Object?> toJson() => _$ProfileTriggerToJson(this);
|
||||
|
||||
factory ProfileTrigger.fromJson(Map<String, Object?> json) =>
|
||||
_$ProfileTriggerFromJson(json);
|
||||
}
|
||||
|
|
@ -45,10 +45,12 @@ class const Room({
|
|||
final IMap<String, IMap<String, int>> state = const .empty(),
|
||||
|
||||
final IMap<String, IList<ReadReceipt>> receipts = const .empty(),
|
||||
|
||||
@JsonKey(fromJson: Room.accountDataJsonToIMap)
|
||||
final IMap<String, Map<String, dynamic>> accountData = const .empty(),
|
||||
final bool dismissNotifications = false,
|
||||
final bool hasMore = true,
|
||||
|
||||
// IMap<String, AccountData> accountData,
|
||||
// IList<Notification> notifications,
|
||||
}) with _$Room {
|
||||
static IMap<int, int?> timelineTupleJsonToIMap(List<dynamic> json) =>
|
||||
|
|
@ -61,6 +63,15 @@ class const Room({
|
|||
),
|
||||
);
|
||||
|
||||
static IMap<String, Map<String, dynamic>> accountDataJsonToIMap(
|
||||
Map<String, dynamic> json,
|
||||
) => .fromEntries(
|
||||
json.entries.map(
|
||||
(entry) =>
|
||||
.new(entry.key, Map<String, dynamic>.from(entry.value["content"])),
|
||||
),
|
||||
);
|
||||
|
||||
static IMap<int, Event> eventsJsonToIMap(List<dynamic> json) =>
|
||||
IMap.fromEntries(
|
||||
json.map((eventJson) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class const Settings({
|
|||
final RoomOrder roomOrder = .unreadFirst,
|
||||
final NameColor nameColor = .powerLevel,
|
||||
final ShowAndSend typingIndicators = .showAndSend,
|
||||
final bool personas = false,
|
||||
|
||||
/// When not sending, read receipts are still sent privately, so that the
|
||||
/// user's other devices know what has been read.
|
||||
|
|
|
|||
Loading…
Reference in a new issue