From 411d29cc89891f845697076eb10b9fff9914e028 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sat, 21 Nov 2020 15:28:05 +0100 Subject: [PATCH] feat: Implement room tombstones --- lib/src/room.dart | 11 +++++++++++ lib/src/utils/tombstone_content.dart | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 lib/src/utils/tombstone_content.dart diff --git a/lib/src/room.dart b/lib/src/room.dart index ac10e3ad..2b5f2ed4 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -18,6 +18,7 @@ import 'dart:async'; +import 'package:famedlysdk/src/utils/tombstone_content.dart'; import 'package:html_unescape/html_unescape.dart'; import 'package:matrix_file_e2ee/matrix_file_e2ee.dart'; @@ -1665,4 +1666,14 @@ class Room { await client.handleSync(syncUpdate, sortAtTheEnd: sortAtTheEnd); } } + + /// Whether this is an extinct room which has been archived in favor of a new + /// room which replaces this. Use [getLegacyRoomInformations] to get more + /// informations about it if this is true. + bool get isExtinct => getState(EventTypes.RoomTombstone) != null; + + /// Returns informations about how this room is + TombstoneContent get extinctInformations => isExtinct + ? TombstoneContent.fromJson(getState(EventTypes.RoomTombstone).content) + : null; } diff --git a/lib/src/utils/tombstone_content.dart b/lib/src/utils/tombstone_content.dart new file mode 100644 index 00000000..b740e4d9 --- /dev/null +++ b/lib/src/utils/tombstone_content.dart @@ -0,0 +1,15 @@ +class TombstoneContent { + String body; + String replacementRoom; + + TombstoneContent.fromJson(Map json) + : body = json['body'], + replacementRoom = json['replacement_room']; + + Map toJson() { + final data = {}; + data['body'] = body; + data['replacement_room'] = replacementRoom; + return data; + } +}