From e7bcf956e3a964504f7e9405e556bc1f59f43d3e Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Tue, 19 May 2026 22:46:36 -0400 Subject: [PATCH] improve legibility of content parsing --- lib/models/event.dart | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/models/event.dart b/lib/models/event.dart index f647460..c74e2f3 100644 --- a/lib/models/event.dart +++ b/lib/models/event.dart @@ -16,6 +16,12 @@ abstract class Event with _$Event { static String typeJsonFromJson(Map json, _) => json["decrypted_type"] ?? json["type"]; + static Map getContentFromJson(Map 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 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