forked from Nexus/nexus
148 lines
5.1 KiB
Dart
148 lines
5.1 KiB
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";
|
|
import "package:nexus/models/push_rules.dart";
|
|
|
|
part "account_data.freezed.dart";
|
|
part "account_data.g.dart";
|
|
|
|
@Freezed(toJson: false, fromJson: false)
|
|
@JsonSerializable()
|
|
class const AccountData({
|
|
@JsonKey(name: AccountData.invitePermissionConfigKey)
|
|
final InvitePermissionConfig invitePermissionConfig =
|
|
const InvitePermissionConfig(),
|
|
|
|
@JsonKey(name: AccountData.directKey)
|
|
final IMap<String, IList<String>> directMessages = const .empty(),
|
|
|
|
@JsonKey(name: AccountData.recentEmojiKey)
|
|
final RecentEmojiData recentEmoji = const RecentEmojiData(),
|
|
|
|
/// Room image packs the user has enabled everywhere
|
|
@JsonKey(name: AccountData.imagePackRoomsKey)
|
|
final ImagePackRooms? imagePackRooms,
|
|
@JsonKey(name: AccountData.legacyImagePackRoomsKey)
|
|
final ImagePackRooms? legacyImagePackRooms,
|
|
@JsonKey(name: AccountData.pushRulesKey)
|
|
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";
|
|
static const recentEmojiKey = "m.recent_emoji";
|
|
static const imagePackRoomsKey = "m.image_pack.rooms";
|
|
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();
|
|
|
|
Map<String, Object?> toJson() => _$AccountDataToJson(this);
|
|
|
|
factory AccountData.fromJson(Map<String, Object?> json) =>
|
|
_$AccountDataFromJson(json);
|
|
}
|
|
|
|
@Freezed(toJson: false, fromJson: false)
|
|
@JsonSerializable()
|
|
class const RecentEmojiData({
|
|
final IList<RecentEmoji> recentEmoji = const .empty(),
|
|
}) with _$RecentEmojiData {
|
|
Map<String, Object?> toJson() => _$RecentEmojiDataToJson(this);
|
|
|
|
factory RecentEmojiData.fromJson(Map<String, Object?> json) =>
|
|
_$RecentEmojiDataFromJson(json);
|
|
}
|
|
|
|
@Freezed(toJson: false, fromJson: false)
|
|
@JsonSerializable()
|
|
class const ImagePackRooms({
|
|
/// Room IDs to the state keys of their enabled packs, each to a (currently
|
|
/// empty) object
|
|
final IMap<String, IMap<String, Map<String, dynamic>>> rooms = const .empty(),
|
|
}) with _$ImagePackRooms {
|
|
bool contains(String roomId, String stateKey) =>
|
|
rooms[roomId]?.containsKey(stateKey) ?? false;
|
|
|
|
ImagePackRooms withPack(
|
|
String roomId,
|
|
String stateKey, {
|
|
required bool enabled,
|
|
}) {
|
|
final packs =
|
|
rooms[roomId] ?? const IMap<String, Map<String, dynamic>>.empty();
|
|
final updated = switch ((enabled, packs.containsKey(stateKey))) {
|
|
(true, false) => packs.add(stateKey, const {}),
|
|
(false, true) => packs.remove(stateKey),
|
|
_ => packs,
|
|
};
|
|
|
|
return copyWith(
|
|
rooms: updated.isEmpty
|
|
? rooms.remove(roomId)
|
|
: rooms.add(roomId, updated),
|
|
);
|
|
}
|
|
|
|
Map<String, Object?> toJson() => _$ImagePackRoomsToJson(this);
|
|
|
|
factory ImagePackRooms.fromJson(Map<String, Object?> json) =>
|
|
_$ImagePackRoomsFromJson(json);
|
|
}
|
|
|
|
@Freezed(toJson: false, fromJson: false)
|
|
@JsonSerializable()
|
|
class const IgnoredUserList({
|
|
/// Blocked user IDs, each to a (currently empty) object
|
|
@JsonKey(name: "ignored_users")
|
|
final IMap<String, Map<String, dynamic>> ignoredUsers = const .empty(),
|
|
}) with _$IgnoredUserList {
|
|
bool contains(String userId) => ignoredUsers.containsKey(userId);
|
|
|
|
IgnoredUserList withUser(String userId, {required bool ignored}) => copyWith(
|
|
ignoredUsers: ignored
|
|
? ignoredUsers.add(userId, const {})
|
|
: ignoredUsers.remove(userId),
|
|
);
|
|
|
|
Map<String, Object?> toJson() => _$IgnoredUserListToJson(this);
|
|
|
|
factory IgnoredUserList.fromJson(Map<String, Object?> json) =>
|
|
_$IgnoredUserListFromJson(json);
|
|
}
|
|
|
|
@Freezed(toJson: false, fromJson: false)
|
|
@JsonSerializable()
|
|
class const InvitePermissionConfig({
|
|
@JsonKey(unknownEnumValue: DefaultInviteAction.allow)
|
|
final DefaultInviteAction defaultAction = DefaultInviteAction.allow,
|
|
}) with _$InvitePermissionConfig {
|
|
Map<String, Object?> toJson() => _$InvitePermissionConfigToJson(this);
|
|
|
|
factory InvitePermissionConfig.fromJson(Map<String, Object?> json) =>
|
|
_$InvitePermissionConfigFromJson(json);
|
|
}
|
|
|
|
@Freezed(toJson: false, fromJson: false)
|
|
@JsonSerializable()
|
|
class const RecentEmoji({required final String emoji, required final int total})
|
|
with _$RecentEmoji {
|
|
Map<String, Object?> toJson() => _$RecentEmojiToJson(this);
|
|
|
|
factory RecentEmoji.fromJson(Map<String, Object?> json) =>
|
|
_$RecentEmojiFromJson(json);
|
|
}
|
|
|
|
@JsonEnum(fieldRename: .snake)
|
|
enum DefaultInviteAction {
|
|
allow,
|
|
deny,
|
|
@JsonValue("uk.timedout.msc4494.deny_public")
|
|
denyPublic,
|
|
}
|