add quite a few more content types
This commit is contained in:
parent
17603f0d16
commit
7e2c90381c
8 changed files with 159 additions and 1 deletions
14
lib/models/content/avatar.dart
Normal file
14
lib/models/content/avatar.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
import "package:nexus/models/info/image.dart";
|
||||
part "avatar.freezed.dart";
|
||||
part "avatar.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class AvatarContent extends Content with _$AvatarContent {
|
||||
AvatarContent._();
|
||||
const factory AvatarContent({ImageInfo? info, Uri? url}) = _AvatarContent;
|
||||
|
||||
factory AvatarContent.fromJson(Map<String, Object?> json) =>
|
||||
_$AvatarContentFromJson(json);
|
||||
}
|
||||
|
|
@ -1,10 +1,16 @@
|
|||
import "package:collection/collection.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/avatar.dart";
|
||||
import "package:nexus/models/content/canonical_alias.dart";
|
||||
import "package:nexus/models/content/create.dart";
|
||||
import "package:nexus/models/content/encryption.dart";
|
||||
import "package:nexus/models/content/join_rules.dart";
|
||||
import "package:nexus/models/content/membership.dart";
|
||||
import "package:nexus/models/content/message.dart";
|
||||
import "package:nexus/models/content/name.dart";
|
||||
import "package:nexus/models/content/power_levels.dart";
|
||||
import "package:nexus/models/content/server_acl.dart";
|
||||
import "package:nexus/models/content/topic.dart";
|
||||
|
||||
class Content {
|
||||
Content();
|
||||
|
|
@ -22,10 +28,16 @@ class Content {
|
|||
@JsonEnum(valueField: "type")
|
||||
enum EventType {
|
||||
encrypted("m.room.encrypted", Content.fromJson),
|
||||
encryption("m.room.encryption", EncryptionContent.fromJson),
|
||||
membership("m.room.member", MembershipContent.fromJson),
|
||||
create("m.room.create", CreateContent.fromJson),
|
||||
canonicalAlias("m.room.canonical_alias", CanonicalAliasContent.fromJson),
|
||||
joinRules("m.room.join_rules", JoinRulesContent.fromJson),
|
||||
powerLevels("m.room.power_levels", PowerLevelsContent.fromJson),
|
||||
serverACL("m.room.server_acl", ServerACLContent.fromJson),
|
||||
avatar("m.room.avatar", AvatarContent.fromJson),
|
||||
topic("m.room.topic", TopicContent.fromJson),
|
||||
name("m.room.name", NameContent.fromJson),
|
||||
message("m.room.message", MessageContent.fromJson);
|
||||
|
||||
final String type;
|
||||
|
|
|
|||
23
lib/models/content/encryption.dart
Normal file
23
lib/models/content/encryption.dart
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
part "encryption.freezed.dart";
|
||||
part "encryption.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class EncryptionContent extends Content with _$EncryptionContent {
|
||||
EncryptionContent._();
|
||||
const factory EncryptionContent({
|
||||
required String algorithm,
|
||||
|
||||
@JsonKey(name: "rotation_period_ms")
|
||||
@Default(604800000)
|
||||
int rotationPeriodMS,
|
||||
|
||||
@JsonKey(name: "rotation_period_msgs")
|
||||
@Default(100)
|
||||
int rotationPeriodMessages,
|
||||
}) = _EncryptionContent;
|
||||
|
||||
factory EncryptionContent.fromJson(Map<String, Object?> json) =>
|
||||
_$EncryptionContentFromJson(json);
|
||||
}
|
||||
13
lib/models/content/name.dart
Normal file
13
lib/models/content/name.dart
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
part "name.freezed.dart";
|
||||
part "name.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class NameContent extends Content with _$NameContent {
|
||||
NameContent._();
|
||||
const factory NameContent({required String name}) = _NameContent;
|
||||
|
||||
factory NameContent.fromJson(Map<String, Object?> json) =>
|
||||
_$NameContentFromJson(json);
|
||||
}
|
||||
38
lib/models/content/power_levels.dart
Normal file
38
lib/models/content/power_levels.dart
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
|
||||
part "power_levels.freezed.dart";
|
||||
part "power_levels.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class PowerLevelsContent extends Content with _$PowerLevelsContent {
|
||||
PowerLevelsContent._();
|
||||
|
||||
const factory PowerLevelsContent({
|
||||
@Default(IMap.empty()) IMap<String, int> events,
|
||||
@Default(IMap.empty()) IMap<String, int> users,
|
||||
Notifications? notifications,
|
||||
@Default(50) int ban,
|
||||
@Default(0) int eventsDefault,
|
||||
@Default(0) int invite,
|
||||
@Default(50) int kick,
|
||||
@Default(50) int redact,
|
||||
@Default(50) int stateDefault,
|
||||
@Default(0) int usersDefault,
|
||||
}) = _PowerLevelsContent;
|
||||
|
||||
factory PowerLevelsContent.fromJson(Map<String, Object?> json) =>
|
||||
_$PowerLevelsContentFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class Notifications with _$Notifications {
|
||||
const factory Notifications({
|
||||
@Default(50) int room,
|
||||
@Default(IMapConst({})) IMap<String, int> other,
|
||||
}) = _Notifications;
|
||||
|
||||
factory Notifications.fromJson(Map<String, Object?> json) =>
|
||||
_$NotificationsFromJson(json);
|
||||
}
|
||||
18
lib/models/content/server_acl.dart
Normal file
18
lib/models/content/server_acl.dart
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
part "server_acl.freezed.dart";
|
||||
part "server_acl.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class ServerACLContent extends Content with _$ServerACLContent {
|
||||
ServerACLContent._();
|
||||
const factory ServerACLContent({
|
||||
@Default(IList.empty()) IList<String> allow,
|
||||
@Default(IList.empty()) IList<String> deny,
|
||||
@Default(true) allowIpLiterals,
|
||||
}) = _ServerACLContent;
|
||||
|
||||
factory ServerACLContent.fromJson(Map<String, Object?> json) =>
|
||||
_$ServerACLContentFromJson(json);
|
||||
}
|
||||
40
lib/models/content/topic.dart
Normal file
40
lib/models/content/topic.dart
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
part "topic.freezed.dart";
|
||||
part "topic.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class TopicContent extends Content with _$TopicContent {
|
||||
TopicContent._();
|
||||
const factory TopicContent({
|
||||
required String topic,
|
||||
@JsonKey(name: "m.topic") TopicContentBlock? content,
|
||||
}) = _TopicContent;
|
||||
|
||||
factory TopicContent.fromJson(Map<String, Object?> json) =>
|
||||
_$TopicContentFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class TopicContentBlock with _$TopicContentBlock {
|
||||
const factory TopicContentBlock({
|
||||
@Default(IList.empty())
|
||||
@JsonKey(name: "m.text")
|
||||
IList<TextualRepresentation> representations,
|
||||
}) = _TopicContentBlock;
|
||||
|
||||
factory TopicContentBlock.fromJson(Map<String, Object?> json) =>
|
||||
_$TopicContentBlockFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class TextualRepresentation with _$TextualRepresentation {
|
||||
const factory TextualRepresentation({
|
||||
required String body,
|
||||
@Default("text/plain") String mimetype,
|
||||
}) = _TextualRepresentation;
|
||||
|
||||
factory TextualRepresentation.fromJson(Map<String, Object?> json) =>
|
||||
_$TextualRepresentationFromJson(json);
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ abstract class Event with _$Event {
|
|||
required String roomId,
|
||||
required String eventId,
|
||||
required String sender,
|
||||
required String type,
|
||||
required EventType type,
|
||||
String? stateKey,
|
||||
@EpochDateTimeConverter() required DateTime timestamp,
|
||||
IMap<String, dynamic>? decrypted,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue