Deprecate debug mode

This commit is contained in:
Christian Pauly 2020-08-06 08:55:35 +02:00
parent 2796ca613a
commit 6779ab6624
12 changed files with 33 additions and 63 deletions

View File

@ -88,9 +88,6 @@ class MatrixApi {
/// timeout which is usually 30 seconds.
int syncTimeoutSec;
/// Whether debug prints should be displayed.
final bool debug;
http.Client httpClient = http.Client();
bool get _testMode =>
@ -101,7 +98,6 @@ class MatrixApi {
MatrixApi({
this.homeserver,
this.accessToken,
this.debug = false,
http.Client httpClient,
this.syncTimeoutSec = 30,
}) {
@ -161,11 +157,6 @@ class MatrixApi {
headers['Authorization'] = 'Bearer ${accessToken}';
}
if (debug) {
print(
'[REQUEST ${describeEnum(type)}] $action, Data: ${jsonEncode(data)}');
}
http.Response resp;
var jsonResp = <String, dynamic>{};
try {
@ -212,8 +203,6 @@ class MatrixApi {
throw exception;
}
if (debug) print('[RESPONSE] ${jsonResp.toString()}');
_timeoutFactor = 1;
} on TimeoutException catch (_) {
_timeoutFactor *= 2;
@ -1300,7 +1289,6 @@ class MatrixApi {
streamedRequest.contentLength = await file.length;
streamedRequest.sink.add(file);
streamedRequest.sink.close();
if (debug) print('[UPLOADING] $fileName');
var streamedResponse = _testMode ? null : await streamedRequest.send();
Map<String, dynamic> jsonResponse = json.decode(
String.fromCharCodes(_testMode

View File

@ -81,14 +81,16 @@ class Client {
/// - m.room.canonical_alias
/// - m.room.tombstone
/// - *some* m.room.member events, where needed
Client(this.clientName,
{this.debug = false,
this.database,
this.enableE2eeRecovery = false,
this.verificationMethods,
http.Client httpClient,
this.importantStateEvents,
this.pinUnreadRooms = false}) {
Client(
this.clientName, {
this.database,
this.enableE2eeRecovery = false,
this.verificationMethods,
http.Client httpClient,
this.importantStateEvents,
this.pinUnreadRooms = false,
@deprecated bool debug,
}) {
verificationMethods ??= <KeyVerificationMethod>{};
importantStateEvents ??= <String>{};
importantStateEvents.addAll([
@ -100,17 +102,9 @@ class Client {
EventTypes.RoomCanonicalAlias,
EventTypes.RoomTombstone,
]);
api = MatrixApi(debug: debug, httpClient: httpClient);
onLoginStateChanged.stream.listen((loginState) {
if (debug) {
print('[LoginState]: ${loginState.toString()}');
}
});
api = MatrixApi(httpClient: httpClient);
}
/// Whether debug prints should be displayed.
final bool debug;
/// The required name for this client.
final String clientName;
@ -634,8 +628,8 @@ class Client {
return;
}
encryption = Encryption(
debug: debug, client: this, enableE2eeRecovery: enableE2eeRecovery);
encryption =
Encryption(client: this, enableE2eeRecovery: enableE2eeRecovery);
await encryption.init(olmAccount);
if (database != null) {

View File

@ -263,10 +263,8 @@ class Timeline {
}
sortAndUpdate();
} catch (e, s) {
if (room.client.debug) {
print('[WARNING] (_handleEventUpdate) ${e.toString()}');
print(s);
}
print('[WARNING] (_handleEventUpdate) ${e.toString()}');
print(s);
}
}

View File

@ -48,7 +48,7 @@ void main() {
group('FluffyMatrix', () {
/// Check if all Elements get created
matrix = Client('testclient', debug: true, httpClient: FakeMatrixApi());
matrix = Client('testclient', httpClient: FakeMatrixApi());
roomUpdateListFuture = matrix.onRoomUpdate.stream.toList();
eventUpdateListFuture = matrix.onEvent.stream.toList();
@ -322,7 +322,7 @@ void main() {
});
test('Login', () async {
matrix = Client('testclient', debug: true, httpClient: FakeMatrixApi());
matrix = Client('testclient', httpClient: FakeMatrixApi());
roomUpdateListFuture = matrix.onRoomUpdate.stream.toList();
eventUpdateListFuture = matrix.onEvent.stream.toList();
@ -395,8 +395,7 @@ void main() {
});
});
test('Test the fake store api', () async {
var client1 =
Client('testclient', debug: true, httpClient: FakeMatrixApi());
var client1 = Client('testclient', httpClient: FakeMatrixApi());
client1.database = getDatabase();
client1.connect(
@ -413,8 +412,7 @@ void main() {
expect(client1.isLogged(), true);
expect(client1.rooms.length, 2);
var client2 =
Client('testclient', debug: true, httpClient: FakeMatrixApi());
var client2 = Client('testclient', httpClient: FakeMatrixApi());
client2.database = client1.database;
client2.connect();

View File

@ -42,8 +42,7 @@ void main() {
if (!olmEnabled) return;
Client client;
var otherClient =
Client('othertestclient', debug: true, httpClient: FakeMatrixApi());
var otherClient = Client('othertestclient', httpClient: FakeMatrixApi());
DeviceKeys device;
Map<String, dynamic> payload;

View File

@ -82,8 +82,7 @@ void main() {
test('setupClient', () async {
client1 = await getClient();
client2 =
Client('othertestclient', debug: true, httpClient: FakeMatrixApi());
client2 = Client('othertestclient', httpClient: FakeMatrixApi());
client2.database = client1.database;
await client2.checkServer('https://fakeServer.notExisting');
client2.connect(

View File

@ -50,7 +50,7 @@ void main() {
'status': 2,
'content': contentJson,
};
var client = Client('testclient', debug: true, httpClient: FakeMatrixApi());
var client = Client('testclient', httpClient: FakeMatrixApi());
var event = Event.fromJson(
jsonObj, Room(id: '!localpart:server.abc', client: client));
@ -211,8 +211,7 @@ void main() {
];
for (final testType in testTypes) {
redactJsonObj['type'] = testType;
final room =
Room(id: '1234', client: Client('testclient', debug: true));
final room = Room(id: '1234', client: Client('testclient'));
final redactionEventJson = {
'content': {'reason': 'Spamming'},
'event_id': '143273582443PhrSn:example.org',
@ -236,7 +235,7 @@ void main() {
test('remove', () async {
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();
event.status = 0;
final removed2 = await event.remove();
@ -245,8 +244,7 @@ void main() {
});
test('sendAgain', () async {
var matrix =
Client('testclient', debug: true, httpClient: FakeMatrixApi());
var matrix = Client('testclient', httpClient: FakeMatrixApi());
await matrix.checkServer('https://fakeServer.notExisting');
await matrix.login('test', '1234');
@ -262,8 +260,7 @@ void main() {
});
test('requestKey', () async {
var matrix =
Client('testclient', debug: true, httpClient: FakeMatrixApi());
var matrix = Client('testclient', httpClient: FakeMatrixApi());
await matrix.checkServer('https://fakeServer.notExisting');
await matrix.login('test', '1234');
@ -310,8 +307,7 @@ void main() {
expect(event.canRedact, true);
});
test('getLocalizedBody', () async {
final matrix =
Client('testclient', debug: true, httpClient: FakeMatrixApi());
final matrix = Client('testclient', httpClient: FakeMatrixApi());
final room = Room(id: '!1234:example.com', client: matrix);
var event = Event.fromJson({
'content': {

View File

@ -29,7 +29,7 @@ const pickledOlmAccount =
'N2v1MkIFGcl0mQpo2OCwSopxPQJ0wnl7oe7PKiT4141AijfdTIhRu+ceXzXKy3Kr00nLqXtRv7kid6hU4a+V0rfJWLL0Y51+3Rp/ORDVnQy+SSeo6Fn4FHcXrxifJEJ0djla5u98fBcJ8BSkhIDmtXRPi5/oJAvpiYn+8zMjFHobOeZUAxYR0VfQ9JzSYBsSovoQ7uFkNks1M4EDUvHtuyg3RxViwdNxs3718fyAqQ/VSwbXsY0Nl+qQbF+nlVGHenGqk5SuNl1P6e1PzZxcR0IfXA94Xij1Ob5gDv5YH4UCn9wRMG0abZsQP0YzpDM0FLaHSCyo9i5JD/vMlhH+nZWrgAzPPCTNGYewNV8/h3c+VyJh8ZTx/fVi6Yq46Fv+27Ga2ETRZ3Qn+Oyx6dLBjnBZ9iUvIhqpe2XqaGA1PopOz8iDnaZitw';
Future<Client> getClient() async {
final client = Client('testclient', debug: true, httpClient: FakeMatrixApi());
final client = Client('testclient', httpClient: FakeMatrixApi());
client.database = getDatabase();
await client.checkServer('https://fakeServer.notExisting');
final resp = await client.api.login(

View File

@ -33,7 +33,6 @@ void main() {
group('Matrix API', () {
final matrixApi = MatrixApi(
httpClient: FakeMatrixApi(),
debug: true,
);
test('MatrixException test', () async {
final exception = MatrixException.fromJson({

View File

@ -33,7 +33,7 @@ void main() {
var updateCount = 0;
var insertList = <int>[];
var client = Client('testclient', debug: true, httpClient: FakeMatrixApi());
var client = Client('testclient', httpClient: FakeMatrixApi());
var room = Room(
id: roomID, client: client, prev_batch: '1234', roomAccountData: {});

View File

@ -27,7 +27,7 @@ import 'fake_matrix_api.dart';
void main() {
/// All Tests related to the Event
group('User', () {
var client = Client('testclient', debug: true, httpClient: FakeMatrixApi());
var client = Client('testclient', httpClient: FakeMatrixApi());
final user1 = User(
'@alice:example.com',
membership: 'join',

View File

@ -18,14 +18,14 @@ const String testMessage6 = 'Hello mars';
void test() async {
print('++++ Login $testUserA ++++');
var testClientA = Client('TestClientA', debug: false);
var testClientA = Client('TestClientA');
testClientA.database = getDatabase();
await testClientA.checkServer(homeserver);
await testClientA.login(testUserA, testPasswordA);
assert(testClientA.encryptionEnabled);
print('++++ Login $testUserB ++++');
var testClientB = Client('TestClientB', debug: false);
var testClientB = Client('TestClientB');
testClientB.database = getDatabase();
await testClientB.checkServer(homeserver);
await testClientB.login(testUserB, testPasswordA);
@ -212,8 +212,7 @@ void test() async {
"++++ ($testUserA) Received decrypted message: '${room.lastMessage}' ++++");
print('++++ Login $testUserB in another client ++++');
var testClientC =
Client('TestClientC', debug: false, database: getDatabase());
var testClientC = Client('TestClientC', database: getDatabase());
await testClientC.checkServer(homeserver);
await testClientC.login(testUserB, testPasswordA);
await Future.delayed(Duration(seconds: 3));