Deprecate debug mode
This commit is contained in:
parent
2796ca613a
commit
6779ab6624
|
@ -88,9 +88,6 @@ class MatrixApi {
|
||||||
/// timeout which is usually 30 seconds.
|
/// timeout which is usually 30 seconds.
|
||||||
int syncTimeoutSec;
|
int syncTimeoutSec;
|
||||||
|
|
||||||
/// Whether debug prints should be displayed.
|
|
||||||
final bool debug;
|
|
||||||
|
|
||||||
http.Client httpClient = http.Client();
|
http.Client httpClient = http.Client();
|
||||||
|
|
||||||
bool get _testMode =>
|
bool get _testMode =>
|
||||||
|
@ -101,7 +98,6 @@ class MatrixApi {
|
||||||
MatrixApi({
|
MatrixApi({
|
||||||
this.homeserver,
|
this.homeserver,
|
||||||
this.accessToken,
|
this.accessToken,
|
||||||
this.debug = false,
|
|
||||||
http.Client httpClient,
|
http.Client httpClient,
|
||||||
this.syncTimeoutSec = 30,
|
this.syncTimeoutSec = 30,
|
||||||
}) {
|
}) {
|
||||||
|
@ -161,11 +157,6 @@ class MatrixApi {
|
||||||
headers['Authorization'] = 'Bearer ${accessToken}';
|
headers['Authorization'] = 'Bearer ${accessToken}';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
|
||||||
print(
|
|
||||||
'[REQUEST ${describeEnum(type)}] $action, Data: ${jsonEncode(data)}');
|
|
||||||
}
|
|
||||||
|
|
||||||
http.Response resp;
|
http.Response resp;
|
||||||
var jsonResp = <String, dynamic>{};
|
var jsonResp = <String, dynamic>{};
|
||||||
try {
|
try {
|
||||||
|
@ -212,8 +203,6 @@ class MatrixApi {
|
||||||
|
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) print('[RESPONSE] ${jsonResp.toString()}');
|
|
||||||
_timeoutFactor = 1;
|
_timeoutFactor = 1;
|
||||||
} on TimeoutException catch (_) {
|
} on TimeoutException catch (_) {
|
||||||
_timeoutFactor *= 2;
|
_timeoutFactor *= 2;
|
||||||
|
@ -1300,7 +1289,6 @@ class MatrixApi {
|
||||||
streamedRequest.contentLength = await file.length;
|
streamedRequest.contentLength = await file.length;
|
||||||
streamedRequest.sink.add(file);
|
streamedRequest.sink.add(file);
|
||||||
streamedRequest.sink.close();
|
streamedRequest.sink.close();
|
||||||
if (debug) print('[UPLOADING] $fileName');
|
|
||||||
var streamedResponse = _testMode ? null : await streamedRequest.send();
|
var streamedResponse = _testMode ? null : await streamedRequest.send();
|
||||||
Map<String, dynamic> jsonResponse = json.decode(
|
Map<String, dynamic> jsonResponse = json.decode(
|
||||||
String.fromCharCodes(_testMode
|
String.fromCharCodes(_testMode
|
||||||
|
|
|
@ -81,14 +81,16 @@ class Client {
|
||||||
/// - m.room.canonical_alias
|
/// - m.room.canonical_alias
|
||||||
/// - m.room.tombstone
|
/// - m.room.tombstone
|
||||||
/// - *some* m.room.member events, where needed
|
/// - *some* m.room.member events, where needed
|
||||||
Client(this.clientName,
|
Client(
|
||||||
{this.debug = false,
|
this.clientName, {
|
||||||
this.database,
|
this.database,
|
||||||
this.enableE2eeRecovery = false,
|
this.enableE2eeRecovery = false,
|
||||||
this.verificationMethods,
|
this.verificationMethods,
|
||||||
http.Client httpClient,
|
http.Client httpClient,
|
||||||
this.importantStateEvents,
|
this.importantStateEvents,
|
||||||
this.pinUnreadRooms = false}) {
|
this.pinUnreadRooms = false,
|
||||||
|
@deprecated bool debug,
|
||||||
|
}) {
|
||||||
verificationMethods ??= <KeyVerificationMethod>{};
|
verificationMethods ??= <KeyVerificationMethod>{};
|
||||||
importantStateEvents ??= <String>{};
|
importantStateEvents ??= <String>{};
|
||||||
importantStateEvents.addAll([
|
importantStateEvents.addAll([
|
||||||
|
@ -100,17 +102,9 @@ class Client {
|
||||||
EventTypes.RoomCanonicalAlias,
|
EventTypes.RoomCanonicalAlias,
|
||||||
EventTypes.RoomTombstone,
|
EventTypes.RoomTombstone,
|
||||||
]);
|
]);
|
||||||
api = MatrixApi(debug: debug, httpClient: httpClient);
|
api = MatrixApi(httpClient: httpClient);
|
||||||
onLoginStateChanged.stream.listen((loginState) {
|
|
||||||
if (debug) {
|
|
||||||
print('[LoginState]: ${loginState.toString()}');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether debug prints should be displayed.
|
|
||||||
final bool debug;
|
|
||||||
|
|
||||||
/// The required name for this client.
|
/// The required name for this client.
|
||||||
final String clientName;
|
final String clientName;
|
||||||
|
|
||||||
|
@ -634,8 +628,8 @@ class Client {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
encryption = Encryption(
|
encryption =
|
||||||
debug: debug, client: this, enableE2eeRecovery: enableE2eeRecovery);
|
Encryption(client: this, enableE2eeRecovery: enableE2eeRecovery);
|
||||||
await encryption.init(olmAccount);
|
await encryption.init(olmAccount);
|
||||||
|
|
||||||
if (database != null) {
|
if (database != null) {
|
||||||
|
|
|
@ -263,10 +263,8 @@ class Timeline {
|
||||||
}
|
}
|
||||||
sortAndUpdate();
|
sortAndUpdate();
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
if (room.client.debug) {
|
print('[WARNING] (_handleEventUpdate) ${e.toString()}');
|
||||||
print('[WARNING] (_handleEventUpdate) ${e.toString()}');
|
print(s);
|
||||||
print(s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ void main() {
|
||||||
group('FluffyMatrix', () {
|
group('FluffyMatrix', () {
|
||||||
/// Check if all Elements get created
|
/// Check if all Elements get created
|
||||||
|
|
||||||
matrix = Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
matrix = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
|
|
||||||
roomUpdateListFuture = matrix.onRoomUpdate.stream.toList();
|
roomUpdateListFuture = matrix.onRoomUpdate.stream.toList();
|
||||||
eventUpdateListFuture = matrix.onEvent.stream.toList();
|
eventUpdateListFuture = matrix.onEvent.stream.toList();
|
||||||
|
@ -322,7 +322,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Login', () async {
|
test('Login', () async {
|
||||||
matrix = Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
matrix = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
|
|
||||||
roomUpdateListFuture = matrix.onRoomUpdate.stream.toList();
|
roomUpdateListFuture = matrix.onRoomUpdate.stream.toList();
|
||||||
eventUpdateListFuture = matrix.onEvent.stream.toList();
|
eventUpdateListFuture = matrix.onEvent.stream.toList();
|
||||||
|
@ -395,8 +395,7 @@ void main() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('Test the fake store api', () async {
|
test('Test the fake store api', () async {
|
||||||
var client1 =
|
var client1 = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
|
||||||
client1.database = getDatabase();
|
client1.database = getDatabase();
|
||||||
|
|
||||||
client1.connect(
|
client1.connect(
|
||||||
|
@ -413,8 +412,7 @@ void main() {
|
||||||
expect(client1.isLogged(), true);
|
expect(client1.isLogged(), true);
|
||||||
expect(client1.rooms.length, 2);
|
expect(client1.rooms.length, 2);
|
||||||
|
|
||||||
var client2 =
|
var client2 = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
|
||||||
client2.database = client1.database;
|
client2.database = client1.database;
|
||||||
|
|
||||||
client2.connect();
|
client2.connect();
|
||||||
|
|
|
@ -42,8 +42,7 @@ void main() {
|
||||||
if (!olmEnabled) return;
|
if (!olmEnabled) return;
|
||||||
|
|
||||||
Client client;
|
Client client;
|
||||||
var otherClient =
|
var otherClient = Client('othertestclient', httpClient: FakeMatrixApi());
|
||||||
Client('othertestclient', debug: true, httpClient: FakeMatrixApi());
|
|
||||||
DeviceKeys device;
|
DeviceKeys device;
|
||||||
Map<String, dynamic> payload;
|
Map<String, dynamic> payload;
|
||||||
|
|
||||||
|
|
|
@ -82,8 +82,7 @@ void main() {
|
||||||
|
|
||||||
test('setupClient', () async {
|
test('setupClient', () async {
|
||||||
client1 = await getClient();
|
client1 = await getClient();
|
||||||
client2 =
|
client2 = Client('othertestclient', httpClient: FakeMatrixApi());
|
||||||
Client('othertestclient', debug: true, httpClient: FakeMatrixApi());
|
|
||||||
client2.database = client1.database;
|
client2.database = client1.database;
|
||||||
await client2.checkServer('https://fakeServer.notExisting');
|
await client2.checkServer('https://fakeServer.notExisting');
|
||||||
client2.connect(
|
client2.connect(
|
||||||
|
|
|
@ -50,7 +50,7 @@ void main() {
|
||||||
'status': 2,
|
'status': 2,
|
||||||
'content': contentJson,
|
'content': contentJson,
|
||||||
};
|
};
|
||||||
var client = Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
var client = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
var event = Event.fromJson(
|
var event = Event.fromJson(
|
||||||
jsonObj, Room(id: '!localpart:server.abc', client: client));
|
jsonObj, Room(id: '!localpart:server.abc', client: client));
|
||||||
|
|
||||||
|
@ -211,8 +211,7 @@ void main() {
|
||||||
];
|
];
|
||||||
for (final testType in testTypes) {
|
for (final testType in testTypes) {
|
||||||
redactJsonObj['type'] = testType;
|
redactJsonObj['type'] = testType;
|
||||||
final room =
|
final room = Room(id: '1234', client: Client('testclient'));
|
||||||
Room(id: '1234', client: Client('testclient', debug: true));
|
|
||||||
final redactionEventJson = {
|
final redactionEventJson = {
|
||||||
'content': {'reason': 'Spamming'},
|
'content': {'reason': 'Spamming'},
|
||||||
'event_id': '143273582443PhrSn:example.org',
|
'event_id': '143273582443PhrSn:example.org',
|
||||||
|
@ -236,7 +235,7 @@ void main() {
|
||||||
|
|
||||||
test('remove', () async {
|
test('remove', () async {
|
||||||
var event = Event.fromJson(
|
var event = Event.fromJson(
|
||||||
jsonObj, Room(id: '1234', client: Client('testclient', debug: true)));
|
jsonObj, Room(id: '1234', client: Client('testclient')));
|
||||||
final removed1 = await event.remove();
|
final removed1 = await event.remove();
|
||||||
event.status = 0;
|
event.status = 0;
|
||||||
final removed2 = await event.remove();
|
final removed2 = await event.remove();
|
||||||
|
@ -245,8 +244,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sendAgain', () async {
|
test('sendAgain', () async {
|
||||||
var matrix =
|
var matrix = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
|
||||||
await matrix.checkServer('https://fakeServer.notExisting');
|
await matrix.checkServer('https://fakeServer.notExisting');
|
||||||
await matrix.login('test', '1234');
|
await matrix.login('test', '1234');
|
||||||
|
|
||||||
|
@ -262,8 +260,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('requestKey', () async {
|
test('requestKey', () async {
|
||||||
var matrix =
|
var matrix = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
|
||||||
await matrix.checkServer('https://fakeServer.notExisting');
|
await matrix.checkServer('https://fakeServer.notExisting');
|
||||||
await matrix.login('test', '1234');
|
await matrix.login('test', '1234');
|
||||||
|
|
||||||
|
@ -310,8 +307,7 @@ void main() {
|
||||||
expect(event.canRedact, true);
|
expect(event.canRedact, true);
|
||||||
});
|
});
|
||||||
test('getLocalizedBody', () async {
|
test('getLocalizedBody', () async {
|
||||||
final matrix =
|
final matrix = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
|
||||||
final room = Room(id: '!1234:example.com', client: matrix);
|
final room = Room(id: '!1234:example.com', client: matrix);
|
||||||
var event = Event.fromJson({
|
var event = Event.fromJson({
|
||||||
'content': {
|
'content': {
|
||||||
|
|
|
@ -29,7 +29,7 @@ const pickledOlmAccount =
|
||||||
'N2v1MkIFGcl0mQpo2OCwSopxPQJ0wnl7oe7PKiT4141AijfdTIhRu+ceXzXKy3Kr00nLqXtRv7kid6hU4a+V0rfJWLL0Y51+3Rp/ORDVnQy+SSeo6Fn4FHcXrxifJEJ0djla5u98fBcJ8BSkhIDmtXRPi5/oJAvpiYn+8zMjFHobOeZUAxYR0VfQ9JzSYBsSovoQ7uFkNks1M4EDUvHtuyg3RxViwdNxs3718fyAqQ/VSwbXsY0Nl+qQbF+nlVGHenGqk5SuNl1P6e1PzZxcR0IfXA94Xij1Ob5gDv5YH4UCn9wRMG0abZsQP0YzpDM0FLaHSCyo9i5JD/vMlhH+nZWrgAzPPCTNGYewNV8/h3c+VyJh8ZTx/fVi6Yq46Fv+27Ga2ETRZ3Qn+Oyx6dLBjnBZ9iUvIhqpe2XqaGA1PopOz8iDnaZitw';
|
'N2v1MkIFGcl0mQpo2OCwSopxPQJ0wnl7oe7PKiT4141AijfdTIhRu+ceXzXKy3Kr00nLqXtRv7kid6hU4a+V0rfJWLL0Y51+3Rp/ORDVnQy+SSeo6Fn4FHcXrxifJEJ0djla5u98fBcJ8BSkhIDmtXRPi5/oJAvpiYn+8zMjFHobOeZUAxYR0VfQ9JzSYBsSovoQ7uFkNks1M4EDUvHtuyg3RxViwdNxs3718fyAqQ/VSwbXsY0Nl+qQbF+nlVGHenGqk5SuNl1P6e1PzZxcR0IfXA94Xij1Ob5gDv5YH4UCn9wRMG0abZsQP0YzpDM0FLaHSCyo9i5JD/vMlhH+nZWrgAzPPCTNGYewNV8/h3c+VyJh8ZTx/fVi6Yq46Fv+27Ga2ETRZ3Qn+Oyx6dLBjnBZ9iUvIhqpe2XqaGA1PopOz8iDnaZitw';
|
||||||
|
|
||||||
Future<Client> getClient() async {
|
Future<Client> getClient() async {
|
||||||
final client = Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
final client = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
client.database = getDatabase();
|
client.database = getDatabase();
|
||||||
await client.checkServer('https://fakeServer.notExisting');
|
await client.checkServer('https://fakeServer.notExisting');
|
||||||
final resp = await client.api.login(
|
final resp = await client.api.login(
|
||||||
|
|
|
@ -33,7 +33,6 @@ void main() {
|
||||||
group('Matrix API', () {
|
group('Matrix API', () {
|
||||||
final matrixApi = MatrixApi(
|
final matrixApi = MatrixApi(
|
||||||
httpClient: FakeMatrixApi(),
|
httpClient: FakeMatrixApi(),
|
||||||
debug: true,
|
|
||||||
);
|
);
|
||||||
test('MatrixException test', () async {
|
test('MatrixException test', () async {
|
||||||
final exception = MatrixException.fromJson({
|
final exception = MatrixException.fromJson({
|
||||||
|
|
|
@ -33,7 +33,7 @@ void main() {
|
||||||
var updateCount = 0;
|
var updateCount = 0;
|
||||||
var insertList = <int>[];
|
var insertList = <int>[];
|
||||||
|
|
||||||
var client = Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
var client = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
|
|
||||||
var room = Room(
|
var room = Room(
|
||||||
id: roomID, client: client, prev_batch: '1234', roomAccountData: {});
|
id: roomID, client: client, prev_batch: '1234', roomAccountData: {});
|
||||||
|
|
|
@ -27,7 +27,7 @@ import 'fake_matrix_api.dart';
|
||||||
void main() {
|
void main() {
|
||||||
/// All Tests related to the Event
|
/// All Tests related to the Event
|
||||||
group('User', () {
|
group('User', () {
|
||||||
var client = Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
var client = Client('testclient', httpClient: FakeMatrixApi());
|
||||||
final user1 = User(
|
final user1 = User(
|
||||||
'@alice:example.com',
|
'@alice:example.com',
|
||||||
membership: 'join',
|
membership: 'join',
|
||||||
|
|
|
@ -18,14 +18,14 @@ const String testMessage6 = 'Hello mars';
|
||||||
|
|
||||||
void test() async {
|
void test() async {
|
||||||
print('++++ Login $testUserA ++++');
|
print('++++ Login $testUserA ++++');
|
||||||
var testClientA = Client('TestClientA', debug: false);
|
var testClientA = Client('TestClientA');
|
||||||
testClientA.database = getDatabase();
|
testClientA.database = getDatabase();
|
||||||
await testClientA.checkServer(homeserver);
|
await testClientA.checkServer(homeserver);
|
||||||
await testClientA.login(testUserA, testPasswordA);
|
await testClientA.login(testUserA, testPasswordA);
|
||||||
assert(testClientA.encryptionEnabled);
|
assert(testClientA.encryptionEnabled);
|
||||||
|
|
||||||
print('++++ Login $testUserB ++++');
|
print('++++ Login $testUserB ++++');
|
||||||
var testClientB = Client('TestClientB', debug: false);
|
var testClientB = Client('TestClientB');
|
||||||
testClientB.database = getDatabase();
|
testClientB.database = getDatabase();
|
||||||
await testClientB.checkServer(homeserver);
|
await testClientB.checkServer(homeserver);
|
||||||
await testClientB.login(testUserB, testPasswordA);
|
await testClientB.login(testUserB, testPasswordA);
|
||||||
|
@ -212,8 +212,7 @@ void test() async {
|
||||||
"++++ ($testUserA) Received decrypted message: '${room.lastMessage}' ++++");
|
"++++ ($testUserA) Received decrypted message: '${room.lastMessage}' ++++");
|
||||||
|
|
||||||
print('++++ Login $testUserB in another client ++++');
|
print('++++ Login $testUserB in another client ++++');
|
||||||
var testClientC =
|
var testClientC = Client('TestClientC', database: getDatabase());
|
||||||
Client('TestClientC', debug: false, database: getDatabase());
|
|
||||||
await testClientC.checkServer(homeserver);
|
await testClientC.checkServer(homeserver);
|
||||||
await testClientC.login(testUserB, testPasswordA);
|
await testClientC.login(testUserB, testPasswordA);
|
||||||
await Future.delayed(Duration(seconds: 3));
|
await Future.delayed(Duration(seconds: 3));
|
||||||
|
|
Loading…
Reference in a new issue