refactor: Get rid of dynamic lists
This commit is contained in:
parent
4953784be4
commit
e81898ef7f
|
|
@ -44,7 +44,7 @@ T? tryCast<T>(dynamic object) => object is T ? object : null;
|
||||||
|
|
||||||
/// A mock http client for testing purposes.
|
/// A mock http client for testing purposes.
|
||||||
class FakeMatrixApi extends MockClient {
|
class FakeMatrixApi extends MockClient {
|
||||||
static final calledEndpoints = <String, List<dynamic>>{};
|
static final calledEndpoints = <String, List<Object?>>{};
|
||||||
static int eventCounter = 0;
|
static int eventCounter = 0;
|
||||||
|
|
||||||
FakeMatrixApi()
|
FakeMatrixApi()
|
||||||
|
|
@ -82,7 +82,7 @@ class FakeMatrixApi extends MockClient {
|
||||||
|
|
||||||
// Call API
|
// Call API
|
||||||
if (!calledEndpoints.containsKey(action)) {
|
if (!calledEndpoints.containsKey(action)) {
|
||||||
calledEndpoints[action] = <dynamic>[];
|
calledEndpoints[action] = [];
|
||||||
}
|
}
|
||||||
calledEndpoints[action]!.add(data);
|
calledEndpoints[action]!.add(data);
|
||||||
if (api.containsKey(method) && api[method]!.containsKey(action)) {
|
if (api.containsKey(method) && api[method]!.containsKey(action)) {
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,10 @@ class MatrixException implements Exception {
|
||||||
/// to authenticate itself. Each flow comprises a series of stages. If this request
|
/// to authenticate itself. Each flow comprises a series of stages. If this request
|
||||||
/// doesn't need additional authentication, then this is null.
|
/// doesn't need additional authentication, then this is null.
|
||||||
List<AuthenticationFlow>? get authenticationFlows => raw
|
List<AuthenticationFlow>? get authenticationFlows => raw
|
||||||
.tryGet<List<dynamic>>('flows')
|
.tryGet<List<Object?>>('flows')
|
||||||
?.whereType<Map<String, Object?>>()
|
?.whereType<Map<String, Object?>>()
|
||||||
.map((flow) => flow['stages'])
|
.map((flow) => flow['stages'])
|
||||||
.whereType<List<dynamic>>()
|
.whereType<List<Object?>>()
|
||||||
.map((stages) =>
|
.map((stages) =>
|
||||||
AuthenticationFlow(List<String>.from(stages.whereType<String>())))
|
AuthenticationFlow(List<String>.from(stages.whereType<String>())))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
|
||||||
|
|
@ -51,15 +51,15 @@ class SyncUpdate {
|
||||||
return temp != null ? RoomsUpdate.fromJson(temp) : null;
|
return temp != null ? RoomsUpdate.fromJson(temp) : null;
|
||||||
}()),
|
}()),
|
||||||
presence = json
|
presence = json
|
||||||
.tryGetMap<String, List<dynamic>>('presence')?['events']
|
.tryGetMap<String, List<Object?>>('presence')?['events']
|
||||||
?.map((i) => Presence.fromJson(i as Map<String, Object?>))
|
?.map((i) => Presence.fromJson(i as Map<String, Object?>))
|
||||||
.toList(),
|
.toList(),
|
||||||
accountData = json
|
accountData = json
|
||||||
.tryGetMap<String, List<dynamic>>('account_data')?['events']
|
.tryGetMap<String, List<Object?>>('account_data')?['events']
|
||||||
?.map((i) => BasicEvent.fromJson(i as Map<String, Object?>))
|
?.map((i) => BasicEvent.fromJson(i as Map<String, Object?>))
|
||||||
.toList(),
|
.toList(),
|
||||||
toDevice = json
|
toDevice = json
|
||||||
.tryGetMap<String, List<dynamic>>('to_device')?['events']
|
.tryGetMap<String, List<Object?>>('to_device')?['events']
|
||||||
?.map(
|
?.map(
|
||||||
(i) => BasicEventWithSender.fromJson(i as Map<String, Object?>))
|
(i) => BasicEventWithSender.fromJson(i as Map<String, Object?>))
|
||||||
.toList(),
|
.toList(),
|
||||||
|
|
@ -167,16 +167,16 @@ class JoinedRoomUpdate extends SyncRoomUpdate {
|
||||||
JoinedRoomUpdate.fromJson(Map<String, Object?> json)
|
JoinedRoomUpdate.fromJson(Map<String, Object?> json)
|
||||||
: summary = json.tryGetFromJson('summary', RoomSummary.fromJson),
|
: summary = json.tryGetFromJson('summary', RoomSummary.fromJson),
|
||||||
state = json
|
state = json
|
||||||
.tryGetMap<String, List<dynamic>>('state')?['events']
|
.tryGetMap<String, List<Object?>>('state')?['events']
|
||||||
?.map((i) => MatrixEvent.fromJson(i as Map<String, Object?>))
|
?.map((i) => MatrixEvent.fromJson(i as Map<String, Object?>))
|
||||||
.toList(),
|
.toList(),
|
||||||
timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson),
|
timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson),
|
||||||
ephemeral = json
|
ephemeral = json
|
||||||
.tryGetMap<String, List<dynamic>>('ephemeral')?['events']
|
.tryGetMap<String, List<Object?>>('ephemeral')?['events']
|
||||||
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
|
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
|
||||||
.toList(),
|
.toList(),
|
||||||
accountData = json
|
accountData = json
|
||||||
.tryGetMap<String, List<dynamic>>('account_data')?['events']
|
.tryGetMap<String, List<Object?>>('account_data')?['events']
|
||||||
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
|
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
|
||||||
.toList(),
|
.toList(),
|
||||||
unreadNotifications = json.tryGetFromJson(
|
unreadNotifications = json.tryGetFromJson(
|
||||||
|
|
@ -219,7 +219,7 @@ class InvitedRoomUpdate extends SyncRoomUpdate {
|
||||||
|
|
||||||
InvitedRoomUpdate.fromJson(Map<String, Object?> json)
|
InvitedRoomUpdate.fromJson(Map<String, Object?> json)
|
||||||
: inviteState = json
|
: inviteState = json
|
||||||
.tryGetMap<String, List<dynamic>>('invite_state')?['events']
|
.tryGetMap<String, List<Object?>>('invite_state')?['events']
|
||||||
?.map((i) => StrippedStateEvent.fromJson(i as Map<String, Object?>))
|
?.map((i) => StrippedStateEvent.fromJson(i as Map<String, Object?>))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
|
@ -247,12 +247,12 @@ class LeftRoomUpdate extends SyncRoomUpdate {
|
||||||
|
|
||||||
LeftRoomUpdate.fromJson(Map<String, Object?> json)
|
LeftRoomUpdate.fromJson(Map<String, Object?> json)
|
||||||
: state = json
|
: state = json
|
||||||
.tryGetMap<String, List<dynamic>>('state')?['events']
|
.tryGetMap<String, List<Object?>>('state')?['events']
|
||||||
?.map((i) => MatrixEvent.fromJson(i as Map<String, Object?>))
|
?.map((i) => MatrixEvent.fromJson(i as Map<String, Object?>))
|
||||||
.toList(),
|
.toList(),
|
||||||
timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson),
|
timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson),
|
||||||
accountData = json
|
accountData = json
|
||||||
.tryGetMap<String, List<dynamic>>('account_data')?['events']
|
.tryGetMap<String, List<Object?>>('account_data')?['events']
|
||||||
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
|
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue