Remove flutter chat #26
2 changed files with 40 additions and 2 deletions
add create event
commit
e60e247093
|
|
@ -1,16 +1,18 @@
|
||||||
import "package:collection/collection.dart";
|
import "package:collection/collection.dart";
|
||||||
import "package:freezed_annotation/freezed_annotation.dart";
|
import "package:freezed_annotation/freezed_annotation.dart";
|
||||||
|
import "package:nexus/models/content/create.dart";
|
||||||
import "package:nexus/models/content/membership.dart";
|
import "package:nexus/models/content/membership.dart";
|
||||||
import "package:nexus/models/content/message.dart";
|
import "package:nexus/models/content/message.dart";
|
||||||
|
|
||||||
class Content {
|
class Content {
|
||||||
Content();
|
Content();
|
||||||
factory Content.fromJson(Map<String, dynamic> json) => Content();
|
|
||||||
|
|
||||||
|
factory Content.fromJson(Map<String, dynamic> json) => Content();
|
||||||
Map<String, dynamic> toJson() => {};
|
Map<String, dynamic> toJson() => {};
|
||||||
|
|
||||||
static Content fromEventJson(Map<String, dynamic> eventJson) =>
|
static Content fromEventJson(Map<String, dynamic> eventJson) =>
|
||||||
(EventType.values
|
(EventType.values
|
||||||
.firstWhereOrNull((eventType) => eventType == eventJson["type"])
|
.firstWhereOrNull((eventType) => eventType.type == eventJson["type"])
|
||||||
?.contentFromJson ??
|
?.contentFromJson ??
|
||||||
Content.fromJson)(eventJson);
|
Content.fromJson)(eventJson);
|
||||||
}
|
}
|
||||||
|
|
@ -19,6 +21,7 @@ class Content {
|
||||||
enum EventType {
|
enum EventType {
|
||||||
encrypted("m.room.encrypted", Content.fromJson),
|
encrypted("m.room.encrypted", Content.fromJson),
|
||||||
membership("m.room.member", MembershipContent.fromJson),
|
membership("m.room.member", MembershipContent.fromJson),
|
||||||
|
create("m.room.create", CreateContent.fromJson),
|
||||||
message("m.room.message", MessageContent.fromJson);
|
message("m.room.message", MessageContent.fromJson);
|
||||||
|
|
||||||
final String type;
|
final String type;
|
||||||
|
|
|
||||||
35
lib/models/content/create.dart
Normal file
35
lib/models/content/create.dart
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
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._();
|
||||||
|
const 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,
|
||||||
|
required String type,
|
||||||
|
}) = _CreateContent;
|
||||||
|
|
||||||
|
factory CreateContent.fromJson(Map<String, Object?> json) =>
|
||||||
|
_$CreateContentFromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
abstract class PreviousRoom with _$PreviousRoom {
|
||||||
|
const factory PreviousRoom({required int roomId}) = _PreviousRoom;
|
||||||
|
|
||||||
|
factory PreviousRoom.fromJson(Map<String, Object?> json) =>
|
||||||
|
_$PreviousRoomFromJson(json);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue