add thread support

Fixes #129
This commit is contained in:
Henry Hiles 2026-11-05 19:14:46 -05:00
commit 7f7bdbf525
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
3 changed files with 1477 additions and 577 deletions

View file

@ -0,0 +1,17 @@
import "package:freezed_annotation/freezed_annotation.dart";
part "get_threads.freezed.dart";
part "get_threads.g.dart";
@Freezed(toJson: false, fromJson: false)
@JsonSerializable()
class const GetThreadsRequest({
required final String roomId,
final String? since,
final int limit = 20,
}) with _$GetThreadsRequest {
Map<String, Object?> toJson() => _$GetThreadsRequestToJson(this);
factory GetThreadsRequest.fromJson(Map<String, Object?> json) =>
_$GetThreadsRequestFromJson(json);
}

View file

@ -14,7 +14,7 @@ class const SendEventRequest({
// Merged into the content by toJson, as gomuks doesn't take these
@JsonKey(includeToJson: false) final String? relatesTo,
@JsonKey(includeToJson: false) final String? relationType,
@JsonKey(includeToJson: false) final String? replyTo,
@JsonKey(includeToJson: false) final Relation? reply,
@JsonKey(includeToJson: false) final Mentions? mentions,
final bool synchronous = false,
final bool disableEncryption = false,
@ -27,14 +27,14 @@ class const SendEventRequest({
"content": {
...content,
"m.mentions": ?mentions?.toJson(),
if (relatesTo != null || replyTo != null)
if (relatesTo != null || reply != null)
"m.relates_to": {
...((content["m.relates_to"] as Map<String, dynamic>?) ?? {}),
if (relatesTo != null) ...{
"event_id": relatesTo,
"rel_type": relationType,
},
if (replyTo != null) "m.in_reply_to": {"event_id": replyTo},
...?reply?.toJson(),
},
},
};

View file

@ -38,11 +38,18 @@ class const Mentions({
class const Relation({
required final String eventId,
required final RelationType relationType,
final String? threadRoot,
final bool isFallingBack = false,
}) with _$Relation {
Map<String, dynamic> toJson() {
switch (relationType) {
case RelationType.reply:
return {
if (threadRoot != null) ...{
"rel_type": "m.thread",
"event_id": threadRoot,
"is_falling_back": isFallingBack,
},
"m.in_reply_to": {"event_id": eventId},
};