fix: use ChildrenState for children_state in the room hierarchy response

This commit is contained in:
Henri Carnot 2022-06-08 15:54:26 +00:00 committed by Nicolas Werner
parent cc509671f6
commit 80a4498ba9
3 changed files with 59 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import '../model/auth/authentication_identifier.dart';
import '../model/matrix_keys.dart';
import '../model/sync_update.dart';
import '../model/matrix_event.dart';
import '../model/children_state.dart';
import 'model.dart';
import 'fixed_model.dart';
@ -1977,7 +1978,7 @@ class Api {
/// returns `global`:
/// The global ruleset.
Future<PushRuleSet> getPushRules() async {
final requestUri = Uri(path: '_matrix/client/v3/pushrules');
final requestUri = Uri(path: '_matrix/client/v3/pushrules/');
final request = Request('GET', baseUri!.resolveUri(requestUri));
request.headers['authorization'] = 'Bearer ${bearerToken!}';
final response = await httpClient.send(request);

View File

@ -4,6 +4,7 @@ import '../model/auth/authentication_identifier.dart';
import '../model/matrix_keys.dart';
import '../model/sync_update.dart';
import '../model/matrix_event.dart';
import '../model/children_state.dart';
import 'internal.dart';
import 'package:enhanced_enum/enhanced_enum.dart';
@ -169,7 +170,7 @@ class SpaceRoomsChunkBase {
SpaceRoomsChunkBase.fromJson(Map<String, dynamic> json)
: childrenState = (json['children_state'] as List)
.map((v) => MatrixEvent.fromJson(v))
.map((v) => ChildrenState.fromJson(v))
.toList(),
roomType = ((v) => v != null ? v as String : null)(json['room_type']);
Map<String, dynamic> toJson() {
@ -184,7 +185,7 @@ class SpaceRoomsChunkBase {
/// as [Stripped State Events](#stripped-state) with an added `origin_server_ts` key.
///
/// If the room is not a space-room, this should be empty.
List<MatrixEvent> childrenState;
List<ChildrenState> childrenState;
/// The `type` of room (from [`m.room.create`](https://spec.matrix.org/unstable/client-server-api/#mroomcreate)), if any.
String? roomType;
@ -219,7 +220,7 @@ class SpaceRoomsChunk implements PublicRoomsChunk, SpaceRoomsChunkBase {
topic = ((v) => v != null ? v as String : null)(json['topic']),
worldReadable = json['world_readable'] as bool,
childrenState = (json['children_state'] as List)
.map((v) => MatrixEvent.fromJson(v))
.map((v) => ChildrenState.fromJson(v))
.toList(),
roomType = ((v) => v != null ? v as String : null)(json['room_type']);
Map<String, dynamic> toJson() {
@ -278,7 +279,7 @@ class SpaceRoomsChunk implements PublicRoomsChunk, SpaceRoomsChunkBase {
/// as [Stripped State Events](#stripped-state) with an added `origin_server_ts` key.
///
/// If the room is not a space-room, this should be empty.
List<MatrixEvent> childrenState;
List<ChildrenState> childrenState;
/// The `type` of room (from [`m.room.create`](https://spec.matrix.org/unstable/client-server-api/#mroomcreate)), if any.
String? roomType;

View File

@ -0,0 +1,52 @@
/* MIT License
*
* Copyright (C) 2022 Famedly GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import 'stripped_state_event.dart';
class ChildrenState extends StrippedStateEvent {
DateTime originServerTs;
ChildrenState({
required String type,
required Map<String, dynamic> content,
required String senderId,
required String stateKey,
required this.originServerTs,
}) : super(
type: type,
content: content,
senderId: senderId,
stateKey: stateKey);
ChildrenState.fromJson(Map<String, dynamic> json)
: originServerTs =
DateTime.fromMillisecondsSinceEpoch(json['origin_server_ts']),
super.fromJson(json);
@override
Map<String, dynamic> toJson() {
final data = super.toJson();
data['origin_server_ts'] = originServerTs.millisecondsSinceEpoch;
return data;
}
}