import "package:freezed_annotation/freezed_annotation.dart"; import "package:nexus/models/content/content.dart"; import "package:nexus/models/requests/send_message.dart"; part "send_event.freezed.dart"; part "send_event.g.dart"; @Freezed(toJson: false, fromJson: false) @JsonSerializable() class const SendEventRequest({ required final String roomId, required final String type, required final Content content, // Merged into the content by toJson, as gomuks doesn't take these @JsonKey(includeToJson: false) final String? relatesTo, @JsonKey(includeToJson: false) final String? relationType, @JsonKey(includeToJson: false) final Relation? reply, @JsonKey(includeToJson: false) final Mentions? mentions, final bool synchronous = false, final bool disableEncryption = false, }) with _$SendEventRequest { Map toJson() { final content = this.content.toJson(); return { ..._$SendEventRequestToJson(this), "content": { ...content, "m.mentions": ?mentions?.toJson(), if (relatesTo != null || reply != null) "m.relates_to": { ...((content["m.relates_to"] as Map?) ?? {}), if (relatesTo != null) ...{ "event_id": relatesTo, "rel_type": relationType, }, ...?reply?.toJson(), }, }, }; } factory SendEventRequest.fromJson(Map json) => _$SendEventRequestFromJson(json); }