implement all msgtypes
This commit is contained in:
parent
66356202c0
commit
3325ebcad7
7 changed files with 145 additions and 2 deletions
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
|
@ -6,6 +6,7 @@
|
||||||
"Gomuks",
|
"Gomuks",
|
||||||
"Homeserver",
|
"Homeserver",
|
||||||
"localpart",
|
"localpart",
|
||||||
|
"msgtype",
|
||||||
"muks",
|
"muks",
|
||||||
"prefs"
|
"prefs"
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,77 @@
|
||||||
import "package:freezed_annotation/freezed_annotation.dart";
|
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/content/content.dart";
|
||||||
|
import "package:nexus/models/info/file.dart";
|
||||||
|
import "package:nexus/models/info/image.dart";
|
||||||
part "message.freezed.dart";
|
part "message.freezed.dart";
|
||||||
part "message.g.dart";
|
part "message.g.dart";
|
||||||
|
|
||||||
@freezed
|
@Freezed(unionKey: "msgtype", fallbackUnion: "default")
|
||||||
abstract class MessageContent extends Content with _$MessageContent {
|
abstract class MessageContent extends Content with _$MessageContent {
|
||||||
static const type = "m.room.message";
|
static const type = "m.room.message";
|
||||||
|
|
||||||
MessageContent._();
|
MessageContent._();
|
||||||
const factory MessageContent({required String msgtype}) = _MessageContent;
|
const factory MessageContent({
|
||||||
|
required String msgtype,
|
||||||
|
required String body,
|
||||||
|
String? format,
|
||||||
|
String? formattedBody,
|
||||||
|
}) = _TextMessageContent;
|
||||||
|
|
||||||
|
@FreezedUnionValue("m.image")
|
||||||
|
const factory MessageContent.image({
|
||||||
|
required String msgtype,
|
||||||
|
required String body,
|
||||||
|
String? format,
|
||||||
|
String? formattedBody,
|
||||||
|
// EncryptedFile? file
|
||||||
|
String? filename,
|
||||||
|
ImageInfo? info,
|
||||||
|
String? url,
|
||||||
|
}) = _ImageMessageContent;
|
||||||
|
|
||||||
|
@FreezedUnionValue("m.file")
|
||||||
|
const factory MessageContent.file({
|
||||||
|
required String msgtype,
|
||||||
|
required String body,
|
||||||
|
String? format,
|
||||||
|
String? formattedBody,
|
||||||
|
// EncryptedFile? file
|
||||||
|
String? filename,
|
||||||
|
FileInfo? info,
|
||||||
|
String? url,
|
||||||
|
}) = _FileMessageContent;
|
||||||
|
|
||||||
|
@FreezedUnionValue("m.audio")
|
||||||
|
const factory MessageContent.audio({
|
||||||
|
required String msgtype,
|
||||||
|
required String body,
|
||||||
|
String? format,
|
||||||
|
String? formattedBody,
|
||||||
|
// EncryptedFile? file
|
||||||
|
String? filename,
|
||||||
|
AudioInfo? info,
|
||||||
|
String? url,
|
||||||
|
}) = _AudioMessageContent;
|
||||||
|
|
||||||
|
@FreezedUnionValue("m.video")
|
||||||
|
const factory MessageContent.video({
|
||||||
|
required String msgtype,
|
||||||
|
required String body,
|
||||||
|
String? format,
|
||||||
|
String? formattedBody,
|
||||||
|
// EncryptedFile? file
|
||||||
|
String? filename,
|
||||||
|
AudioInfo? info,
|
||||||
|
String? url,
|
||||||
|
}) = _AudioMessageContent;
|
||||||
|
|
||||||
|
@FreezedUnionValue("m.location")
|
||||||
|
const factory MessageContent.location({
|
||||||
|
required String msgtype,
|
||||||
|
required String body,
|
||||||
|
required Uri geoUri,
|
||||||
|
}) = _LocationMessageContent;
|
||||||
|
|
||||||
factory MessageContent.fromJson(Map<String, Object?> json) =>
|
factory MessageContent.fromJson(Map<String, Object?> json) =>
|
||||||
_$MessageContentFromJson(json);
|
_$MessageContentFromJson(json);
|
||||||
|
|
|
||||||
17
lib/models/info/audio.dart
Normal file
17
lib/models/info/audio.dart
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
import "package:freezed_annotation/freezed_annotation.dart";
|
||||||
|
import "package:nexus/models/ms_duration.dart";
|
||||||
|
part "audio.freezed.dart";
|
||||||
|
part "audio.g.dart";
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
abstract class AudioInfo with _$AudioInfo {
|
||||||
|
/// Information for images, [size] is in bytes.
|
||||||
|
const factory AudioInfo({
|
||||||
|
@MSDuration() Duration? duration,
|
||||||
|
@JsonKey(name: "mimetype") String? mimeType,
|
||||||
|
int? size,
|
||||||
|
}) = _AudioInfo;
|
||||||
|
|
||||||
|
factory AudioInfo.fromJson(Map<String, Object?> json) =>
|
||||||
|
_$AudioInfoFromJson(json);
|
||||||
|
}
|
||||||
15
lib/models/info/file.dart
Normal file
15
lib/models/info/file.dart
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import "package:freezed_annotation/freezed_annotation.dart";
|
||||||
|
part "file.freezed.dart";
|
||||||
|
part "file.g.dart";
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
abstract class FileInfo with _$FileInfo {
|
||||||
|
/// Information for images, [size] is in bytes.
|
||||||
|
const factory FileInfo({
|
||||||
|
@JsonKey(name: "mimetype") String? mimeType,
|
||||||
|
int? size,
|
||||||
|
}) = _FileInfo;
|
||||||
|
|
||||||
|
factory FileInfo.fromJson(Map<String, Object?> json) =>
|
||||||
|
_$FileInfoFromJson(json);
|
||||||
|
}
|
||||||
17
lib/models/info/image.dart
Normal file
17
lib/models/info/image.dart
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
import "package:freezed_annotation/freezed_annotation.dart";
|
||||||
|
part "image.freezed.dart";
|
||||||
|
part "image.g.dart";
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
abstract class ImageInfo with _$ImageInfo {
|
||||||
|
/// Information for images, [size] is in bytes.
|
||||||
|
const factory ImageInfo({
|
||||||
|
@JsonKey(name: "h") int? height,
|
||||||
|
@JsonKey(name: "w") int? width,
|
||||||
|
@JsonKey(name: "mimetype") String? mimeType,
|
||||||
|
int? size,
|
||||||
|
}) = _ImageInfo;
|
||||||
|
|
||||||
|
factory ImageInfo.fromJson(Map<String, Object?> json) =>
|
||||||
|
_$ImageInfoFromJson(json);
|
||||||
|
}
|
||||||
19
lib/models/info/video.dart
Normal file
19
lib/models/info/video.dart
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import "package:freezed_annotation/freezed_annotation.dart";
|
||||||
|
import "package:nexus/models/ms_duration.dart";
|
||||||
|
part "video.freezed.dart";
|
||||||
|
part "video.g.dart";
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
abstract class VideoInfo with _$VideoInfo {
|
||||||
|
/// Information for images, [size] is in bytes.
|
||||||
|
const factory VideoInfo({
|
||||||
|
@JsonKey(name: "h") int? height,
|
||||||
|
@JsonKey(name: "w") int? width,
|
||||||
|
@JsonKey(name: "mimetype") String? mimeType,
|
||||||
|
@MSDuration() Duration? duration,
|
||||||
|
int? size,
|
||||||
|
}) = _VideoInfo;
|
||||||
|
|
||||||
|
factory VideoInfo.fromJson(Map<String, Object?> json) =>
|
||||||
|
_$VideoInfoFromJson(json);
|
||||||
|
}
|
||||||
11
lib/models/ms_duration.dart
Normal file
11
lib/models/ms_duration.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import "package:freezed_annotation/freezed_annotation.dart";
|
||||||
|
|
||||||
|
class MSDuration implements JsonConverter<Duration, int> {
|
||||||
|
const MSDuration();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Duration fromJson(int ms) => Duration(milliseconds: ms);
|
||||||
|
|
||||||
|
@override
|
||||||
|
int toJson(Duration duration) => duration.inMilliseconds;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue