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, _) =>
|
||||
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({
|
||||
@JsonKey(name: "rowid") required int rowId,
|
||||
@JsonKey(name: "timeline_rowid") required int timelineRowId,
|
||||
|
|
@ -44,14 +50,11 @@ abstract class Event with _$Event {
|
|||
|
||||
factory Event.fromJson(Map<String, dynamic> json) =>
|
||||
_$EventFromJson(json).copyWith(
|
||||
replyTo:
|
||||
((json["decrypted"] ?? json["content"])["m.new_content"] ??
|
||||
json["decrypted"] ??
|
||||
json["content"])?["m.relates_to"]?["m.in_reply_to"]?["event_id"],
|
||||
replyTo: getContentFromJson(
|
||||
json,
|
||||
)["m.relates_to"]?["m.in_reply_to"]?["event_id"],
|
||||
content: Content.fromEventJson(
|
||||
(json["decrypted"] ?? json["content"])["m.new_content"] ??
|
||||
json["decrypted"] ??
|
||||
json["content"],
|
||||
getContentFromJson(json),
|
||||
json["decrypted_type"] ?? json["type"],
|
||||
),
|
||||
previousContent: json["unsigned"]?["prev_content"] == null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue