From 4ca2a5eee350a33371aec23326a94e4150d9c9df Mon Sep 17 00:00:00 2001 From: OfficialDakari Date: Tue, 21 Oct 2025 19:03:17 +0500 Subject: [PATCH] implement Thread.fromJson --- lib/src/room.dart | 3 +- lib/src/thread.dart | 37 +++++++++---------- lib/src/thread_timeline.dart | 69 ++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 19 deletions(-) create mode 100644 lib/src/thread_timeline.dart diff --git a/lib/src/room.dart b/lib/src/room.dart index 76d72a40..a6d1f83a 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -26,6 +26,7 @@ import 'package:html_unescape/html_unescape.dart'; import 'package:matrix/matrix.dart'; import 'package:matrix/src/models/timeline_chunk.dart'; +import 'package:matrix/src/room_timeline.dart'; import 'package:matrix/src/utils/cached_stream_controller.dart'; import 'package:matrix/src/utils/file_send_request_credentials.dart'; import 'package:matrix/src/utils/markdown.dart'; @@ -1690,7 +1691,7 @@ class Room { } } - final timeline = Timeline( + final timeline = RoomTimeline( room: this, chunk: chunk, onChange: onChange, diff --git a/lib/src/thread.dart b/lib/src/thread.dart index aa707a8e..eb7842ea 100644 --- a/lib/src/thread.dart +++ b/lib/src/thread.dart @@ -1,27 +1,28 @@ -import 'dart:async'; -import 'dart:convert'; -import 'dart:math'; - -import 'package:async/async.dart'; -import 'package:collection/collection.dart'; -import 'package:html_unescape/html_unescape.dart'; - import 'package:matrix/matrix.dart'; -import 'package:matrix/src/models/timeline_chunk.dart'; -import 'package:matrix/src/utils/cached_stream_controller.dart'; -import 'package:matrix/src/utils/file_send_request_credentials.dart'; -import 'package:matrix/src/utils/markdown.dart'; -import 'package:matrix/src/utils/marked_unread.dart'; -import 'package:matrix/src/utils/space_child.dart'; class Thread { final Room room; final MatrixEvent rootEvent; + final MatrixEvent? lastEvent; Thread({ - required Room this.room, - required MatrixEvent this.rootEvent - }) { + required this.room, + required this.rootEvent, + this.lastEvent, + }); + factory Thread.fromJson(Map json, Client client) { + final room = client.getRoomById(json['room_id']); + if (room == null) throw Error(); + MatrixEvent? lastEvent; + if (json['unsigned']?['m.relations']?['m.thread']?['latest_event'] != null) { + lastEvent = MatrixEvent.fromJson(json['unsigned']?['m.relations']?['m.thread']?['latest_event']); + } + final thread = Thread( + room: room, + rootEvent: MatrixEvent.fromJson(json), + lastEvent: lastEvent + ); + return thread; } -} \ No newline at end of file +} diff --git a/lib/src/thread_timeline.dart b/lib/src/thread_timeline.dart new file mode 100644 index 00000000..032057b3 --- /dev/null +++ b/lib/src/thread_timeline.dart @@ -0,0 +1,69 @@ +import 'package:matrix/matrix.dart'; +import 'package:matrix/src/models/timeline_chunk.dart'; +import 'package:matrix/src/thread.dart'; + +class ThreadTimeline extends Timeline { + final Thread thread; + + @override + List get events => chunk.events; + + TimelineChunk chunk; + + ThreadTimeline({ + required this.thread, + required this.chunk + }) { + + } + + + @override + // TODO: implement canRequestFuture + bool get canRequestFuture => throw UnimplementedError(); + + @override + // TODO: implement canRequestHistory + bool get canRequestHistory => throw UnimplementedError(); + + @override + void cancelSubscriptions() { + // TODO: implement cancelSubscriptions + } + + @override + Future getEventById(String id) { + // TODO: implement getEventById + throw UnimplementedError(); + } + + @override + Future requestFuture({int historyCount = Room.defaultHistoryCount, StateFilter? filter}) { + // TODO: implement requestFuture + throw UnimplementedError(); + } + + @override + Future requestHistory({int historyCount = Room.defaultHistoryCount, StateFilter? filter}) { + // TODO: implement requestHistory + throw UnimplementedError(); + } + + @override + void requestKeys({bool tryOnlineBackup = true, bool onlineKeyBackupOnly = true}) { + // TODO: implement requestKeys + } + + @override + Future setReadMarker({String? eventId, bool? public}) { + // TODO: implement setReadMarker + throw UnimplementedError(); + } + + @override + Stream<(List, String?)> startSearch({String? searchTerm, int requestHistoryCount = 100, int maxHistoryRequests = 10, String? prevBatch, String? sinceEventId, int? limit, bool Function(Event p1)? searchFunc}) { + // TODO: implement startSearch + throw UnimplementedError(); + } + +} \ No newline at end of file