make SendEventRequest use a Content
This commit is contained in:
parent
4d00631fed
commit
952bda6985
4 changed files with 31 additions and 11 deletions
|
|
@ -170,8 +170,24 @@ class ClientController extends AsyncNotifier<int> {
|
||||||
Future<Event> sendMessage(SendMessageRequest request) async =>
|
Future<Event> sendMessage(SendMessageRequest request) async =>
|
||||||
Event.fromJson(await _sendCommand("send_message", request.toJson()));
|
Event.fromJson(await _sendCommand("send_message", request.toJson()));
|
||||||
|
|
||||||
Future<Event> sendEvent(SendEventRequest request) async =>
|
Future<Event> sendEvent(SendEventRequest request) async {
|
||||||
Event.fromJson(await _sendCommand("send_event", request.toJson()));
|
final json = request.toJson();
|
||||||
|
final content = request.content.toJson();
|
||||||
|
|
||||||
|
return Event.fromJson(
|
||||||
|
await _sendCommand("send_event", {
|
||||||
|
...json,
|
||||||
|
"content": {
|
||||||
|
...content,
|
||||||
|
"m.relates_to": {
|
||||||
|
...((content["m.relates_to"] as Map<String, dynamic>?) ?? {}),
|
||||||
|
"event_id": request.relatesTo,
|
||||||
|
"rel_type": request.relationType,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<String?> setState(SetStateRequest request) async =>
|
Future<String?> setState(SetStateRequest request) async =>
|
||||||
await _sendCommand("set_state", request.toJson());
|
await _sendCommand("set_state", request.toJson());
|
||||||
|
|
|
||||||
|
|
@ -205,15 +205,11 @@ class RoomChatController extends AsyncNotifier<IList<Event>?> {
|
||||||
.new(
|
.new(
|
||||||
roomId: roomId,
|
roomId: roomId,
|
||||||
type: EventType.reaction.type,
|
type: EventType.reaction.type,
|
||||||
content: {
|
content: ReactionContent(key: reaction),
|
||||||
"m.relates_to": {
|
|
||||||
"event_id": event.eventId,
|
|
||||||
"rel_type": "m.annotation",
|
|
||||||
"key": reaction,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
synchronous: true,
|
synchronous: true,
|
||||||
disableEncryption: true,
|
disableEncryption: true,
|
||||||
|
relatesTo: event.eventId,
|
||||||
|
relationType: "m.annotation",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import "package:nexus/models/content/content.dart";
|
||||||
part "reaction.freezed.dart";
|
part "reaction.freezed.dart";
|
||||||
part "reaction.g.dart";
|
part "reaction.g.dart";
|
||||||
|
|
||||||
@freezed
|
@Freezed(toJson: false)
|
||||||
abstract class ReactionContent extends Content with _$ReactionContent {
|
abstract class ReactionContent extends Content with _$ReactionContent {
|
||||||
ReactionContent._();
|
ReactionContent._();
|
||||||
static String? keyJsonFromJson(Map<dynamic, dynamic> json, String key) =>
|
static String? keyJsonFromJson(Map<dynamic, dynamic> json, String key) =>
|
||||||
|
|
@ -13,6 +13,11 @@ abstract class ReactionContent extends Content with _$ReactionContent {
|
||||||
@JsonKey(readValue: ReactionContent.keyJsonFromJson) String? key,
|
@JsonKey(readValue: ReactionContent.keyJsonFromJson) String? key,
|
||||||
}) = _ReactionContent;
|
}) = _ReactionContent;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
"m.relates_to": {"key": key},
|
||||||
|
};
|
||||||
|
|
||||||
factory ReactionContent.fromJson(Map<String, Object?> json) =>
|
factory ReactionContent.fromJson(Map<String, Object?> json) =>
|
||||||
_$ReactionContentFromJson(json);
|
_$ReactionContentFromJson(json);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import "package:freezed_annotation/freezed_annotation.dart";
|
import "package:freezed_annotation/freezed_annotation.dart";
|
||||||
|
import "package:nexus/models/content/content.dart";
|
||||||
part "send_event_request.freezed.dart";
|
part "send_event_request.freezed.dart";
|
||||||
part "send_event_request.g.dart";
|
part "send_event_request.g.dart";
|
||||||
|
|
||||||
|
|
@ -7,7 +8,9 @@ abstract class SendEventRequest with _$SendEventRequest {
|
||||||
const factory SendEventRequest({
|
const factory SendEventRequest({
|
||||||
required String roomId,
|
required String roomId,
|
||||||
required String type,
|
required String type,
|
||||||
required Map<String, dynamic> content,
|
required Content content,
|
||||||
|
String? relatesTo,
|
||||||
|
String? relationType,
|
||||||
@Default(false) bool synchronous,
|
@Default(false) bool synchronous,
|
||||||
@Default(false) bool disableEncryption,
|
@Default(false) bool disableEncryption,
|
||||||
}) = _SendEventRequest;
|
}) = _SendEventRequest;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue