From 80a4498ba9bcb3c9cca4d10b72f3ca61e2cf400b Mon Sep 17 00:00:00 2001 From: Henri Carnot Date: Wed, 8 Jun 2022 15:54:26 +0000 Subject: [PATCH] fix: use ChildrenState for children_state in the room hierarchy response --- lib/src/generated/api.dart | 3 +- lib/src/generated/model.dart | 9 +++--- lib/src/model/children_state.dart | 52 +++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 lib/src/model/children_state.dart diff --git a/lib/src/generated/api.dart b/lib/src/generated/api.dart index 059101ab..7a495b1c 100644 --- a/lib/src/generated/api.dart +++ b/lib/src/generated/api.dart @@ -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 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); diff --git a/lib/src/generated/model.dart b/lib/src/generated/model.dart index 1ccbebd9..37e3e477 100644 --- a/lib/src/generated/model.dart +++ b/lib/src/generated/model.dart @@ -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 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 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 childrenState; + List 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 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 childrenState; + List childrenState; /// The `type` of room (from [`m.room.create`](https://spec.matrix.org/unstable/client-server-api/#mroomcreate)), if any. String? roomType; diff --git a/lib/src/model/children_state.dart b/lib/src/model/children_state.dart new file mode 100644 index 00000000..ed0d6c26 --- /dev/null +++ b/lib/src/model/children_state.dart @@ -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 content, + required String senderId, + required String stateKey, + required this.originServerTs, + }) : super( + type: type, + content: content, + senderId: senderId, + stateKey: stateKey); + + ChildrenState.fromJson(Map json) + : originServerTs = + DateTime.fromMillisecondsSinceEpoch(json['origin_server_ts']), + super.fromJson(json); + + @override + Map toJson() { + final data = super.toJson(); + data['origin_server_ts'] = originServerTs.millisecondsSinceEpoch; + return data; + } +}