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.
|
||||
class FakeMatrixApi extends MockClient {
|
||||
static final calledEndpoints = <String, List<dynamic>>{};
|
||||
static final calledEndpoints = <String, List<Object?>>{};
|
||||
static int eventCounter = 0;
|
||||
|
||||
FakeMatrixApi()
|
||||
|
|
@ -82,7 +82,7 @@ class FakeMatrixApi extends MockClient {
|
|||
|
||||
// Call API
|
||||
if (!calledEndpoints.containsKey(action)) {
|
||||
calledEndpoints[action] = <dynamic>[];
|
||||
calledEndpoints[action] = [];
|
||||
}
|
||||
calledEndpoints[action]!.add(data);
|
||||
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
|
||||
/// doesn't need additional authentication, then this is null.
|
||||
List<AuthenticationFlow>? get authenticationFlows => raw
|
||||
.tryGet<List<dynamic>>('flows')
|
||||
.tryGet<List<Object?>>('flows')
|
||||
?.whereType<Map<String, Object?>>()
|
||||
.map((flow) => flow['stages'])
|
||||
.whereType<List<dynamic>>()
|
||||
.whereType<List<Object?>>()
|
||||
.map((stages) =>
|
||||
AuthenticationFlow(List<String>.from(stages.whereType<String>())))
|
||||
.toList();
|
||||
|
|
|
|||
|
|
@ -51,15 +51,15 @@ class SyncUpdate {
|
|||
return temp != null ? RoomsUpdate.fromJson(temp) : null;
|
||||
}()),
|
||||
presence = json
|
||||
.tryGetMap<String, List<dynamic>>('presence')?['events']
|
||||
.tryGetMap<String, List<Object?>>('presence')?['events']
|
||||
?.map((i) => Presence.fromJson(i as Map<String, Object?>))
|
||||
.toList(),
|
||||
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?>))
|
||||
.toList(),
|
||||
toDevice = json
|
||||
.tryGetMap<String, List<dynamic>>('to_device')?['events']
|
||||
.tryGetMap<String, List<Object?>>('to_device')?['events']
|
||||
?.map(
|
||||
(i) => BasicEventWithSender.fromJson(i as Map<String, Object?>))
|
||||
.toList(),
|
||||
|
|
@ -167,16 +167,16 @@ class JoinedRoomUpdate extends SyncRoomUpdate {
|
|||
JoinedRoomUpdate.fromJson(Map<String, Object?> json)
|
||||
: summary = json.tryGetFromJson('summary', RoomSummary.fromJson),
|
||||
state = json
|
||||
.tryGetMap<String, List<dynamic>>('state')?['events']
|
||||
.tryGetMap<String, List<Object?>>('state')?['events']
|
||||
?.map((i) => MatrixEvent.fromJson(i as Map<String, Object?>))
|
||||
.toList(),
|
||||
timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson),
|
||||
ephemeral = json
|
||||
.tryGetMap<String, List<dynamic>>('ephemeral')?['events']
|
||||
.tryGetMap<String, List<Object?>>('ephemeral')?['events']
|
||||
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
|
||||
.toList(),
|
||||
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?>))
|
||||
.toList(),
|
||||
unreadNotifications = json.tryGetFromJson(
|
||||
|
|
@ -219,7 +219,7 @@ class InvitedRoomUpdate extends SyncRoomUpdate {
|
|||
|
||||
InvitedRoomUpdate.fromJson(Map<String, Object?> 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?>))
|
||||
.toList();
|
||||
|
||||
|
|
@ -247,12 +247,12 @@ class LeftRoomUpdate extends SyncRoomUpdate {
|
|||
|
||||
LeftRoomUpdate.fromJson(Map<String, Object?> json)
|
||||
: state = json
|
||||
.tryGetMap<String, List<dynamic>>('state')?['events']
|
||||
.tryGetMap<String, List<Object?>>('state')?['events']
|
||||
?.map((i) => MatrixEvent.fromJson(i as Map<String, Object?>))
|
||||
.toList(),
|
||||
timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson),
|
||||
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?>))
|
||||
.toList();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue