...
 
Commits (2)
......@@ -41,10 +41,12 @@ class PowerLevelsChangeEvent extends StateEvent {
final int redact = content['redact'] ?? 50;
final int eventsDefault = content['events_default'] ?? 0;
final filteredEvents = content['events']
..removeWhere((type, powerLevel) => Event.typeOf(type) == null);
final jsonEvents = content['events'];
if (jsonEvents != null) {
jsonEvents.removeWhere((type, powerLevel) => Event.typeOf(type) == null);
}
final Map<Type, int> events = filteredEvents.map((eventType, powerLevel) {
final Map<Type, int> events = jsonEvents.map((eventType, powerLevel) {
return MapEntry<Type, int>(Event.typeOf(eventType), powerLevel);
}).cast<Type, int>();
......
......@@ -36,6 +36,7 @@ import 'package:meta/meta.dart';
/// Represents a Matrix homeserver. Also used as the main entry point
/// of the SDK.
class Homeserver {
final http.Client _httpClient;
final ChopperClient _chopper;
// TODO: Make lazy
ClientService get _client => _chopper.getService();
......@@ -98,7 +99,12 @@ class Homeserver {
// TODO: Validation
}
Homeserver(this.url) : _chopper = createChopper(url: url) {
Homeserver(this.url, {http.Client httpClient})
: _httpClient = httpClient,
_chopper = createChopper(
url: url,
client: httpClient,
) {
scope = url.toString() + hashCode.toString();
Container().registerInstance(this, name: scope);
......@@ -137,6 +143,7 @@ class Homeserver {
store: store,
homeserver: this,
accessToken: accessToken,
httpClient: _httpClient,
);
await store?.open(user: localUser);
......
......@@ -32,6 +32,7 @@ import 'package:matrix_sdk/src/store.dart';
import 'package:matrix_sdk/src/util/chopper.dart';
import 'package:meta/meta.dart';
import 'package:url/url.dart';
import 'package:http/http.dart' as http;
class UserState implements Comparable<UserState> {
UserId _userId;
......@@ -155,7 +156,9 @@ class LocalUser extends User {
@required this.homeserver,
@required this.accessToken,
@required Store store,
http.Client httpClient,
}) : _chopper = createChopper(
client: httpClient,
url: homeserver.url,
interceptors: [AccessTokenInterceptor(accessToken)]),
_store = store,
......
......@@ -21,8 +21,13 @@ import 'package:matrix_sdk/src/api/exception_interceptor.dart';
import 'package:matrix_sdk/src/api/media.dart';
import 'package:meta/meta.dart';
import 'package:url/url.dart';
import 'package:http/http.dart' as http;
ChopperClient createChopper({@required Url url, List<dynamic> interceptors}) {
ChopperClient createChopper({
@required Url url,
http.Client client,
List<dynamic> interceptors,
}) {
if (interceptors == null) {
interceptors = [];
}
......@@ -30,6 +35,7 @@ ChopperClient createChopper({@required Url url, List<dynamic> interceptors}) {
interceptors.add(ExceptionInterceptor());
return ChopperClient(
client: client,
baseUrl: url.toString(),
services: [ClientService.create(), MediaService.create()],
interceptors: interceptors,
......
......@@ -19,6 +19,7 @@ dependencies:
dev_dependencies:
pedantic: ^1.0.0
test: ^1.0.0
mockito: ^4.1.0
build_runner: ^1.0.0
chopper_generator: ^2.4.2
dotenv: ^1.0.0
......@@ -18,6 +18,8 @@
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:test/test.dart';
import 'homeserver_test.dart';
void main() {
group('Identifier validity', () {
test('UserId', () {
......@@ -44,5 +46,5 @@ void main() {
});
});
// TODO: Add proper unit testing
testHomeserver();
}