improve legibility of content parsing
This commit is contained in:
parent
dbef2d709b
commit
e7bcf956e3
1 changed files with 10 additions and 7 deletions
|
|
@ -16,6 +16,12 @@ abstract class Event with _$Event {
|
||||||
static String typeJsonFromJson(Map<dynamic, dynamic> json, _) =>
|
static String typeJsonFromJson(Map<dynamic, dynamic> json, _) =>
|
||||||
json["decrypted_type"] ?? json["type"];
|
json["decrypted_type"] ?? json["type"];
|
||||||
|
|
||||||
|
static Map<String, dynamic> getContentFromJson(Map<dynamic, dynamic> json) {
|
||||||
|
final content = json["decrypted"] ?? json["content"];
|
||||||
|
|
||||||
|
return content["m.new_content"] ?? content;
|
||||||
|
}
|
||||||
|
|
||||||
const factory Event({
|
const factory Event({
|
||||||
@JsonKey(name: "rowid") required int rowId,
|
@JsonKey(name: "rowid") required int rowId,
|
||||||
@JsonKey(name: "timeline_rowid") required int timelineRowId,
|
@JsonKey(name: "timeline_rowid") required int timelineRowId,
|
||||||
|
|
@ -44,14 +50,11 @@ abstract class Event with _$Event {
|
||||||
|
|
||||||
factory Event.fromJson(Map<String, dynamic> json) =>
|
factory Event.fromJson(Map<String, dynamic> json) =>
|
||||||
_$EventFromJson(json).copyWith(
|
_$EventFromJson(json).copyWith(
|
||||||
replyTo:
|
replyTo: getContentFromJson(
|
||||||
((json["decrypted"] ?? json["content"])["m.new_content"] ??
|
json,
|
||||||
json["decrypted"] ??
|
)["m.relates_to"]?["m.in_reply_to"]?["event_id"],
|
||||||
json["content"])?["m.relates_to"]?["m.in_reply_to"]?["event_id"],
|
|
||||||
content: Content.fromEventJson(
|
content: Content.fromEventJson(
|
||||||
(json["decrypted"] ?? json["content"])["m.new_content"] ??
|
getContentFromJson(json),
|
||||||
json["decrypted"] ??
|
|
||||||
json["content"],
|
|
||||||
json["decrypted_type"] ?? json["type"],
|
json["decrypted_type"] ?? json["type"],
|
||||||
),
|
),
|
||||||
previousContent: json["unsigned"]?["prev_content"] == null
|
previousContent: json["unsigned"]?["prev_content"] == null
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue