mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 11:18:41 +00:00
improve logging
This commit is contained in:
parent
5371114e21
commit
f57c2fec79
11 changed files with 63 additions and 52 deletions
|
|
@ -119,11 +119,10 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
||||||
..where(
|
..where(
|
||||||
(m) =>
|
(m) =>
|
||||||
m.groupId.equals(group.groupId) &
|
m.groupId.equals(group.groupId) &
|
||||||
// m.messageId.equals(lastMessage.messageId).not() &
|
|
||||||
(m.mediaStored.equals(true) &
|
(m.mediaStored.equals(true) &
|
||||||
m.isDeletedFromSender.equals(true) |
|
m.isDeletedFromSender.equals(true) |
|
||||||
m.mediaStored.equals(false)) &
|
m.mediaStored.equals(false)) &
|
||||||
(m.openedByAll.isSmallerThanValue(deletionTime) |
|
(m.openedAt.isSmallerThanValue(deletionTime) |
|
||||||
(m.isDeletedFromSender.equals(true) &
|
(m.isDeletedFromSender.equals(true) &
|
||||||
m.createdAt.isSmallerThanValue(deletionTime))),
|
m.createdAt.isSmallerThanValue(deletionTime))),
|
||||||
))
|
))
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class ConnectPreKeyStore extends PreKeyStore {
|
||||||
.get();
|
.get();
|
||||||
if (preKeyRecord.isEmpty) {
|
if (preKeyRecord.isEmpty) {
|
||||||
throw InvalidKeyIdException(
|
throw InvalidKeyIdException(
|
||||||
'[PREKEY] No such preKey record! - $preKeyId',
|
'[PREKEY] No such preKey record!',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final preKey = preKeyRecord.first.preKey;
|
final preKey = preKeyRecord.first.preKey;
|
||||||
|
|
|
||||||
|
|
@ -78,12 +78,7 @@ class ApiService {
|
||||||
await _channel!.ready;
|
await _channel!.ready;
|
||||||
Log.info('websocket connected to $apiUrl');
|
Log.info('websocket connected to $apiUrl');
|
||||||
return true;
|
return true;
|
||||||
} on WebSocketChannelException catch (e) {
|
} catch (_) {
|
||||||
if (!e.message
|
|
||||||
.toString()
|
|
||||||
.contains('No address associated with hostname')) {
|
|
||||||
Log.error('could not connect to api got: $e');
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -311,17 +306,17 @@ class ApiService {
|
||||||
|
|
||||||
final res = asResult(await _waitForResponse(seq));
|
final res = asResult(await _waitForResponse(seq));
|
||||||
if (res.isError) {
|
if (res.isError) {
|
||||||
Log.error('got error from server: ${res.error}');
|
Log.warn('Got error from server: ${res.error}');
|
||||||
if (res.error == ErrorCode.AppVersionOutdated) {
|
if (res.error == ErrorCode.AppVersionOutdated) {
|
||||||
globalCallbackAppIsOutdated();
|
globalCallbackAppIsOutdated();
|
||||||
Log.error('App Version is OUTDATED.');
|
Log.warn('App Version is OUTDATED.');
|
||||||
appIsOutdated = true;
|
appIsOutdated = true;
|
||||||
await close(() {});
|
await close(() {});
|
||||||
return Result.error(ErrorCode.InternalError);
|
return Result.error(ErrorCode.InternalError);
|
||||||
}
|
}
|
||||||
if (res.error == ErrorCode.NewDeviceRegistered) {
|
if (res.error == ErrorCode.NewDeviceRegistered) {
|
||||||
globalCallbackNewDeviceRegistered();
|
globalCallbackNewDeviceRegistered();
|
||||||
Log.error(
|
Log.warn(
|
||||||
'Device is disabled, as a newer device restore twonly Backup.',
|
'Device is disabled, as a newer device restore twonly Backup.',
|
||||||
);
|
);
|
||||||
appIsOutdated = true;
|
appIsOutdated = true;
|
||||||
|
|
@ -336,13 +331,13 @@ class ApiService {
|
||||||
// this will send the request one more time.
|
// this will send the request one more time.
|
||||||
return sendRequestSync(request, authenticated: false);
|
return sendRequestSync(request, authenticated: false);
|
||||||
} else {
|
} else {
|
||||||
Log.error('session is not authenticated');
|
Log.warn('Session is not authenticated');
|
||||||
return Result.error(ErrorCode.InternalError);
|
return Result.error(ErrorCode.InternalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (res.error == ErrorCode.UserIdNotFound && contactId != null) {
|
if (res.error == ErrorCode.UserIdNotFound && contactId != null) {
|
||||||
Log.error('Contact deleted their account $contactId.');
|
Log.warn('Contact deleted their account $contactId.');
|
||||||
final contact = await twonlyDB.contactsDao
|
final contact = await twonlyDB.contactsDao
|
||||||
.getContactByUserId(contactId)
|
.getContactByUserId(contactId)
|
||||||
.getSingleOrNull();
|
.getSingleOrNull();
|
||||||
|
|
|
||||||
|
|
@ -13,33 +13,45 @@ Future<void> handleMessageUpdate(
|
||||||
Log.info(
|
Log.info(
|
||||||
'Opened message $targetMessageId',
|
'Opened message $targetMessageId',
|
||||||
);
|
);
|
||||||
|
try {
|
||||||
await twonlyDB.messagesDao.handleMessageOpened(
|
await twonlyDB.messagesDao.handleMessageOpened(
|
||||||
contactId,
|
contactId,
|
||||||
targetMessageId,
|
targetMessageId,
|
||||||
fromTimestamp(messageUpdate.timestamp),
|
fromTimestamp(messageUpdate.timestamp),
|
||||||
);
|
);
|
||||||
|
} catch (e) {
|
||||||
|
Log.warn(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case EncryptedContent_MessageUpdate_Type.DELETE:
|
case EncryptedContent_MessageUpdate_Type.DELETE:
|
||||||
if (!await isSender(contactId, messageUpdate.senderMessageId)) {
|
if (!await isSender(contactId, messageUpdate.senderMessageId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.info('Delete message ${messageUpdate.senderMessageId}');
|
Log.info('Delete message ${messageUpdate.senderMessageId}');
|
||||||
|
try {
|
||||||
await twonlyDB.messagesDao.handleMessageDeletion(
|
await twonlyDB.messagesDao.handleMessageDeletion(
|
||||||
contactId,
|
contactId,
|
||||||
messageUpdate.senderMessageId,
|
messageUpdate.senderMessageId,
|
||||||
fromTimestamp(messageUpdate.timestamp),
|
fromTimestamp(messageUpdate.timestamp),
|
||||||
);
|
);
|
||||||
|
} catch (e) {
|
||||||
|
Log.warn(e);
|
||||||
|
}
|
||||||
case EncryptedContent_MessageUpdate_Type.EDIT_TEXT:
|
case EncryptedContent_MessageUpdate_Type.EDIT_TEXT:
|
||||||
if (!await isSender(contactId, messageUpdate.senderMessageId)) {
|
if (!await isSender(contactId, messageUpdate.senderMessageId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.info('Edit message ${messageUpdate.senderMessageId}');
|
Log.info('Edit message ${messageUpdate.senderMessageId}');
|
||||||
|
try {
|
||||||
await twonlyDB.messagesDao.handleTextEdit(
|
await twonlyDB.messagesDao.handleTextEdit(
|
||||||
contactId,
|
contactId,
|
||||||
messageUpdate.senderMessageId,
|
messageUpdate.senderMessageId,
|
||||||
messageUpdate.text,
|
messageUpdate.text,
|
||||||
fromTimestamp(messageUpdate.timestamp),
|
fromTimestamp(messageUpdate.timestamp),
|
||||||
);
|
);
|
||||||
|
} catch (e) {
|
||||||
|
Log.warn(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ Future<void> finishStartedPreprocessing() async {
|
||||||
}
|
}
|
||||||
await startBackgroundMediaUpload(service);
|
await startBackgroundMediaUpload(service);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Log.error(e);
|
Log.warn(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ Future<(Uint8List, Uint8List?)?> tryToSendCompleteMessage({
|
||||||
);
|
);
|
||||||
|
|
||||||
if (resp.isError) {
|
if (resp.isError) {
|
||||||
Log.error('Could not transmit message $receiptId got ${resp.error}.');
|
Log.warn('Could not transmit message got ${resp.error}.');
|
||||||
if (resp.error == ErrorCode.UserIdNotFound) {
|
if (resp.error == ErrorCode.UserIdNotFound) {
|
||||||
await twonlyDB.receiptsDao.deleteReceipt(receiptId);
|
await twonlyDB.receiptsDao.deleteReceipt(receiptId);
|
||||||
await twonlyDB.contactsDao.updateContact(
|
await twonlyDB.contactsDao.updateContact(
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
import 'package:hashlib/random.dart';
|
import 'package:hashlib/random.dart';
|
||||||
import 'package:mutex/mutex.dart';
|
import 'package:mutex/mutex.dart';
|
||||||
|
|
@ -63,7 +62,7 @@ Future<void> handleClient2ClientMessage(int fromUserId, Uint8List body) async {
|
||||||
|
|
||||||
await protectReceiptCheck.protect(() async {
|
await protectReceiptCheck.protect(() async {
|
||||||
if (await twonlyDB.receiptsDao.isDuplicated(receiptId)) {
|
if (await twonlyDB.receiptsDao.isDuplicated(receiptId)) {
|
||||||
Log.error('Got duplicated message from the server. Ignoring it.');
|
Log.warn('Got duplicated message from the server.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await twonlyDB.receiptsDao.gotReceipt(receiptId);
|
await twonlyDB.receiptsDao.gotReceipt(receiptId);
|
||||||
|
|
@ -135,11 +134,12 @@ Future<void> handleClient2ClientMessage(int fromUserId, Uint8List body) async {
|
||||||
..receiptId = receiptId
|
..receiptId = receiptId
|
||||||
..type = Message_Type.PLAINTEXT_CONTENT
|
..type = Message_Type.PLAINTEXT_CONTENT
|
||||||
..plaintextContent = responsePlaintextContent;
|
..plaintextContent = responsePlaintextContent;
|
||||||
Log.error('Sending decryption error ($receiptId)');
|
Log.error('Sending decryption error');
|
||||||
} else {
|
} else {
|
||||||
response = Message()..type = Message_Type.SENDER_DELIVERY_RECEIPT;
|
response = Message()..type = Message_Type.SENDER_DELIVERY_RECEIPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await twonlyDB.receiptsDao.insertReceipt(
|
await twonlyDB.receiptsDao.insertReceipt(
|
||||||
ReceiptsCompanion(
|
ReceiptsCompanion(
|
||||||
receiptId: Value(receiptId),
|
receiptId: Value(receiptId),
|
||||||
|
|
@ -148,6 +148,9 @@ Future<void> handleClient2ClientMessage(int fromUserId, Uint8List body) async {
|
||||||
contactWillSendsReceipt: const Value(false),
|
contactWillSendsReceipt: const Value(false),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
} catch (e) {
|
||||||
|
Log.warn(e);
|
||||||
|
}
|
||||||
await tryToSendCompleteMessage(receiptId: receiptId);
|
await tryToSendCompleteMessage(receiptId: receiptId);
|
||||||
}
|
}
|
||||||
case Message_Type.TEST_NOTIFICATION:
|
case Message_Type.TEST_NOTIFICATION:
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ Future<void> compressImage(
|
||||||
|
|
||||||
if (compressedBytes == null) {
|
if (compressedBytes == null) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
'Could not compress media file: $sourceFile. Sending original file.',
|
'Could not compress media file: Sending original file.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ Future<void> compressImage(
|
||||||
|
|
||||||
await destinationFile.writeAsBytes(compressedBytes);
|
await destinationFile.writeAsBytes(compressedBytes);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Log.error('$e');
|
Log.warn('$e');
|
||||||
sourceFile.copySync(destinationFile.path);
|
sourceFile.copySync(destinationFile.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -325,7 +325,7 @@ Future<Uint8List?> encryptPushNotification(
|
||||||
content.kind != PushKind.testNotification) {
|
content.kind != PushKind.testNotification) {
|
||||||
// this will be enforced after every app uses this system... :/
|
// this will be enforced after every app uses this system... :/
|
||||||
// return null;
|
// return null;
|
||||||
Log.error('Using insecure key as the receiver does not send a push key!');
|
Log.warn('Using insecure key as the receiver does not send a push key!');
|
||||||
|
|
||||||
await sendCipherText(
|
await sendCipherText(
|
||||||
toUserId,
|
toUserId,
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ Future<void> removeTwonlySafeFromServer() async {
|
||||||
);
|
);
|
||||||
Log.info('Download deleted with: ${response.statusCode}');
|
Log.info('Download deleted with: ${response.statusCode}');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Log.error('Could not connect to the server.');
|
Log.error('Could not connect upload the backup.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,13 @@ class _LastMessageTimeState extends State<LastMessageTime> {
|
||||||
lastMessageInSeconds =
|
lastMessageInSeconds =
|
||||||
DateTime.now().difference(widget.dateTime!).inSeconds;
|
DateTime.now().difference(widget.dateTime!).inSeconds;
|
||||||
}
|
}
|
||||||
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (lastMessageInSeconds < 0) {
|
if (lastMessageInSeconds < 0) {
|
||||||
lastMessageInSeconds = 0;
|
lastMessageInSeconds = 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue