forked from Nexus/nexus
Remove flutter chat (#26)
Had to squash merge manually as Forgejo was erroring
This commit is contained in:
parent
bd1d5ea745
commit
16cf126df4
111 changed files with 3162 additions and 2366 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._();
|
||||
factory AvatarContent({ImageInfo? info, Uri? url}) = _AvatarContent;
|
||||
|
||||
factory AvatarContent.fromJson(Map<String, Object?> json) =>
|
||||
_$AvatarContentFromJson(json);
|
||||
}
|
||||
15
lib/models/content/canonical_alias.dart
Normal file
15
lib/models/content/canonical_alias.dart
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
part "canonical_alias.freezed.dart";
|
||||
part "canonical_alias.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class CanonicalAliasContent extends Content
|
||||
with _$CanonicalAliasContent {
|
||||
CanonicalAliasContent._();
|
||||
factory CanonicalAliasContent({String? alias, @Default([]) altAliases}) =
|
||||
_CanonicalAliasContent;
|
||||
|
||||
factory CanonicalAliasContent.fromJson(Map<String, Object?> json) =>
|
||||
_$CanonicalAliasContentFromJson(json);
|
||||
}
|
||||
61
lib/models/content/content.dart
Normal file
61
lib/models/content/content.dart
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import "package:collection/collection.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/pinned_events.dart";
|
||||
import "package:nexus/models/content/power_levels.dart";
|
||||
import "package:nexus/models/content/reaction.dart";
|
||||
import "package:nexus/models/content/encrypted.dart";
|
||||
import "package:nexus/models/content/redaction.dart";
|
||||
import "package:nexus/models/content/server_acl.dart";
|
||||
import "package:nexus/models/content/topic.dart";
|
||||
|
||||
class Content {
|
||||
final Error? parseError;
|
||||
Content({this.parseError});
|
||||
|
||||
factory Content.fromJson(Map<String, dynamic> json) => Content();
|
||||
Map<String, dynamic> toJson() => {};
|
||||
|
||||
static Map<String, dynamic> readValue(Map<dynamic, dynamic> json, _) =>
|
||||
json["decrypted"] ?? json["content"];
|
||||
|
||||
static Content fromEventJson(Map<String, dynamic> json, String type) {
|
||||
try {
|
||||
return (EventType.values
|
||||
.firstWhereOrNull((eventType) => eventType.type == type)
|
||||
?.contentFromJson ??
|
||||
Content.fromJson)(json);
|
||||
} catch (error) {
|
||||
if (error is Error) return Content(parseError: error);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum EventType {
|
||||
encrypted("m.room.encrypted", EncryptedContent.fromJson),
|
||||
redaction("m.room.redaction", RedactionContent.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),
|
||||
reaction("m.reaction", ReactionContent.fromJson),
|
||||
pinnedEvents("m.room.pinned_events", PinnedEventsContent.fromJson),
|
||||
message("m.room.message", MessageContent.fromJson);
|
||||
|
||||
final String type;
|
||||
final Content Function(Map<String, dynamic> json) contentFromJson;
|
||||
const EventType(this.type, this.contentFromJson);
|
||||
}
|
||||
41
lib/models/content/create.dart
Normal file
41
lib/models/content/create.dart
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
part "create.freezed.dart";
|
||||
part "create.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class CreateContent extends Content with _$CreateContent {
|
||||
CreateContent._();
|
||||
factory CreateContent({
|
||||
@JsonKey(name: "creator") String? creatorId,
|
||||
|
||||
@JsonKey(name: "additional_creators")
|
||||
@Default(IList.empty())
|
||||
IList<String> additionalCreatorIds,
|
||||
|
||||
PreviousRoom? predecessor,
|
||||
|
||||
@JsonKey(name: "m.federate") @Default(true) bool federated,
|
||||
|
||||
@Default("1") String roomVersion,
|
||||
@JsonKey(unknownEnumValue: RoomType.room) RoomType? type,
|
||||
}) = _CreateContent;
|
||||
|
||||
factory CreateContent.fromJson(Map<String, Object?> json) =>
|
||||
_$CreateContentFromJson(json);
|
||||
}
|
||||
|
||||
enum RoomType {
|
||||
room,
|
||||
@JsonValue("m.space")
|
||||
space,
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class PreviousRoom with _$PreviousRoom {
|
||||
const factory PreviousRoom({required String roomId}) = _PreviousRoom;
|
||||
|
||||
factory PreviousRoom.fromJson(Map<String, Object?> json) =>
|
||||
_$PreviousRoomFromJson(json);
|
||||
}
|
||||
13
lib/models/content/encrypted.dart
Normal file
13
lib/models/content/encrypted.dart
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
part "encrypted.freezed.dart";
|
||||
part "encrypted.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class EncryptedContent extends Content with _$EncryptedContent {
|
||||
EncryptedContent._();
|
||||
factory EncryptedContent() = _EncryptedContent;
|
||||
|
||||
factory EncryptedContent.fromJson(Map<String, Object?> json) =>
|
||||
_$EncryptedContentFromJson(json);
|
||||
}
|
||||
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._();
|
||||
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);
|
||||
}
|
||||
34
lib/models/content/join_rules.dart
Normal file
34
lib/models/content/join_rules.dart
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
import "package:nexus/models/join_rule.dart";
|
||||
part "join_rules.freezed.dart";
|
||||
part "join_rules.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class JoinRulesContent extends Content with _$JoinRulesContent {
|
||||
JoinRulesContent._();
|
||||
factory JoinRulesContent({
|
||||
required JoinRule joinRule,
|
||||
@Default(IList.empty()) IList<AllowCondition> allow,
|
||||
}) = _JoinRulesContent;
|
||||
|
||||
factory JoinRulesContent.fromJson(Map<String, Object?> json) =>
|
||||
_$JoinRulesContentFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class AllowCondition with _$AllowCondition {
|
||||
const factory AllowCondition({
|
||||
String? roomId,
|
||||
required AllowConditionType type,
|
||||
}) = _AllowCondition;
|
||||
|
||||
factory AllowCondition.fromJson(Map<String, Object?> json) =>
|
||||
_$AllowConditionFromJson(json);
|
||||
}
|
||||
|
||||
enum AllowConditionType {
|
||||
@JsonValue("m.room_membership")
|
||||
membership,
|
||||
}
|
||||
19
lib/models/content/membership.dart
Normal file
19
lib/models/content/membership.dart
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
import "package:nexus/models/membership_status.dart";
|
||||
part "membership.freezed.dart";
|
||||
part "membership.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class MembershipContent extends Content with _$MembershipContent {
|
||||
MembershipContent._();
|
||||
factory MembershipContent({
|
||||
@JsonKey(name: "displayname") required String? displayName,
|
||||
@JsonKey(name: "membership") required MembershipStatus status,
|
||||
Uri? avatarUrl,
|
||||
String? reason,
|
||||
}) = _MembershipContent;
|
||||
|
||||
factory MembershipContent.fromJson(Map<String, Object?> json) =>
|
||||
_$MembershipContentFromJson(json);
|
||||
}
|
||||
92
lib/models/content/message.dart
Normal file
92
lib/models/content/message.dart
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/info/audio.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
import "package:nexus/models/info/file.dart";
|
||||
import "package:nexus/models/info/image.dart";
|
||||
import "package:nexus/models/info/video.dart";
|
||||
part "message.freezed.dart";
|
||||
part "message.g.dart";
|
||||
|
||||
@Freezed(unionKey: "msgtype", fallbackUnion: "default")
|
||||
abstract class MessageContent extends Content with _$MessageContent {
|
||||
MessageContent._();
|
||||
factory MessageContent({required String body}) = UnknownMessageContent;
|
||||
|
||||
@FreezedUnionValue("m.text")
|
||||
factory MessageContent.text({
|
||||
required String body,
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
}) = TextMessageContent;
|
||||
|
||||
@FreezedUnionValue("m.notice")
|
||||
factory MessageContent.notice({
|
||||
required String body,
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
}) = NoticeMessageContent;
|
||||
|
||||
@FreezedUnionValue("m.emote")
|
||||
factory MessageContent.emote({
|
||||
required String body,
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
}) = EmoteMessageContent;
|
||||
|
||||
@FreezedUnionValue("m.image")
|
||||
factory MessageContent.image({
|
||||
required String body,
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
// EncryptedFile? file
|
||||
String? filename,
|
||||
ImageInfo? info,
|
||||
Uri? url,
|
||||
}) = ImageMessageContent;
|
||||
|
||||
@FreezedUnionValue("m.file")
|
||||
factory MessageContent.file({
|
||||
required String body,
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
// EncryptedFile? file
|
||||
String? filename,
|
||||
FileInfo? info,
|
||||
Uri? url,
|
||||
}) = FileMessageContent;
|
||||
|
||||
@FreezedUnionValue("m.audio")
|
||||
factory MessageContent.audio({
|
||||
required String body,
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
// EncryptedFile? file
|
||||
String? filename,
|
||||
AudioInfo? info,
|
||||
Uri? url,
|
||||
}) = AudioMessageContent;
|
||||
|
||||
@FreezedUnionValue("m.video")
|
||||
factory MessageContent.video({
|
||||
required String body,
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
// EncryptedFile? file
|
||||
String? filename,
|
||||
VideoInfo? info,
|
||||
Uri? url,
|
||||
}) = VideoMessageContent;
|
||||
|
||||
@FreezedUnionValue("m.location")
|
||||
factory MessageContent.location({required String body, required Uri geoUri}) =
|
||||
LocationMessageContent;
|
||||
|
||||
factory MessageContent.fromJson(Map<String, Object?> json) =>
|
||||
_$MessageContentFromJson(json);
|
||||
}
|
||||
|
||||
@JsonEnum()
|
||||
enum MessageFormat {
|
||||
@JsonValue("org.matrix.custom.html")
|
||||
html,
|
||||
}
|
||||
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._();
|
||||
factory NameContent({required String name}) = _NameContent;
|
||||
|
||||
factory NameContent.fromJson(Map<String, Object?> json) =>
|
||||
_$NameContentFromJson(json);
|
||||
}
|
||||
15
lib/models/content/pinned_events.dart
Normal file
15
lib/models/content/pinned_events.dart
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
part "pinned_events.freezed.dart";
|
||||
part "pinned_events.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class PinnedEventsContent extends Content with _$PinnedEventsContent {
|
||||
PinnedEventsContent._();
|
||||
factory PinnedEventsContent({@Default(IList.empty()) IList<String> pinned}) =
|
||||
_PinnedEventsContent;
|
||||
|
||||
factory PinnedEventsContent.fromJson(Map<String, Object?> json) =>
|
||||
_$PinnedEventsContentFromJson(json);
|
||||
}
|
||||
36
lib/models/content/power_levels.dart
Normal file
36
lib/models/content/power_levels.dart
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
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._();
|
||||
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/reaction.dart
Normal file
18
lib/models/content/reaction.dart
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
part "reaction.freezed.dart";
|
||||
part "reaction.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class ReactionContent extends Content with _$ReactionContent {
|
||||
ReactionContent._();
|
||||
static String? keyJsonFromJson(Map<dynamic, dynamic> json, String key) =>
|
||||
json["m.relates_to"]?["key"];
|
||||
|
||||
factory ReactionContent({
|
||||
@JsonKey(readValue: ReactionContent.keyJsonFromJson) String? key,
|
||||
}) = _ReactionContent;
|
||||
|
||||
factory ReactionContent.fromJson(Map<String, Object?> json) =>
|
||||
_$ReactionContentFromJson(json);
|
||||
}
|
||||
14
lib/models/content/redaction.dart
Normal file
14
lib/models/content/redaction.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
part "redaction.freezed.dart";
|
||||
part "redaction.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class RedactionContent extends Content with _$RedactionContent {
|
||||
RedactionContent._();
|
||||
factory RedactionContent({String? reason, String? redacts}) =
|
||||
_RedactionContent;
|
||||
|
||||
factory RedactionContent.fromJson(Map<String, Object?> json) =>
|
||||
_$RedactionContentFromJson(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._();
|
||||
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._();
|
||||
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 {
|
||||
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 {
|
||||
factory TextualRepresentation({
|
||||
required String body,
|
||||
@Default("text/plain") String mimetype,
|
||||
}) = _TextualRepresentation;
|
||||
|
||||
factory TextualRepresentation.fromJson(Map<String, Object?> json) =>
|
||||
_$TextualRepresentationFromJson(json);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue