Commit 94280db9 authored by Wilko Manger's avatar Wilko Manger

Don't serialize width and height if null

parent 9ade70bf
......@@ -90,8 +90,8 @@ abstract class MessageEvent extends RoomEvent {
var info = content['info'];
if (info != null) {
var width = content['info']['w'];
var height = content['info']['h'];
var width = info['w'];
var height = info['h'];
if (width is! int) {
width = width?.round();
......@@ -128,9 +128,9 @@ abstract class MessageEvent extends RoomEvent {
var info = content['info'];
if (info != null) {
info = AudioInfo(
duration: content['info']['duration'],
mimetype: content['info']['mimetype'],
size: content['info']['size']
duration: info['duration'],
mimetype: info['mimetype'],
size: info['size']
);
}
......@@ -249,15 +249,27 @@ class ImageMessage extends MessageEventContent {
ImageMessage({@required this.body, this.url, this.info, this.inReplyToId});
@override
Map<String, dynamic> toJson() => super.toJson()
..addAll({
'body': body,
'url': url.toString(),
'info': {
'w': info.width,
'h': info.height
Map<String, dynamic> toJson() {
final json = super.toJson()
..addAll({
'body': body,
'url': url.toString()
});
if (info != null) {
final jsonInfo = json['info'] = { };
if (info.width != null) {
jsonInfo['w'] = info.width;
}
});
if (info.height != null) {
jsonInfo['h'] = info.height;
}
}
return json;
}
}
class ImageInfo {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment