improve legibility of content parsing

This commit is contained in:
Henry Hiles 2026-05-19 22:46:36 -04:00
commit e7bcf956e3
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -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