Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
fix: wrong types in spaces hierarchy API
Browse files Browse the repository at this point in the history
BREAKING CHANGE (because from is now optional, so it can't be specified
conditionally)

See also:

- matrix-org/matrix-spec#1110
- matrix-org/matrix-spec#1097
  • Loading branch information
nico-famedly committed Jun 7, 2022
1 parent 113616f commit ae95c29
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
16 changes: 8 additions & 8 deletions generated/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ class Api {
/// [from] A pagination token from a previous result. If specified, `max_depth` and `suggested_only` cannot
/// be changed from the first request.
Future<GetSpaceHierarchyResponse> getSpaceHierarchy(String roomId,
{bool? suggestedOnly,
double? limit,
double? maxDepth,
String? from}) async {
{bool? suggestedOnly, int? limit, int? maxDepth, String? from}) async {
final requestUri = Uri(
path:
'_matrix/client/v1/rooms/${Uri.encodeComponent(roomId)}/hierarchy',
Expand Down Expand Up @@ -3234,6 +3231,10 @@ class Api {
/// by a previous request to this endpoint, though servers are not
/// required to support this. Clients should not rely on the behaviour.
///
/// If it is not provided, the homeserver shall return a list of messages
/// from the first or last (per the value of the `dir` parameter) visible
/// event in the room history for the requesting user.
///
/// [to] The token to stop returning events at. This token can be obtained from
/// a `prev_batch` or `next_batch` token returned by the `/sync` endpoint,
/// or from an `end` token returned by a previous request to this endpoint.
Expand All @@ -3246,13 +3247,12 @@ class Api {
/// [limit] The maximum number of events to return. Default: 10.
///
/// [filter] A JSON RoomEventFilter to filter returned events with.
Future<GetRoomEventsResponse> getRoomEvents(
String roomId, String from, Direction dir,
{String? to, int? limit, String? filter}) async {
Future<GetRoomEventsResponse> getRoomEvents(String roomId, Direction dir,
{String? from, String? to, int? limit, String? filter}) async {
final requestUri = Uri(
path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/messages',
queryParameters: {
'from': from,
if (from != null) 'from': from,
if (to != null) 'to': to,
'dir': dir.name,
if (limit != null) 'limit': limit.toString(),
Expand Down
26 changes: 15 additions & 11 deletions generated/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,21 @@ class PublicRoomsChunk {
class SpaceRoomsChunkBase {
SpaceRoomsChunkBase({
required this.childrenState,
required this.roomType,
this.roomType,
});

SpaceRoomsChunkBase.fromJson(Map<String, dynamic> json)
: childrenState = (json['children_state'] as List)
.map((v) => MatrixEvent.fromJson(v))
.toList(),
roomType = json['room_type'] as String;
Map<String, dynamic> toJson() => {
'children_state': childrenState.map((v) => v.toJson()).toList(),
'room_type': roomType,
};
roomType = ((v) => v != null ? v as String : null)(json['room_type']);
Map<String, dynamic> toJson() {
final roomType = this.roomType;
return {
'children_state': childrenState.map((v) => v.toJson()).toList(),
if (roomType != null) 'room_type': roomType,
};
}

/// The [`m.space.child`](#mspacechild) events of the space-room, represented
/// as [Stripped State Events](#stripped-state) with an added `origin_server_ts` key.
Expand All @@ -184,7 +187,7 @@ class SpaceRoomsChunkBase {
List<MatrixEvent> childrenState;

/// The `type` of room (from [`m.room.create`](https://spec.matrix.org/unstable/client-server-api/#mroomcreate)), if any.
String roomType;
String? roomType;
}

@_NameSource('rule override generated')
Expand All @@ -200,7 +203,7 @@ class SpaceRoomsChunk implements PublicRoomsChunk, SpaceRoomsChunkBase {
this.topic,
required this.worldReadable,
required this.childrenState,
required this.roomType,
this.roomType,
});

SpaceRoomsChunk.fromJson(Map<String, dynamic> json)
Expand All @@ -218,13 +221,14 @@ class SpaceRoomsChunk implements PublicRoomsChunk, SpaceRoomsChunkBase {
childrenState = (json['children_state'] as List)
.map((v) => MatrixEvent.fromJson(v))
.toList(),
roomType = json['room_type'] as String;
roomType = ((v) => v != null ? v as String : null)(json['room_type']);
Map<String, dynamic> toJson() {
final avatarUrl = this.avatarUrl;
final canonicalAlias = this.canonicalAlias;
final joinRule = this.joinRule;
final name = this.name;
final topic = this.topic;
final roomType = this.roomType;
return {
if (avatarUrl != null) 'avatar_url': avatarUrl.toString(),
if (canonicalAlias != null) 'canonical_alias': canonicalAlias,
Expand All @@ -236,7 +240,7 @@ class SpaceRoomsChunk implements PublicRoomsChunk, SpaceRoomsChunkBase {
if (topic != null) 'topic': topic,
'world_readable': worldReadable,
'children_state': childrenState.map((v) => v.toJson()).toList(),
'room_type': roomType,
if (roomType != null) 'room_type': roomType,
};
}

Expand Down Expand Up @@ -277,7 +281,7 @@ class SpaceRoomsChunk implements PublicRoomsChunk, SpaceRoomsChunkBase {
List<MatrixEvent> childrenState;

/// The `type` of room (from [`m.room.create`](https://spec.matrix.org/unstable/client-server-api/#mroomcreate)), if any.
String roomType;
String? roomType;
}

@_NameSource('generated')
Expand Down

0 comments on commit ae95c29

Please sign in to comment.